From: Peter Hutterer Date: Tue, 3 Mar 2009 05:44:45 +0000 (+1000) Subject: Add test_xi2 for xi2 testing. X-Git-Url: https://diplodocus.org/git/xorg-xinput/commitdiff_plain/57940c7995a3779792213468cafe7d982d009035?hp=3cad22debfaceca754fc166ca766d92b7a8faf70 Add test_xi2 for xi2 testing. --- diff --git a/src/Makefile.am b/src/Makefile.am index 1efddb8..a6dedb7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,8 +26,8 @@ xinput_LDADD = $(XINPUT_LIBS) if HAVE_XI2 - xinput2_files = hierarchy.c setcp.c -endif # HAVE_XI2 +xinput2_files = hierarchy.c setcp.c test_xi2.c +endif xinput_SOURCES = \ buttonmap.c \ diff --git a/src/test_xi2.c b/src/test_xi2.c new file mode 100644 index 0000000..ecaf0dc --- /dev/null +++ b/src/test_xi2.c @@ -0,0 +1,104 @@ +/* + * Copyright © 2009 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + + +#include "xinput.h" + + +#define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7))) + +static Window create_win(Display *dpy) +{ + Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, + 200, 0, 0, WhitePixel(dpy, 0)); + + XMapWindow(dpy, win); + XFlush(dpy); + return win; +} + +int +test_xi2(Display *display, + int argc, + char *argv[], + char *name, + char *desc) +{ + int i; + XIDeviceEventMask mask; + Window win; + + list(display, argc, argv, name, desc); + win = create_win(display); + + /* Select for motion events */ + mask.deviceid = AllDevices; + mask.mask_len = 1; + mask.mask = calloc(1, sizeof(char)); + mask.mask[0] = XI_ButtonPressMask | XI_ButtonReleaseMask | XI_MotionMask | + XI_KeyPressMask | XI_KeyReleaseMask; + XISelectEvent(display, win, &mask, 1); + free(mask.mask); + + while(1) + { + XIEvent ev; + XNextEvent(display, (XEvent*)&ev); + if (ev.type == GenericEvent) + { + XIDeviceEvent *event = (XIDeviceEvent*)&ev; + double *val; + + printf("EVENT type %d\n", event->evtype); + printf(" device: %d (%d)\n", event->deviceid, event->sourceid); + printf(" detail: %d\n", event->detail); + printf(" buttons:"); + for (i = 0; i < event->buttons->mask_len * 8; i++) + if (BitIsOn(event->buttons->mask, i)) + printf(" %d", i); + printf("\n"); + + printf(" modifiers: locked 0x%x latched 0x%x base 0x%x\n", + event->mods->locked, event->mods->latched, + event->mods->base); + printf(" group: locked 0x%x latched 0x%x base 0x%x\n", + event->group->locked, event->group->latched, + event->group->base); + printf(" valuators:"); + + val = event->valuators->values; + for (i = 0; i < event->valuators->mask_len * 8; i++) + if (BitIsOn(event->valuators->mask, i)) + printf(" %.2f", *val++); + printf("\n"); + + printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n", + event->root, event->event, event->child); + } + + XIFreeEventData(&ev); + } + + return EXIT_SUCCESS; +} diff --git a/src/xinput.c b/src/xinput.c index 88fe2fa..cc85aff 100644 --- a/src/xinput.c +++ b/src/xinput.c @@ -106,6 +106,10 @@ static entry drivers[] = " ", set_clientpointer }, + { "test-xi2", + "", + test_xi2, + }, #endif { "list-props", " [ ...]",