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 or AnyButton. like, which mouse button we're talking about, or literally all of them. πŸ–±οΈ
  • confine_to β€” Specifies the window to confine the pointer in or None. keep the mouse trapped in a specific window, or let it roam free bestie. πŸͺŸ
  • cursor β€” Specifies the cursor that is to be displayed or None. 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 pass GrabModeSync or GrabModeAsync. keyboard vibes: sync or async, pick one. ⌨️
  • modifiers β€” Specifies the set of keymasks or AnyModifier. 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 pass GrabModeSync or GrabModeAsync. 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_window contains the pointer. πŸͺŸ
  • The confine_to window (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 a Cursor argument does not name a defined Cursor. 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 a Window argument does not name a defined Window. 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