]> diplodocus.org Git - xorg-xinput/commitdiff
Add --loop to "xinput list". Re-prints devices when hierarchy changes.
authorPeter Hutterer <peter@cs.unisa.edu.au>
Thu, 20 Dec 2007 01:51:34 +0000 (12:21 +1030)
committerPeter Hutterer <peter@cs.unisa.edu.au>
Thu, 20 Dec 2007 01:53:08 +0000 (12:23 +1030)
src/list.c
src/xinput.c

index d1bc0866f58b33b1892fb240903546e41bd6dae7..85b766da7eac3c4fd3f43f461eb61b794c6c824c 100644 (file)
@@ -115,17 +115,35 @@ list(Display      *display,
     XDeviceInfo                *info;
     int                        loop;
     int                 shortformat = False;
+    int                 daemon = False;
 
     shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
+    daemon = (argc == 1 && strcmp(argv[0], "--loop") == 0);
 
-    if (argc == 0 || shortformat) {
+    if (argc == 0 || shortformat || daemon) {
        int             num_devices;
-
-       info = XListInputDevices(display, &num_devices);
-
-       for(loop=0; loop<num_devices; loop++) {
-           print_info(info+loop, shortformat);
-       }
+        XEvent  ev;
+        int     daemon = argc;
+
+        if (daemon)
+        {
+            XiSelectEvent(display, DefaultRootWindow(display),
+                          XI_DeviceHierarchyChangedMask);
+        }
+
+        do {
+            info = XListInputDevices(display, &num_devices);
+            for(loop=0; loop<num_devices; loop++) {
+                print_info(info+loop, shortformat);
+            }
+
+            /* just wait for the next generic event to come along */
+            while (daemon && !XNextEvent(display, &ev))
+            {
+                if (ev.type == GenericEvent)
+                    break;
+            }
+        } while(daemon);
     } else {
        int     ret = EXIT_SUCCESS;
 
index 68f7f0b298c349d6b0ba3b1936bda72ee6e142c9..47603d292c5dd38a1e28ee55147ae79ca75990ce 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
- *                                                                            
+ *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is  hereby granted without fee, provided that
  * the  above copyright   notice appear  in   all  copies and  that both  that
@@ -9,8 +9,8 @@
  * advertising or publicity pertaining to distribution of the software without
  * specific,  written      prior  permission.     Frederic  Lepied   makes  no
  * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.                   
- *                                                                            
+ * is provided "as is" without express or implied warranty.
+ *
  * FREDERIC  LEPIED DISCLAIMS ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
  * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
  * EVENT  SHALL FREDERIC  LEPIED BE   LIABLE   FOR ANY  SPECIAL, INDIRECT   OR
@@ -32,7 +32,7 @@ typedef int (*prog)(
 #endif
 );
 
-typedef struct 
+typedef struct
 {
     char       *func_name;
     char       *arg_desc;
@@ -66,7 +66,7 @@ static entry drivers[] =
      set_mode
     },
     {"list",
-     "[--short || <device name>...]",
+     "[--loop || --short || <device name>...]",
      list
     },
     {"query-state",
@@ -106,7 +106,7 @@ is_xinput_present(Display   *display)
 {
     XExtensionVersion  *version;
     Bool               present;
-    
+
     version = XGetExtensionVersion(display, INAME);
 
     if (version && (version != (XExtensionVersion*) NoSuchExtension)) {