Created
January 28, 2013 23:50
-
-
Save yasar11732/4660420 to your computer and use it in GitHub Desktop.
This file contains 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/XInput2.h> | |
#include <signal.h> | |
#include <assert.h> | |
int working = 1; | |
void signal_callback_handler(int signum) { | |
working = 0; | |
} | |
int main() { | |
/* Connect to the X server */ | |
signal(SIGINT, signal_callback_handler); | |
signal(SIGTSTP, signal_callback_handler); | |
signal(SIGTERM, signal_callback_handler); | |
Display *dpy = XOpenDisplay(NULL); | |
assert(dpy); | |
/* XInput Extension available? */ | |
int opcode, event, error; | |
if (!XQueryExtension(dpy, "XInputExtension", &opcode, &event, &error)) { | |
printf("X Input extension not available.\n"); | |
return -1; | |
} | |
/* Which version of XI2? We support 2.0 */ | |
int major = 2, minor = 0; | |
if (XIQueryVersion(dpy, &major, &minor) == BadRequest) { | |
printf("XI2 not available. Server supports %d.%d\n", major, minor); | |
return -1; | |
} | |
XIEventMask eventmask; | |
unsigned char mask[1] = { 0 }; /* the actual mask */ | |
eventmask.deviceid = XIAllDevices; | |
eventmask.mask_len = sizeof(mask); /* always in bytes */ | |
eventmask.mask = mask; | |
/* now set the mask */ | |
XISetMask(mask, XI_RawButtonPress); | |
/* select on the window */ | |
XISelectEvents(dpy, DefaultRootWindow(dpy), &eventmask, 1); | |
while(working) { | |
XEvent ev; | |
XNextEvent(dpy, &ev); | |
if (ev.xcookie.type == GenericEvent && | |
ev.xcookie.extension == opcode && | |
XGetEventData(dpy, &ev.xcookie)) | |
{ | |
switch(ev.xcookie.evtype) | |
{ | |
case XI_RawButtonPress: | |
printf("RawButtonPress"); | |
break; | |
} | |
} | |
XFreeEventData(dpy, &ev.xcookie); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
X Error of failed request: XI_BadDevice (invalid Device parameter)
Major opcode of failed request: 131 (XInputExtension)
Minor opcode of failed request: 46 ()
Device id in failed request: 0xad
Serial number of failed request: 15
Current serial number in output stream: 15