[dev] [dwm] Window mapping
Hello, I'd like to submit the following patch to the list of dwm
patches, but before that I thought I could gather some comments and
see if it could be improved in any way.
The basic goal is, instead of moving windows out of sight, to do
proper window (un)mapping in order for some external programs to
recognize when this happens. Namely, with this patch, we are able
to have programs like picom(1) execute window fading when switching
dwm tags.
Best regards,
Ivan
P.S. The patch follows:
diff --git a/dwm.c b/dwm.c
index 0fc328a..6defe8f 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -1616,6 +1616,46 @@ seturgent(Client *c, int urg)
XFree(wmh);
}
+void
+window_set_state(Display *dpy, Window win, long state)
+{
+ long data[] = { state, None };
+
+ XChangeProperty(dpy, win, wmatom[WMState], wmatom[WMState], 32,
+ PropModeReplace, (unsigned char*)data, 2);
+}
+
+void
+window_map(Display *dpy, Client *c, int deiconify)
+{
+ Window win = c->win;
+
+ if (deiconify)
+ window_set_state(dpy, win, NormalState);
+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+ XSetInputFocus(dpy, win, RevertToPointerRoot, CurrentTime);
+ XMapWindow(dpy, win);
+}
+
+void
+window_unmap(Display *dpy, Window win, Window root, int iconify)
+{
+ static XWindowAttributes ra, ca;
+
+ XGrabServer(dpy);
+ XGetWindowAttributes(dpy, root, &ra);
+ XGetWindowAttributes(dpy, win, &ca);
+ /* Prevent UnmapNotify events */
+ XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
+ XSelectInput(dpy, win, ca.your_event_mask & ~StructureNotifyMask);
+ XUnmapWindow(dpy, win);
+ if (iconify)
+ window_set_state(dpy, win, IconicState);
+ XSelectInput(dpy, root, ra.your_event_mask);
+ XSelectInput(dpy, win, ca.your_event_mask);
+ XUngrabServer(dpy);
+}
+
void
showhide(Client *c)
{
_AT_@ -1623,14 +1663,12 @@ showhide(Client *c)
return;
if (ISVISIBLE(c)) {
/* show clients top down */
- XMoveWindow(dpy, c->win, c->x, c->y);
- if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
- resize(c, c->x, c->y, c->w, c->h, 0);
+ window_map(dpy, c, 1);
showhide(c->snext);
} else {
/* hide clients bottom up */
showhide(c->snext);
- XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
+ window_unmap(dpy, c->win, root, 1);
}
}
Received on Mon Apr 25 2022 - 18:34:31 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 25 2022 - 19:24:08 CEST