fix(wm,tray,replace): fix fullscreen focus, systray XEmbed race, and display-scoped cleanup
This commit is contained in:
1 parent
be7e3a3155
commit
8da5c5d1cb
4 files changed
+989
-69
No files matched your search
@@ -72,6 +72,26 @@ class XWMHints(ctypes.Structure):
|
||||
]
|
||||
|
||||
|
||||
class XSetWindowAttributes(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("background_pixmap", ctypes.c_ulong),
|
||||
("background_pixel", ctypes.c_ulong),
|
||||
("border_pixmap", ctypes.c_ulong),
|
||||
("border_pixel", ctypes.c_ulong),
|
||||
("bit_gravity", ctypes.c_int),
|
||||
("win_gravity", ctypes.c_int),
|
||||
("backing_store", ctypes.c_int),
|
||||
("backing_planes", ctypes.c_ulong),
|
||||
("backing_pixel", ctypes.c_ulong),
|
||||
("save_under", ctypes.c_int),
|
||||
("event_mask", ctypes.c_long),
|
||||
("do_not_propagate_mask", ctypes.c_long),
|
||||
("override_redirect", ctypes.c_int),
|
||||
("colormap", ctypes.c_ulong),
|
||||
("cursor", ctypes.c_ulong),
|
||||
]
|
||||
|
||||
|
||||
X11.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
X11.XOpenDisplay.restype = Display_p
|
||||
X11.XCloseDisplay.argtypes = [Display_p]
|
||||
@@ -95,6 +115,8 @@ X11.XCreateSimpleWindow.argtypes = [
|
||||
]
|
||||
X11.XCreateSimpleWindow.restype = Window
|
||||
X11.XDestroyWindow.argtypes = [Display_p, Window]
|
||||
X11.XMapWindow.argtypes = [Display_p, Window]
|
||||
X11.XChangeWindowAttributes.argtypes = [Display_p, Window, ctypes.c_ulong, ctypes.POINTER(XSetWindowAttributes)]
|
||||
X11.XChangeProperty.argtypes = [
|
||||
Display_p, Window, Atom, Atom, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int
|
||||
]
|
||||
@@ -770,6 +792,564 @@ def test_gtk_xsettings_no_double_scale():
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_fullscreen_workspace_switch_focus():
|
||||
if not shutil.which("xdotool"):
|
||||
print("test_x11_xvfb: xdotool not installed (skipping fullscreen 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", "")
|
||||
)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-noreset", "-screen", "0", "1280x800x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dpy = None
|
||||
dwm = None
|
||||
game = 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"
|
||||
|
||||
game_code = (
|
||||
"import ctypes, ctypes.util, json, sys, 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.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.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.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.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"
|
||||
"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"
|
||||
"dpy = X11.XOpenDisplay(None)\n"
|
||||
"root = X11.XDefaultRootWindow(dpy)\n"
|
||||
"win = X11.XCreateSimpleWindow(dpy, root, 0, 0, 1280, 800, 0, 0, 0x222222)\n"
|
||||
"wm_state = X11.XInternAtom(dpy, b'_NET_WM_STATE', 0)\n"
|
||||
"wm_fs = X11.XInternAtom(dpy, b'_NET_WM_STATE_FULLSCREEN', 0)\n"
|
||||
"fs_val = ctypes.c_ulong(wm_fs)\n"
|
||||
"X11.XChangeProperty(dpy, win, wm_state, 4, 32, 0, ctypes.byref(fs_val), 1)\n"
|
||||
"mask = (1<<0)|(1<<2)|(1<<6)|(1<<4)|(1<<5)|(1<<17)|(1<<21)\n"
|
||||
"X11.XSelectInput(dpy, win, mask)\n"
|
||||
"X11.XMapWindow(dpy, win)\n"
|
||||
"X11.XFlush(dpy)\n"
|
||||
"buf = (ctypes.c_long * 32)()\n"
|
||||
"print('READY', flush=True)\n"
|
||||
"t0 = time.monotonic()\n"
|
||||
"while time.monotonic() - t0 < 8.0:\n"
|
||||
" while X11.XPending(dpy):\n"
|
||||
" X11.XNextEvent(dpy, buf)\n"
|
||||
" et = ctypes.c_int.from_buffer(buf).value\n"
|
||||
" if et == 9:\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"
|
||||
" elif et == 22:\n"
|
||||
" ce = XConfigureEvent.from_buffer(buf)\n"
|
||||
" print(json.dumps({'ev': 'ConfigureNotify', 'pos': [ce.x, ce.y], 'size': [ce.width, ce.height]}), flush=True)\n"
|
||||
" elif et in (2, 4, 6, 7, 8):\n"
|
||||
" names = {2: 'KeyPress', 4: 'ButtonPress', 6: 'MotionNotify', 7: 'EnterNotify', 8: 'LeaveNotify'}\n"
|
||||
" print(json.dumps({'ev': names[et]}), flush=True)\n"
|
||||
" time.sleep(0.005)\n"
|
||||
)
|
||||
game = subprocess.Popen(
|
||||
[sys.executable, "-c", game_code],
|
||||
env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True,
|
||||
)
|
||||
assert game.stdout.readline().strip() == "READY"
|
||||
time.sleep(0.35)
|
||||
|
||||
subprocess.run(["xdotool", "mousemove", "640", "400", "click", "1"], env=env, check=True)
|
||||
time.sleep(0.15)
|
||||
|
||||
# Switch Tag 1 -> Tag 2 while holding Super_L
|
||||
subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.08)
|
||||
subprocess.run(["xdotool", "key", "2"], env=env, check=True)
|
||||
time.sleep(0.12)
|
||||
subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.25)
|
||||
|
||||
# Open and focus a window on Tag 2 so Tag 2 takes X11 focus/pointer
|
||||
tag2_client = subprocess.Popen(
|
||||
[os.path.join(BUILD, "st", "st"), "-e", "sh", "-c", "sleep 4"],
|
||||
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.2)
|
||||
|
||||
# Switch Tag 2 -> Tag 1 while holding Super_L (this previously caused GrabFrozen & offscreen FocusIn)
|
||||
subprocess.run(["xdotool", "keydown", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.08)
|
||||
subprocess.run(["xdotool", "key", "1"], env=env, check=True)
|
||||
time.sleep(0.12)
|
||||
subprocess.run(["xdotool", "keyup", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.3)
|
||||
|
||||
# Interact with game after returning to Tag 1
|
||||
subprocess.run(["xdotool", "mousemove", "500", "500", "click", "1", "mousemove", "700", "300", "key", "a"],
|
||||
env=env, check=True)
|
||||
time.sleep(0.25)
|
||||
|
||||
# Verify quick Super_L tap-latch still works under GrabModeAsync
|
||||
subprocess.run(["xdotool", "key", "Super_L"], env=env, check=True)
|
||||
time.sleep(0.08)
|
||||
subprocess.run(["xdotool", "key", "2"], env=env, check=True)
|
||||
time.sleep(0.25)
|
||||
|
||||
terminate(game)
|
||||
out, err = game.communicate(timeout=3)
|
||||
import json
|
||||
events = [json.loads(line) for line in out.splitlines() if line.strip().startswith("{")]
|
||||
|
||||
offscreen_idx = next((i for i, e in enumerate(events) if e["ev"] == "ConfigureNotify" and e["pos"][0] < 0), None)
|
||||
assert offscreen_idx is not None, f"Game never moved offscreen on tag switch: {events}"
|
||||
|
||||
post_return = events[offscreen_idx:]
|
||||
onscreen_cfg_idx = next(
|
||||
(i for i, e in enumerate(post_return)
|
||||
if e["ev"] == "ConfigureNotify" and e["pos"] == [0, 0] and e["size"] == [1280, 800]),
|
||||
None,
|
||||
)
|
||||
assert onscreen_cfg_idx is not None, f"Missing ConfigureNotify(0,0) on return to Tag 1: {post_return}"
|
||||
|
||||
first_focusin_idx = next((i for i, e in enumerate(post_return) if e["ev"] == "FocusIn"), None)
|
||||
assert first_focusin_idx is not None, f"Missing FocusIn on return to Tag 1: {post_return}"
|
||||
assert onscreen_cfg_idx < first_focusin_idx, f"FocusIn arrived before ConfigureNotify(0,0): {post_return}"
|
||||
|
||||
fi = post_return[first_focusin_idx]
|
||||
assert fi["pos"] == [0, 0], f"Game was offscreen at FocusIn: {fi}"
|
||||
assert fi["mode"] == 0, f"FocusIn was not NotifyNormal (Super_L grab still active?): {fi}"
|
||||
assert fi["grab"] == 0, f"XGrabPointer failed on FocusIn after return (GrabFrozen/etc): {fi} ({post_return})"
|
||||
|
||||
# Ensure no FocusIn while holding Super_L failed grab AND mouse/key events worked after returning
|
||||
post_focus_names = [e["ev"] for e in post_return[first_focusin_idx:]]
|
||||
for req in ("MotionNotify", "ButtonPress", "KeyPress"):
|
||||
assert req in post_focus_names, f"Missing {req} after return to Tag 1: {post_return}"
|
||||
|
||||
# Confirm tap-latch switched back away to Tag 2 at the end
|
||||
last_off = next((i for i, e in enumerate(post_return[first_focusin_idx:]) if e["ev"] == "ConfigureNotify" and e["pos"][0] < 0), None)
|
||||
assert last_off is not None, f"Super_L tap-latch did not switch back to Tag 2: {post_return}"
|
||||
finally:
|
||||
terminate(tag2_client)
|
||||
terminate(game)
|
||||
terminate(dwm)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def test_wine_take_focus_workspace_switch():
|
||||
if not shutil.which("xdotool"):
|
||||
print("test_x11_xvfb: xdotool not installed (skipping Wine WM_TAKE_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.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.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 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.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.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"
|
||||
"win = X11.XCreateSimpleWindow(dpy, root, 0, 0, 800, 600, 0, 0, 0x222222)\n"
|
||||
"wmh = X11.XAllocWMHints()\n"
|
||||
"wmh.contents.flags = 1\n" # InputHint
|
||||
"wmh.contents.input = 0\n" # globally-active Wine-style client
|
||||
"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"
|
||||
"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_maxh = X11.XInternAtom(dpy, b'_NET_WM_STATE_MAXIMIZED_HORZ', 0)\n"
|
||||
"wm_fs = X11.XInternAtom(dpy, b'_NET_WM_STATE_FULLSCREEN', 0)\n"
|
||||
"states = (ctypes.c_ulong * 2)(wm_maxh, wm_fs)\n" # fullscreen NOT at index 0
|
||||
"X11.XChangeProperty(dpy, win, wm_state, 4, 32, 0, states, 2)\n"
|
||||
"mask = (1<<0)|(1<<2)|(1<<6)|(1<<4)|(1<<5)|(1<<17)|(1<<21)\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"
|
||||
"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"
|
||||
" 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 == 9:\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"
|
||||
" elif et == 22:\n"
|
||||
" ce = XConfigureEvent.from_buffer(buf)\n"
|
||||
" print(json.dumps({'ev': 'ConfigureNotify', 'pos': [ce.x, ce.y], 'size': [ce.width, ce.height]}), flush=True)\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"
|
||||
" 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)
|
||||
|
||||
net_wm_state_atom = X11.XInternAtom(dpy, b"_NET_WM_STATE", 0)
|
||||
atom_maxh = X11.XInternAtom(dpy, b"_NET_WM_STATE_MAXIMIZED_HORZ", 0)
|
||||
atom_fs = X11.XInternAtom(dpy, b"_NET_WM_STATE_FULLSCREEN", 0)
|
||||
atom_foc = X11.XInternAtom(dpy, b"_NET_WM_STATE_FOCUSED", 0)
|
||||
|
||||
def get_win_states():
|
||||
return get_cardinal_prop(dpy, win_id, "_NET_WM_STATE")
|
||||
|
||||
init_states = wait_until(
|
||||
lambda: (lambda s: s if atom_fs in s and atom_foc in s else None)(get_win_states())
|
||||
)
|
||||
assert init_states is not None, f"Missing expected _NET_WM_STATE atoms: {get_win_states()}"
|
||||
assert atom_maxh in init_states, f"_NET_WM_STATE_MAXIMIZED_HORZ was overwritten: {init_states}"
|
||||
a_init = XWindowAttributes()
|
||||
X11.XGetWindowAttributes(dpy, win_id, ctypes.byref(a_init))
|
||||
assert (a_init.x, a_init.y, a_init.width, a_init.height) == (0, 0, 1280, 800), (
|
||||
f"Multi-atom _NET_WM_STATE_FULLSCREEN not detected fullscreen: {(a_init.x, a_init.y, a_init.width, a_init.height)}"
|
||||
)
|
||||
|
||||
# Switch Tag 1 -> Tag 2 via Super_L + 2, spawn and click st on Tag 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.2)
|
||||
|
||||
# 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)
|
||||
|
||||
# Phase 2: switch away to Tag 2 via Super_L + 2, wait, then return via bar Tag 1 click (x=50, y=10)
|
||||
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)
|
||||
subprocess.run(["xdotool", "mousemove", "400", "400", "click", "1"], env=env, check=True)
|
||||
time.sleep(0.2)
|
||||
subprocess.run(["xdotool", "mousemove", "50", "10", "click", "1"], env=env, check=True)
|
||||
time.sleep(0.3)
|
||||
subprocess.run(["xdotool", "mousemove", "520", "480", "click", "1", "mousemove", "720", "320", "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_indices = [i for i, e in enumerate(events) if e["ev"] == "ConfigureNotify" and e["pos"][0] < 0]
|
||||
assert len(off_indices) >= 2, f"Expected two workspace switches away from Tag 1: {events}"
|
||||
|
||||
pre_switch = events[:off_indices[0]]
|
||||
init_tf = [e for e in pre_switch if e["ev"] == "WM_TAKE_FOCUS"]
|
||||
assert init_tf and init_tf[0]["time"] > 0, f"Initial WM_TAKE_FOCUS must have non-zero time: {pre_switch}"
|
||||
|
||||
# Check Phase 1 (Super_L + 1 return)
|
||||
seg1 = events[off_indices[0]:off_indices[1]]
|
||||
tf1 = [e for e in seg1 if e["ev"] == "WM_TAKE_FOCUS"]
|
||||
assert len(tf1) == 1, f"Expected exactly 1 WM_TAKE_FOCUS on Super_L+1 return, got {len(tf1)}: {seg1}"
|
||||
assert tf1[0]["time"] > init_tf[-1]["time"], f"WM_TAKE_FOCUS timestamp did not advance: {tf1[0]} vs {init_tf[-1]}"
|
||||
fi1 = [e for e in seg1 if e["ev"] == "FocusIn"]
|
||||
assert fi1, f"Missing FocusIn on Super_L+1 return: {seg1}"
|
||||
assert fi1[0]["mode"] == 0 and fi1[0]["pos"] == [0, 0] and fi1[0]["grab"] == 0, f"Bad FocusIn/grab on Super_L+1 return: {fi1[0]}"
|
||||
seg1_names = [e["ev"] for e in seg1]
|
||||
for req in ("MotionNotify", "ButtonPress", "KeyPress"):
|
||||
assert req in seg1_names, f"Missing {req} after Super_L+1 return: {seg1}"
|
||||
|
||||
# Check Phase 2 (bar Tag 1 click return)
|
||||
seg2 = events[off_indices[1]:]
|
||||
tf2 = [e for e in seg2 if e["ev"] == "WM_TAKE_FOCUS"]
|
||||
assert len(tf2) == 1, f"Expected exactly 1 WM_TAKE_FOCUS on bar click return, got {len(tf2)}: {seg2}"
|
||||
assert tf2[0]["time"] > tf1[0]["time"], f"WM_TAKE_FOCUS timestamp did not advance on bar click: {tf2[0]} vs {tf1[0]}"
|
||||
fi2 = [e for e in seg2 if e["ev"] == "FocusIn"]
|
||||
assert fi2, f"Missing FocusIn on bar click return: {seg2}"
|
||||
assert fi2[0]["mode"] == 0 and fi2[0]["pos"] == [0, 0] and fi2[0]["grab"] == 0, f"Bad FocusIn/grab on bar click return: {fi2[0]}"
|
||||
seg2_names = [e["ev"] for e in seg2]
|
||||
for req in ("MotionNotify", "ButtonPress", "KeyPress"):
|
||||
assert req in seg2_names, f"Missing {req} after bar click return: {seg2}"
|
||||
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:
|
||||
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(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
|
||||
cdpy = None
|
||||
dwm = None
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert dpy, f"Failed to open Xvfb {disp}"
|
||||
cdpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert cdpy, f"Failed to open client display on Xvfb {disp}"
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env)
|
||||
tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0)
|
||||
tray_win = wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom))
|
||||
assert tray_win, "DWM failed to acquire _NET_SYSTEM_TRAY_S0"
|
||||
|
||||
xembed_info = X11.XInternAtom(cdpy, b"_XEMBED_INFO", 0)
|
||||
op_atom = X11.XInternAtom(cdpy, b"_NET_SYSTEM_TRAY_OPCODE", 0)
|
||||
|
||||
def set_xembed(ic, mapped):
|
||||
arr = (ctypes.c_ulong * 2)(1, 1 if mapped else 0)
|
||||
X11.XChangeProperty(cdpy, ic, xembed_info, xembed_info, 32, 0, arr, 2)
|
||||
|
||||
def send_dock(ic):
|
||||
ev = XClientMessageEvent()
|
||||
ev.type = 33
|
||||
ev.display = cdpy
|
||||
ev.window = tray_win
|
||||
ev.message_type = op_atom
|
||||
ev.format = 32
|
||||
ev.data.l[0] = 0
|
||||
ev.data.l[1] = 0
|
||||
ev.data.l[2] = ic
|
||||
X11.XSendEvent(cdpy, tray_win, 0, 0, ctypes.byref(ev))
|
||||
|
||||
def assert_icon_viewable_resized(ic, desc):
|
||||
def check():
|
||||
if ic not in query_children(dpy, tray_win):
|
||||
return None
|
||||
a = XWindowAttributes()
|
||||
if not X11.XGetWindowAttributes(dpy, ic, ctypes.byref(a)):
|
||||
return None
|
||||
if a.map_state == 2 and 8 <= a.width <= 48 and 8 <= a.height <= 48:
|
||||
return (a.width, a.height)
|
||||
return None
|
||||
res = wait_until(check, timeout=3.0)
|
||||
if not res:
|
||||
a = XWindowAttributes()
|
||||
X11.XGetWindowAttributes(dpy, ic, ctypes.byref(a))
|
||||
raise AssertionError(
|
||||
f"{desc}: icon {hex(ic)} failed systray check "
|
||||
f"(in_tray={ic in query_children(dpy, tray_win)}, map_state={a.map_state}, size={a.width}x{a.height})"
|
||||
)
|
||||
|
||||
# Subtest A: GTK2/HexChat burst race (_XEMBED_INFO=(1,0) -> REQUEST_DOCK -> _XEMBED_INFO=(1,1))
|
||||
for delay in (0.0, 0.0005, 0.002, 0.01):
|
||||
ic = X11.XCreateSimpleWindow(cdpy, root, 0, 0, 200, 200, 0, 0, 0xffffff)
|
||||
set_xembed(ic, False)
|
||||
send_dock(ic)
|
||||
X11.XFlush(cdpy)
|
||||
if delay > 0.0:
|
||||
time.sleep(delay)
|
||||
set_xembed(ic, True)
|
||||
X11.XFlush(cdpy)
|
||||
assert_icon_viewable_resized(ic, f"Subtest A (delay={delay})")
|
||||
|
||||
# Subtest B: Already-mapped icon docking
|
||||
ic_mapped = X11.XCreateSimpleWindow(cdpy, root, 0, 0, 200, 200, 0, 0, 0xffffff)
|
||||
swa = XSetWindowAttributes()
|
||||
swa.override_redirect = 1
|
||||
X11.XChangeWindowAttributes(cdpy, ic_mapped, 1 << 9, ctypes.byref(swa))
|
||||
set_xembed(ic_mapped, True)
|
||||
X11.XMapWindow(cdpy, ic_mapped)
|
||||
X11.XSync(cdpy, 0)
|
||||
send_dock(ic_mapped)
|
||||
X11.XFlush(cdpy)
|
||||
assert_icon_viewable_resized(ic_mapped, "Subtest B (already-mapped)")
|
||||
|
||||
# Subtest C: Toggle XEMBED_MAPPED 1 -> 0 -> 1
|
||||
ic_toggle = X11.XCreateSimpleWindow(cdpy, root, 0, 0, 200, 200, 0, 0, 0xffffff)
|
||||
set_xembed(ic_toggle, True)
|
||||
send_dock(ic_toggle)
|
||||
X11.XFlush(cdpy)
|
||||
assert_icon_viewable_resized(ic_toggle, "Subtest C (initial map)")
|
||||
|
||||
set_xembed(ic_toggle, False)
|
||||
X11.XFlush(cdpy)
|
||||
def is_unmapped():
|
||||
a = XWindowAttributes()
|
||||
return X11.XGetWindowAttributes(dpy, ic_toggle, ctypes.byref(a)) and a.map_state == 0
|
||||
assert wait_until(is_unmapped, timeout=3.0), "Subtest C: icon did not unmap on XEMBED_MAPPED=0"
|
||||
|
||||
set_xembed(ic_toggle, True)
|
||||
X11.XFlush(cdpy)
|
||||
assert_icon_viewable_resized(ic_toggle, "Subtest C (remap)")
|
||||
finally:
|
||||
terminate(dwm)
|
||||
if cdpy:
|
||||
X11.XCloseDisplay(cdpy)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_x11_xvfb: Xvfb not installed (skipping)")
|
||||
@@ -788,6 +1368,12 @@ def main():
|
||||
print("test_x11_xvfb: lockscreen overlaps systray OK")
|
||||
test_gtk_xsettings_no_double_scale()
|
||||
print("test_x11_xvfb: GTK/XSETTINGS non-double-scaling OK")
|
||||
test_fullscreen_workspace_switch_focus()
|
||||
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_systray_xembed_dock_race()
|
||||
print("test_x11_xvfb: systray XEmbed dock/map race OK")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user