MITMisc.c revision 485f0483
1/*
2 * $Xorg: MITMisc.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
3 *
4Copyright 1989, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25 *
26 */
27/* $XFree86: xc/lib/Xext/MITMisc.c,v 1.3 2002/10/16 00:37:27 dawes Exp $ */
28
29/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
30
31#define NEED_REPLIES
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35#include <X11/Xlibint.h>
36#include <X11/extensions/MITMisc.h>
37#include <X11/extensions/mitmiscproto.h>
38#include <X11/extensions/Xext.h>
39#include <X11/extensions/extutil.h>
40
41static XExtensionInfo _mit_info_data;
42static XExtensionInfo *mit_info = &_mit_info_data;
43static /* const */ char *mit_extension_name = MITMISCNAME;
44
45#define MITCheckExtension(dpy,i,val) \
46  XextCheckExtension (dpy, i, mit_extension_name, val)
47
48/*****************************************************************************
49 *                                                                           *
50 *			   private utility routines                          *
51 *                                                                           *
52 *****************************************************************************/
53
54static int close_display(Display *dpy, XExtCodes *codes);
55static /* const */ XExtensionHooks mit_extension_hooks = {
56    NULL,				/* create_gc */
57    NULL,				/* copy_gc */
58    NULL,				/* flush_gc */
59    NULL,				/* free_gc */
60    NULL,				/* create_font */
61    NULL,				/* free_font */
62    close_display,			/* close_display */
63    NULL,				/* wire_to_event */
64    NULL,				/* event_to_wire */
65    NULL,				/* error */
66    NULL				/* error_string */
67};
68
69static XEXT_GENERATE_FIND_DISPLAY (find_display, mit_info, mit_extension_name,
70				   &mit_extension_hooks, MITMiscNumberEvents,
71				   NULL)
72
73static XEXT_GENERATE_CLOSE_DISPLAY (close_display, mit_info)
74
75
76/*****************************************************************************
77 *                                                                           *
78 *		    public routines               			     *
79 *                                                                           *
80 *****************************************************************************/
81
82Bool XMITMiscQueryExtension (Display *dpy, int *event_basep, int *error_basep)
83{
84    XExtDisplayInfo *info = find_display (dpy);
85
86    if (XextHasExtension(info)) {
87	*event_basep = info->codes->first_event;
88	*error_basep = info->codes->first_error;
89	return True;
90    } else {
91	return False;
92    }
93}
94
95
96Status XMITMiscSetBugMode(Display *dpy, Bool onOff)
97{
98    XExtDisplayInfo *info = find_display (dpy);
99    register xMITSetBugModeReq *req;
100
101    MITCheckExtension (dpy, info, 0);
102
103    LockDisplay(dpy);
104    GetReq(MITSetBugMode, req);
105    req->reqType = info->codes->major_opcode;
106    req->mitReqType = X_MITSetBugMode;
107    req->onOff = onOff;
108    UnlockDisplay(dpy);
109    SyncHandle();
110    return 1;
111}
112
113Bool XMITMiscGetBugMode(Display *dpy)
114{
115    XExtDisplayInfo *info = find_display (dpy);
116    register xMITGetBugModeReq *req;
117    xMITGetBugModeReply rep;
118
119    MITCheckExtension (dpy, info, 0);
120
121    LockDisplay(dpy);
122    GetReq(MITGetBugMode, req);
123    req->reqType = info->codes->major_opcode;
124    req->mitReqType = X_MITGetBugMode;
125    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
126	UnlockDisplay(dpy);
127	SyncHandle();
128	return False;
129    }
130    UnlockDisplay(dpy);
131    SyncHandle();
132    return rep.onOff;
133}
134