1
/* $Xorg: XTest.c,v 1.5 2001/02/09 02:04:00 xorgcvs Exp $ */
3
Copyright 1990, 1991 by UniSoft Group Limited
8
Copyright 1992, 1993, 1998 The Open Group
10
Permission to use, copy, modify, distribute, and sell this software and its
11
documentation for any purpose is hereby granted without fee, provided that
12
the above copyright notice appear in all copies and that both that
13
copyright notice and this permission notice appear in supporting
16
The above copyright notice and this permission notice shall be included
17
in all copies or substantial portions of the Software.
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
23
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
OTHER DEALINGS IN THE SOFTWARE.
27
Except as contained in this notice, the name of The Open Group shall
28
not be used in advertising or otherwise to promote the sale, use or
29
other dealings in this Software without prior written authorization
33
/* $XFree86: xc/lib/Xtst/XTest.c,v 1.5 2001/12/14 19:56:40 dawes Exp $ */
36
#include <X11/Xlibint.h>
37
#include <X11/extensions/XTest.h>
38
#include <X11/extensions/xteststr.h>
39
#include <X11/extensions/Xext.h>
40
#include <X11/extensions/extutil.h>
41
#include <X11/extensions/XInput.h>
42
#include <X11/extensions/XIproto.h>
44
static XExtensionInfo _xtest_info_data;
45
static XExtensionInfo *xtest_info = &_xtest_info_data;
46
static /* const */ char *xtest_extension_name = XTestExtensionName;
48
#define XTestCheckExtension(dpy,i,val) \
49
XextCheckExtension (dpy, i, xtest_extension_name, val)
51
#define XTestICheckExtension(dpy,i,val) \
52
XextCheckExtension (dpy, i, xtest_extension_name, val); \
53
if (!i->data) return val
55
/*****************************************************************************
57
* private utility routines *
59
*****************************************************************************/
61
static int close_display();
62
static /* const */ XExtensionHooks xtest_extension_hooks = {
67
NULL, /* create_font */
69
close_display, /* close_display */
70
NULL, /* wire_to_event */
71
NULL, /* event_to_wire */
73
NULL /* error_string */
80
int major_opcode, first_event, first_error;
83
XQueryExtension(dpy, INAME, &major_opcode, &first_event, &first_error);
84
return (XPointer)(long)first_event;
87
static XEXT_GENERATE_FIND_DISPLAY (find_display, xtest_info,
89
&xtest_extension_hooks, XTestNumberEvents,
92
static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xtest_info)
94
/*****************************************************************************
98
*****************************************************************************/
101
XTestQueryExtension (dpy, event_basep, error_basep, majorp, minorp)
103
int *event_basep, *error_basep;
104
int *majorp, *minorp;
106
XExtDisplayInfo *info = find_display (dpy);
107
register xXTestGetVersionReq *req;
108
xXTestGetVersionReply rep;
110
if (XextHasExtension(info)) {
112
GetReq(XTestGetVersion, req);
113
req->reqType = info->codes->major_opcode;
114
req->xtReqType = X_XTestGetVersion;
115
req->majorVersion = XTestMajorVersion;
116
req->minorVersion = XTestMinorVersion;
117
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
124
*event_basep = info->codes->first_event;
125
*error_basep = info->codes->first_error;
126
*majorp = rep.majorVersion;
127
*minorp = rep.minorVersion;
135
XTestCompareCursorWithWindow(dpy, window, cursor)
140
XExtDisplayInfo *info = find_display (dpy);
141
register xXTestCompareCursorReq *req;
142
xXTestCompareCursorReply rep;
144
XTestCheckExtension (dpy, info, 0);
147
GetReq(XTestCompareCursor, req);
148
req->reqType = info->codes->major_opcode;
149
req->xtReqType = X_XTestCompareCursor;
150
req->window = window;
151
req->cursor = cursor;
152
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
163
XTestCompareCurrentCursorWithWindow(dpy, window)
167
return XTestCompareCursorWithWindow(dpy, window, XTestCurrentCursor);
171
XTestFakeKeyEvent(dpy, keycode, is_press, delay)
173
unsigned int keycode;
177
XExtDisplayInfo *info = find_display (dpy);
178
register xXTestFakeInputReq *req;
180
XTestCheckExtension (dpy, info, 0);
183
GetReq(XTestFakeInput, req);
184
req->reqType = info->codes->major_opcode;
185
req->xtReqType = X_XTestFakeInput;
186
req->type = is_press ? KeyPress : KeyRelease;
187
req->detail = keycode;
195
XTestFakeButtonEvent(dpy, button, is_press, delay)
201
XExtDisplayInfo *info = find_display (dpy);
202
register xXTestFakeInputReq *req;
204
XTestCheckExtension (dpy, info, 0);
207
GetReq(XTestFakeInput, req);
208
req->reqType = info->codes->major_opcode;
209
req->xtReqType = X_XTestFakeInput;
210
req->type = is_press ? ButtonPress : ButtonRelease;
211
req->detail = button;
219
XTestFakeMotionEvent(dpy, screen, x, y, delay)
225
XExtDisplayInfo *info = find_display (dpy);
226
register xXTestFakeInputReq *req;
228
XTestCheckExtension (dpy, info, 0);
231
GetReq(XTestFakeInput, req);
232
req->reqType = info->codes->major_opcode;
233
req->xtReqType = X_XTestFakeInput;
234
req->type = MotionNotify;
239
req->root = RootWindow(dpy, screen);
249
XTestFakeRelativeMotionEvent(dpy, dx, dy, delay)
254
XExtDisplayInfo *info = find_display (dpy);
255
register xXTestFakeInputReq *req;
257
XTestCheckExtension (dpy, info, 0);
260
GetReq(XTestFakeInput, req);
261
req->reqType = info->codes->major_opcode;
262
req->xtReqType = X_XTestFakeInput;
263
req->type = MotionNotify;
275
send_axes(dpy, info, req, dev, first_axis, axes, n_axes)
277
XExtDisplayInfo *info;
278
xXTestFakeInputReq *req;
287
req->deviceid |= MORE_EVENTS;
288
req->length += ((n_axes + 5) / 6) * (SIZEOF(xEvent) >> 2);
289
ev.type = XI_DeviceValuator + (long)info->data;
290
ev.deviceid = dev->device_id;
291
ev.num_valuators = n_axes;
292
ev.first_valuator = first_axis;
299
ev.valuator5 = *(axes+5);
301
ev.valuator4 = *(axes+4);
303
ev.valuator3 = *(axes+3);
305
ev.valuator2 = *(axes+2);
307
ev.valuator1 = *(axes+1);
309
ev.valuator0 = *axes;
311
Data(dpy, (char *)&ev, SIZEOF(xEvent));
314
ev.first_valuator += n;
319
XTestFakeDeviceKeyEvent(dpy, dev, keycode, is_press, axes, n_axes, delay)
322
unsigned int keycode;
328
XExtDisplayInfo *info = find_display (dpy);
329
register xXTestFakeInputReq *req;
331
XTestICheckExtension (dpy, info, 0);
334
GetReq(XTestFakeInput, req);
335
req->reqType = info->codes->major_opcode;
336
req->xtReqType = X_XTestFakeInput;
337
req->type = is_press ? XI_DeviceKeyPress : XI_DeviceKeyRelease;
338
req->type += (int)(long)info->data;
339
req->detail = keycode;
341
req->deviceid = dev->device_id;
343
send_axes(dpy, info, req, dev, 0, axes, n_axes);
350
XTestFakeDeviceButtonEvent(dpy, dev, button, is_press, axes, n_axes, delay)
359
XExtDisplayInfo *info = find_display (dpy);
360
register xXTestFakeInputReq *req;
362
XTestICheckExtension (dpy, info, 0);
365
GetReq(XTestFakeInput, req);
366
req->reqType = info->codes->major_opcode;
367
req->xtReqType = X_XTestFakeInput;
368
req->type = is_press ? XI_DeviceButtonPress : XI_DeviceButtonRelease;
369
req->type += (int)(long)info->data;
370
req->detail = button;
372
req->deviceid = dev->device_id;
374
send_axes(dpy, info, req, dev, 0, axes, n_axes);
381
XTestFakeProximityEvent(dpy, dev, in_prox, axes, n_axes, delay)
389
XExtDisplayInfo *info = find_display (dpy);
390
register xXTestFakeInputReq *req;
392
XTestICheckExtension (dpy, info, 0);
395
GetReq(XTestFakeInput, req);
396
req->reqType = info->codes->major_opcode;
397
req->xtReqType = X_XTestFakeInput;
398
req->type = in_prox ? XI_ProximityIn : XI_ProximityOut;
399
req->type += (int)(long)info->data;
401
req->deviceid = dev->device_id;
403
send_axes(dpy, info, req, dev, 0, axes, n_axes);
410
XTestFakeDeviceMotionEvent(dpy, dev, is_relative,
411
first_axis, axes, n_axes, delay)
420
XExtDisplayInfo *info = find_display (dpy);
421
register xXTestFakeInputReq *req;
423
XTestICheckExtension (dpy, info, 0);
426
GetReq(XTestFakeInput, req);
427
req->reqType = info->codes->major_opcode;
428
req->xtReqType = X_XTestFakeInput;
429
req->type = XI_DeviceMotionNotify + (int)(long)info->data;
430
req->detail = is_relative;
432
req->deviceid = dev->device_id;
433
send_axes(dpy, info, req, dev, first_axis, axes, n_axes);
440
XTestGrabControl(dpy, impervious)
444
XExtDisplayInfo *info = find_display (dpy);
445
register xXTestGrabControlReq *req;
447
XTestCheckExtension (dpy, info, 0);
450
GetReq(XTestGrabControl, req);
451
req->reqType = info->codes->major_opcode;
452
req->xtReqType = X_XTestGrabControl;
453
req->impervious = impervious;
460
XTestSetGContextOfGC(gc, gid)
468
XTestSetVisualIDOfVisual(visual, visualid)
472
visual->visualid = visualid;
475
static xReq _dummy_request = {
487
if ((something = (dpy->bufptr != dpy->buffer))) {
488
for (ptr = dpy->buffer;
490
ptr += (((xReq *)ptr)->length << 2))
492
dpy->bufptr = dpy->buffer;
493
dpy->last_req = (char *)&_dummy_request;