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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
/* $XdotOrg: xc/programs/Xserver/Xext/xtest.c,v 1.2 2004/04/23 18:44:42 eich Exp $ */
/* $Xorg: xtest.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */
/*
Copyright 1992, 1998 The Open Group
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 OPEN GROUP 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 Open Group 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 Open Group.
*/
/* $XFree86: xc/programs/Xserver/Xext/xtest.c,v 3.10 2003/10/28 23:08:44 tsi Exp $ */
#include "X.h"
#define NEED_EVENTS
#include "Xproto.h"
#include "misc.h"
#include "os.h"
#include "dixstruct.h"
#include "extnsionst.h"
#include "windowstr.h"
#include "inputstr.h"
#include "scrnintstr.h"
#include "dixevents.h"
#include "sleepuntil.h"
#define _XTEST_SERVER_
#include "XTest.h"
#include "xteststr.h"
#ifdef XINPUT
#include "XI.h"
#include "XIproto.h"
#define EXTENSION_EVENT_BASE 64
#include "extinit.h" /* LookupDeviceIntRec */
#endif /* XINPUT */
#ifdef EXTMODULE
#include "xf86_ansic.h"
#endif
#include "modinit.h"
#if 0
static unsigned char XTestReqCode;
#endif
#ifdef XINPUT
extern int DeviceValuator;
#endif /* XINPUT */
#ifdef PANORAMIX
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif
static void XTestResetProc(
ExtensionEntry * /* extEntry */
);
static int XTestSwapFakeInput(
ClientPtr /* client */,
xReq * /* req */
);
static DISPATCH_PROC(ProcXTestCompareCursor);
static DISPATCH_PROC(ProcXTestDispatch);
static DISPATCH_PROC(ProcXTestFakeInput);
static DISPATCH_PROC(ProcXTestGetVersion);
static DISPATCH_PROC(ProcXTestGrabControl);
static DISPATCH_PROC(SProcXTestCompareCursor);
static DISPATCH_PROC(SProcXTestDispatch);
static DISPATCH_PROC(SProcXTestFakeInput);
static DISPATCH_PROC(SProcXTestGetVersion);
static DISPATCH_PROC(SProcXTestGrabControl);
void
XTestExtensionInit(INITARGS)
{
#if 0
ExtensionEntry *extEntry;
if ((extEntry = AddExtension(XTestExtensionName, 0, 0,
ProcXTestDispatch, SProcXTestDispatch,
XTestResetProc, StandardMinorOpcode)) != 0)
XTestReqCode = (unsigned char)extEntry->base;
#else
(void) AddExtension(XTestExtensionName, 0, 0,
ProcXTestDispatch, SProcXTestDispatch,
XTestResetProc, StandardMinorOpcode);
#endif
}
/*ARGSUSED*/
static void
XTestResetProc (extEntry)
ExtensionEntry *extEntry;
{
}
static int
ProcXTestGetVersion(client)
register ClientPtr client;
{
xXTestGetVersionReply rep;
register int n;
REQUEST_SIZE_MATCH(xXTestGetVersionReq);
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.majorVersion = XTestMajorVersion;
rep.minorVersion = XTestMinorVersion;
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
swaps(&rep.minorVersion, n);
}
WriteToClient(client, sizeof(xXTestGetVersionReply), (char *)&rep);
return(client->noClientException);
}
static int
ProcXTestCompareCursor(client)
register ClientPtr client;
{
REQUEST(xXTestCompareCursorReq);
xXTestCompareCursorReply rep;
WindowPtr pWin;
CursorPtr pCursor;
register int n;
REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
pWin = (WindowPtr)LookupWindow(stuff->window, client);
if (!pWin)
return(BadWindow);
if (stuff->cursor == None)
pCursor = NullCursor;
else if (stuff->cursor == XTestCurrentCursor)
pCursor = GetSpriteCursor();
else {
pCursor = (CursorPtr)LookupIDByType(stuff->cursor, RT_CURSOR);
if (!pCursor)
{
client->errorValue = stuff->cursor;
return (BadCursor);
}
}
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.same = (wCursor(pWin) == pCursor);
if (client->swapped) {
swaps(&rep.sequenceNumber, n);
}
WriteToClient(client, sizeof(xXTestCompareCursorReply), (char *)&rep);
return(client->noClientException);
}
static int
ProcXTestFakeInput(client)
register ClientPtr client;
{
REQUEST(xXTestFakeInputReq);
int nev;
int n;
xEvent *ev;
DeviceIntPtr dev = NULL;
WindowPtr root;
int type;
#ifdef XINPUT
Bool extension = FALSE;
deviceValuator *dv = NULL;
int base;
int *values;
#endif /* XINPUT */
nev = (stuff->length << 2) - sizeof(xReq);
if ((nev % sizeof(xEvent)) || !nev)
return BadLength;
nev /= sizeof(xEvent);
UpdateCurrentTime();
ev = (xEvent *)&((xReq *)stuff)[1];
type = ev->u.u.type & 0177;
#ifdef XINPUT
if (type >= EXTENSION_EVENT_BASE)
{
type -= DeviceValuator;
switch (type) {
case XI_DeviceKeyPress:
case XI_DeviceKeyRelease:
case XI_DeviceButtonPress:
case XI_DeviceButtonRelease:
case XI_DeviceMotionNotify:
case XI_ProximityIn:
case XI_ProximityOut:
break;
default:
client->errorValue = ev->u.u.type;
return BadValue;
}
if (nev == 1 && type == XI_DeviceMotionNotify)
return BadLength;
if (type == XI_DeviceMotionNotify)
base = ((deviceValuator *)(ev+1))->first_valuator;
else
base = 0;
for (n = 1; n < nev; n++)
{
dv = (deviceValuator *)(ev + n);
if (dv->type != DeviceValuator)
{
client->errorValue = dv->type;
return BadValue;
}
if (dv->first_valuator != base)
{
client->errorValue = dv->first_valuator;
return BadValue;
}
if (!dv->num_valuators || dv->num_valuators > 6)
{
client->errorValue = dv->num_valuators;
return BadValue;
}
base += dv->num_valuators;
}
type = type - XI_DeviceKeyPress + KeyPress;
extension = TRUE;
}
else
#endif /* XINPUT */
{
if (nev != 1)
return BadLength;
switch (type)
{
case KeyPress:
case KeyRelease:
case MotionNotify:
case ButtonPress:
case ButtonRelease:
break;
default:
client->errorValue = ev->u.u.type;
return BadValue;
}
}
if (ev->u.keyButtonPointer.time)
{
TimeStamp activateTime;
CARD32 ms;
activateTime = currentTime;
ms = activateTime.milliseconds + ev->u.keyButtonPointer.time;
if (ms < activateTime.milliseconds)
activateTime.months++;
activateTime.milliseconds = ms;
ev->u.keyButtonPointer.time = 0;
/* see mbuf.c:QueueDisplayRequest for code similar to this */
if (!ClientSleepUntil(client, &activateTime, NULL, NULL))
{
return BadAlloc;
}
/* swap the request back so we can simply re-execute it */
if (client->swapped)
{
(void) XTestSwapFakeInput(client, (xReq *)stuff);
swaps(&stuff->length, n);
}
ResetCurrentRequest (client);
client->sequence--;
return Success;
}
#ifdef XINPUT
if (extension)
{
dev = LookupDeviceIntRec(stuff->deviceid & 0177);
if (!dev)
{
client->errorValue = stuff->deviceid & 0177;
return BadValue;
}
if (nev > 1)
{
dv = (deviceValuator *)(ev + 1);
if (!dev->valuator || dv->first_valuator >= dev->valuator->numAxes)
{
client->errorValue = dv->first_valuator;
return BadValue;
}
if (dv->first_valuator + dv->num_valuators >
dev->valuator->numAxes)
{
client->errorValue = dv->num_valuators;
return BadValue;
}
}
}
#endif /* XINPUT */
switch (type)
{
case KeyPress:
case KeyRelease:
#ifdef XINPUT
if (!extension)
#endif /* XINPUT */
dev = (DeviceIntPtr)LookupKeyboardDevice();
if (ev->u.u.detail < dev->key->curKeySyms.minKeyCode ||
ev->u.u.detail > dev->key->curKeySyms.maxKeyCode)
{
client->errorValue = ev->u.u.detail;
return BadValue;
}
break;
case MotionNotify:
#ifdef XINPUT
if (extension)
{
if (ev->u.u.detail != xFalse && ev->u.u.detail != xTrue)
{
client->errorValue = ev->u.u.detail;
return BadValue;
}
if (ev->u.u.detail == xTrue && dev->valuator->mode == Absolute)
{
values = dev->valuator->axisVal + dv->first_valuator;
for (n = 1; n < nev; n++)
{
dv = (deviceValuator *)(ev + n);
switch (dv->num_valuators)
{
case 6:
dv->valuator5 += values[5];
case 5:
dv->valuator4 += values[4];
case 4:
dv->valuator3 += values[3];
case 3:
dv->valuator2 += values[2];
case 2:
dv->valuator1 += values[1];
case 1:
dv->valuator0 += values[0];
}
values += 6;
}
}
break;
}
#endif /* XINPUT */
dev = (DeviceIntPtr)LookupPointerDevice();
if (ev->u.keyButtonPointer.root == None)
root = GetCurrentRootWindow();
else
{
root = LookupWindow(ev->u.keyButtonPointer.root, client);
if (!root)
return BadWindow;
if (root->parent)
{
client->errorValue = ev->u.keyButtonPointer.root;
return BadValue;
}
}
if (ev->u.u.detail == xTrue)
{
int x, y;
GetSpritePosition(&x, &y);
ev->u.keyButtonPointer.rootX += x;
ev->u.keyButtonPointer.rootY += y;
}
else if (ev->u.u.detail != xFalse)
{
client->errorValue = ev->u.u.detail;
return BadValue;
}
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
ScreenPtr pScreen = root->drawable.pScreen;
BoxRec box;
int i;
int x = ev->u.keyButtonPointer.rootX + panoramiXdataPtr[0].x;
int y = ev->u.keyButtonPointer.rootY + panoramiXdataPtr[0].y;
if (!POINT_IN_REGION(pScreen, &XineramaScreenRegions[pScreen->myNum],
x, y, &box)) {
FOR_NSCREENS(i) {
if (i == pScreen->myNum) continue;
if (POINT_IN_REGION(pScreen,
&XineramaScreenRegions[i],
x, y, &box)) {
root = WindowTable[i];
x -= panoramiXdataPtr[i].x;
y -= panoramiXdataPtr[i].y;
ev->u.keyButtonPointer.rootX = x;
ev->u.keyButtonPointer.rootY = y;
break;
}
}
}
}
#endif
if (ev->u.keyButtonPointer.rootX < 0)
ev->u.keyButtonPointer.rootX = 0;
else if (ev->u.keyButtonPointer.rootX >= root->drawable.width)
ev->u.keyButtonPointer.rootX = root->drawable.width - 1;
if (ev->u.keyButtonPointer.rootY < 0)
ev->u.keyButtonPointer.rootY = 0;
else if (ev->u.keyButtonPointer.rootY >= root->drawable.height)
ev->u.keyButtonPointer.rootY = root->drawable.height - 1;
#ifdef PANORAMIX
if ((!noPanoramiXExtension
&& root->drawable.pScreen->myNum != XineramaGetCursorScreen())
|| (noPanoramiXExtension && root != GetCurrentRootWindow()))
#else
if (root != GetCurrentRootWindow())
#endif
{
NewCurrentScreen(root->drawable.pScreen,
ev->u.keyButtonPointer.rootX,
ev->u.keyButtonPointer.rootY);
return client->noClientException;
}
(*root->drawable.pScreen->SetCursorPosition)
(root->drawable.pScreen,
ev->u.keyButtonPointer.rootX,
ev->u.keyButtonPointer.rootY, FALSE);
break;
case ButtonPress:
case ButtonRelease:
#ifdef XINPUT
if (!extension)
#endif /* XINPUT */
dev = (DeviceIntPtr)LookupPointerDevice();
if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons)
{
client->errorValue = ev->u.u.detail;
return BadValue;
}
break;
}
if (screenIsSaved == SCREEN_SAVER_ON)
SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
ev->u.keyButtonPointer.time = currentTime.milliseconds;
(*dev->public.processInputProc)(ev, dev, nev);
return client->noClientException;
}
static int
ProcXTestGrabControl(client)
register ClientPtr client;
{
REQUEST(xXTestGrabControlReq);
REQUEST_SIZE_MATCH(xXTestGrabControlReq);
if ((stuff->impervious != xTrue) && (stuff->impervious != xFalse))
{
client->errorValue = stuff->impervious;
return(BadValue);
}
if (stuff->impervious)
MakeClientGrabImpervious(client);
else
MakeClientGrabPervious(client);
return(client->noClientException);
}
static int
ProcXTestDispatch (client)
register ClientPtr client;
{
REQUEST(xReq);
switch (stuff->data)
{
case X_XTestGetVersion:
return ProcXTestGetVersion(client);
case X_XTestCompareCursor:
return ProcXTestCompareCursor(client);
case X_XTestFakeInput:
return ProcXTestFakeInput(client);
case X_XTestGrabControl:
return ProcXTestGrabControl(client);
default:
return BadRequest;
}
}
static int
SProcXTestGetVersion(client)
register ClientPtr client;
{
register int n;
REQUEST(xXTestGetVersionReq);
swaps(&stuff->length, n);
REQUEST_SIZE_MATCH(xXTestGetVersionReq);
swaps(&stuff->minorVersion, n);
return ProcXTestGetVersion(client);
}
static int
SProcXTestCompareCursor(client)
register ClientPtr client;
{
register int n;
REQUEST(xXTestCompareCursorReq);
swaps(&stuff->length, n);
REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
swapl(&stuff->window, n);
swapl(&stuff->cursor, n);
return ProcXTestCompareCursor(client);
}
static int
XTestSwapFakeInput(client, req)
register ClientPtr client;
xReq *req;
{
register int nev;
register xEvent *ev;
xEvent sev;
EventSwapPtr proc;
nev = ((req->length << 2) - sizeof(xReq)) / sizeof(xEvent);
for (ev = (xEvent *)&req[1]; --nev >= 0; ev++)
{
/* Swap event */
proc = EventSwapVector[ev->u.u.type & 0177];
/* no swapping proc; invalid event type? */
if (!proc || proc == NotImplemented) {
client->errorValue = ev->u.u.type;
return BadValue;
}
(*proc)(ev, &sev);
*ev = sev;
}
return Success;
}
static int
SProcXTestFakeInput(client)
register ClientPtr client;
{
register int n;
REQUEST(xReq);
swaps(&stuff->length, n);
n = XTestSwapFakeInput(client, stuff);
if (n != Success)
return n;
return ProcXTestFakeInput(client);
}
static int
SProcXTestGrabControl(client)
register ClientPtr client;
{
register int n;
REQUEST(xXTestGrabControlReq);
swaps(&stuff->length, n);
REQUEST_SIZE_MATCH(xXTestGrabControlReq);
return ProcXTestGrabControl(client);
}
static int
SProcXTestDispatch (client)
register ClientPtr client;
{
REQUEST(xReq);
switch (stuff->data)
{
case X_XTestGetVersion:
return SProcXTestGetVersion(client);
case X_XTestCompareCursor:
return SProcXTestCompareCursor(client);
case X_XTestFakeInput:
return SProcXTestFakeInput(client);
case X_XTestGrabControl:
return SProcXTestGrabControl(client);
default:
return BadRequest;
}
}
|