From 6a53e3a859cd55b6f01ecb2a8a8a30af5d940345 Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 16 Sep 2016 14:32:02 +0000 Subject: During init, query screen for _NET_ACTIVE_WINDOW and set that client as active; while we already look at what's under the pointer, use this information first, then look under the pointer (saving that round-trip). This restores the active state to a client after restart even if the pointer is not above it (and of course the pointer is not above another client). --- calmwm.h | 3 ++- client.c | 10 +++++----- screen.c | 5 +++-- xevents.c | 2 +- xutil.c | 16 ++++++++++++++++ 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/calmwm.h b/calmwm.h index f21de98..c6d9ca7 100644 --- a/calmwm.h +++ b/calmwm.h @@ -398,7 +398,7 @@ void client_lower(struct client_ctx *); void client_map(struct client_ctx *); void client_msg(struct client_ctx *, Atom, Time); void client_move(struct client_ctx *); -struct client_ctx *client_init(Window, struct screen_ctx *); +struct client_ctx *client_init(Window, struct screen_ctx *, int); void client_ptrsave(struct client_ctx *); void client_ptrwarp(struct client_ctx *); void client_raise(struct client_ctx *); @@ -564,6 +564,7 @@ void xu_ewmh_net_workarea(struct screen_ctx *); void xu_ewmh_net_client_list(struct screen_ctx *); void xu_ewmh_net_client_list_stacking(struct screen_ctx *); void xu_ewmh_net_active_window(struct screen_ctx *, Window); +Window xu_ewmh_get_net_active_window(struct screen_ctx *); void xu_ewmh_net_wm_desktop_viewport(struct screen_ctx *); void xu_ewmh_net_wm_number_of_desktops(struct screen_ctx *); void xu_ewmh_net_showing_desktop(struct screen_ctx *); diff --git a/client.c b/client.c index 5c2148b..d42391b 100644 --- a/client.c +++ b/client.c @@ -43,13 +43,13 @@ static int client_inbound(struct client_ctx *, int, int); struct client_ctx *curcc = NULL; struct client_ctx * -client_init(Window win, struct screen_ctx *sc) +client_init(Window win, struct screen_ctx *sc, int active) { struct client_ctx *cc; XWindowAttributes wattr; int mapped; Window rwin, cwin; - int x, y, wx, wy, activate = 0; + int x, y, wx, wy; unsigned int mask; if (win == None) @@ -105,9 +105,9 @@ client_init(Window win, struct screen_ctx *sc) if ((cc->wmh) && (cc->wmh->flags & StateHint)) client_set_wm_state(cc, cc->wmh->initial_state); } else { - if ((XQueryPointer(X_Dpy, cc->win, &rwin, &cwin, + if ((active == 0) && (XQueryPointer(X_Dpy, cc->win, &rwin, &cwin, &x, &y, &wx, &wy, &mask)) && (cwin != None)) - activate = 1; + active = 1; } XSelectInput(X_Dpy, cc->win, ColormapChangeMask | EnterWindowMask | @@ -145,7 +145,7 @@ out: XSync(X_Dpy, False); XUngrabServer(X_Dpy); - if (activate) + if (active) client_setactive(cc); return(cc); diff --git a/screen.c b/screen.c index a1b8b30..7f2132f 100644 --- a/screen.c +++ b/screen.c @@ -35,7 +35,7 @@ void screen_init(int which) { struct screen_ctx *sc; - Window *wins, w0, w1; + Window *wins, w0, w1, active = None; XSetWindowAttributes rootattr; unsigned int nwins, i; @@ -65,6 +65,7 @@ screen_init(int which) xu_ewmh_net_wm_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 | @@ -77,7 +78,7 @@ screen_init(int which) /* Deal with existing clients. */ if (XQueryTree(X_Dpy, sc->rootwin, &w0, &w1, &wins, &nwins)) { for (i = 0; i < nwins; i++) - (void)client_init(wins[i], sc); + (void)client_init(wins[i], sc, (active == wins[i])); XFree(wins); } diff --git a/xevents.c b/xevents.c index 8763c8a..582f839 100644 --- a/xevents.c +++ b/xevents.c @@ -81,7 +81,7 @@ xev_handle_maprequest(XEvent *ee) client_ptrsave(old_cc); if ((cc = client_find(e->window)) == NULL) - cc = client_init(e->window, NULL); + cc = client_init(e->window, NULL, 0); if ((cc != NULL) && (!(cc->flags & CLIENT_IGNORE))) client_ptrwarp(cc); diff --git a/xutil.c b/xutil.c index a831794..eaaa0a4 100644 --- a/xutil.c +++ b/xutil.c @@ -256,6 +256,22 @@ xu_ewmh_net_active_window(struct screen_ctx *sc, Window w) XA_WINDOW, 32, PropModeReplace, (unsigned char *)&w, 1); } +Window +xu_ewmh_get_net_active_window(struct screen_ctx *sc) +{ + long *p; + Window win; + + if ((xu_getprop(sc->rootwin, ewmh[_NET_ACTIVE_WINDOW], + XA_WINDOW, 32, (unsigned char **)&p)) <= 0) + return(None); + + win = (Window)*p; + XFree(p); + + return(win); +} + void xu_ewmh_net_wm_desktop_viewport(struct screen_ctx *sc) { -- cgit 1.4.1