From 08fd92f18455de662b472d97d09d825ddaddf25e Mon Sep 17 00:00:00 2001 From: Luxferre Date: Thu, 26 Nov 2026 20:18:48 +0200 Subject: [PATCH] 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. --- src/dwm/dwm.c | 69 +++++++-- tests/test_x11_xvfb.py | 328 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 387 insertions(+), 10 deletions(-) diff --git a/src/dwm/dwm.c b/src/dwm/dwm.c index a9dd926..729b817 100644 --- a/src/dwm/dwm.c +++ b/src/dwm/dwm.c @@ -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); diff --git a/tests/test_x11_xvfb.py b/tests/test_x11_xvfb.py index 77ca284..aecc493 100755 --- a/tests/test_x11_xvfb.py +++ b/tests/test_x11_xvfb.py @@ -1227,6 +1227,332 @@ def test_wine_take_focus_workspace_switch(): terminate(xvfb) +def test_wine_dxvk_iconic_workspace_switch(): + if not shutil.which("xdotool"): + print("test_x11_xvfb: xdotool not installed (skipping Wine/DXVK iconic focus test)") + return + disp = pick_display() + with tempfile.TemporaryDirectory() as home: + env = dict(os.environ) + env["DISPLAY"] = disp + env["HOME"] = home + env["XDG_CONFIG_HOME"] = os.path.join(home, ".config") + env["ANODE_PREFIX"] = ROOT + env["ANODE_NO_SIGNAL"] = "1" + env["PATH"] = ( + os.path.join(BUILD, "dwm") + ":" + + os.path.join(BUILD, "st") + ":" + + os.path.join(ROOT, "scripts") + ":" + + env.get("PATH", "") + ) + subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "1.00", "--touch=0"], env=env, check=True) + + xvfb = subprocess.Popen( + ["Xvfb", disp, "-noreset", "-screen", "0", "1280x800x24", "-nolisten", "tcp"], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + ) + dpy = None + dwm = None + wine_sim = None + tag2_client = None + try: + dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode())) + assert dpy, f"Failed to open Xvfb {disp}" + + dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env) + tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0) + assert wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom)), "DWM failed to start on Xvfb" + + sim_code = ( + "import ctypes, ctypes.util, json, time\n" + "X11 = ctypes.CDLL(ctypes.util.find_library('X11') or 'libX11.so.6')\n" + "X11.XOpenDisplay.restype = ctypes.c_void_p\n" + "X11.XDefaultRootWindow.argtypes = [ctypes.c_void_p]\n" + "X11.XDefaultRootWindow.restype = ctypes.c_ulong\n" + "X11.XDefaultScreen.argtypes = [ctypes.c_void_p]\n" + "X11.XDefaultScreen.restype = ctypes.c_int\n" + "X11.XCreateSimpleWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint, ctypes.c_uint, ctypes.c_ulong, ctypes.c_ulong]\n" + "X11.XCreateSimpleWindow.restype = ctypes.c_ulong\n" + "X11.XInternAtom.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int]\n" + "X11.XInternAtom.restype = ctypes.c_ulong\n" + "X11.XChangeProperty.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int]\n" + "X11.XGetWindowProperty.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_long, ctypes.c_long, ctypes.c_int, ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte))]\n" + "X11.XGetWindowProperty.restype = ctypes.c_int\n" + "X11.XSetWMProtocols.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong), ctypes.c_int]\n" + "class XWMHints(ctypes.Structure):\n" + " _fields_ = [('flags', ctypes.c_long), ('input', ctypes.c_int), ('initial_state', ctypes.c_int),\n" + " ('icon_pixmap', ctypes.c_ulong), ('icon_window', ctypes.c_ulong),\n" + " ('icon_x', ctypes.c_int), ('icon_y', ctypes.c_int),\n" + " ('icon_mask', ctypes.c_ulong), ('window_group', ctypes.c_ulong)]\n" + "class XFocusChangeEvent(ctypes.Structure):\n" + " _fields_ = [('type', ctypes.c_int), ('serial', ctypes.c_ulong), ('send_event', ctypes.c_int),\n" + " ('display', ctypes.c_void_p), ('window', ctypes.c_ulong), ('mode', ctypes.c_int), ('detail', ctypes.c_int)]\n" + "class XConfigureEvent(ctypes.Structure):\n" + " _fields_ = [('type', ctypes.c_int), ('serial', ctypes.c_ulong), ('send_event', ctypes.c_int),\n" + " ('display', ctypes.c_void_p), ('event', ctypes.c_ulong), ('window', ctypes.c_ulong),\n" + " ('x', ctypes.c_int), ('y', ctypes.c_int), ('width', ctypes.c_int), ('height', ctypes.c_int),\n" + " ('border_width', ctypes.c_int), ('above', ctypes.c_ulong), ('override_redirect', ctypes.c_int)]\n" + "class XPropertyEvent(ctypes.Structure):\n" + " _fields_ = [('type', ctypes.c_int), ('serial', ctypes.c_ulong), ('send_event', ctypes.c_int),\n" + " ('display', ctypes.c_void_p), ('window', ctypes.c_ulong), ('atom', ctypes.c_ulong),\n" + " ('time', ctypes.c_ulong), ('state', ctypes.c_int)]\n" + "class XClientMessageData(ctypes.Union):\n" + " _fields_ = [('b', ctypes.c_char * 20), ('s', ctypes.c_short * 10), ('l', ctypes.c_long * 5)]\n" + "class XClientMessageEvent(ctypes.Structure):\n" + " _fields_ = [('type', ctypes.c_int), ('serial', ctypes.c_ulong), ('send_event', ctypes.c_int),\n" + " ('display', ctypes.c_void_p), ('window', ctypes.c_ulong), ('message_type', ctypes.c_ulong),\n" + " ('format', ctypes.c_int), ('data', XClientMessageData)]\n" + "X11.XAllocWMHints.restype = ctypes.POINTER(XWMHints)\n" + "X11.XSetWMHints.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.POINTER(XWMHints)]\n" + "X11.XFree.argtypes = [ctypes.c_void_p]\n" + "X11.XSelectInput.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_long]\n" + "X11.XMapWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong]\n" + "X11.XIconifyWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int]\n" + "X11.XIconifyWindow.restype = ctypes.c_int\n" + "X11.XMoveResizeWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint]\n" + "X11.XSendEvent.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_long, ctypes.c_void_p]\n" + "X11.XFlush.argtypes = [ctypes.c_void_p]\n" + "X11.XPending.argtypes = [ctypes.c_void_p]\n" + "X11.XNextEvent.argtypes = [ctypes.c_void_p, ctypes.c_void_p]\n" + "X11.XSetInputFocus.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_ulong]\n" + "X11.XLookupKeysym.argtypes = [ctypes.c_void_p, ctypes.c_int]\n" + "X11.XLookupKeysym.restype = ctypes.c_ulong\n" + "X11.XGrabPointer.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_int, ctypes.c_uint, ctypes.c_int, ctypes.c_int, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong]\n" + "X11.XGrabPointer.restype = ctypes.c_int\n" + "X11.XUngrabPointer.argtypes = [ctypes.c_void_p, ctypes.c_ulong]\n" + "X11.XTranslateCoordinates.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_ulong)]\n" + "dpy = X11.XOpenDisplay(None)\n" + "root = X11.XDefaultRootWindow(dpy)\n" + "scr = X11.XDefaultScreen(dpy)\n" + "win = X11.XCreateSimpleWindow(dpy, root, 0, 0, 1280, 800, 0, 0, 0x222222)\n" + "wmh = X11.XAllocWMHints()\n" + "wmh.contents.flags = 1\n" + "wmh.contents.input = 0\n" + "X11.XSetWMHints(dpy, win, wmh)\n" + "X11.XFree(wmh)\n" + "wm_proto = X11.XInternAtom(dpy, b'WM_PROTOCOLS', 0)\n" + "wm_del = X11.XInternAtom(dpy, b'WM_DELETE_WINDOW', 0)\n" + "wm_take = X11.XInternAtom(dpy, b'WM_TAKE_FOCUS', 0)\n" + "wm_state_atom = X11.XInternAtom(dpy, b'WM_STATE', 0)\n" + "protos = (ctypes.c_ulong * 2)(wm_del, wm_take)\n" + "X11.XSetWMProtocols(dpy, win, protos, 2)\n" + "wm_state = X11.XInternAtom(dpy, b'_NET_WM_STATE', 0)\n" + "wm_fs = X11.XInternAtom(dpy, b'_NET_WM_STATE_FULLSCREEN', 0)\n" + "states = (ctypes.c_ulong * 1)(wm_fs)\n" + "X11.XChangeProperty(dpy, win, wm_state, 4, 32, 0, states, 1)\n" + "mask = (1<<0)|(1<<2)|(1<<6)|(1<<4)|(1<<5)|(1<<17)|(1<<21)|(1<<22)\n" + "X11.XSelectInput(dpy, win, mask)\n" + "X11.XMapWindow(dpy, win)\n" + "X11.XFlush(dpy)\n" + "buf = (ctypes.c_long * 32)()\n" + "print(json.dumps({'ready': int(win)}), flush=True)\n" + "seen_focusin = False\n" + "deactivated = False\n" + "offscreen = False\n" + "triggered_deactivate = False\n" + "pending_wm_state = False\n" + "pending_net_wm_state = False\n" + "pending_config = False\n" + "def read_wm_state():\n" + " da, di = ctypes.c_ulong(), ctypes.c_int()\n" + " n, dl = ctypes.c_ulong(), ctypes.c_ulong()\n" + " prop = ctypes.POINTER(ctypes.c_ubyte)()\n" + " rc = X11.XGetWindowProperty(dpy, win, wm_state_atom, 0, 2, 0, wm_state_atom,\n" + " ctypes.byref(da), ctypes.byref(di), ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop))\n" + " val = None\n" + " if rc == 0 and prop:\n" + " if di.value == 32 and n.value >= 1:\n" + " val = int(ctypes.cast(prop, ctypes.POINTER(ctypes.c_ulong))[0])\n" + " X11.XFree(prop)\n" + " return val\n" + "def maybe_trigger():\n" + " global triggered_deactivate, pending_wm_state, pending_net_wm_state, pending_config\n" + " if seen_focusin and deactivated and offscreen and not triggered_deactivate:\n" + " triggered_deactivate = True\n" + " pending_wm_state = True\n" + " X11.XIconifyWindow(dpy, win, scr)\n" + " pending_net_wm_state = True\n" + " ev = XClientMessageEvent()\n" + " ev.type = 33\n" + " ev.display = dpy\n" + " ev.window = win\n" + " ev.message_type = wm_state\n" + " ev.format = 32\n" + " ev.data.l[0] = 1\n" + " ev.data.l[1] = wm_fs\n" + " ev.data.l[2] = 0\n" + " ev.data.l[3] = 1\n" + " X11.XSendEvent(dpy, root, 0, (1<<19)|(1<<20), ctypes.byref(ev))\n" + " pending_config = True\n" + " X11.XMoveResizeWindow(dpy, win, 0, 0, 1280, 800)\n" + " X11.XFlush(dpy)\n" + "t0 = time.monotonic()\n" + "while time.monotonic() - t0 < 10.0:\n" + " while X11.XPending(dpy):\n" + " X11.XNextEvent(dpy, buf)\n" + " et = ctypes.c_int.from_buffer(buf).value\n" + " if et == 33:\n" + " cm = XClientMessageEvent.from_buffer(buf)\n" + " if cm.message_type == wm_proto and cm.data.l[0] == wm_take:\n" + " ts = int(cm.data.l[1]) & 0xffffffff\n" + " if pending_wm_state:\n" + " print(json.dumps({'ev': 'WM_TAKE_FOCUS_IGNORED', 'time': ts}), flush=True)\n" + " else:\n" + " X11.XSetInputFocus(dpy, win, 1, ts)\n" + " X11.XFlush(dpy)\n" + " print(json.dumps({'ev': 'WM_TAKE_FOCUS', 'time': ts}), flush=True)\n" + " elif et == 28:\n" + " pe = XPropertyEvent.from_buffer(buf)\n" + " if pe.state == 0 and pe.atom == wm_state_atom:\n" + " val = read_wm_state()\n" + " if val in (1, 3):\n" + " pending_wm_state = False\n" + " print(json.dumps({'ev': 'WM_STATE', 'state': val, 'pending': pending_wm_state}), flush=True)\n" + " elif pe.state == 0 and pe.atom == wm_state:\n" + " if pending_net_wm_state:\n" + " pending_net_wm_state = False\n" + " print(json.dumps({'ev': 'NET_WM_STATE_ACK'}), flush=True)\n" + " elif et == 9:\n" + " seen_focusin = True\n" + " fe = XFocusChangeEvent.from_buffer(buf)\n" + " tx, ty, ch = ctypes.c_int(), ctypes.c_int(), ctypes.c_ulong()\n" + " X11.XTranslateCoordinates(dpy, win, root, 0, 0, ctypes.byref(tx), ctypes.byref(ty), ctypes.byref(ch))\n" + " grc = X11.XGrabPointer(dpy, win, 1, (1<<2)|(1<<3)|(1<<6), 1, 1, win, 0, 0)\n" + " print(json.dumps({'ev': 'FocusIn', 'mode': fe.mode, 'pos': [tx.value, ty.value], 'grab': grc}), flush=True)\n" + " elif et == 10:\n" + " fe = XFocusChangeEvent.from_buffer(buf)\n" + " X11.XUngrabPointer(dpy, 0)\n" + " print(json.dumps({'ev': 'FocusOut', 'mode': fe.mode}), flush=True)\n" + " if seen_focusin:\n" + " deactivated = True\n" + " maybe_trigger()\n" + " elif et == 22:\n" + " ce = XConfigureEvent.from_buffer(buf)\n" + " if ce.x < 0:\n" + " offscreen = True\n" + " if pending_config and ce.send_event:\n" + " pending_config = False\n" + " print(json.dumps({'ev': 'ConfigureRequestAck', 'pos': [ce.x, ce.y], 'size': [ce.width, ce.height]}), flush=True)\n" + " print(json.dumps({'ev': 'ConfigureNotify', 'send_event': bool(ce.send_event), 'pos': [ce.x, ce.y], 'size': [ce.width, ce.height]}), flush=True)\n" + " maybe_trigger()\n" + " elif et in (2, 4, 6):\n" + " names = {2: 'KeyPress', 4: 'ButtonPress', 6: 'MotionNotify'}\n" + " print(json.dumps({'ev': names[et]}), flush=True)\n" + " if et == 2 and X11.XLookupKeysym(buf, 0) == 0x62:\n" + " pending_wm_state = True\n" + " print(json.dumps({'ev': 'VISIBLE_ICONIFY_REQ'}), flush=True)\n" + " X11.XIconifyWindow(dpy, win, scr)\n" + " X11.XFlush(dpy)\n" + " time.sleep(0.005)\n" + ) + wine_sim = subprocess.Popen( + [sys.executable, "-c", sim_code], + env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, + ) + import json + ready_info = json.loads(wine_sim.stdout.readline().strip()) + win_id = ready_info["ready"] + time.sleep(0.4) + + # Switch Tag 1 -> Tag 2 via Super_L + 2 + subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True) + time.sleep(0.06) + subprocess.run(["xdotool", "key", "2"], env=env, check=True) + time.sleep(0.08) + subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True) + time.sleep(0.25) + + tag2_client = subprocess.Popen( + [os.path.join(BUILD, "st", "st"), "-e", "sh", "-c", "sleep 6"], + env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + ) + time.sleep(0.4) + subprocess.run(["xdotool", "mousemove", "400", "400", "click", "1"], env=env, check=True) + time.sleep(0.25) + + # Switch Tag 2 -> Tag 1 via Super_L + 1 + subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True) + time.sleep(0.06) + subprocess.run(["xdotool", "key", "1"], env=env, check=True) + time.sleep(0.08) + subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True) + time.sleep(0.3) + + subprocess.run(["xdotool", "mousemove", "500", "500", "click", "1", "mousemove", "700", "300", "key", "a"], + env=env, check=True) + time.sleep(0.25) + + # Verify visible XIconifyWindow on Tag 1 is rejected with NormalState + subprocess.run(["xdotool", "key", "b"], env=env, check=True) + time.sleep(0.25) + + terminate(wine_sim) + out, _ = wine_sim.communicate(timeout=3) + events = [json.loads(line) for line in out.splitlines() if line.strip().startswith("{")] + + off_idx = next((i for i, e in enumerate(events) if e["ev"] == "ConfigureNotify" and e["pos"][0] < 0), None) + assert off_idx is not None, f"Client never moved offscreen on Tag 1 -> Tag 2: {events}" + + post_off = events[off_idx:] + return_idx = next( + (i for i, e in enumerate(post_off) + if e["ev"] == "ConfigureNotify" and not e["send_event"] + and e["pos"] == [0, 0] and e["size"] == [1280, 800]), + None, + ) + assert return_idx is not None, f"Missing ConfigureNotify return to (0,0): {post_off}" + + during_hide = post_off[:return_idx] + wm_iconics = [e for e in during_hide if e["ev"] == "WM_STATE" and e["state"] == 3 and not e["pending"]] + assert wm_iconics, f"Missing WM_STATE IconicState acceptance while hidden on Tag 2: {during_hide}" + wm_premature_normals = [e for e in during_hide if e["ev"] == "WM_STATE" and e["state"] == 1] + assert not wm_premature_normals, f"Premature WM_STATE NormalState while still hidden on Tag 2: {during_hide}" + assert any(e["ev"] == "NET_WM_STATE_ACK" for e in during_hide), ( + f"Missing PropertyNotify(_NET_WM_STATE) ack for redundant _NET_WM_STATE_ADD: {during_hide}" + ) + assert any(e["ev"] == "ConfigureRequestAck" for e in during_hide), ( + f"Missing synthetic ConfigureNotify ack for hidden ConfigureRequest: {during_hide}" + ) + assert not any(e["ev"] == "WM_TAKE_FOCUS_IGNORED" for e in events), ( + f"WM_TAKE_FOCUS was dropped due to pending WM_STATE: {events}" + ) + + post_return = post_off[return_idx:] + norm_idx = next( + (i for i, e in enumerate(post_return) if e["ev"] == "WM_STATE" and e["state"] == 1), + None, + ) + tf_idx = next((i for i, e in enumerate(post_return) if e["ev"] == "WM_TAKE_FOCUS"), None) + assert norm_idx is not None, f"Missing WM_STATE NormalState restoration on Tag 2 -> Tag 1 return: {post_return}" + assert tf_idx is not None, f"Missing WM_TAKE_FOCUS after Tag 2 -> Tag 1 return: {post_return}" + assert norm_idx < tf_idx, f"WM_STATE NormalState ({norm_idx}) must precede WM_TAKE_FOCUS ({tf_idx}): {post_return}" + fi = [e for e in post_return if e["ev"] == "FocusIn"] + assert fi, f"Missing FocusIn after Tag 2 -> Tag 1 return: {post_return}" + assert fi[0]["mode"] == 0 and fi[0]["pos"] == [0, 0] and fi[0]["grab"] == 0, ( + f"Bad FocusIn/grab after Tag 2 -> Tag 1 return: {fi[0]}" + ) + post_names = [e["ev"] for e in post_return] + for req in ("MotionNotify", "ButtonPress", "KeyPress"): + assert req in post_names, f"Missing {req} after return to Tag 1: {post_return}" + + vis_req_idx = next((i for i, e in enumerate(events) if e["ev"] == "VISIBLE_ICONIFY_REQ"), None) + assert vis_req_idx is not None, f"Visible XIconifyWindow trigger never fired: {events}" + after_vis = events[vis_req_idx:] + assert any(e["ev"] == "WM_STATE" and e["state"] == 1 and not e["pending"] for e in after_vis), ( + f"Visible XIconifyWindow was not rejected with WM_STATE NormalState: {after_vis}" + ) + assert not any(e["ev"] == "WM_STATE" and e["state"] == 3 for e in after_vis), ( + f"Visible XIconifyWindow unexpectedly accepted IconicState: {after_vis}" + ) + finally: + terminate(tag2_client) + terminate(wine_sim) + terminate(dwm) + if dpy: + X11.XCloseDisplay(dpy) + terminate(xvfb) + + def test_systray_xembed_dock_race(): disp = pick_display() with tempfile.TemporaryDirectory() as home: @@ -1372,6 +1698,8 @@ def main(): print("test_x11_xvfb: fullscreen workspace switch focus OK") test_wine_take_focus_workspace_switch() print("test_x11_xvfb: Wine WM_TAKE_FOCUS workspace switch OK") + test_wine_dxvk_iconic_workspace_switch() + print("test_x11_xvfb: Wine/DXVK WM_CHANGE_STATE iconic workspace switch OK") test_systray_xembed_dock_race() print("test_x11_xvfb: systray XEmbed dock/map race OK") return 0