From 19eacc39316879fb7008f3b71b36e52b09f3b464 Mon Sep 17 00:00:00 2001 From: okan Date: Tue, 24 Mar 2020 14:47:29 +0000 Subject: Instead of using _NET_ACTIVE_WINDOW on restart, use the pointer location to determine what client to set active. Reduces a round trip for every window. --- screen.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'screen.c') diff --git a/screen.c b/screen.c index 2e55ac3..b76cf7a 100644 --- a/screen.c +++ b/screen.c @@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: screen.c,v 1.96 2020/03/20 15:16:31 okan Exp $ + * $OpenBSD: screen.c,v 1.97 2020/03/24 14:47:29 okan Exp $ */ #include @@ -33,13 +33,12 @@ #include "calmwm.h" static struct geom screen_apply_gap(struct screen_ctx *, struct geom); -static void screen_scan(struct screen_ctx *, Window); +static void screen_scan(struct screen_ctx *); void screen_init(int which) { struct screen_ctx *sc; - Window active = None; XSetWindowAttributes attr; sc = xmalloc(sizeof(*sc)); @@ -67,7 +66,6 @@ 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); attr.cursor = Conf.cursor[CF_NORMAL]; attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | @@ -77,7 +75,7 @@ screen_init(int which) if (Conf.xrandr) XRRSelectInput(X_Dpy, sc->rootwin, RRScreenChangeNotifyMask); - screen_scan(sc, active); + screen_scan(sc); screen_updatestackingorder(sc); TAILQ_INSERT_TAIL(&Screenq, sc, entry); @@ -86,17 +84,26 @@ screen_init(int which) } static void -screen_scan(struct screen_ctx *sc, Window active) +screen_scan(struct screen_ctx *sc) { - Window *wins, w0, w1; - unsigned int nwins, i; + struct client_ctx *cc, *active = NULL; + Window *wins, w0, w1, rwin, cwin; + unsigned int nwins, i, mask; + int rx, ry, wx, wy; - if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { - for (i = 0; i < nwins; i++) - (void)client_init(wins[i], sc, (active == wins[i])); + 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 * -- cgit v1.2.3-2-gb3c3