[PATCH] reattach: Default to return to VCP/VCK when returnMode is AttachToMaster

Thomas Jaeger ThJaeger at gmail.com
Sun Jun 14 10:58:39 PDT 2009


Signed-off-by: Thomas Jaeger <ThJaeger at gmail.com>
---
 src/hierarchy.c |   40 ++++++++++++++++++++++++++++++++++++----
 src/xinput.c    |    2 +-
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/hierarchy.c b/src/hierarchy.c
index cf0f783..cb25876 100644
--- a/src/hierarchy.c
+++ b/src/hierarchy.c
@@ -77,8 +77,8 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
     info = xi2_find_device_info(dpy, argv[0]);
 
     if (!info) {
-	fprintf(stderr, "unable to find device %s\n", argv[0]);
-	return EXIT_FAILURE;
+        fprintf(stderr, "unable to find device %s\n", argv[0]);
+        return EXIT_FAILURE;
     }
 
     r.type = XIRemoveMaster;
@@ -96,8 +96,40 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
 
     if (r.return_mode == XIAttachToMaster)
     {
-        r.return_pointer = atoi(argv[2]);
-        r.return_keyboard = atoi(argv[3]);
+        r.return_pointer = 0;
+        if (argc >= 3) {
+            info = xi2_find_device_info(dpy, argv[2]);
+            if (!info) {
+                fprintf(stderr, "unable to find device %s\n", argv[2]);
+                return EXIT_FAILURE;
+            }
+
+            r.return_pointer = info->deviceid;
+        }
+
+        r.return_keyboard = 0;
+        if (argc >= 4) {
+            info = xi2_find_device_info(dpy, argv[3]);
+            if (!info) {
+                fprintf(stderr, "unable to find device %s\n", argv[3]);
+                return EXIT_FAILURE;
+            }
+
+            r.return_keyboard = info->deviceid;
+        }
+
+        if (!r.return_pointer || !r.return_keyboard) {
+            int i, ndevices;
+            info = XIQueryDevice(dpy, XIAllMasterDevices, &ndevices);
+            for(i = 0; i < ndevices; i++) {
+                if (info[i].use == XIMasterPointer && !r.return_pointer)
+                    r.return_pointer = info[i].deviceid;
+                if (info[i].use == XIMasterKeyboard && !r.return_keyboard)
+                    r.return_keyboard = info[i].deviceid;
+            }
+
+            XIFreeDeviceInfo(info);
+        }
     }
 
     ret = XIChangeHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&r, 1);
diff --git a/src/xinput.c b/src/xinput.c
index 007fe2c..7c47c3c 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -87,7 +87,7 @@ static entry drivers[] =
       create_master
     },
     { "remove-master",
-      "<id> [returnMode (dflt:Floating)] [returnPointer] [returnKeyboard]",
+      "<id> [returnMode (dflt:Floating, AttachToMaster)] [returnPointer] [returnKeyboard]",
       remove_master
     },
     { "reattach",
-- 
1.6.3.1


--------------030104060104030302040203--


More information about the xorg-devel mailing list