From 66bdc51b1c927c8d77979a949be48aa91ffa83a2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 29 Apr 2026 05:58:14 +0000 Subject: [PATCH] Xi: fix ProcXIGrabDevice returning AlreadyGrabbed as X error code When the target device is disabled, ProcXIGrabDevice returns AlreadyGrabbed directly as the request handler return value. AlreadyGrabbed (1) is a grab status code, not an X error code. The server dispatch loop interprets any non-zero return value as an X protocol error, so the client receives BadRequest (error code 1) instead of a proper XIGrabDevice reply with status=AlreadyGrabbed. And use XIAlreadyGrabbed since this is an XI2 request. It's the same value anyway. This is the same class of bug that was fixed in ProcXIPassiveGrabDevice by commit 'Xi: Fix XIPassiveGrab handling of keycodes > 255' Fix by jumping to the reply path with status=AlreadyGrabbed instead of returning the status code directly. Part-of: --- Xi/xigrabdev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c index e1b43f695..5b55fe9e4 100644 --- a/Xi/xigrabdev.c +++ b/Xi/xigrabdev.c @@ -81,8 +81,10 @@ ProcXIGrabDevice(ClientPtr client) if (ret != Success) return ret; - if (!dev->enabled) - return AlreadyGrabbed; + if (!dev->enabled) { + status = XIAlreadyGrabbed; + goto reply; + } if (!IsMaster(dev)) stuff->paired_device_mode = GrabModeAsync; @@ -122,6 +124,7 @@ ProcXIGrabDevice(ClientPtr client) if (ret != Success) return ret; +reply: rep = (xXIGrabDeviceReply) { .repType = X_Reply, .RepType = X_XIGrabDevice,