X-Git-Url: https://diplodocus.org/git/xorg-xinput/blobdiff_plain/7458e7dde70f5d9ff281848fb1a56e9a5f1dd783..refs/heads/master:/src/hierarchy.c?ds=sidebyside diff --git a/src/hierarchy.c b/src/hierarchy.c index 77960d5..f3eb378 100644 --- a/src/hierarchy.c +++ b/src/hierarchy.c @@ -1,28 +1,25 @@ /* - * Copyright 2007 Peter Hutterer + * Copyright © 2007 Peter Hutterer + * Copyright © 2009 Red Hat, Inc. * - * 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 - * copyright notice and this permission notice appear in supporting - * documentation. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * 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. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR - * 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. + * The above copyright notice and this permission notice (including the next + * paragraph) 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. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 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. */ #include "xinput.h" @@ -40,7 +37,7 @@ int create_master(Display* dpy, int argc, char** argv, char* name, char *desc) { - XICreateMasterInfo c; + XIAddMasterInfo c; if (argc == 0) { @@ -48,9 +45,9 @@ create_master(Display* dpy, int argc, char** argv, char* name, char *desc) return EXIT_FAILURE; } - c.type = XICreateMaster; + c.type = XIAddMaster; c.name = argv[0]; - c.sendCore = (argc >= 2) ? atoi(argv[1]) : 1; + c.send_core = (argc >= 2) ? atoi(argv[1]) : 1; c.enable = (argc >= 3) ? atoi(argv[2]) : 1; return XIChangeHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1); @@ -77,27 +74,61 @@ 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]); + fprintf(stderr, "unable to find device '%s'\n", argv[0]); return EXIT_FAILURE; } r.type = XIRemoveMaster; - r.device = info->deviceid; + r.deviceid = info->deviceid; if (argc >= 2) { if (!strcmp(argv[1], "Floating")) - r.returnMode = XIFloating; + r.return_mode = XIFloating; else if (!strcmp(argv[1], "AttachToMaster")) - r.returnMode = XIAttachToMaster; + r.return_mode = XIAttachToMaster; else - Error(BadValue, "Invalid returnMode.\n"); + Error(BadValue, "Invalid return_mode.\n"); } else - r.returnMode = XIFloating; + r.return_mode = XIFloating; - if (r.returnMode == XIAttachToMaster) + if (r.return_mode == XIAttachToMaster) { - r.returnPointer = atoi(argv[2]); - r.returnKeyboard = 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; + if (r.return_pointer && r.return_keyboard) + break; + } + + XIFreeDeviceInfo(info); + } } ret = XIChangeHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&r, 1); @@ -124,18 +155,18 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc) md_info= xi2_find_device_info(dpy, argv[1]); if (!sd_info) { - fprintf(stderr, "unable to find device %s\n", argv[0]); + fprintf(stderr, "unable to find device '%s'\n", argv[0]); return EXIT_FAILURE; } if (!md_info) { - fprintf(stderr, "unable to find device %s\n", argv[1]); + fprintf(stderr, "unable to find device '%s'\n", argv[1]); return EXIT_FAILURE; } c.type = XIAttachSlave; - c.device = sd_info->deviceid; - c.newMaster = md_info->deviceid; + c.deviceid = sd_info->deviceid; + c.new_master = md_info->deviceid; ret = XIChangeHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1); return ret; @@ -160,12 +191,12 @@ float_device(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]); + fprintf(stderr, "unable to find device '%s'\n", argv[0]); return EXIT_FAILURE; } c.type = XIDetachSlave; - c.device = info->deviceid; + c.deviceid = info->deviceid; ret = XIChangeHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1); return ret;