]>
diplodocus.org Git - xorg-xinput/blob - src/hierarchy.c
453fb3fc7d0585d79d3963208e2643d5030318be
2 * Copyright © 2007 Peter Hutterer
3 * Copyright © 2009 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 #define Error(error, ...) \
30 fprintf(stderr, __VA_ARGS__); \
34 * Create a new master device. Name must be supplied, other values are
38 create_master(Display
* dpy
, int argc
, char** argv
, char* name
, char *desc
)
44 fprintf(stderr
, "Usage: xinput %s %s\n", name
, desc
);
50 c
.send_core
= (argc
>= 2) ? atoi(argv
[1]) : 1;
51 c
.enable
= (argc
>= 3) ? atoi(argv
[2]) : 1;
53 return XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);
57 * Remove a master device.
58 * By default, all attached devices are set to Floating, unless parameters are
62 remove_master(Display
* dpy
, int argc
, char** argv
, char *name
, char *desc
)
70 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
74 info
= xi2_find_device_info(dpy
, argv
[0]);
77 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
81 r
.type
= XIRemoveMaster
;
82 r
.deviceid
= info
->deviceid
;
85 if (!strcmp(argv
[1], "Floating"))
86 r
.return_mode
= XIFloating
;
87 else if (!strcmp(argv
[1], "AttachToMaster"))
88 r
.return_mode
= XIAttachToMaster
;
90 Error(BadValue
, "Invalid return_mode.\n");
92 r
.return_mode
= XIFloating
;
94 if (r
.return_mode
== XIAttachToMaster
)
98 info
= xi2_find_device_info(dpy
, argv
[2]);
100 fprintf(stderr
, "unable to find device %s\n", argv
[2]);
104 r
.return_pointer
= info
->deviceid
;
107 r
.return_keyboard
= 0;
109 info
= xi2_find_device_info(dpy
, argv
[3]);
111 fprintf(stderr
, "unable to find device %s\n", argv
[3]);
115 r
.return_keyboard
= info
->deviceid
;
118 if (!r
.return_pointer
|| !r
.return_keyboard
) {
120 info
= XIQueryDevice(dpy
, XIAllMasterDevices
, &ndevices
);
121 for(i
= 0; i
< ndevices
; i
++) {
122 if (info
[i
].use
== XIMasterPointer
&& !r
.return_pointer
)
123 r
.return_pointer
= info
[i
].deviceid
;
124 if (info
[i
].use
== XIMasterKeyboard
&& !r
.return_keyboard
)
125 r
.return_keyboard
= info
[i
].deviceid
;
126 if (r
.return_pointer
&& r
.return_keyboard
)
130 XIFreeDeviceInfo(info
);
134 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&r
, 1);
139 * Swap a device from one master to another.
142 change_attachment(Display
* dpy
, int argc
, char** argv
, char *name
, char* desc
)
144 XIDeviceInfo
*sd_info
, *md_info
;
150 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
154 sd_info
= xi2_find_device_info(dpy
, argv
[0]);
155 md_info
= xi2_find_device_info(dpy
, argv
[1]);
158 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
163 fprintf(stderr
, "unable to find device %s\n", argv
[1]);
167 c
.type
= XIAttachSlave
;
168 c
.deviceid
= sd_info
->deviceid
;
169 c
.new_master
= md_info
->deviceid
;
171 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);
176 * Set a device floating.
179 float_device(Display
* dpy
, int argc
, char** argv
, char* name
, char* desc
)
187 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
191 info
= xi2_find_device_info(dpy
, argv
[0]);
194 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
198 c
.type
= XIDetachSlave
;
199 c
.deviceid
= info
->deviceid
;
201 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);