]> diplodocus.org Git - xorg-xinput/blobdiff - src/hierarchy.c
Require inputproto 1.9.99.5
[xorg-xinput] / src / hierarchy.c
index edb66a1970f99173f35fb07a8577c474350f6825..869c3fd8e41ea39781877aebff43d701716c1c2c 100644 (file)
@@ -6,10 +6,10 @@
  * the above copyright notice appear in all copies and that both that
  * copyright notice and this permission notice appear in supporting
  * documentation.
- * 
+ *
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
- * 
+ *
  * Except as contained in this notice, the name of the author shall
  * not be used in advertising or otherwise to promote the sale, use or
  * other dealings in this Software without prior written authorization
  * from the author.
- * 
+ *
  */
 
 #include "xinput.h"
  * Create a new master device. Name must be supplied, other values are
  * optional.
  */
-int 
+int
 create_master(Display* dpy, int argc, char** argv, char* name, char *desc)
 {
     XCreateMasterInfo c;
-    XCreateMasterInfo* pc = &c;
 
     if (argc == 0)
     {
@@ -54,7 +53,7 @@ create_master(Display* dpy, int argc, char** argv, char* name, char *desc)
     c.sendCore = (argc >= 2) ? atoi(argv[1]) : 1;
     c.enable = (argc >= 3) ? atoi(argv[2]) : 1;
 
-    return XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+    return XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
 }
 
 /**
@@ -65,8 +64,8 @@ create_master(Display* dpy, int argc, char** argv, char* name, char *desc)
 int
 remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
 {
+    XDeviceInfo *info;
     XRemoveMasterInfo r;
-    XRemoveMasterInfo* pr = &r;
     XDevice* master = NULL, *ptr = NULL, *keybd = NULL;
     int ret;
 
@@ -76,9 +75,16 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
         return EXIT_FAILURE;
     }
 
-    master = XOpenDevice(dpy, atoi(argv[0]));
+    info = find_device_info(dpy, argv[0], False);
+
+    if (!info) {
+       fprintf(stderr, "unable to find device %s\n", argv[0]);
+       return EXIT_FAILURE;
+    }
+
+    master = XOpenDevice(dpy, info->id);
     if (!master)
-        Error(BadValue, "Invalid master device.\n");
+        Error(BadValue, "Unable to open device %s.\n", argv[0]);
 
     r.type = CH_RemoveMasterDevice;
     r.device = master;
@@ -88,7 +94,7 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
             r.returnMode = Floating;
         else if (!strcmp(argv[1], "AttachToMaster"))
             r.returnMode = AttachToMaster;
-        else 
+        else
             Error(BadValue, "Invalid returnMode.\n");
     } else
         r.returnMode = Floating;
@@ -103,7 +109,7 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
         r.returnKeyboard = keybd;
     }
 
-    ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pr);
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&r, 1);
     if (ptr)
         XCloseDevice(dpy, ptr);
     if (keybd)
@@ -117,8 +123,8 @@ 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)
 {
+    XDeviceInfo *info_sd, *info_md;
     XChangeAttachmentInfo c;
-    XChangeAttachmentInfo* pc = &c;
     XDevice *slave, *master;
     int ret;
 
@@ -128,8 +134,21 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
         return EXIT_FAILURE;
     }
 
-    slave = XOpenDevice(dpy, atoi(argv[0]));
-    master = XOpenDevice(dpy, atoi(argv[1]));
+    info_sd = find_device_info(dpy, argv[0], True);
+    info_md = find_device_info(dpy, argv[1], False);
+
+    if (!info_sd) {
+       fprintf(stderr, "unable to find device %s\n", argv[0]);
+       return EXIT_FAILURE;
+    }
+
+    if (!info_md) {
+       fprintf(stderr, "unable to find device %s\n", argv[1]);
+       return EXIT_FAILURE;
+    }
+
+    slave = XOpenDevice(dpy, info_sd->id);
+    master = XOpenDevice(dpy, info_md->id);
 
     if (!slave)
         Error(BadValue, "Invalid slave device given %d\n", atoi(argv[0]));
@@ -142,7 +161,7 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
     c.device = slave;
     c.newMaster = master;
 
-    ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
     XCloseDevice(dpy, slave);
     XCloseDevice(dpy, master);
     return ret;
@@ -154,8 +173,8 @@ 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)
 {
+    XDeviceInfo *info;
     XChangeAttachmentInfo c;
-    XChangeAttachmentInfo* pc = &c;
     XDevice *slave;
     int ret;
 
@@ -165,8 +184,14 @@ float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
         return EXIT_FAILURE;
     }
 
+    info = find_device_info(dpy, argv[0], True);
+
+    if (!info) {
+       fprintf(stderr, "unable to find device %s\n", argv[0]);
+       return EXIT_FAILURE;
+    }
 
-    slave = XOpenDevice(dpy, atoi(argv[0]));
+    slave = XOpenDevice(dpy, info->id);
 
     if (!slave)
         return BadValue;
@@ -175,7 +200,7 @@ float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
     c.changeMode = Floating;
     c.device = slave;
 
-    ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+    ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
     XCloseDevice(dpy, slave);
     return ret;
 }