fix(wm): handle WM_CHANGE_STATE and WM_STATE for Wine/DXVK focus recovery

- Track iconic state on hidden clients and reply to WM_CHANGE_STATE(IconicState)
  with IconicState while hidden on an inactive tag (or NormalState if visible),
  restoring NormalState in showhide() before WM_TAKE_FOCUS on workspace return.
- Re-assert _NET_WM_STATE PropertyNotify on no-op client messages and always
  emit ICCCM ConfigureNotify replies for hidden/fullscreen ConfigureRequests.
- Keep hidden fullscreen clients offscreen during root ConfigureNotify and run
  arrange()/restack() before focus().
- Add test_wine_dxvk_iconic_workspace_switch() in tests/test_x11_xvfb.py.
This commit is contained in:
Luxferre committed 2026-11-26 20:18:48 +02:00
1 parent 8da5c5d1cb
commit 08fd92f184
2 files changed
+387 -10

No files matched your search

+59 -10
View File
@@ -64,7 +64,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMWindowType, NetWMWindowTypeDialog, NetWMWindowTypeDock,
NetWMStrutPartial, NetWMStrut, NetClientList, NetWMPid, NetLast };
enum { Manager, Xembed, XembedInfo, XLast };
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast };
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMChangeState, WMLast };
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkLauncher,
ClkCloseBtn, ClkClientWin, ClkRootWin, ClkLast };
@@ -93,7 +93,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isiconic;
Client *next;
Client *snext;
Monitor *mon;
@@ -218,6 +218,7 @@ static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
static void reloadxres(const Arg *arg);
static unsigned long readatomlist(Client *c, Atom prop, Atom *out, unsigned long max_atoms);
static void refreshwmstate(Client *c);
static void removesystrayicon(Client *i);
static void removewmstate(Client *c, Atom state);
static void resize(Client *c, int x, int y, int w, int h, int interact);
@@ -751,13 +752,33 @@ static void clientmessage(XEvent *e) {
if (!c) return;
if (cme->message_type == netatom[NetWMState]) {
int was_fs = c->isfullscreen;
if ((Atom)cme->data.l[1] == netatom[NetWMFullscreen] ||
(Atom)cme->data.l[2] == netatom[NetWMFullscreen]) {
setfullscreen(c, (cme->data.l[0] == 1 ||
(cme->data.l[0] == 2 && !c->isfullscreen)));
}
if (c->isfullscreen == was_fs)
refreshwmstate(c);
} else if (cme->message_type == wmatom[WMChangeState]) {
if (cme->data.l[0] == IconicState) {
if (!ISVISIBLE(c)) {
c->isiconic = 1;
setclientstate(c, IconicState);
} else {
c->isiconic = 0;
setclientstate(c, NormalState);
}
} else if (cme->data.l[0] == NormalState && c->isiconic) {
c->isiconic = 0;
setclientstate(c, NormalState);
}
} else if (cme->message_type == netatom[NetActiveWindow]) {
if (ISVISIBLE(c) && c->mon == selmon) {
if (c->isiconic) {
c->isiconic = 0;
setclientstate(c, NormalState);
}
if (c != selmon->sel)
focus(c);
else
@@ -799,14 +820,26 @@ static void configurenotify(XEvent *e) {
drw_resize(drw, (unsigned int)sw, (unsigned int)bh);
updatebars();
for (m = mons; m; m = m->next) {
for (c = m->clients; c; c = c->next)
if (c->isfullscreen) resizeclient(c, m->mx, m->my, m->mw, m->mh);
for (c = m->clients; c; c = c->next) {
if (c->isfullscreen) {
if (ISVISIBLE(c)) {
resizeclient(c, m->mx, m->my, m->mw, m->mh);
} else {
c->oldx = c->x; c->oldy = c->y;
c->oldw = c->w; c->oldh = c->h;
c->x = m->mx; c->y = m->my;
c->w = m->mw; c->h = m->mh;
}
}
}
resizebarwin(m);
}
updatesystray(1);
updateworkarea();
focus(NULL);
arrange(NULL);
for (m = mons; m; m = m->next)
restack(m);
focus(NULL);
}
}
}
@@ -819,11 +852,12 @@ static void configurerequest(XEvent *e) {
if ((c = wintoclient(ev->window))) {
if (c->isfullscreen) {
if (ISVISIBLE(c))
configure(c);
configure(c);
} else if (ev->value_mask & CWBorderWidth) {
c->bw = ev->border_width;
configure(c);
} else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
int ox = c->x, oy = c->y, ow = c->w, oh = c->h;
m = c->mon;
if (ev->value_mask & CWX) { c->oldx = c->x; c->x = m->mx + ev->x; }
if (ev->value_mask & CWY) { c->oldy = c->y; c->y = m->my + ev->y; }
@@ -833,10 +867,13 @@ static void configurerequest(XEvent *e) {
c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2);
if ((c->y + c->h) > m->my + m->mh && c->isfloating)
c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2);
if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
configure(c);
if (ISVISIBLE(c))
if (ISVISIBLE(c) && (c->x != ox || c->y != oy || c->w != ow || c->h != oh)) {
XMoveResizeWindow(dpy, c->win, c->x, c->y, (unsigned int)c->w, (unsigned int)c->h);
if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
configure(c);
} else {
configure(c);
}
} else {
configure(c);
}
@@ -1204,6 +1241,13 @@ static void removewmstate(Client *c, Atom state) {
XDeleteProperty(dpy, c->win, netatom[NetWMState]);
}
static void refreshwmstate(Client *c) {
Atom atoms[64];
unsigned long n = readatomlist(c, netatom[NetWMState], atoms, LENGTH(atoms));
XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char *)atoms, (int)n);
}
static int getrootptr(int *x, int *y) {
int di;
unsigned int dui;
@@ -2236,6 +2280,7 @@ static void setup(void) {
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
wmatom[WMChangeState] = XInternAtom(dpy, "WM_CHANGE_STATE", False);
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
@@ -2333,6 +2378,10 @@ static void showhide(Client *c) {
if (!c->mon->lt[c->mon->sellt]->arrange || c->isfloating)
resize(c, c->x, c->y, c->w, c->h, 0);
}
if (c->isiconic) {
c->isiconic = 0;
setclientstate(c, NormalState);
}
showhide(c->snext);
} else {
showhide(c->snext);