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, orNone.focus_returnβ returns the focus window,PointerRoot,FollowKeyboard, orNone.revert_toβ tells you where the input focus reverts to if the window becomes not viewable. you can passRevertToParent,RevertToPointerRoot,RevertToFollowKeyboard, orRevertToNone.revert_to_returnβ returns the current focus state:RevertToParent,RevertToPointerRoot,RevertToFollowKeyboard, orRevertToNone.time_returnβ returns thelast_focus_timefor the device.timeβ specifies the time. you can pass either a timestamp orCurrentTime.
π 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
focusisNone, all device events are discarded until a new focus window is set, and therevert_toargument is ignored. just ignored. bye. - if
focusis 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
focusisPointerRoot, 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, therevert_toargument is ignored. again. ignored. - if
focusisFollowKeyboard, 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_toisRevertToParent, the focus reverts to the parent (or the closest viewable ancestor), and the newrevert_tovalue is taken to beRevertToNone. - if
revert_toisRevertToPointerRoot,RevertToFollowKeyboard, orRevertToNone, the focus reverts toPointerRoot,FollowKeyboard, orNone, 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 viaXOpenInputDevice. 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 aWindowargument does not name a defined Window. rude tbh.BadMatchβ this error may occur if anXGetDeviceFocusorXSetDeviceFocusrequest was made specifying a device that the server implementation does not allow to be focused.
π reminder: check yourrevert_to, make sure your focus window is viewable, and verify your device supports focus before you start drama. the server will hit you with aBadMatchand 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
- fedora 44: libXi-devel 1.8.3-1.fc44 Β· MIT-open-group AND SMLNJ AND MIT
- fedora 44: libXi-devel 1.8.3-1.fc44 Β· MIT-open-group AND SMLNJ AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms