XGrabButton(3)
π XGrabButton(3) β the manual page, but make it make sense β¨
okay so bestie, this is a page from the Xlib functions manual β XGrabButton and XUngrabButton. think of it as the group chat for handling mouse buttons in X11. let's get into it. π±οΈπ
πΈ SYNTAX πΈ
like, literally here's the exact function signatures, don't @ me:
int XGrabButton(Display *display, unsigned int button, unsigned int
modifiers, Window grab_window, Bool owner_events, unsigned int
event_mask, int pointer_mode, keyboard_mode, Window confine_to,
Cursor cursor);
int XUngrabButton(Display *display, unsigned int button, unsigned int
modifiers, Window grab_window);
π ARGUMENTS π
okay so every single one of these matters, no skipping:
buttonβ Specifies the pointer button that is to be grabbed or released orAnyButton. like, which mouse button we're talking about, or literally all of them. π±οΈconfine_toβ Specifies the window to confine the pointer in orNone. keep the mouse trapped in a specific window, or let it roam free bestie. πͺcursorβ Specifies the cursor that is to be displayed orNone. what the mouse pointer looks like, or nothing at all. πdisplayβ Specifies the connection to the X server. the X server said "let me introduce myself." πevent_maskβ Specifies which pointer events are reported to the client. The mask is the bitwise inclusive OR of the valid pointer event mask bits. basically, which events you want to hear about β combine them with bitwise inclusive OR. π¨grab_windowβ Specifies the grab window. the window where the grabbing happens. πkeyboard_modeβ Specifies further processing of keyboard events. You can passGrabModeSyncorGrabModeAsync. keyboard vibes: sync or async, pick one. β¨οΈmodifiersβ Specifies the set of keymasks orAnyModifier. The mask is the bitwise inclusive OR of the valid keymask bits. like, which modifier keys (shift, ctrl, etc.) are part of the combo. πΉowner_eventsβ Specifies a Boolean value that indicates whether the pointer events are to be reported as usual or reported with respect to the grab window if selected by the event mask. do events go to the usual place or get redirected to the grab window? your call. π«Άpointer_modeβ Specifies further processing of pointer events. You can passGrabModeSyncorGrabModeAsync. pointer vibes: sync or async. π±οΈ
β¨ DESCRIPTION β¨
The XGrabButton function establishes a passive grab. like, it's not grabbing right now, but it's ready to grab in the future. π
In the future, the pointer is actively grabbed (as for XGrabPointer), the last-pointer-grab time is set to the time at which the button was pressed (as transmitted in the ButtonPress event), and the ButtonPress event is reported if all of the following conditions are true:
- The pointer is not grabbed, and the specified button is logically pressed when the specified modifier keys are logically down, and no other buttons or modifier keys are logically down. π―
- The
grab_windowcontains the pointer. πͺ - The
confine_towindow (if any) is viewable. π - A passive grab on the same button/key combination does not exist on any ancestor of
grab_window. like, no other grab is already happening upstream. π«
The interpretation of the remaining arguments is as for XGrabPointer. The active grab is terminated automatically when the logical state of the pointer has all buttons released (independent of the state of the logical modifier keys), at which point a ButtonRelease event is reported to the grabbing window. so when you let go of all the buttons, the grab ends and you get a ButtonRelease. π
β οΈ Note that the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen. like, what the app thinks is happening might be behind what's actually happening if event processing is paused. π
This request overrides all previous grabs by the same client on the same button/key combinations on the same window. A modifiers of AnyModifier is equivalent to issuing the grab request for all possible modifier combinations (including the combination of no modifiers). It is not required that all modifiers specified have currently assigned KeyCodes. A button of AnyButton is equivalent to issuing the request for all possible buttons. Otherwise, it is not required that the specified button currently be assigned to a physical button. so AnyModifier and AnyButton are like "do it for literally everything," and you don't even need those keys/buttons to actually exist yet. π
If some other client has already issued a XGrabButton with the same button/key combination on the same window, a BadAccess error results. When using AnyModifier or AnyButton, the request fails completely, and a BadAccess error results (no grabs are established) if there is a conflicting grab for any combination. XGrabButton has no effect on an active grab. like, if someone else already grabbed that combo, you get BadAccess β and with the Any options, it's all-or-nothing, no partial grabs. also, it doesn't touch an active grab. π
XGrabButton can generate BadCursor, BadValue, and BadWindow errors. noted. π
The XUngrabButton function releases the passive button/key combination on the specified window if it was grabbed by this client. A modifiers of AnyModifier is equivalent to issuing the ungrab request for all possible modifier combinations, including the combination of no modifiers. A button of AnyButton is equivalent to issuing the request for all possible buttons. XUngrabButton has no effect on an active grab. so it undoes your passive grab, AnyModifier and AnyButton mean "all of them," and it won't stop an active grab. π
XUngrabButton can generate BadValue and BadWindow errors. noted again. π
π DIAGNOSTICS π
BadCursorβ A value for aCursorargument does not name a definedCursor. like, that cursor doesn't exist bestie. π»BadValueβ Some numeric value falls outside the range of values accepted by the request. Unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. Any argument defined as a set of alternatives can generate this error. basically, a number is out of bounds. πBadWindowβ A value for aWindowargument does not name a definedWindow. that window? not a real one. πͺβ
π¦ SEE ALSO π¦
like, go read these too:
XAllowEvents(3), XGrabPointer(3), XGrabKey(3), XGrabKeyboard(3), Xlib - C Language X Interface
that's the whole page bestie, no cap. π
X Version 11 Β· libX11 1.8.14 β this iconic little manual page was brought to you by the X11 era, and yes it's giving vintage but make it slay. π«Άβ¨
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms