]> diplodocus.org Git - xorg-xinput/commitdiff
Get the XIDeviceInfo instead of just the id.
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 7 May 2009 04:13:45 +0000 (14:13 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 7 May 2009 04:49:25 +0000 (14:49 +1000)
This way we leak the XIDeviceInfo array, but then again it doesn't matter
since we exit after the command anyway.
And with the XIDeviceInfo around, we can actually print the name and
whatnot.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/hierarchy.c
src/setcp.c
src/xinput.c
src/xinput.h

index 7739074bb598863bd871587c97929a87e5bb448d..ed5e93035c8cea6692f233e67c08f8015c801108 100644 (file)
@@ -65,7 +65,8 @@ int
 remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
 {
     XIRemoveMasterInfo r;
-    int ret, id;
+    XIDeviceInfo *info;
+    int ret;
 
     if (argc == 0)
     {
@@ -73,15 +74,15 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
         return EXIT_FAILURE;
     }
 
-    id = xi2_find_device_id(dpy, argv[0]);
+    info = xi2_find_device_info(dpy, argv[0]);
 
-    if (id == -1) {
+    if (!info) {
        fprintf(stderr, "unable to find device %s\n", argv[0]);
        return EXIT_FAILURE;
     }
 
     r.type = CH_RemoveMasterDevice;
-    r.device = id;
+    r.device = info->deviceid;
     if (argc >= 2)
     {
         if (!strcmp(argv[1], "Floating"))
@@ -109,7 +110,7 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
 int
 change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
 {
-    int sd_id, md_id;
+    XIDeviceInfo *sd_info, *md_info;
     XIAttachSlaveInfo c;
     int ret;
 
@@ -119,22 +120,22 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
         return EXIT_FAILURE;
     }
 
-    sd_id = xi2_find_device_id(dpy, argv[0]);
-    md_id = xi2_find_device_id(dpy, argv[1]);
+    sd_info = xi2_find_device_info(dpy, argv[0]);
+    md_info= xi2_find_device_info(dpy, argv[1]);
 
-    if (sd_id == -1) {
+    if (!sd_info) {
        fprintf(stderr, "unable to find device %s\n", argv[0]);
        return EXIT_FAILURE;
     }
 
-    if (md_id == -1) {
+    if (!md_info) {
        fprintf(stderr, "unable to find device %s\n", argv[1]);
        return EXIT_FAILURE;
     }
 
     c.type = CH_AttachSlave;
-    c.device = sd_id;
-    c.newMaster = md_id;
+    c.device = sd_info->deviceid;
+    c.newMaster = md_info->deviceid;
 
     ret = XIChangeDeviceHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1);
     return ret;
@@ -146,7 +147,7 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
 int
 float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
 {
-    int id;
+    XIDeviceInfo *info;
     XIDetachSlaveInfo c;
     int ret;
 
@@ -156,15 +157,15 @@ float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
         return EXIT_FAILURE;
     }
 
-    id = xi2_find_device_id(dpy, argv[0]);
+    info = xi2_find_device_info(dpy, argv[0]);
 
-    if (id == -1) {
+    if (!info) {
        fprintf(stderr, "unable to find device %s\n", argv[0]);
        return EXIT_FAILURE;
     }
 
     c.type = CH_DetachSlave;
-    c.device = id;
+    c.device = info->deviceid;
 
     ret = XIChangeDeviceHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1);
     return ret;
index f2b2a6c5d79d3b131053f2526e963995ebc55e73..7a2864479cf7b195bc785226d70f56b6656391f3 100644 (file)
@@ -32,7 +32,7 @@
 int
 set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
 {
-    int deviceid;
+    XIDeviceInfo *info;
     XID window;
     char* id;
     char* dummy;
@@ -49,13 +49,13 @@ set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
 
     window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10);
 
-    deviceid = xi2_find_device_id(dpy, argv[1]);
+    info = xi2_find_device_info(dpy, argv[1]);
 
-    if (deviceid == -1) {
+    if (!info) {
        fprintf(stderr, "unable to find device %s\n", argv[1]);
        return EXIT_FAILURE;
     }
 
-    XISetClientPointer(dpy, window, deviceid);
+    XISetClientPointer(dpy, window, info->deviceid);
     return 0;
 }
index 4acb7bfc3f6b4262a6e26a8e13b6aeab2205550f..cff33d5100fd507730c1ca55ab74058231c3de5c 100644 (file)
@@ -203,8 +203,8 @@ find_device_info(Display    *display,
 }
 
 #ifdef HAVE_XI2
-int
-xi2_find_device_id(Display *display, char *name)
+XIDeviceInfo*
+xi2_find_device_info(Display *display, char *name)
 {
     XIDeviceInfo *info;
     int ndevices;
@@ -220,22 +220,20 @@ xi2_find_device_id(Display *display, char *name)
 
     if (is_id) {
        id = atoi(name);
-    } else
+    }
+
+    info = XIQueryDevice(display, AllDevices, &ndevices);
+    for(i = 0; i < ndevices; i++)
     {
-        info = XIQueryDevice(display, AllDevices, &ndevices);
-        for(i = 0; i < ndevices; i++)
+        if ((is_id && info[i].deviceid == id) ||
+                (!is_id && strcmp(info[i].name, name) == 0))
         {
-            if ((is_id && info[i].deviceid == id) ||
-                    (!is_id && strcmp(info[i].name, name) == 0))
-            {
-                id = info[i].deviceid;
-                break;
-            }
+            return &info[i];
         }
-
-        XIFreeDeviceInfo(info);
     }
-    return id;;
+
+    XIFreeDeviceInfo(info);
+    return NULL;
 }
 #endif
 
index c7269b932db9bc2f01ab89c624350b170700c64a..f3fc26634784bf60076e5f87a3ee5f28d23edaf0 100644 (file)
 
 
 XDeviceInfo* find_device_info( Display *display, char *name, Bool only_extended);
-int xi2_find_device_id(Display *display, char *name);
+#if HAVE_XI2
+XIDeviceInfo* xi2_find_device_info(Display *display, char *name);
 int xinput_version(Display* display);
+#endif
 
 int get_feedbacks( Display* display, int argc, char *argv[], char *prog_name, char *prog_desc);
 int set_ptr_feedback( Display* display, int argc, char *argv[], char *prog_name, char *prog_desc);