A problem about reading the source code

Uli Schlachter psychon at znc.in
Wed Jan 3 07:56:44 UTC 2024


Hi,

Am 02.01.24 um 07:17 schrieb starcold14:
[...]
> I encountered a problem when I was using the computer, the left mouse button
> would randomly appear to be unresponsive,

That sounds like some program grabbed the mouse. I just do not have any 
good ideas on which program or why.

[...]
> 1. The keyboard can be used, so I use crtl+alt+T to open gnome-terminal, enter
> xinput test-xi2, press enter, and then click the left mouse button to confirm
> that gnome-terminal can output the record of mouse click events (thus I think
> the driver and kernel work well);

Nice idea!

I think this still fits an active grab.

> 2. When I input xwininfo in gnome-terminal, the error message "Can't grab the
> mouse." is displayed.

This also fits the "there is an active grab"-theory.

You can find the X11 protocol specification at [0]. Relevant part:

 > The request fails with status AlreadyGrabbed if the pointer is
 > actively grabbed by some other client. The request fails with status
 > Frozen if the pointer is frozen by an active grab of another client.
 > The request fails with status NotViewable if grab-window or confine-to
 > window is not viewable or if the confine-to window lies completely
 > outside the boundaries of the root window. The request fails with
 > status InvalidTime if the specified time is earlier than the
 > last-pointer-grab time or later than the current server time.

[0]: 
https://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.html#requests:GrabPointer

We can rule out InvalidTime since the code uses XCB_TIME_CURRENT_TIME.
We can rule out NotViewable since the grab is established on the root 
window. That one is always visible.
That leaves AlreadyGrabbed or Frozen which both basically are "some 
other program grabbed mouse input".

[...]
>          grab_cookie = xcb_grab_pointer
>      (dpy, False, root,
>      XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
>      XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
>      root, cursor, XCB_TIME_CURRENT_TIME);
>          grab_reply = xcb_grab_pointer_reply (dpy, grab_cookie, &err);
>          if (grab_reply->status != XCB_GRAB_STATUS_SUCCESS)
>      Fatal_Error ("Can't grab the mouse.");

If you want to "compare symptoms" and check whether we can cause this 
issue at will, you could try with the attached program. It can be 
compiled with "gcc foo.c -lxcb". The possible errors when a grab fails 
are (from /usr/include/xcb/xproto.h):

typedef enum xcb_grab_status_t {
     XCB_GRAB_STATUS_SUCCESS = 0,
     XCB_GRAB_STATUS_ALREADY_GRABBED = 1,
     XCB_GRAB_STATUS_INVALID_TIME = 2,
     XCB_GRAB_STATUS_NOT_VIEWABLE = 3,
     XCB_GRAB_STATUS_FROZEN = 4
} xcb_grab_status_t;

Sadly, I have no good suggestion on what to do about this random grab or 
how to figure out which program grabbed the mouse.

Cheers,
Uli
-- 
Nothing would make me happier than being happy
     -- Barney
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 839 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20240103/b2cb4ec9/attachment.c>


More information about the Xcb mailing list