[PATCH xinput 3/4] test-xi2: support a device option

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 18 23:35:29 PDT 2011


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 man/xinput.man |    6 +++---
 src/test_xi2.c |   13 ++++++++++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/man/xinput.man b/man/xinput.man
index 5470f29..085a5fc 100644
--- a/man/xinput.man
+++ b/man/xinput.man
@@ -104,9 +104,9 @@ loop displaying events received. If the -proximity is given, ProximityIn
 and ProximityOut are registered.
 .PP
 .TP 8
-.B --test-xi2
-Register for a number of XI2 events and display them. This option does not
-take a device argument.
+.B --test-xi2 [\fIdevice\fP]
+Register for a number of XI2 events and display them. If a device is given,
+only events on this device are displayed.
 .PP
 .TP 8
 .B --create-master \fIprefix\fP [sendCore] [enable]
diff --git a/src/test_xi2.c b/src/test_xi2.c
index 619a6b2..92c88da 100644
--- a/src/test_xi2.c
+++ b/src/test_xi2.c
@@ -306,12 +306,18 @@ test_xi2(Display	*display,
 {
     XIEventMask mask;
     Window win;
+    int deviceid = -1;
 
     list(display, argc, argv, name, desc);
+    if (argc >= 1) {
+        XIDeviceInfo *info;
+        info = xi2_find_device_info(display, argv[0]);
+        deviceid = info->deviceid;
+    }
     win = create_win(display);
 
     /* Select for motion events */
-    mask.deviceid = XIAllDevices;
+    mask.deviceid = (deviceid == -1) ? XIAllDevices : deviceid;
     mask.mask_len = XIMaskLen(XI_RawMotion);
     mask.mask = calloc(mask.mask_len, sizeof(char));
     XISetMask(mask.mask, XI_ButtonPress);
@@ -324,7 +330,8 @@ test_xi2(Display	*display,
     XISetMask(mask.mask, XI_Leave);
     XISetMask(mask.mask, XI_FocusIn);
     XISetMask(mask.mask, XI_FocusOut);
-    XISetMask(mask.mask, XI_HierarchyChanged);
+    if (mask.deviceid == XIAllDevices)
+        XISetMask(mask.mask, XI_HierarchyChanged);
     XISetMask(mask.mask, XI_PropertyEvent);
     XISelectEvents(display, win, &mask, 1);
     XMapWindow(display, win);
@@ -349,7 +356,7 @@ test_xi2(Display	*display,
         XIUngrabKeycode(display, 3, 24 /* q */, win, nmods - 2, &modifiers[2]);
     }
 
-    mask.deviceid = XIAllMasterDevices;
+    mask.deviceid = (deviceid == -1) ? XIAllMasterDevices : deviceid;
     memset(mask.mask, 0, mask.mask_len);
     XISetMask(mask.mask, XI_RawKeyPress);
     XISetMask(mask.mask, XI_RawKeyRelease);
-- 
1.7.6



More information about the xorg-devel mailing list