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