[PATCH xinput 4/4] test-xi2: add support for test-xi2 --root

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 2 17:09:55 PDT 2013


Select on the root window instead of a newly created one

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

diff --git a/man/xinput.man b/man/xinput.man
index 540308b..87be8c7 100644
--- a/man/xinput.man
+++ b/man/xinput.man
@@ -104,9 +104,11 @@ loop displaying events received. If the -proximity is given, ProximityIn
 and ProximityOut are registered.
 .PP
 .TP 8
-.B --test-xi2 [\fIdevice\fP]
+.B --test-xi2 [--root] [\fIdevice\fP]
 Register for a number of XI2 events and display them. If a device is given,
-only events on this device are displayed.
+only events on this device are displayed. If --root is given, events are
+selected on the root window only. Otherwise, a new client window is created
+(similar to xev).
 .PP
 .TP 8
 .B --create-master \fIprefix\fP [sendCore] [enable]
diff --git a/src/test_xi2.c b/src/test_xi2.c
index 40cc76e..a83bb22 100644
--- a/src/test_xi2.c
+++ b/src/test_xi2.c
@@ -325,20 +325,32 @@ test_xi2(Display	*display,
     XIEventMask *m;
     Window win;
     int deviceid = -1;
+    int use_root = 0;
     int rc;
 
     setlinebuf(stdout);
 
+    if (argc >= 1 && strcmp(argv[0], "--root") == 0) {
+        use_root = 1;
+
+        argc--;
+        argv++;
+    }
+
     rc = list(display, argc, argv, name, desc);
     if (rc != EXIT_SUCCESS)
         return rc;
 
+    if (use_root)
+        win = DefaultRootWindow(display);
+    else
+        win = create_win(display);
+
     if (argc >= 1) {
         XIDeviceInfo *info;
         info = xi2_find_device_info(display, argv[0]);
         deviceid = info->deviceid;
     }
-    win = create_win(display);
 
     /* Select for motion events */
     m = &mask[0];
@@ -379,15 +391,17 @@ test_xi2(Display	*display,
     XISetMask(m->mask, XI_RawTouchEnd);
 #endif
 
-    XISelectEvents(display, win, &mask[0], 1);
-    XISelectEvents(display, DefaultRootWindow(display), &mask[1], 1);
-    XMapWindow(display, win);
+    XISelectEvents(display, win, &mask[0], use_root ? 2 : 1);
+    if (!use_root) {
+        XISelectEvents(display, DefaultRootWindow(display), &mask[1], 1);
+        XMapWindow(display, win);
+    }
     XSync(display, False);
 
     free(mask[0].mask);
     free(mask[1].mask);
 
-    {
+    if (!use_root) {
         XEvent event;
         XMaskEvent(display, ExposureMask, &event);
         XSelectInput(display, win, 0);
diff --git a/src/xinput.c b/src/xinput.c
index 16a13df..e6e468c 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -101,7 +101,7 @@ static entry drivers[] =
       set_clientpointer
     },
     { "test-xi2",
-      "<device>",
+      "[--root] <device>",
       test_xi2,
     },
     { "map-to-output",
-- 
1.8.2.1



More information about the xorg-devel mailing list