]>
diplodocus.org Git - xorg-xinput/blob - src/hierarchy.c
2 * Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the name of the author shall
22 * not be used in advertising or otherwise to promote the sale, use or
23 * other dealings in this Software without prior written authorization
31 #define Error(error, ...) \
33 fprintf(stderr, __VA_ARGS__); \
37 * Create a new master device. Name must be supplied, other values are
41 create_master(Display
* dpy
, int argc
, char** argv
, char* name
, char *desc
)
47 fprintf(stderr
, "Usage: xinput %s %s\n", name
, desc
);
53 c
.send_core
= (argc
>= 2) ? atoi(argv
[1]) : 1;
54 c
.enable
= (argc
>= 3) ? atoi(argv
[2]) : 1;
56 return XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);
60 * Remove a master device.
61 * By default, all attached devices are set to Floating, unless parameters are
65 remove_master(Display
* dpy
, int argc
, char** argv
, char *name
, char *desc
)
73 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
77 info
= xi2_find_device_info(dpy
, argv
[0]);
80 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
84 r
.type
= XIRemoveMaster
;
85 r
.deviceid
= info
->deviceid
;
88 if (!strcmp(argv
[1], "Floating"))
89 r
.return_mode
= XIFloating
;
90 else if (!strcmp(argv
[1], "AttachToMaster"))
91 r
.return_mode
= XIAttachToMaster
;
93 Error(BadValue
, "Invalid return_mode.\n");
95 r
.return_mode
= XIFloating
;
97 if (r
.return_mode
== XIAttachToMaster
)
101 info
= xi2_find_device_info(dpy
, argv
[2]);
103 fprintf(stderr
, "unable to find device %s\n", argv
[2]);
107 r
.return_pointer
= info
->deviceid
;
110 r
.return_keyboard
= 0;
112 info
= xi2_find_device_info(dpy
, argv
[3]);
114 fprintf(stderr
, "unable to find device %s\n", argv
[3]);
118 r
.return_keyboard
= info
->deviceid
;
121 if (!r
.return_pointer
|| !r
.return_keyboard
) {
123 info
= XIQueryDevice(dpy
, XIAllMasterDevices
, &ndevices
);
124 for(i
= 0; i
< ndevices
; i
++) {
125 if (info
[i
].use
== XIMasterPointer
&& !r
.return_pointer
)
126 r
.return_pointer
= info
[i
].deviceid
;
127 if (info
[i
].use
== XIMasterKeyboard
&& !r
.return_keyboard
)
128 r
.return_keyboard
= info
[i
].deviceid
;
129 if (r
.return_pointer
&& r
.return_keyboard
)
133 XIFreeDeviceInfo(info
);
137 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&r
, 1);
142 * Swap a device from one master to another.
145 change_attachment(Display
* dpy
, int argc
, char** argv
, char *name
, char* desc
)
147 XIDeviceInfo
*sd_info
, *md_info
;
153 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
157 sd_info
= xi2_find_device_info(dpy
, argv
[0]);
158 md_info
= xi2_find_device_info(dpy
, argv
[1]);
161 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
166 fprintf(stderr
, "unable to find device %s\n", argv
[1]);
170 c
.type
= XIAttachSlave
;
171 c
.deviceid
= sd_info
->deviceid
;
172 c
.new_master
= md_info
->deviceid
;
174 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);
179 * Set a device floating.
182 float_device(Display
* dpy
, int argc
, char** argv
, char* name
, char* desc
)
190 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
194 info
= xi2_find_device_info(dpy
, argv
[0]);
197 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
201 c
.type
= XIDetachSlave
;
202 c
.deviceid
= info
->deviceid
;
204 ret
= XIChangeHierarchy(dpy
, (XIAnyHierarchyChangeInfo
*)&c
, 1);