// gcc rawmotion.c -o rawmotion -lXi #include #include #include #include #include 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_value = 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_value %d: %f [valuator %f] ", i, *raw_value, *valuator); raw_value++; 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); } XCloseDisplay(dpy); return 0; }