XSETDEVICEFOCUS(3)

πŸŽ€ XSETDEVICEFOCUS(3) β€” the whole manual page, bestie πŸŽ€

okay so. you wanna control the focus of your extension input devices? this is literally the page for that. it's XSetDeviceFocus and XGetDeviceFocus from the X Input extension, and yes, it's giving main character energy. let's go. πŸ’–


✨ NAME ✨

XSetDeviceFocus, XGetDeviceFocus β€” control extension input device focus. that's it, that's the name. slay.


🌸 SYNOPSIS 🌸

first things first, you gotta include the header:

#include <X11/extensions/XInput.h>

then here are the two functions, exactly as they are, no cap:

XSetDeviceFocus( Display *display,
                 XDevice *device,
                 Window focus,
                 int revert_to,
                 Time time);

XGetDeviceFocus( Display *display,
                 XDevice *device,
                 Window *focus_return,
                 int *revert_to_return,
                 int * time_return);

πŸ¦‹ Arguments πŸ¦‹

here's the breakdown of every single argument, one by one, because we do NOT skip:

  • display β€” the connection to the X server. your lil pipeline to the server, bestie.
  • device β€” the device whose focus is about to be queried or changed. yes, that device.
  • focus β€” specifies the window, PointerRoot, FollowKeyboard, or None.
  • focus_return β€” returns the focus window, PointerRoot, FollowKeyboard, or None.
  • revert_to β€” tells you where the input focus reverts to if the window becomes not viewable. you can pass RevertToParent, RevertToPointerRoot, RevertToFollowKeyboard, or RevertToNone.
  • revert_to_return β€” returns the current focus state: RevertToParent, RevertToPointerRoot, RevertToFollowKeyboard, or RevertToNone.
  • time_return β€” returns the last_focus_time for the device.
  • time β€” specifies the time. you can pass either a timestamp or CurrentTime.

πŸ’œ DESCRIPTION πŸ’œ

so the XSetDeviceFocus request changes the focus of the specified device and its last-focus-change time. iconic. but heads up β€” it has no effect if the specified time is earlier than the current last-focus-change time, or if it's later than the current X server time. otherwise, the last-focus-change time gets set to the specified time, and CurrentTime is replaced by the current X server time. and bestie, XSetDeviceFocus causes the X server to generate DeviceFocusIn and DeviceFocusOut events. periodt.

now, depending on the focus argument, here's what goes down:

  • if focus is None, all device events are discarded until a new focus window is set, and the revert_to argument is ignored. just ignored. bye.
  • if focus is a window, it becomes the device's focus window. if a generated device event would normally be reported to this window or one of its inferiors, the event is reported as usual. otherwise, the event is reported relative to the focus window.
  • if focus is PointerRoot, the focus window is dynamically taken to be the root window of whatever screen the pointer is on at each event from the specified device. in this case, the revert_to argument is ignored. again. ignored.
  • if focus is FollowKeyboard, the focus window is dynamically taken to be the window to which the X keyboard focus is set at each input event.

okay and now the important part β€” the specified focus window must be viewable at the time XSetDeviceFocus is called, or a BadMatch error results. so don't be messy. if the focus window later becomes not viewable, the X server evaluates the revert_to argument to figure out the new focus window, like this:

  • if revert_to is RevertToParent, the focus reverts to the parent (or the closest viewable ancestor), and the new revert_to value is taken to be RevertToNone.
  • if revert_to is RevertToPointerRoot, RevertToFollowKeyboard, or RevertToNone, the focus reverts to PointerRoot, FollowKeyboard, or None, respectively.

when the focus reverts, the X server generates DeviceFocusIn and DeviceFocusOut events, but the last-focus-change time is not affected. noted. πŸ“

now here's a lil reality check: input extension devices are not required to support the ability to be focused. attempting to set the focus of a device that doesn't support this request will result in a BadMatch error. rip. so how do you know if a device can do it? whether or not a given device can support this request can be determined by the information returned by XOpenDevice. for those devices that do support focus, XOpenDevice will return an XInputClassInfo structure with the input_class field equal to the constant FocusClass (defined in the file XI.h). iykyk. ✨

XSetDeviceFocus can generate BadDevice, BadMatch, BadValue, and BadWindow errors.

and the XGetDeviceFocus request returns the focus window and the current focus state. simple, clean, gorgeous.

but β€” not all input extension devices can be focused. attempting to query the focus state of a device that can't be focused results in a BadMatch error. a device that can be focused returns information for input Class Focus when an XOpenDevice request is made.

XGetDeviceFocus can generate BadDevice, and BadMatch errors.


πŸ”₯ DIAGNOSTICS πŸ”₯

here come the errors, bestie. know them, respect them, fear them a little:

  • BadDevice β€” an invalid device was specified. the specified device does not exist, or has not been opened by this client via XOpenInputDevice. this error may also occur if the specified device is the X keyboard or X pointer device. 😭
  • 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.
  • BadWindow β€” a value for a Window argument does not name a defined Window. rude tbh.
  • BadMatch β€” this error may occur if an XGetDeviceFocus or XSetDeviceFocus request was made specifying a device that the server implementation does not allow to be focused.

🌈 reminder: check your revert_to, make sure your focus window is viewable, and verify your device supports focus before you start drama. the server will hit you with a BadMatch and it will not be cute. πŸ’€

okay that's the whole page, you ate it, you're obsessed, you're a Unix girlie now. this lil manual dropped on 05/18/2026, so if you're reading it after that, you're reading vintage content. stay focused (pun fully intended) and go be the main character of your own X server. πŸ«Άβœ¨πŸ’…

πŸ“¦ where this page comes from