diff options
Diffstat (limited to 'screen.c')
-rw-r--r-- | screen.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/screen.c b/screen.c index 4ef86d5..59b6eff 100644 --- a/screen.c +++ b/screen.c @@ -33,14 +33,13 @@ #include "calmwm.h" static struct geom screen_apply_gap(struct screen_ctx *, struct geom); +static void screen_scan(struct screen_ctx *); void screen_init(int which) { struct screen_ctx *sc; - Window *wins, w0, w1, active = None; - XSetWindowAttributes rootattr; - unsigned int nwins, w; + XSetWindowAttributes attr; sc = xmalloc(sizeof(*sc)); @@ -67,33 +66,46 @@ screen_init(int which) xu_ewmh_net_number_of_desktops(sc); xu_ewmh_net_showing_desktop(sc); xu_ewmh_net_virtual_roots(sc); - active = xu_ewmh_get_net_active_window(sc); - rootattr.cursor = Conf.cursor[CF_NORMAL]; - rootattr.event_mask = SubstructureRedirectMask | - SubstructureNotifyMask | PropertyChangeMask | EnterWindowMask | - LeaveWindowMask | ColormapChangeMask | BUTTONMASK; - - XChangeWindowAttributes(X_Dpy, sc->rootwin, - (CWEventMask | CWCursor), &rootattr); - - /* Deal with existing clients. */ - if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { - for (w = 0; w < nwins; w++) - (void)client_init(wins[w], sc, (active == wins[w])); - - XFree(wins); - } - screen_updatestackingorder(sc); + attr.cursor = Conf.cursor[CF_NORMAL]; + attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | + EnterWindowMask | PropertyChangeMask | ButtonPressMask; + XChangeWindowAttributes(X_Dpy, sc->rootwin, (CWEventMask | CWCursor), &attr); if (Conf.xrandr) XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); + screen_scan(sc); + screen_updatestackingorder(sc); + TAILQ_INSERT_TAIL(&Screenq, sc, entry); XSync(X_Dpy, False); } +static void +screen_scan(struct screen_ctx *sc) +{ + struct client_ctx *cc, *active = NULL; + Window *wins, w0, w1, rwin, cwin; + unsigned int nwins, i, mask; + int rx, ry, wx, wy; + + XQueryPointer(X_Dpy, sc->rootwin, &rwin, &cwin, + &rx, &ry, &wx, &wy, &mask); + + if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { + for (i = 0; i < nwins; i++) { + if ((cc = client_init(wins[i], sc)) != NULL) + if (cc->win == cwin) + active = cc; + } + XFree(wins); + } + if (active) + client_set_active(active); +} + struct screen_ctx * screen_find(Window win) { @@ -101,10 +113,10 @@ screen_find(Window win) TAILQ_FOREACH(sc, &Screenq, entry) { if (sc->rootwin == win) - return(sc); + return sc; } warnx("%s: failure win 0x%lx", __func__, win); - return(NULL); + return NULL; } void @@ -138,11 +150,11 @@ region_find(struct screen_ctx *sc, int x, int y) break; } } - return(rc); + return rc; } struct geom -screen_area(struct screen_ctx *sc, int x, int y, enum apply_gap apply_gap) +screen_area(struct screen_ctx *sc, int x, int y, int apply_gap) { struct region_ctx *rc; struct geom area = sc->view; @@ -156,7 +168,7 @@ screen_area(struct screen_ctx *sc, int x, int y, enum apply_gap apply_gap) } if (apply_gap) area = screen_apply_gap(sc, area); - return(area); + return area; } void @@ -226,7 +238,7 @@ screen_apply_gap(struct screen_ctx *sc, struct geom geom) geom.w -= (sc->gap.left + sc->gap.right); geom.h -= (sc->gap.top + sc->gap.bottom); - return(geom); + return geom; } /* Bring back clients which are beyond the screen. */ |