XTest.c revision 25b89263
1a253d6aeSmrg/*
2a253d6aeSmrgCopyright 1990, 1991 by UniSoft Group Limited
3a253d6aeSmrg*/
4a253d6aeSmrg
5a253d6aeSmrg/*
6a253d6aeSmrg
7a253d6aeSmrgCopyright 1992, 1993, 1998  The Open Group
8a253d6aeSmrg
9a253d6aeSmrgPermission to use, copy, modify, distribute, and sell this software and its
10a253d6aeSmrgdocumentation for any purpose is hereby granted without fee, provided that
11a253d6aeSmrgthe above copyright notice appear in all copies and that both that
12a253d6aeSmrgcopyright notice and this permission notice appear in supporting
13a253d6aeSmrgdocumentation.
14a253d6aeSmrg
15a253d6aeSmrgThe above copyright notice and this permission notice shall be included
16a253d6aeSmrgin all copies or substantial portions of the Software.
17a253d6aeSmrg
18a253d6aeSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19a253d6aeSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20a253d6aeSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21a253d6aeSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
22a253d6aeSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23a253d6aeSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24a253d6aeSmrgOTHER DEALINGS IN THE SOFTWARE.
25a253d6aeSmrg
26a253d6aeSmrgExcept as contained in this notice, the name of The Open Group shall
27a253d6aeSmrgnot be used in advertising or otherwise to promote the sale, use or
28a253d6aeSmrgother dealings in this Software without prior written authorization
29a253d6aeSmrgfrom The Open Group.
30a253d6aeSmrg
31a253d6aeSmrg*/
32a253d6aeSmrg
33a253d6aeSmrg#include <X11/Xlibint.h>
34a253d6aeSmrg#include <X11/extensions/XTest.h>
35ea133fd7Smrg#include <X11/extensions/xtestproto.h>
36a253d6aeSmrg#include <X11/extensions/Xext.h>
37a253d6aeSmrg#include <X11/extensions/extutil.h>
38a253d6aeSmrg#include <X11/extensions/XInput.h>
39a253d6aeSmrg#include <X11/extensions/XIproto.h>
40a253d6aeSmrg
41a253d6aeSmrgstatic XExtensionInfo _xtest_info_data;
42a253d6aeSmrgstatic XExtensionInfo *xtest_info = &_xtest_info_data;
43a253d6aeSmrgstatic /* const */ char *xtest_extension_name = XTestExtensionName;
44a253d6aeSmrg
45a253d6aeSmrg#define XTestCheckExtension(dpy,i,val) \
46a253d6aeSmrg  XextCheckExtension (dpy, i, xtest_extension_name, val)
47a253d6aeSmrg
48a253d6aeSmrg#define XTestICheckExtension(dpy,i,val) \
49a253d6aeSmrg  XextCheckExtension (dpy, i, xtest_extension_name, val); \
50a253d6aeSmrg  if (!i->data) return val
51a253d6aeSmrg
52a253d6aeSmrg/*****************************************************************************
53a253d6aeSmrg *                                                                           *
54a253d6aeSmrg *			   private utility routines                          *
55a253d6aeSmrg *                                                                           *
56a253d6aeSmrg *****************************************************************************/
57a253d6aeSmrg
58a253d6aeSmrgstatic int close_display(Display *dpy, XExtCodes *codes);
59a253d6aeSmrgstatic /* const */ XExtensionHooks xtest_extension_hooks = {
60a253d6aeSmrg    NULL,				/* create_gc */
61a253d6aeSmrg    NULL,				/* copy_gc */
62a253d6aeSmrg    NULL,				/* flush_gc */
63a253d6aeSmrg    NULL,				/* free_gc */
64a253d6aeSmrg    NULL,				/* create_font */
65a253d6aeSmrg    NULL,				/* free_font */
66a253d6aeSmrg    close_display,			/* close_display */
67a253d6aeSmrg    NULL,				/* wire_to_event */
68a253d6aeSmrg    NULL,				/* event_to_wire */
69a253d6aeSmrg    NULL,				/* error */
70a253d6aeSmrg    NULL				/* error_string */
71a253d6aeSmrg};
72a253d6aeSmrg
73a253d6aeSmrgstatic XPointer
74a253d6aeSmrgget_xinput_base(Display *dpy)
75a253d6aeSmrg{
76a253d6aeSmrg    int major_opcode, first_event, first_error;
77a253d6aeSmrg    first_event = 0;
78a253d6aeSmrg
79a253d6aeSmrg    XQueryExtension(dpy, INAME, &major_opcode, &first_event, &first_error);
80a253d6aeSmrg    return (XPointer)(long)first_event;
81a253d6aeSmrg}
82a253d6aeSmrg
83a253d6aeSmrgstatic XEXT_GENERATE_FIND_DISPLAY (find_display, xtest_info,
84a253d6aeSmrg				   xtest_extension_name,
85a253d6aeSmrg				   &xtest_extension_hooks, XTestNumberEvents,
86a253d6aeSmrg				   get_xinput_base(dpy))
87a253d6aeSmrg
88a253d6aeSmrgstatic XEXT_GENERATE_CLOSE_DISPLAY (close_display, xtest_info)
89a253d6aeSmrg
90a253d6aeSmrg/*****************************************************************************
91a253d6aeSmrg *                                                                           *
92a253d6aeSmrg *		    public routines               			     *
93a253d6aeSmrg *                                                                           *
94a253d6aeSmrg *****************************************************************************/
95a253d6aeSmrg
96a253d6aeSmrgBool
97ea133fd7SmrgXTestQueryExtension (Display *dpy,
98ea133fd7Smrg		     int *event_base_return, int *error_base_return,
99ea133fd7Smrg		     int *major_return, int *minor_return)
100a253d6aeSmrg{
101a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
102a253d6aeSmrg    register xXTestGetVersionReq *req;
103a253d6aeSmrg    xXTestGetVersionReply rep;
104a253d6aeSmrg
105a253d6aeSmrg    if (XextHasExtension(info)) {
106a253d6aeSmrg	LockDisplay(dpy);
107a253d6aeSmrg	GetReq(XTestGetVersion, req);
108a253d6aeSmrg	req->reqType = info->codes->major_opcode;
109a253d6aeSmrg	req->xtReqType = X_XTestGetVersion;
110a253d6aeSmrg	req->majorVersion = XTestMajorVersion;
111a253d6aeSmrg	req->minorVersion = XTestMinorVersion;
112a253d6aeSmrg	if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
113a253d6aeSmrg	    UnlockDisplay(dpy);
114a253d6aeSmrg	    SyncHandle();
115a253d6aeSmrg	    return False;
116a253d6aeSmrg	}
117a253d6aeSmrg	UnlockDisplay(dpy);
118a253d6aeSmrg	SyncHandle();
119ea133fd7Smrg	*event_base_return = info->codes->first_event;
120ea133fd7Smrg	*error_base_return = info->codes->first_error;
121ea133fd7Smrg	*major_return = rep.majorVersion;
122ea133fd7Smrg	*minor_return = rep.minorVersion;
123a253d6aeSmrg	return True;
124a253d6aeSmrg    } else {
125a253d6aeSmrg	return False;
126a253d6aeSmrg    }
127a253d6aeSmrg}
128a253d6aeSmrg
129a253d6aeSmrgBool
130ea133fd7SmrgXTestCompareCursorWithWindow(Display *dpy, Window window, Cursor cursor)
131a253d6aeSmrg{
132a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
133a253d6aeSmrg    register xXTestCompareCursorReq *req;
134a253d6aeSmrg    xXTestCompareCursorReply rep;
135a253d6aeSmrg
136a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
137a253d6aeSmrg
138a253d6aeSmrg    LockDisplay(dpy);
139a253d6aeSmrg    GetReq(XTestCompareCursor, req);
140a253d6aeSmrg    req->reqType = info->codes->major_opcode;
141a253d6aeSmrg    req->xtReqType = X_XTestCompareCursor;
142a253d6aeSmrg    req->window = window;
143a253d6aeSmrg    req->cursor = cursor;
144a253d6aeSmrg    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
145a253d6aeSmrg	UnlockDisplay(dpy);
146a253d6aeSmrg	SyncHandle();
147a253d6aeSmrg	return False;
148a253d6aeSmrg    }
149a253d6aeSmrg    UnlockDisplay(dpy);
150a253d6aeSmrg    SyncHandle();
151a253d6aeSmrg    return rep.same;
152a253d6aeSmrg}
153a253d6aeSmrg
154a253d6aeSmrgBool
155ea133fd7SmrgXTestCompareCurrentCursorWithWindow(Display *dpy, Window window)
156a253d6aeSmrg{
157a253d6aeSmrg    return XTestCompareCursorWithWindow(dpy, window, XTestCurrentCursor);
158a253d6aeSmrg}
159a253d6aeSmrg
160a253d6aeSmrgint
161ea133fd7SmrgXTestFakeKeyEvent(Display *dpy, unsigned int keycode,
162ea133fd7Smrg		  Bool is_press, unsigned long delay)
163a253d6aeSmrg{
164a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
165a253d6aeSmrg    register xXTestFakeInputReq *req;
166a253d6aeSmrg
167a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
168a253d6aeSmrg
169a253d6aeSmrg    LockDisplay(dpy);
170a253d6aeSmrg    GetReq(XTestFakeInput, req);
171a253d6aeSmrg    req->reqType = info->codes->major_opcode;
172a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
173a253d6aeSmrg    req->type = is_press ? KeyPress : KeyRelease;
174a253d6aeSmrg    req->detail = keycode;
175a253d6aeSmrg    req->time = delay;
176a253d6aeSmrg    UnlockDisplay(dpy);
177a253d6aeSmrg    SyncHandle();
178a253d6aeSmrg    return 1;
179a253d6aeSmrg}
180a253d6aeSmrg
181a253d6aeSmrgint
182ea133fd7SmrgXTestFakeButtonEvent(Display *dpy, unsigned int button,
183ea133fd7Smrg		     Bool is_press, unsigned long delay)
184a253d6aeSmrg{
185a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
186a253d6aeSmrg    register xXTestFakeInputReq *req;
187a253d6aeSmrg
188a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
189a253d6aeSmrg
190a253d6aeSmrg    LockDisplay(dpy);
191a253d6aeSmrg    GetReq(XTestFakeInput, req);
192a253d6aeSmrg    req->reqType = info->codes->major_opcode;
193a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
194a253d6aeSmrg    req->type = is_press ? ButtonPress : ButtonRelease;
195a253d6aeSmrg    req->detail = button;
196a253d6aeSmrg    req->time = delay;
197a253d6aeSmrg    UnlockDisplay(dpy);
198a253d6aeSmrg    SyncHandle();
199a253d6aeSmrg    return 1;
200a253d6aeSmrg}
201a253d6aeSmrg
202a253d6aeSmrgint
203ea133fd7SmrgXTestFakeMotionEvent(Display *dpy, int screen, int x, int y, unsigned long delay)
204a253d6aeSmrg{
205a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
206a253d6aeSmrg    register xXTestFakeInputReq *req;
207a253d6aeSmrg
208a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
209a253d6aeSmrg
210a253d6aeSmrg    LockDisplay(dpy);
211a253d6aeSmrg    GetReq(XTestFakeInput, req);
212a253d6aeSmrg    req->reqType = info->codes->major_opcode;
213a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
214a253d6aeSmrg    req->type = MotionNotify;
215a253d6aeSmrg    req->detail = False;
216a253d6aeSmrg    if (screen == -1)
217a253d6aeSmrg	req->root = None;
218a253d6aeSmrg    else
219a253d6aeSmrg	req->root = RootWindow(dpy, screen);
220a253d6aeSmrg    req->rootX = x;
221a253d6aeSmrg    req->rootY = y;
222a253d6aeSmrg    req->time = delay;
223a253d6aeSmrg    UnlockDisplay(dpy);
224a253d6aeSmrg    SyncHandle();
225a253d6aeSmrg    return 1;
226a253d6aeSmrg}
227a253d6aeSmrg
228a253d6aeSmrgint
229ea133fd7SmrgXTestFakeRelativeMotionEvent(Display *dpy, int dx, int dy, unsigned long delay)
230a253d6aeSmrg{
231a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
232a253d6aeSmrg    register xXTestFakeInputReq *req;
233a253d6aeSmrg
234a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
235a253d6aeSmrg
236a253d6aeSmrg    LockDisplay(dpy);
237a253d6aeSmrg    GetReq(XTestFakeInput, req);
238a253d6aeSmrg    req->reqType = info->codes->major_opcode;
239a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
240a253d6aeSmrg    req->type = MotionNotify;
241a253d6aeSmrg    req->detail = True;
242a253d6aeSmrg    req->root = None;
243a253d6aeSmrg    req->rootX = dx;
244a253d6aeSmrg    req->rootY = dy;
245a253d6aeSmrg    req->time = delay;
246a253d6aeSmrg    UnlockDisplay(dpy);
247a253d6aeSmrg    SyncHandle();
248a253d6aeSmrg    return 1;
249a253d6aeSmrg}
250a253d6aeSmrg
251a253d6aeSmrgstatic void
252a253d6aeSmrgsend_axes(
253a253d6aeSmrg    Display *dpy,
254a253d6aeSmrg    XExtDisplayInfo *info,
255a253d6aeSmrg    xXTestFakeInputReq *req,
256a253d6aeSmrg    XDevice *dev,
257a253d6aeSmrg    int first_axis,
258a253d6aeSmrg    int *axes,
259a253d6aeSmrg    int n_axes)
260a253d6aeSmrg{
261a253d6aeSmrg    deviceValuator ev;
262a253d6aeSmrg    int n;
263a253d6aeSmrg
264a253d6aeSmrg    req->deviceid |= MORE_EVENTS;
265a253d6aeSmrg    req->length += ((n_axes + 5) / 6) * (SIZEOF(xEvent) >> 2);
266a253d6aeSmrg    ev.type = XI_DeviceValuator + (long)info->data;
267a253d6aeSmrg    ev.deviceid = dev->device_id;
268a253d6aeSmrg    ev.first_valuator = first_axis;
269a253d6aeSmrg    while (n_axes > 0) {
27025b89263Smrg	n = n_axes > 6 ? 6 : n_axes;
27125b89263Smrg	ev.num_valuators = n;
272a253d6aeSmrg	switch (n) {
273a253d6aeSmrg	case 6:
274a253d6aeSmrg	    ev.valuator5 = *(axes+5);
275a253d6aeSmrg	case 5:
276a253d6aeSmrg	    ev.valuator4 = *(axes+4);
277a253d6aeSmrg	case 4:
278a253d6aeSmrg	    ev.valuator3 = *(axes+3);
279a253d6aeSmrg	case 3:
280a253d6aeSmrg	    ev.valuator2 = *(axes+2);
281a253d6aeSmrg	case 2:
282a253d6aeSmrg	    ev.valuator1 = *(axes+1);
283a253d6aeSmrg	case 1:
284a253d6aeSmrg	    ev.valuator0 = *axes;
285a253d6aeSmrg	}
286a253d6aeSmrg	Data(dpy, (char *)&ev, SIZEOF(xEvent));
287a253d6aeSmrg	axes += n;
288a253d6aeSmrg	n_axes -= n;
289a253d6aeSmrg	ev.first_valuator += n;
290a253d6aeSmrg    }
291a253d6aeSmrg}
292a253d6aeSmrg
293a253d6aeSmrgint
294ea133fd7SmrgXTestFakeDeviceKeyEvent(Display *dpy, XDevice *dev,
295ea133fd7Smrg			unsigned int keycode, Bool is_press,
296ea133fd7Smrg			int *axes, int n_axes, unsigned long delay)
297a253d6aeSmrg{
298a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
299a253d6aeSmrg    register xXTestFakeInputReq *req;
300a253d6aeSmrg
301a253d6aeSmrg    XTestICheckExtension (dpy, info, 0);
302a253d6aeSmrg
303a253d6aeSmrg    LockDisplay(dpy);
304a253d6aeSmrg    GetReq(XTestFakeInput, req);
305a253d6aeSmrg    req->reqType = info->codes->major_opcode;
306a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
307a253d6aeSmrg    req->type = is_press ? XI_DeviceKeyPress : XI_DeviceKeyRelease;
308a253d6aeSmrg    req->type += (int)(long)info->data;
309a253d6aeSmrg    req->detail = keycode;
310a253d6aeSmrg    req->time = delay;
311a253d6aeSmrg    req->deviceid = dev->device_id;
312a253d6aeSmrg    if (n_axes)
313a253d6aeSmrg	send_axes(dpy, info, req, dev, 0, axes, n_axes);
314a253d6aeSmrg    UnlockDisplay(dpy);
315a253d6aeSmrg    SyncHandle();
316a253d6aeSmrg    return 1;
317a253d6aeSmrg}
318a253d6aeSmrg
319a253d6aeSmrgint
320ea133fd7SmrgXTestFakeDeviceButtonEvent(Display *dpy, XDevice *dev,
321ea133fd7Smrg			   unsigned int button, Bool is_press,
322ea133fd7Smrg			   int *axes, int n_axes, unsigned long delay)
323a253d6aeSmrg{
324a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
325a253d6aeSmrg    register xXTestFakeInputReq *req;
326a253d6aeSmrg
327a253d6aeSmrg    XTestICheckExtension (dpy, info, 0);
328a253d6aeSmrg
329a253d6aeSmrg    LockDisplay(dpy);
330a253d6aeSmrg    GetReq(XTestFakeInput, req);
331a253d6aeSmrg    req->reqType = info->codes->major_opcode;
332a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
333a253d6aeSmrg    req->type = is_press ? XI_DeviceButtonPress : XI_DeviceButtonRelease;
334a253d6aeSmrg    req->type += (int)(long)info->data;
335a253d6aeSmrg    req->detail = button;
336a253d6aeSmrg    req->time = delay;
337a253d6aeSmrg    req->deviceid = dev->device_id;
338a253d6aeSmrg    if (n_axes)
339a253d6aeSmrg	send_axes(dpy, info, req, dev, 0, axes, n_axes);
340a253d6aeSmrg    UnlockDisplay(dpy);
341a253d6aeSmrg    SyncHandle();
342a253d6aeSmrg    return 1;
343a253d6aeSmrg}
344a253d6aeSmrg
345a253d6aeSmrgint
346ea133fd7SmrgXTestFakeProximityEvent(Display *dpy, XDevice *dev, Bool in_prox,
347ea133fd7Smrg			int *axes, int n_axes, unsigned long delay)
348a253d6aeSmrg{
349a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
350a253d6aeSmrg    register xXTestFakeInputReq *req;
351a253d6aeSmrg
352a253d6aeSmrg    XTestICheckExtension (dpy, info, 0);
353a253d6aeSmrg
354a253d6aeSmrg    LockDisplay(dpy);
355a253d6aeSmrg    GetReq(XTestFakeInput, req);
356a253d6aeSmrg    req->reqType = info->codes->major_opcode;
357a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
358a253d6aeSmrg    req->type = in_prox ? XI_ProximityIn : XI_ProximityOut;
359a253d6aeSmrg    req->type += (int)(long)info->data;
360a253d6aeSmrg    req->time = delay;
361a253d6aeSmrg    req->deviceid = dev->device_id;
362a253d6aeSmrg    if (n_axes)
363a253d6aeSmrg	send_axes(dpy, info, req, dev, 0, axes, n_axes);
364a253d6aeSmrg    UnlockDisplay(dpy);
365a253d6aeSmrg    SyncHandle();
366a253d6aeSmrg    return 1;
367a253d6aeSmrg}
368a253d6aeSmrg
369a253d6aeSmrgint
370ea133fd7SmrgXTestFakeDeviceMotionEvent(Display *dpy, XDevice *dev,
371ea133fd7Smrg			   Bool is_relative, int first_axis,
372ea133fd7Smrg			   int *axes, int n_axes, unsigned long delay)
373a253d6aeSmrg{
374a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
375a253d6aeSmrg    register xXTestFakeInputReq *req;
376a253d6aeSmrg
377a253d6aeSmrg    XTestICheckExtension (dpy, info, 0);
378a253d6aeSmrg
379a253d6aeSmrg    LockDisplay(dpy);
380a253d6aeSmrg    GetReq(XTestFakeInput, req);
381a253d6aeSmrg    req->reqType = info->codes->major_opcode;
382a253d6aeSmrg    req->xtReqType = X_XTestFakeInput;
383a253d6aeSmrg    req->type = XI_DeviceMotionNotify + (int)(long)info->data;
384a253d6aeSmrg    req->detail = is_relative;
385a253d6aeSmrg    req->time = delay;
386a253d6aeSmrg    req->deviceid = dev->device_id;
387a253d6aeSmrg    send_axes(dpy, info, req, dev, first_axis, axes, n_axes);
388a253d6aeSmrg    UnlockDisplay(dpy);
389a253d6aeSmrg    SyncHandle();
390a253d6aeSmrg    return 1;
391a253d6aeSmrg}
392a253d6aeSmrg
393a253d6aeSmrgint
394ea133fd7SmrgXTestGrabControl(Display *dpy, Bool impervious)
395a253d6aeSmrg{
396a253d6aeSmrg    XExtDisplayInfo *info = find_display (dpy);
397a253d6aeSmrg    register xXTestGrabControlReq *req;
398a253d6aeSmrg
399a253d6aeSmrg    XTestCheckExtension (dpy, info, 0);
400a253d6aeSmrg
401a253d6aeSmrg    LockDisplay(dpy);
402a253d6aeSmrg    GetReq(XTestGrabControl, req);
403a253d6aeSmrg    req->reqType = info->codes->major_opcode;
404a253d6aeSmrg    req->xtReqType = X_XTestGrabControl;
405a253d6aeSmrg    req->impervious = impervious;
406a253d6aeSmrg    UnlockDisplay(dpy);
407a253d6aeSmrg    SyncHandle();
408a253d6aeSmrg    return 1;
409a253d6aeSmrg}
410a253d6aeSmrg
411a253d6aeSmrgvoid
412ea133fd7SmrgXTestSetGContextOfGC(GC gc, GContext gid)
413a253d6aeSmrg{
414a253d6aeSmrg    gc->gid = gid;
415a253d6aeSmrg}
416a253d6aeSmrg
417a253d6aeSmrgvoid
418ea133fd7SmrgXTestSetVisualIDOfVisual(Visual *visual, VisualID visualid)
419a253d6aeSmrg{
420a253d6aeSmrg    visual->visualid = visualid;
421a253d6aeSmrg}
422a253d6aeSmrg
423a253d6aeSmrgstatic xReq _dummy_request = {
424a253d6aeSmrg	0, 0, 0
425a253d6aeSmrg};
426a253d6aeSmrg
427a253d6aeSmrgStatus
428ea133fd7SmrgXTestDiscard(Display *dpy)
429a253d6aeSmrg{
430a253d6aeSmrg    Bool something;
431a253d6aeSmrg    register char *ptr;
432a253d6aeSmrg
433a253d6aeSmrg    LockDisplay(dpy);
434a253d6aeSmrg    if ((something = (dpy->bufptr != dpy->buffer))) {
435a253d6aeSmrg	for (ptr = dpy->buffer;
436a253d6aeSmrg	     ptr < dpy->bufptr;
437a253d6aeSmrg	     ptr += (((xReq *)ptr)->length << 2))
438a253d6aeSmrg	    dpy->request--;
439a253d6aeSmrg	dpy->bufptr = dpy->buffer;
440a253d6aeSmrg	dpy->last_req = (char *)&_dummy_request;
441a253d6aeSmrg    }
442a253d6aeSmrg    UnlockDisplay(dpy);
443a253d6aeSmrg    SyncHandle();
444a253d6aeSmrg    return something;
445a253d6aeSmrg}
446