X-Git-Url: https://diplodocus.org/git/xorg-xinput/blobdiff_plain/d1428764180c927cfa45298f5b7d0bf14eacc2da..6f444b5d063452e7a8705c756269960e509241d8:/src/hierarchy.c diff --git a/src/hierarchy.c b/src/hierarchy.c index edb66a1..869c3fd 100644 --- a/src/hierarchy.c +++ b/src/hierarchy.c @@ -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. @@ -17,12 +17,12 @@ * 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" @@ -37,11 +37,10 @@ * 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; }