aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/X11/XKBCtrls.c
blob: 8f2876e126f729689ee4c6521484eb21553bc88e (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/* $Xorg: XKBCtrls.c,v 1.3 2000/08/17 19:45:00 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.

Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting
documentation, and that the name of Silicon Graphics not be 
used in advertising or publicity pertaining to distribution 
of the software without specific prior written permission.
Silicon Graphics makes no representation about the suitability 
of this software for any purpose. It is provided "as is"
without any express or implied warranty.

SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.

********************************************************/
/* $XFree86: xc/lib/X11/XKBCtrls.c,v 1.4 2002/12/10 04:33:48 dawes Exp $ */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include <nx-X11/extensions/XKBproto.h>
#include "XKBlibint.h"


static xkbSetControlsReq *
_XkbGetSetControlsReq(Display *dpy,XkbInfoPtr xkbi,unsigned int deviceSpec)
{
xkbSetControlsReq *req;

    GetReq(kbSetControls,req);
    bzero(req,SIZEOF(xkbSetControlsReq));
    req->reqType = xkbi->codes->major_opcode;
    req->length = (SIZEOF(xkbSetControlsReq)>>2);
    req->xkbReqType = X_kbSetControls;
    req->deviceSpec = deviceSpec;
    return req;
}

Bool 
XkbSetAutoRepeatRate(	Display *dpy,
			unsigned int deviceSpec, 
			unsigned int timeout, 
			unsigned int interval)
{
    register xkbSetControlsReq *req;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    LockDisplay(dpy);
    req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
    req->changeCtrls = XkbRepeatKeysMask;
    req->repeatDelay = timeout;
    req->repeatInterval = interval;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool 
XkbGetAutoRepeatRate(	Display *	dpy,
			unsigned int 	deviceSpec,
			unsigned int *	timeoutp,
			unsigned int *	intervalp)
{
    register xkbGetControlsReq *req;
    xkbGetControlsReply rep;
    XkbInfoPtr xkbi;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    LockDisplay(dpy);
    xkbi = dpy->xkb_info;
    GetReq(kbGetControls, req);
    req->reqType = xkbi->codes->major_opcode;
    req->xkbReqType = X_kbGetControls;
    req->deviceSpec = deviceSpec;
    if (!_XReply(dpy, (xReply *)&rep, 
		(SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return False;
    }
    UnlockDisplay(dpy);
    SyncHandle();
    *timeoutp = rep.repeatDelay;
    *intervalp = rep.repeatInterval;
    return True;
}

Bool
XkbSetServerInternalMods(	Display *	dpy,
				unsigned 	deviceSpec,
				unsigned 	affectReal,
				unsigned 	realValues,
				unsigned 	affectVirtual,
				unsigned 	virtualValues)
{
    register xkbSetControlsReq *req;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    LockDisplay(dpy);
    req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
    req->affectInternalMods = affectReal;
    req->internalMods = realValues;
    req->affectInternalVMods= affectVirtual;
    req->internalVMods= virtualValues;
    req->changeCtrls = XkbInternalModsMask;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool
XkbSetIgnoreLockMods(	Display *	dpy,
			unsigned int 	deviceSpec,
			unsigned 	affectReal,
			unsigned 	realValues,
			unsigned 	affectVirtual,
			unsigned 	virtualValues)
{
    register xkbSetControlsReq *req;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    LockDisplay(dpy);
    req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
    req->affectIgnoreLockMods= affectReal;
    req->ignoreLockMods = realValues;
    req->affectIgnoreLockVMods= affectVirtual;
    req->ignoreLockVMods= virtualValues;
    req->changeCtrls = XkbIgnoreLockModsMask;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Bool
XkbChangeEnabledControls(	Display *	dpy,
				unsigned	deviceSpec,
				unsigned	affect,
				unsigned	values)
{
    register xkbSetControlsReq *req;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    LockDisplay(dpy);
    req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,deviceSpec);
    req->affectEnabledCtrls= affect;
    req->enabledCtrls= (affect&values);
    req->changeCtrls = XkbControlsEnabledMask;
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

Status 
XkbGetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
{
    register xkbGetControlsReq *req;
    xkbGetControlsReply rep;
    XkbControlsPtr	ctrls;
    XkbInfoPtr xkbi;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return BadAccess;
    if ((!xkb) || (!which))
	return BadMatch;

    LockDisplay(dpy);
    xkbi = dpy->xkb_info;
    GetReq(kbGetControls, req);
    if (!xkb->ctrls)  {
	xkb->ctrls = _XkbTypedCalloc(1,XkbControlsRec);
	if (!xkb->ctrls) {
	    UnlockDisplay(dpy);
	    SyncHandle();
	    return BadAlloc;
	} 
    }
    req->reqType = xkbi->codes->major_opcode;
    req->xkbReqType = X_kbGetControls;
    req->deviceSpec = xkb->device_spec;
    if (!_XReply(dpy, (xReply *)&rep, 
		(SIZEOF(xkbGetControlsReply)-SIZEOF(xReply))>>2, xFalse)) {
	UnlockDisplay(dpy);
	SyncHandle();
	return BadImplementation;
    }
    if (xkb->device_spec==XkbUseCoreKbd)
	xkb->device_spec= rep.deviceID;
    ctrls= xkb->ctrls;
    if (which&XkbControlsEnabledMask)
	ctrls->enabled_ctrls = rep.enabledCtrls;
    ctrls->num_groups= rep.numGroups;
    if (which&XkbGroupsWrapMask)
	ctrls->groups_wrap= rep.groupsWrap;
    if (which&XkbInternalModsMask) {
	ctrls->internal.mask = rep.internalMods;
	ctrls->internal.real_mods = rep.internalRealMods;
	ctrls->internal.vmods = rep.internalVMods;
    }
    if (which&XkbIgnoreLockModsMask) {
	ctrls->ignore_lock.mask = rep.ignoreLockMods;
	ctrls->ignore_lock.real_mods = rep.ignoreLockRealMods;
	ctrls->ignore_lock.vmods = rep.ignoreLockVMods;
    }
    if (which&XkbRepeatKeysMask) {
	ctrls->repeat_delay = rep.repeatDelay;
	ctrls->repeat_interval = rep.repeatInterval;
    }
    if (which&XkbSlowKeysMask)
	ctrls->slow_keys_delay = rep.slowKeysDelay;
    if (which&XkbBounceKeysMask)
	ctrls->debounce_delay = rep.debounceDelay;
    if (which&XkbMouseKeysMask) {
	ctrls->mk_dflt_btn = rep.mkDfltBtn;
    }
    if (which&XkbMouseKeysAccelMask) {
	ctrls->mk_delay = rep.mkDelay;
	ctrls->mk_interval = rep.mkInterval;
	ctrls->mk_time_to_max = rep.mkTimeToMax;
	ctrls->mk_max_speed = rep.mkMaxSpeed;
	ctrls->mk_curve = rep.mkCurve;
    }
    if (which&XkbAccessXKeysMask)
	ctrls->ax_options= rep.axOptions;
    if (which&XkbStickyKeysMask) {
	ctrls->ax_options &= ~XkbAX_SKOptionsMask;
	ctrls->ax_options |= rep.axOptions & XkbAX_SKOptionsMask;
    }
    if (which&XkbAccessXFeedbackMask) {
	ctrls->ax_options &= ~XkbAX_FBOptionsMask;
	ctrls->ax_options |= rep.axOptions & XkbAX_FBOptionsMask;
    }
    if (which&XkbAccessXTimeoutMask) {
	ctrls->ax_timeout = rep.axTimeout;
	ctrls->axt_ctrls_mask = rep.axtCtrlsMask;
	ctrls->axt_ctrls_values = rep.axtCtrlsValues;
	ctrls->axt_opts_mask = rep.axtOptsMask;
	ctrls->axt_opts_values= rep.axtOptsValues;
    }
    if (which&XkbPerKeyRepeatMask) {
   	memcpy(ctrls->per_key_repeat,rep.perKeyRepeat,
					  XkbPerKeyBitArraySize); 
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return Success;
}

Bool 
XkbSetControls(Display *dpy, unsigned long which, XkbDescPtr xkb)
{
    register xkbSetControlsReq *req;
    XkbControlsPtr	ctrls;

    if ((dpy->flags & XlibDisplayNoXkb) ||
	(!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)))
	return False;
    if ((!xkb)||(!xkb->ctrls))
	return False;

    ctrls= xkb->ctrls;
    LockDisplay(dpy);
    req= _XkbGetSetControlsReq(dpy,dpy->xkb_info,xkb->device_spec);
    req->changeCtrls = (CARD32)which;
    if (which&XkbInternalModsMask) {
	req->affectInternalMods= ~0;
	req->internalMods= ctrls->internal.real_mods;
	req->affectInternalVMods = ~0;
	req->internalVMods= ctrls->internal.vmods;
    }
    if (which&XkbIgnoreLockModsMask) {
	req->affectIgnoreLockMods= ~0;
	req->ignoreLockMods= ctrls->ignore_lock.real_mods;
	req->affectIgnoreLockVMods= ~0;
	req->ignoreLockVMods= ctrls->ignore_lock.vmods;
    }
    if (which&XkbControlsEnabledMask) {
	req->affectEnabledCtrls= XkbAllBooleanCtrlsMask;
	req->enabledCtrls= ctrls->enabled_ctrls;
    }
    if (which&XkbRepeatKeysMask) {
	req->repeatDelay = ctrls->repeat_delay;
	req->repeatInterval = ctrls->repeat_interval;
    }
    if (which&XkbSlowKeysMask)
	 req->slowKeysDelay = ctrls->slow_keys_delay;
    if (which&XkbBounceKeysMask)
	 req->debounceDelay = ctrls->debounce_delay;
    if (which&XkbMouseKeysMask) {
	req->mkDfltBtn = ctrls->mk_dflt_btn;
    }
    if (which&XkbGroupsWrapMask)
	req->groupsWrap= ctrls->groups_wrap;
    if (which&(XkbAccessXKeysMask|XkbStickyKeysMask|XkbAccessXFeedbackMask))
	req->axOptions= ctrls->ax_options;
    if (which&XkbMouseKeysAccelMask) {
	req->mkDelay = ctrls->mk_delay;
	req->mkInterval = ctrls->mk_interval;
	req->mkTimeToMax = ctrls->mk_time_to_max;
	req->mkMaxSpeed = ctrls->mk_max_speed;
	req->mkCurve = ctrls->mk_curve;
    }
    if (which&XkbAccessXTimeoutMask) {
	 req->axTimeout = ctrls->ax_timeout;
	 req->axtCtrlsMask = ctrls->axt_ctrls_mask;
	 req->axtCtrlsValues = ctrls->axt_ctrls_values;
	 req->axtOptsMask = ctrls->axt_opts_mask;
	 req->axtOptsValues=ctrls->axt_opts_values;
    }
    if (which&XkbPerKeyRepeatMask) {
	memcpy(req->perKeyRepeat,ctrls->per_key_repeat,
					XkbPerKeyBitArraySize);
    }
    UnlockDisplay(dpy);
    SyncHandle();
    return True;
}

/***====================================================================***/

void
XkbNoteControlsChanges(	XkbControlsChangesPtr		old,
			XkbControlsNotifyEvent *	new,
			unsigned int	 		wanted)
{
    old->changed_ctrls|= (new->changed_ctrls&wanted);
    if (new->changed_ctrls&XkbControlsEnabledMask&wanted)
	old->enabled_ctrls_changes^= new->enabled_ctrl_changes;
    /* num_groups_changed?? */
    return;
}