xcb_set_input_focus(3)

๐Ÿ“ฆ
version 1.17.0 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿ’– xcb_set_input_focus โ€” bestie, we're setting the input focus ๐Ÿ’–

okay so this is a page from the XCB Requests corner of the manual, and today's main character is xcb_set_input_focus(3). yes we're doing X11 protocol stuff. yes it's giving โœจkeyboard authorityโœจ. let's go.


๐ŸŒธ NAME ๐ŸŒธ

xcb_set_input_focus โ€” sets input focus ๐ŸŽฏ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

#include <xcb/xproto.h>

โœจ Request function โœจ

xcb_void_cookie_t xcb_set_input_focus(xcb_connection_t *conn,
       uint8_t revert_to, xcb_window_t focus, xcb_timestamp_t time);

like. look at her. four little args and she controls who gets the keyboard. iconic behavior honestly ๐Ÿ’…


๐ŸŽ€ REQUEST ARGUMENTS ๐ŸŽ€

  • conn โ€” the XCB connection to X11. your lil hotline to the server, bestie ๐Ÿซถ
  • revert_to โ€” one of the following values. this is the "what happens when things go sideways" setting, so pay attention:
    • XCB_INPUT_FOCUS_NONE โ€” the focus reverts to XCB_NONE, so literally no window will have the input focus. nobody. zero. empty. ๐Ÿ’€
    • XCB_INPUT_FOCUS_POINTER_ROOT โ€” the focus reverts to XCB_POINTER_ROOT respectively. when the focus reverts, FocusIn and FocusOut events are generated, but the last-focus-change time is not changed. (not me remembering that one specific exception, but yes, noted ๐Ÿ“)
    • XCB_INPUT_FOCUS_PARENT โ€” the focus reverts to the parent (or closest viewable ancestor), and the new revert_to value is XCB_INPUT_FOCUS_NONE.
    • XCB_INPUT_FOCUS_FOLLOW_KEYBOARD โ€” NOT YET DOCUMENTED. only relevant for the xinput extension. (mystery queen. we don't know her. ๐Ÿ”ฎ)

so basically revert_to specifies what happens when the focus window becomes unviewable (that's if focus is neither XCB_NONE nor XCB_POINTER_ROOT).

  • focus โ€” the window to focus. all keyboard events will be reported to this window. the window must be viewable (TODO), or a xcb_match_error_t occurs (TODO).
    • if focus is XCB_NONE (TODO), all keyboard events are discarded until a new focus window is set. keyboard goes quiet. ghost town energy ๐Ÿ‘ป
    • if focus is XCB_POINTER_ROOT (TODO), focus is on the root window of the screen on which the pointer is on currently.
  • time โ€” timestamp to avoid race conditions when running X over the network. bestie, networking is chaos and this is your little shield ๐Ÿ›ก๏ธ
    • the special value XCB_CURRENT_TIME will be replaced with the current server time. slay, let the server decide โฐ

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

changes the input focus and the last-focus-change time. two for one, we love efficiency.

if the specified time is earlier than the current last-focus-change time, the request is ignored (to avoid race conditions when running X over the network). so if you're late with your timestamp, you get nothing. the request said "too slow" and moved on ๐Ÿƒโ™€๏ธ๐Ÿ’จ

a FocusIn and FocusOut event is generated when focus is changed. events! drama! the group chat is notified ๐Ÿ“ฃ


โญ RETURN VALUE โญ

returns an xcb_void_cookie_t. errors (if any) have to be handled in the event loop. no sneaky return-value checks here, you gotta go to the loop for that.

if you want to handle errors directly with xcb_request_check instead, use xcb_set_input_focus_checked. see xcb-requests(3) for details. ๐Ÿ‘‘


๐Ÿ”ฅ ERRORS ๐Ÿ”ฅ

  • xcb_match_error_t โ€” the specified focus window is not viewable.
  • xcb_value_error_t โ€” TODO: Reasons? (the manpage itself is like "idk bestie" ๐Ÿ˜ญ)
  • xcb_window_error_t โ€” the specified focus window does not exist.

๐ŸŒˆ SEE ALSO ๐ŸŒˆ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

generated from xproto.xml. contact xcb@lists.freedesktop.org for corrections and improvements. they're literally asking for feedback, so if you spot something, tell them ๐Ÿซถ


heads up bestie: time matters, focus has to be viewable or you eat an error, and the two TODOs plus the NOT YET DOCUMENTED are exactly how the original page reads. i'm not making anything up, i'm just being cute about it ๐Ÿ’…

and that's the whole page, fr fr. this was X Version 11, from libxcb 1.17.0, and you just read xcb_set_input_focus(3). mwah, go focus a window responsibly ๐ŸŽ€โœจ