XGETDEVICECONTROL(3)

πŸ’– XGETDEVICECONTROL πŸ’–

okay bestie, sit down, hydrate, because today we're learning about XGetDeviceControl and XChangeDeviceControl β€” the iconic duo that lets you query and change input device controls. yes, that's the whole name, we're not being mysterious. it's giving "ask the device a question, then tell it what to do" and honestly? slay. πŸŽ€


✨ SYNOPSIS ✨

#include <X11/extensions/XInput.h>

XDeviceControl *XGetDeviceControl( Display *display,
                                   XDevice *device,
                                   int *controlType);

int XChangeDeviceControl( Display *display,
                          XDevice *device,
                          int controlType,
                          XDeviceControl *control);

now the little arguments, one by one, no skipping (i would never) 🌸

  • display β€” the connection to the X server. your lil phone line to the server, basically.
  • device β€” the device whose control is getting interrogated or modified. yes, interrogated. it did nothing wrong but here we are πŸ’€
  • controlType β€” the type of control being interrogated or changed.
  • control β€” the address of an XDeviceControl structure holding the new values for the Device.

🌈 DESCRIPTION 🌈

so these requests exist to manipulate those input devices that support device control. and here's the tea: a BadMatch error gets generated if the device you're asking about does not support any device controls. so rude of it, but okay.

the valid device control types that play nice with these requests are:

  • DEVICE_RESOLUTION β€” queries or changes the resolution of valuators on input devices. that's the one, that's the list, periodt. ✨

the XGetDeviceControl request returns a pointer to an XDeviceControl structure. and heads up β€” XGetDeviceControl can generate a BadDevice or BadMatch error. 😭

the XChangeDeviceControl request modifies the values of one control on the specified device. that control is identified by the id field of the XDeviceControl structure that you pass along with the request. iykyk.

and XChangeDeviceControl can generate a BadDevice, BadMatch, or BadValue error. three whole errors, main character energy fr fr.


🧚 STRUCTURES 🧚

every control is described by a structure that's specific to that control, and these structures are defined in the file XInput.h. no cap.

XDeviceControl is a generic structure β€” it holds two fields that sit at the beginning of each class of control:

typedef struct {
    XID class;
    int length;
} XDeviceControl;

the XDeviceResolutionState structure defines the information returned for device resolution, for devices with valuators:

typedef struct {
    XID control;
    int length;
    int num_valuators;
    int* resolutions;
    int* min_resolutions;
    int* max_resolutions;
} XDeviceResolutionState;

and the XDeviceResolutionControl structure defines the attributes that can be controlled for keyboard Devices:

typedef struct {
    XID control;
    int length;
    int first_valuator;
    int num_valuators;
    int* resolutions;
} XDeviceResolutionControl;

πŸ’… DIAGNOSTICS πŸ’…

  • BadDevice β€” an invalid device was specified. the specified device doesn't exist, or it hasn't been opened by this client via XOpenInputDevice. this error may also happen if some other client has caused the specified device to become the X keyboard or X pointer device via the XChangeKeyboardDevice or XChangePointerDevice requests. (so basically, someone else stole your device and now you're in your flop era. πŸ™ˆ)
  • BadMatch β€” this error may occur if an XGetDeviceControl request was made specifying a device that has no controls, or if an XChangeDeviceControl request was made with an XDeviceControl structure that contains an invalid Device type. it may also occur if an invalid combination of mask bits is specified (DvKey but no DvAutoRepeatMode for keyboard Devices), or if an invalid KeySym is specified for a string Device. 😭
  • BadValue β€” some numeric value falls outside the range of values accepted by the XChangeDeviceControl request. unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. and any argument defined as a set of alternatives can generate this error. watch those numbers bestie, the server is NOT flexible.
fr fr reminder: BadMatch can pop off just from the device not supporting controls at all β€” always vibe check before you send the request. πŸ’–

okay that's the whole page, you ate that, i'm obsessed. 🫢 this was pulled from the XGetDeviceControl(3) page, dated 05/18/2026 β€” go forth and control your devices, but like, consensually. bye bestie!! πŸ’œβœ¨

πŸ“¦ where this page comes from