Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <X11/Xlib.h>
- #include <X11/extensions/XInput2.h>
- static Window create_win(Display *dpy)
- {
- XIEventMask mask;
- Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200,
- 200, 0, 0, WhitePixel(dpy, 0));
- XSelectInput(dpy, win, ExposureMask);
- mask.mask_len = XIMaskLen(XI_RawMotion);
- mask.mask = calloc(mask.mask_len, sizeof(char));
- mask.deviceid = XIAllMasterDevices;
- memset(mask.mask, 0, mask.mask_len);
- XISetMask(mask.mask, XI_RawMotion);
- XISelectEvents(dpy, DefaultRootWindow(dpy), &mask, 1);
- free(mask.mask);
- XMapWindow(dpy, win);
- XSync(dpy, True);
- return win;
- }
- static void print_rawmotion(XIRawEvent *event)
- {
- int i;
- double *raw_valuator = event->raw_values,
- *valuator = event->valuators.values;
- printf(" device: %d (%d)", event->deviceid, event->sourceid);
- for (i = 0; i < event->valuators.mask_len * 8; i++)
- {
- if (XIMaskIsSet(event->valuators.mask, i))
- {
- printf(" raw_valuator %d: %f", i, *raw_valuator);
- raw_valuator++;
- }
- }
- printf("\n");
- }
- int main (int argc, char **argv)
- {
- Display *dpy;
- int xi_opcode, event, error;
- Window win;
- XEvent ev;
- dpy = XOpenDisplay(NULL);
- if (!dpy) {
- fprintf(stderr, "Failed to open display.\n");
- return -1;
- }
- if (!XQueryExtension(dpy, "XInputExtension", &xi_opcode, &event, &error)) {
- printf("X Input extension not available.\n");
- return -1;
- }
- win = create_win(dpy);
- while(1)
- {
- XGenericEventCookie *cookie = &ev.xcookie;
- XNextEvent(dpy, &ev);
- if (cookie->type != GenericEvent ||
- cookie->extension != xi_opcode ||
- !XGetEventData(dpy, cookie))
- continue;
- switch(cookie->evtype)
- {
- case XI_RawMotion:
- print_rawmotion(cookie->data);
- break;
- }
- XFreeEventData(dpy, cookie);
- static int i = 0;
- i++;
- if(i > 10)
- {
- XWarpPointer(dpy, None, win, 0, 0, 0, 0, 100, 100);
- i = 0;
- }
- }
- XCloseDisplay(dpy);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement