]>
diplodocus.org Git - xorg-xinput/blob - src/hierarchy.c
7eab564cf67e49af6c3b2966bc834d5c64d53875
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
);
51 c
.type
= CH_CreateMasterDevice
;
53 c
.sendCore
= (argc
>= 2) ? atoi(argv
[1]) : 1;
54 c
.enable
= (argc
>= 3) ? atoi(argv
[2]) : 1;
56 return XChangeDeviceHierarchy(dpy
, (XAnyHierarchyChangeInfo
*)&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
)
68 XDevice
* master
= NULL
, *ptr
= NULL
, *keybd
= NULL
;
73 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
77 master
= XOpenDevice(dpy
, atoi(argv
[0]));
79 Error(BadValue
, "Invalid master device.\n");
81 r
.type
= CH_RemoveMasterDevice
;
85 if (!strcmp(argv
[1], "Floating"))
86 r
.returnMode
= Floating
;
87 else if (!strcmp(argv
[1], "AttachToMaster"))
88 r
.returnMode
= AttachToMaster
;
90 Error(BadValue
, "Invalid returnMode.\n");
92 r
.returnMode
= Floating
;
94 if (r
.returnMode
== AttachToMaster
)
96 ptr
= XOpenDevice(dpy
, atoi(argv
[2]));
97 keybd
= XOpenDevice(dpy
, atoi(argv
[3]));
99 Error(BadValue
, "Invalid fallback master.\n");
100 r
.returnPointer
= ptr
;
101 r
.returnKeyboard
= keybd
;
104 ret
= XChangeDeviceHierarchy(dpy
, (XAnyHierarchyChangeInfo
*)&r
, 1);
106 XCloseDevice(dpy
, ptr
);
108 XCloseDevice(dpy
, keybd
);
113 * Swap a device from one master to another.
116 change_attachment(Display
* dpy
, int argc
, char** argv
, char *name
, char* desc
)
118 XChangeAttachmentInfo c
;
119 XDevice
*slave
, *master
;
124 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
128 slave
= XOpenDevice(dpy
, atoi(argv
[0]));
129 master
= XOpenDevice(dpy
, atoi(argv
[1]));
132 Error(BadValue
, "Invalid slave device given %d\n", atoi(argv
[0]));
135 Error(BadValue
, "Invalid master device given %d\n", atoi(argv
[1]));
137 c
.type
= CH_ChangeAttachment
;
138 c
.changeMode
= AttachToMaster
;
140 c
.newMaster
= master
;
142 ret
= XChangeDeviceHierarchy(dpy
, (XAnyHierarchyChangeInfo
*)&c
, 1);
143 XCloseDevice(dpy
, slave
);
144 XCloseDevice(dpy
, master
);
149 * Set a device floating.
152 float_device(Display
* dpy
, int argc
, char** argv
, char* name
, char* desc
)
154 XChangeAttachmentInfo c
;
160 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
165 slave
= XOpenDevice(dpy
, atoi(argv
[0]));
170 c
.type
= CH_ChangeAttachment
;
171 c
.changeMode
= Floating
;
174 ret
= XChangeDeviceHierarchy(dpy
, (XAnyHierarchyChangeInfo
*)&c
, 1);
175 XCloseDevice(dpy
, slave
);