git.strcat.st

/strcat/wm.git/ - summarytreelogarchivereleases

subject
add window tracking for workspaces; fix wmc
commit
c80d9ec1206f00cf81e145754514c831d10b91db
date
2026-04-21T16:00:43Z
message
diff
 wm.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/wm.c b/wm.c
index 24156e2..1067534 100644
--- a/wm.c
+++ b/wm.c
@@ -24,6 +24,35 @@ getidx(Window w)
 	return nwin++;
 }
 
+static void
+trackwins(Display *dpy, Window root)
+{
+	Window rootret, parent, *children;
+	int i, j;
+
+	if (XQueryTree(dpy, root, &rootret, &parent, &children, (unsigned int *)&j)) {
+	    for (i = 0; i < j; i++)
+	        getidx(children[i]);
+	    if (children != None)
+	        XFree(children);
+	}
+}
+
+static int
+isrootchild(Display *dpy, Window root, Window w)
+{
+	Window rootret, parent, *children;
+	unsigned int nchildren;
+
+	if (w == None || w == PointerRoot || w == root)
+	    return 0;
+	if (!XQueryTree(dpy, w, &rootret, &parent, &children, &nchildren))
+	    return 0;
+	if (children != None)
+	    XFree(children);
+	return parent == root;
+}
+
 static void
 showws(Display *dpy, Window root)
 {
@@ -66,6 +95,8 @@ main(void)
 
 	root = DefaultRootWindow(dpy);
 	ctl = XInternAtom(dpy, "_WM_CTL", False);
+	XSelectInput(dpy, root, SubstructureNotifyMask);
+	trackwins(dpy, root);
 
 	XGrabButton(dpy, 1, MODKEY, root, True, ButtonPressMask, GrabModeAsync,
 	    GrabModeAsync, None, None);
@@ -78,10 +109,13 @@ main(void)
 	        i = (int)ev.xclient.data.l[1];
 	        if (i >= 0 && i < 9) {
 	            if (ev.xclient.data.l[0] == CMD_WS && i != curws) {
+	                trackwins(dpy, root);
 	                curws = i;
 	                showws(dpy, root);
 	            } else if (ev.xclient.data.l[0] == CMD_MOVE) {
 	                XGetInputFocus(dpy, &focus, &j);
+	                if (!isrootchild(dpy, root, focus))
+	                    continue;
 	                j = getidx(focus);
 	                if (j >= 0) {
 	                    ws[j] = i;
@@ -92,6 +126,7 @@ main(void)
 	        }
 	    } else if (ev.type == ButtonPress && ev.xbutton.subwindow != None) {
 	        dragwin = ev.xbutton.subwindow;
+	        XSetInputFocus(dpy, dragwin, RevertToPointerRoot, CurrentTime);
 	        j = getidx(dragwin);
 	        if (j >= 0)
 	            ws[j] = curws;