On Sat, Jan 07, 2012 at 10:20:27PM +0200, Ivan Kanakarakis wrote:
> dwm, when it receives a _NET_ACTIVE_WINDOW message, it transfers focus to
> the client that asked for it, but never sets the root window id to that
> window's id. That is ofcourse a choice - the standard doesn't force one to
> do that, but that makes tools like xdotool and xprop fail on some options
> that people may find usefull. Specifically the following commands:
> 
>     $ xprop -root _NET_ACTIVE_WINDOW
>     $ xdotool getactivewindow
> 
> To get those working properly, one would need to,
> 
>     XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32,
>                     PropModeReplace, (unsigned char *)&c->win, 1);
> 
> everytime a new window is focused. I guess that would go into
> setfocus(Client *c) function or something similar.

I use the attached patch for this. In addition it also maintains a
NetClientList, which exposes the list of managed windows in the ewmh
recommended way.  

Andreas
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -60,7 +60,7 @@
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
 enum { NetSupported, NetWMName, NetWMState,
        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
-       NetWMWindowTypeDialog, NetLast };     /* EWMH atoms */
+       NetWMWindowTypeDialog, NetClientList, NetLast };     /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms 
*/
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
@@ -238,6 +238,7 @@
 static Bool updategeom(void);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
+static void updateclientlist(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -499,6 +500,7 @@
                cleanupmon(mons);
        XSync(dpy, False);
        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+       XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
 }
 
 void
@@ -858,8 +860,10 @@
                XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
                setfocus(c);
        }
-       else
+       else {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+               XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+       }
        selmon->sel = c;
        drawbars();
 }
@@ -1157,6 +1161,8 @@
                XRaiseWindow(dpy, c->win);
        attach(c);
        attachstack(c);
+       XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, 
PropModeAppend,
+                       (unsigned char *) &(c->win), 1);
        XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* 
some windows require this */
        setclientstate(c, NormalState);
        if (c->mon == selmon)
@@ -1520,8 +1526,12 @@
 
 void
 setfocus(Client *c) {
-       if(!c->neverfocus)
+       if(!c->neverfocus) {
                XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+               XChangeProperty(dpy, root, netatom[NetActiveWindow],
+                               XA_WINDOW, 32, PropModeReplace,
+                               (unsigned char *) &(c->win), 1);
+       }
        sendevent(c, wmatom[WMTakeFocus]);
 }
 
@@ -1607,6 +1617,7 @@
        netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", 
False);
        netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", 
False);
        netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, 
"_NET_WM_WINDOW_TYPE_DIALOG", False);
+       netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
        /* init cursors */
        cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
        cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1629,6 +1640,7 @@
        /* EWMH support per view */
        XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
                        PropModeReplace, (unsigned char *) netatom, NetLast);
+       XDeleteProperty(dpy, root, netatom[NetClientList]);
        /* select for events */
        wa.cursor = cursor[CurNormal];
        wa.event_mask = 
SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask
@@ -1777,8 +1789,10 @@
                return;
        grabbuttons(c, False);
        XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
-       if(setfocus)
+       if(setfocus) {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+               XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+       }
 }
 
 void
@@ -1802,6 +1816,7 @@
        }
        free(c);
        focus(NULL);
+       updateclientlist();
        arrange(m);
 }
 
@@ -1848,6 +1863,19 @@
                m->by = -bh;
 }
 
+void
+updateclientlist() {
+       Client *c;
+       Monitor *m;
+
+       XDeleteProperty(dpy, root, netatom[NetClientList]);
+       for(m = mons; m; m = m->next)
+               for(c = m->clients; c; c = c->next)
+                       XChangeProperty(dpy, root, netatom[NetClientList],
+                                       XA_WINDOW, 32, PropModeAppend,
+                                       (unsigned char *) &(c->win), 1);
+}
+
 Bool
 updategeom(void) {
        bool dirty = False;

Reply via email to