xcb_grab_key(3)
π xcb_grab_key(3) π
okay so bestie, welcome to xcb_grab_key β this is one of the XCB Requests pages (from libxcb 1.17.0, X Version 11, if you were wondering who's serving looks today π ). It's a request function, it's giving keyboard-grabbing main character energy, and we're gonna go through the WHOLE thing together. no skimming. grab a snack π
β¨ NAME β¨
xcb_grab_key β grab keyboard key(s). literally just. seizing a key. iconic behavior π
β¨ SYNOPSIS β¨
πΈ Request function πΈ
#include <xcb/xproto.h>
xcb_void_cookie_t xcb_grab_key(xcb_connection_t *conn,
uint8_t owner_events, xcb_window_t grab_window,
uint16_t modifiers, xcb_keycode_t key, uint8_t pointer_mode,
uint8_t keyboard_mode);
that's the whole signature bestie, take it in π«Ά
β¨ REQUEST ARGUMENTS β¨
connβ the XCB connection to X11. your lil hotline to the server πowner_eventsβ if it's1, thegrab_windowwill still get the key events. if it's0, events are not reported to thegrab_window. that's the whole deal, no in-between β¨grab_windowβ specifies the window on which the key should be grabbed. which window is getting the honor πmodifiersβ the modifiers to grab.
using the special value XCB_MOD_MASK_ANY means grab the key with all possible modifier combinations. every single one. no cap.
keyβ the keycode of the key to grab.
the special value XCB_GRAB_ANY means grab any key. yes really, any. slay π
pointer_modeβ one of the following values: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. frozen. paused. on ice π§XCB_GRAB_MODE_ASYNCβ keyboard event processing continues normally. business as usual, no drama π
keyboard_modeβ one of the following values: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.
(yes bestie, pointer_mode and keyboard_mode have the exact same two options listed. that's not me being lazy, that's literally the page π)
β¨ DESCRIPTION β¨
so what does this actually do? it establishes a passive grab on the keyboard. in the future, the keyboard is actively grabbed (as for GrabKeyboard), the last-keyboard-grab time is set to the time at which the key was pressed (as transmitted in the KeyPress event), and the KeyPress event is reported if all of the following conditions are true:
- The keyboard is not grabbed and the specified key (which can itself be a modifier key) is logically pressed when the specified modifier keys are logically down, and no other modifier keys are logically down.
- Either the
grab_windowis an ancestor of (or is) the focus window, or thegrab_windowis a descendant of the focus window and contains the pointer. - A passive grab on the same key combination does not exist on any ancestor of
grab_window.
the interpretation of the remaining arguments is as for XGrabKeyboard. the active grab is terminated automatically when the logical state of the keyboard has the specified key released (independent of the logical state of the modifier keys), at which point a KeyRelease event is reported to the grabbing window.
ngl, important note: the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen. so your app might be a lil behind on the tea β
a modifiers argument 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 modifiers specified have currently assigned KeyCodes. a keycode argument of AnyKey is equivalent to issuing the request for all possible KeyCodes. otherwise, the specified keycode must be in the range specified by min_keycode and max_keycode in the connection setup, or a BadValue error results. fr fr, mind your ranges π
if some other client has issued a XGrabKey with the same key combination on the same window, a BadAccess error results. when using AnyModifier or AnyKey, the request fails completely, and a BadAccess error results (no grabs are established) if there is a conflicting grab for any combination. like, all or nothing, periodt.
β¨ RETURN VALUE β¨
returns an xcb_void_cookie_t. errors (if any) have to be handled in the event loop. that's the vibe check β you don't get them handed to you π
if you want to handle errors directly with xcb_request_check instead, use xcb_grab_key_checked. see xcb-requests(3) for details.
β¨ ERRORS β¨
xcb_access_error_tβ another client has already issued aGrabKeywith the same button/key combination on the same window. somebody beat you to it bestie πxcb_value_error_tβ the key is notXCB_GRAB_ANYand not in the range specified bymin_keycodeandmax_keycodein the connection setup.xcb_window_error_tβ the specified window does not exist. it's giving ghost town π»
β¨ SEE ALSO β¨
xcb-requests(3), xcb_grab_keyboard(3)
β¨ AUTHOR β¨
generated from xproto.xml. contact xcb@lists.freedesktop.org for corrections and improvements. (they're the ones to @ when something's off, not me π)
okay that's the whole page, you ate that. this was X Version 11, from libxcb 1.17.0, and the page itself is xcb_grab_key(3) β now go grab a key and be the main character of your own event loop β¨ππ¦
π¦ 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