]> diplodocus.org Git - xorg-xinput/commitdiff
Add test_xi2 for xi2 testing.
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 3 Mar 2009 05:44:45 +0000 (15:44 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Sat, 21 Mar 2009 12:18:41 +0000 (22:18 +1000)
src/Makefile.am
src/test_xi2.c [new file with mode: 0644]
src/xinput.c

index 1efddb8..a6dedb7 100644 (file)
@@ -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 (file)
index 0000000..ecaf0dc
--- /dev/null
@@ -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;
+}
index 88fe2fa..cc85aff 100644 (file)
@@ -106,6 +106,10 @@ static entry drivers[] =
       "<window> <device>",
       set_clientpointer
     },
+    { "test-xi2",
+      "<device>",
+      test_xi2,
+    },
 #endif
     { "list-props",
       "<device> [<device> ...]",