From 248faefc957a9b0877384842540b2d935e1b5c07 Mon Sep 17 00:00:00 2001 From: Benjamin Close Date: Wed, 24 Jun 2009 11:55:00 +0930 Subject: Obtain the XInput opcode and check that GenericEvents are actually XI events Signed-off-by: Benjamin Close Signed-off-by: Peter Hutterer --- src/test_xi2.c | 4 ++-- src/xinput.c | 8 ++++++++ src/xinput.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/test_xi2.c b/src/test_xi2.c index 2201692..b08a395 100644 --- a/src/test_xi2.c +++ b/src/test_xi2.c @@ -240,7 +240,7 @@ test_sync_grab(Display *display, Window win) XIEvent ev; XNextEvent(display, (XEvent*)&ev); - if (ev.type == GenericEvent) + if (ev.type == GenericEvent && ev.extension == xi_opcode ) { XIDeviceEvent *event = (XIDeviceEvent*)&ev; print_deviceevent(event); @@ -325,7 +325,7 @@ test_xi2(Display *display, { XIEvent ev; XNextEvent(display, (XEvent*)&ev); - if (ev.type == GenericEvent) + if (ev.type == GenericEvent && ev.extension == xi_opcode) { XIDeviceEvent *event = (XIDeviceEvent*)&ev; diff --git a/src/xinput.c b/src/xinput.c index 275fa1b..8340211 100644 --- a/src/xinput.c +++ b/src/xinput.c @@ -25,6 +25,8 @@ #include #include +int xi_opcode; + typedef int (*prog)(Display* display, int argc, char *argv[], char *prog_name, char *prog_desc); @@ -257,6 +259,7 @@ main(int argc, char * argv[]) Display *display; entry *driver = drivers; char *func; + int event, error; if (argc < 2) { usage(); @@ -270,6 +273,11 @@ main(int argc, char * argv[]) return EXIT_FAILURE; } + if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &event, &error)) { + printf("X Input extension not available.\n"); + return EXIT_FAILURE; + } + func = argv[1]; while((*func) == '-') func++; diff --git a/src/xinput.h b/src/xinput.h index fd468b0..d44ce09 100644 --- a/src/xinput.h +++ b/src/xinput.h @@ -41,6 +41,7 @@ #define EXIT_FAILURE 0 #endif +extern int xi_opcode; /* xinput extension op code */ XDeviceInfo* find_device_info( Display *display, char *name, Bool only_extended); #if HAVE_XI2 XIDeviceInfo* xi2_find_device_info(Display *display, char *name); -- cgit v1.2.3