xcb_grab_button(3)
β¨ NAME β¨
xcb_grab_button β grab pointer button(s) π±οΈπ
okay so real talk, bestie: this is the page for xcb_grab_button(3), straight outta the XCB Requests manual, and it's about telling the X server "hey, when someone clicks like this, on this window, with these keys held, I want in on that." passive grab city. let's get into it π
πΈ SYNOPSIS πΈ
#include <xcb/xproto.h>
Request function
xcb_void_cookie_t xcb_grab_button(xcb_connection_t *conn,
uint8_t owner_events, xcb_window_t grab_window,
uint16_t event_mask, uint8_t pointer_mode, uint8_t keyboard_mode,
xcb_window_t confine_to, xcb_cursor_t cursor, uint8_t button,
uint16_t modifiers);
π REQUEST ARGUMENTS π
connβ your XCB connection to X11. the whole line to the server, periodt.owner_eventsβ if it's1, thegrab_windowis still gonna get the pointer events. if it's0, events do not get reported to thegrab_window. that's it, that's the whole bit π«Άgrab_windowβ the window where you want the pointer grabbed. the main character of this whole operation.event_maskβ which pointer events get reported to the client.
TODO: which values? π yeah the page literally says that, bestie, we don't know either.
pointer_modeβ one of these:XCB_GRAB_MODE_SYNCβ the state of the keyboard appears to freeze: no further keyboard events are generated by the server until the grabbing client issues a releasingAllowEventsrequest or until the keyboard grab is released. π₯ΆXCB_GRAB_MODE_ASYNCβ keyboard event processing continues normally. as you were β¨
keyboard_modeβ one of these:XCB_GRAB_MODE_SYNCβ the state of the keyboard appears to freeze: no further keyboard events are generated by the server until the grabbing client issues a releasingAllowEventsrequest or until the keyboard grab is released.XCB_GRAB_MODE_ASYNCβ keyboard event processing continues normally.
not me noticing both modes are described with the exact same keyboard-flavored text π that's genuinely what the page says, so that's what you get. keeping the facts, keeping the vibes.
confine_toβ the window you wanna confine the pointer in (so the user literally cannot move the pointer out of that window π). the special valueXCB_NONEmeans don't confine the pointer at all β free range pointer, let it roam π¦cursorβ the cursor that should be displayed, orXCB_NONEto not change the cursor.buttonβ one of these:XCB_BUTTON_INDEX_ANYβ any of the following (or none):XCB_BUTTON_INDEX_1β the left mouse button.XCB_BUTTON_INDEX_2β the right mouse button.XCB_BUTTON_INDEX_3β the middle mouse button.XCB_BUTTON_INDEX_4β scroll wheel. TODO: direction? π€XCB_BUTTON_INDEX_5β scroll wheel. TODO: direction? π€
yeah, 4 and 5 are both scroll wheel and the page is like "TODO: direction?" β iconically unhelpful, we're just reporting it fr fr.
modifiersβ the modifiers to grab. using the special valueXCB_MOD_MASK_ANYmeans grab the pointer with all possible modifier combinations. every single one. all of them. π
π DESCRIPTION π
so this request establishes a passive grab. the pointer gets actively grabbed as described in GrabPointer, 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.
the interpretation of the remaining arguments is the same as for GrabPointer. π
the active grab is terminated automatically when the logical state of the pointer has all buttons released, independent of the logical state of modifier keys. note that the logical state of a device (as seen by means of the protocol) may lag the physical state if device event processing is frozen. π§
this request overrides all previous passive grabs by the same client on the same button/key combinations on the same window.
a modifier of AnyModifier is equivalent to issuing the request for all possible modifier combinations (including the combination of no modifiers). it is not required that all specified modifiers 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 button specified currently be assigned to a physical button.
β οΈ the drama part: anAccesserror is generated if some other client has already issued aGrabButtonrequest with the same button/key combination on the same window. when usingAnyModifierorAnyButton, the request fails completely (no grabs are established at all, zero, nada π), and anAccesserror is generated if there is a conflicting grab for any combination. also β the request has no effect on an active grab. so yeah, know that before you go grabbing, bestie.
π RETURN VALUE π
returns an xcb_void_cookie_t. errors (if any) have to be handled in the event loop.
if you wanna handle errors directly with xcb_request_check instead, use xcb_grab_button_checked. see xcb-requests(3) for details. π«‘
π ERRORS π
xcb_access_error_tβ another client has already issued aGrabButtonwith the same button/key combination on the same window. rude, honestly.xcb_cursor_error_tβ the specified cursor does not exist. πxcb_value_error_tβ TODO: reasons? π€·ββοΈ (again, the page's words, not ours)xcb_window_error_tβ the specified window does not exist.
π¦ SEE ALSO π¦
π§ AUTHOR π§
generated from xproto.xml. contact xcb@lists.freedesktop.org for corrections and improvements. π§
and that's the whole page, bestie, we ate and left no crumbs β¨ this was xcb_grab_button(3) from the XCB Requests manual, brought to you by X Version 11 and libxcb 1.17.0. go forth and grab those buttons responsibly, ily πππ
π¦ where this page comes from
- alpine 3.22: libxcb-doc 1.17.0-r0 Β· MIT
- alpine 3.23: libxcb-doc 1.17.0-r1 Β· MIT
- alpine 3.24: libxcb-doc 1.17.0-r2 Β· MIT
- arch rolling: libxcb 1.17.0-1 Β· X11
- centos-stream 10: libxcb-devel 1.17.0-3.el10 Β· X11
- debian trixie: libxcb-doc 1.17.0-2
- fedora 43: libxcb-devel 1.17.0-6.fc43 Β· X11
- fedora 43: libxcb-devel 1.17.0-6.fc43 Β· X11
- fedora 44: libxcb-devel 1.17.0-7.fc44 Β· X11
- fedora 44: libxcb-devel 1.17.0-7.fc44 Β· X11
- nixpkgs unstable: libxcb 1.17.0
- opensuse-leap 16.0: libxcb-devel-doc 1.17.0-160000.2.2 Β· MIT
- ubuntu questing: libxcb-doc 1.17.0-2build1
- ubuntu resolute: libxcb-doc 1.17.0-2ubuntu1
- ubuntu stonking: libxcb-doc 1.17.0-2ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms