Created
May 27, 2021 06:30
-
-
Save jordansissel/49d0d1afe87d8654f31a255b4b613d47 to your computer and use it in GitHub Desktop.
xinput list devices showing pointer locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <X11/Xlib.h> | |
#include <X11/extensions/XInput.h> | |
#include <X11/extensions/XInput2.h> | |
int main() | |
{ | |
Display *d = XOpenDisplay(":0"); | |
if (d == NULL) { | |
printf("Display failed to open"); | |
} | |
int device_count; | |
// Fetch the list of XInput devices. | |
// Store the "count" of these devices in `device_count` | |
XDeviceInfo *inputs = XListInputDevices(d, &device_count); | |
for (int i = 0; i < device_count; i++) { | |
// Only process pointer inputs | |
if (inputs[i].use == IsXPointer) { | |
double x, y; | |
// Create throw-away storage for saving things we don't want | |
Window _w; | |
double _d; | |
XIButtonState _xib; | |
XIModifierState _xim; | |
XIGroupState _xig; | |
XIQueryPointer(d, // display | |
inputs[i].id, // deviceid | |
DefaultRootWindow(d), // "win" | |
// The rest of the arguments are passed as pointers intended for XIQueryPointer | |
// to store data into | |
&_w, // root_return, we don't care for this example. | |
&_w, // child_return, we don't care for this example. | |
&x, // X coordinate | |
&y, // Y coordinate | |
&_d, // win_x_return, don't care for this example. | |
&_d, // win_y_return, don't care for this example. | |
&_xib, // buttons_return, don't care for this example. | |
&_xim, // modifiers_return, don't care for this example. | |
&_xig // group_return, don't care for this example. | |
); | |
printf("Pointer id:%lu at location %0.0f,%0.0f\n", inputs[i].id, x, y); | |
} | |
} | |
XFreeDeviceList(inputs); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% gcc main.c $(pkg-config --libs x11 xi --cflags) -o xinput-example | |
% ./xinput-example | |
Pointer id:2 at location 1011,756 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment