1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/*
Copyright 2007 Peter Hutterer <peter@cs.unisa.edu.au>
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.
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.
*/
/***********************************************************************
*
* Request change in the device hierarchy.
*
*/
#define NEED_EVENTS
#define NEED_REPLIES
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h> /* for inputstr.h */
#include <X11/Xproto.h> /* Request macro */
#include "inputstr.h" /* DeviceIntPtr */
#include "windowstr.h" /* window structure */
#include "scrnintstr.h" /* screen structure */
#include <X11/extensions/XI.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XIproto.h>
#include <X11/extensions/geproto.h>
#include "extnsionst.h"
#include "exevents.h"
#include "exglobals.h"
#include "geext.h"
#include "chdevhier.h"
/***********************************************************************
*
* This procedure allows a client to change the device hierarchy through
* adding new master devices, removing them, etc.
*
*/
int SProcXChangeDeviceHierarchy(ClientPtr client)
{
char n;
REQUEST(xChangeDeviceHierarchyReq);
swaps(&stuff->length, n);
return (ProcXChangeDeviceHierarchy(client));
}
#define SWAPIF(cmd) if (client->swapped) { cmd; }
int
ProcXChangeDeviceHierarchy(ClientPtr client)
{
DeviceIntPtr ptr, keybd;
DeviceIntRec dummyDev;
xAnyHierarchyChangeInfo *any;
int required_len = sizeof(xChangeDeviceHierarchyReq);
char n;
int rc;
deviceHierarchyChangedEvent ev;
REQUEST(xChangeDeviceHierarchyReq);
REQUEST_AT_LEAST_SIZE(xChangeDeviceHierarchyReq);
/* XXX: check if client is allowed to change hierarch */
any = (xAnyHierarchyChangeInfo*)&stuff[1];
while(stuff->num_changes--)
{
SWAPIF(swapl(&any->type, n));
SWAPIF(swaps(&any->length, n));
required_len += any->length;
if ((stuff->length * 4) < required_len)
return BadLength;
switch(any->type)
{
case CH_CreateMasterDevice:
{
xCreateMasterInfo* c = (xCreateMasterInfo*)any;
char* name;
int ret;
SWAPIF(swaps(&c->namelen, n));
name = xcalloc(c->namelen + 1, sizeof(char));
strncpy(name, (char*)&c[1], c->namelen);
ret = AllocMasterDevice(name, &ptr, &keybd);
if (ret != Success)
{
xfree(name);
return ret;
}
if (!c->sendCore)
ptr->coreEvents = keybd->coreEvents = FALSE;
ActivateDevice(ptr);
ActivateDevice(keybd);
if (c->enable)
{
EnableDevice(ptr);
EnableDevice(keybd);
}
xfree(name);
}
break;
case CH_RemoveMasterDevice:
{
xRemoveMasterInfo* r = (xRemoveMasterInfo*)any;
if (r->returnMode != AttachToMaster &&
r->returnMode != Floating)
return BadValue;
rc = dixLookupDevice(&ptr, r->deviceid, client,
DixWriteAccess);
if (rc != Success)
return rc;
if (!ptr->isMaster)
{
client->errorValue = r->deviceid;
return BadDevice;
}
/* XXX: For now, don't allow removal of VCP, VCK */
if (ptr == inputInfo.pointer ||
ptr == inputInfo.keyboard)
return BadDevice;
/* disable keyboards first */
if (IsPointerDevice(ptr))
keybd = ptr->spriteInfo->paired;
else
{
keybd = ptr;
ptr = keybd->spriteInfo->paired;
}
/* Disabling sends the devices floating, reattach them if
* desired. */
if (r->returnMode == AttachToMaster)
{
DeviceIntPtr attached,
newptr,
newkeybd;
rc = dixLookupDevice(&newptr, r->returnPointer,
client, DixWriteAccess);
if (rc != Success)
return rc;
if (!newptr->isMaster)
{
client->errorValue = r->returnPointer;
return BadDevice;
}
rc = dixLookupDevice(&newkeybd, r->returnKeyboard,
client, DixWriteAccess);
if (rc != Success)
return rc;
if (!newkeybd->isMaster)
{
client->errorValue = r->returnKeyboard;
return BadDevice;
}
for (attached = inputInfo.devices;
attached;
attached = attached->next)
{
if (!attached->isMaster) {
if (attached->u.master == ptr)
AttachDevice(client, attached, newptr);
if (attached->u.master == keybd)
AttachDevice(client, attached, newkeybd);
}
}
}
/* can't disable until we removed pairing */
keybd->spriteInfo->paired = NULL;
ptr->spriteInfo->paired = NULL;
DisableDevice(keybd);
DisableDevice(ptr);
RemoveDevice(keybd);
RemoveDevice(ptr);
}
break;
case CH_ChangeAttachment:
{
xChangeAttachmentInfo* c = (xChangeAttachmentInfo*)any;
rc = dixLookupDevice(&ptr, c->deviceid, client,
DixWriteAccess);
if (rc != Success)
return rc;
if (ptr->isMaster)
{
client->errorValue = c->deviceid;
return BadDevice;
}
if (c->changeMode == Floating)
AttachDevice(client, ptr, NULL);
else
{
DeviceIntPtr newmaster;
rc = dixLookupDevice(&newmaster, c->newMaster,
client, DixWriteAccess);
if (rc != Success)
return rc;
if (!newmaster->isMaster)
{
client->errorValue = c->newMaster;
return BadDevice;
}
if ((IsPointerDevice(newmaster) &&
!IsPointerDevice(ptr)) ||
(IsKeyboardDevice(newmaster) &&
!IsKeyboardDevice(ptr)))
return BadDevice;
AttachDevice(client, ptr, newmaster);
}
}
break;
}
any = (xAnyHierarchyChangeInfo*)((char*)any + any->length);
}
ev.type = GenericEvent;
ev.extension = IReqCode;
ev.length = 0;
ev.evtype = XI_DeviceHierarchyChangedNotify;
ev.time = GetTimeInMillis();
SendEventToAllWindows(&dummyDev, XI_DeviceHierarchyChangedMask,
(xEvent*)&ev, 1);
return Success;
}
|