summaryrefslogtreecommitdiff
path: root/xc/lib/Xxf86misc/XF86Misc.c
blob: 35c77a5e48c9eb108be301c7308120446d87d708 (plain)
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
/* $XFree86: xc/lib/Xxf86misc/XF86Misc.c,v 3.7 1998/06/28 03:52:34 dawes Exp $ */

/*
 * Copyright (c) 1995, 1996  The XFree86 Project, Inc
 */

/* THIS IS NOT AN X CONSORTIUM STANDARD */

#define NEED_EVENTS
#define NEED_REPLIES
#include "Xlibint.h"
#include "xf86mscstr.h"
#include "Xext.h"
#include "extutil.h"

static XExtensionInfo _xf86misc_info_data;
static XExtensionInfo *xf86misc_info = &_xf86misc_info_data;
static char *xf86misc_extension_name = XF86MISCNAME;

#define XF86MiscCheckExtension(dpy,i,val) \
  XextCheckExtension (dpy, i, xf86misc_extension_name, val)

/*****************************************************************************
 *                                                                           *
 *			   private utility routines                          *
 *                                                                           *
 *****************************************************************************/

static int close_display();
static /* const */ XExtensionHooks xf86misc_extension_hooks = {
    NULL,				/* create_gc */
    NULL,				/* copy_gc */
    NULL,				/* flush_gc */
    NULL,				/* free_gc */
    NULL,				/* create_font */
    NULL,				/* free_font */
    close_display,			/* close_display */
    NULL,				/* wire_to_event */
    NULL,				/* event_to_wire */
    NULL,				/* error */
    NULL,				/* error_string */
};

static XEXT_GENERATE_FIND_DISPLAY (find_display, xf86misc_info, 
				   xf86misc_extension_name, 
				   &xf86misc_extension_hooks, 
				   0, NULL)

static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86misc_info)


/*****************************************************************************
 *                                                                           *
 *		    public XFree86-Misc Extension routines                *
 *                                                                           *
 *****************************************************************************/

Bool XF86MiscQueryExtension (dpy, event_basep, error_basep)
    Display *dpy;
    int *event_basep, *error_basep;
{
    XExtDisplayInfo *info = find_display (dpy);

    if (XextHasExtension(info)) {
	*event_basep = info->codes->first_event;
	*error_basep = info->codes->first_error;
	return True;
    } else {
	return False;
    }
}

Bool XF86MiscQueryVersion(dpy, majorVersion, minorVersion)
    Display* dpy;
    int* majorVersion; 
    int* minorVersion;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXF86MiscQueryVersionReply rep;
    xXF86MiscQueryVersionReq *req;

    XF86MiscCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(XF86MiscQueryVersion, req);
    req->reqType = info->codes->major_opcode;
    req->xf86miscReqType = X_XF86MiscQueryVersion;
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    *majorVersion = rep.majorVersion;
    *minorVersion = rep.minorVersion;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool XF86MiscGetMouseSettings(dpy, mouseinfo)
    Display* dpy;
    XF86MiscMouseSettings *mouseinfo;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXF86MiscGetMouseSettingsReply rep;
    xXF86MiscGetMouseSettingsReq *req;
    int i;

    XF86MiscCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(XF86MiscGetMouseSettings, req);
    req->reqType = info->codes->major_opcode;
    req->xf86miscReqType = X_XF86MiscGetMouseSettings;
    if (!_XReply(dpy, (xReply *)&rep,
		(SIZEOF(xXF86MiscGetMouseSettingsReply) - SIZEOF(xReply))>>2,
		xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }

    mouseinfo->type = rep.mousetype;
    mouseinfo->baudrate = rep.baudrate;
    mouseinfo->samplerate = rep.samplerate;
    mouseinfo->resolution = rep.resolution;
    mouseinfo->buttons = rep.buttons;
    mouseinfo->emulate3buttons = rep.emulate3buttons;
    mouseinfo->emulate3timeout = rep.emulate3timeout;
    mouseinfo->chordmiddle = rep.chordmiddle;
    mouseinfo->flags = rep.flags;
    if (rep.devnamelen > 0) {
        if (!(mouseinfo->device = Xcalloc(rep.devnamelen + 1, 1))) {
            _XEatData(dpy, (rep.devnamelen+3) & ~3);
            Xfree(mouseinfo->device);
            return False;
        }
        _XReadPad(dpy, mouseinfo->device, rep.devnamelen);
    } else
	mouseinfo->device = NULL;

    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool XF86MiscGetKbdSettings(dpy, kbdinfo)
    Display* dpy;
    XF86MiscKbdSettings *kbdinfo;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXF86MiscGetKbdSettingsReply rep;
    xXF86MiscGetKbdSettingsReq *req;
    int i;

    XF86MiscCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(XF86MiscGetKbdSettings, req);
    req->reqType = info->codes->major_opcode;
    req->xf86miscReqType = X_XF86MiscGetKbdSettings;
    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }

    kbdinfo->type = rep.kbdtype;
    kbdinfo->rate = rep.rate;
    kbdinfo->delay = rep.delay;
    kbdinfo->servnumlock = rep.servnumlock;

    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool XF86MiscSetMouseSettings(dpy, mouseinfo)
    Display* dpy;
    XF86MiscMouseSettings *mouseinfo;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXF86MiscSetMouseSettingsReq *req;
    int i;

    XF86MiscCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(XF86MiscSetMouseSettings, req);
    req->reqType = info->codes->major_opcode;
    req->xf86miscReqType = X_XF86MiscSetMouseSettings;
    req->mousetype = mouseinfo->type;
    req->baudrate = mouseinfo->baudrate;
    req->samplerate = mouseinfo->samplerate;
    req->resolution = mouseinfo->resolution;
    req->buttons = mouseinfo->buttons;
    req->emulate3buttons = mouseinfo->emulate3buttons;
    req->emulate3timeout = mouseinfo->emulate3timeout;
    req->chordmiddle = mouseinfo->chordmiddle;
    req->flags = mouseinfo->flags;

    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool XF86MiscSetKbdSettings(dpy, kbdinfo)
    Display* dpy;
    XF86MiscKbdSettings *kbdinfo;
{
    XExtDisplayInfo *info = find_display (dpy);
    xXF86MiscSetKbdSettingsReq *req;
    int i;

    XF86MiscCheckExtension (dpy, info, False);

    LockDisplay(dpy);
    GetReq(XF86MiscSetKbdSettings, req);
    req->reqType = info->codes->major_opcode;
    req->xf86miscReqType = X_XF86MiscSetKbdSettings;
    req->kbdtype = kbdinfo->type;
    req->rate = kbdinfo->rate;
    req->delay = kbdinfo->delay;
    req->servnumlock = kbdinfo->servnumlock;

    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}