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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
|
/************************************************************
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.
********************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include "Xlibint.h"
#include <nx-X11/extensions/XKBproto.h>
#include "XKBlibint.h"
XkbInternAtomFunc _XkbInternAtomFunc = XInternAtom;
XkbGetAtomNameFunc _XkbGetAtomNameFunc = XGetAtomName;
Bool
XkbQueryExtension(Display *dpy,
int *opcodeReturn,
int *eventBaseReturn,
int *errorBaseReturn,
int *majorReturn,
int *minorReturn)
{
if (!XkbUseExtension(dpy, majorReturn, minorReturn))
return False;
if (opcodeReturn)
*opcodeReturn = dpy->xkb_info->codes->major_opcode;
if (eventBaseReturn)
*eventBaseReturn = dpy->xkb_info->codes->first_event;
if (errorBaseReturn)
*errorBaseReturn = dpy->xkb_info->codes->first_error;
if (majorReturn)
*majorReturn = dpy->xkb_info->srv_major;
if (minorReturn)
*minorReturn = dpy->xkb_info->srv_minor;
return True;
}
Bool
XkbLibraryVersion(int *libMajorRtrn, int *libMinorRtrn)
{
int supported;
if (*libMajorRtrn != XkbMajorVersion) {
/* version 0.65 is (almost) compatible with 1.00 */
if ((XkbMajorVersion == 1) &&
(((*libMajorRtrn) == 0) && ((*libMinorRtrn) == 65)))
supported = True;
else
supported = False;
}
else {
supported = True;
}
*libMajorRtrn = XkbMajorVersion;
*libMinorRtrn = XkbMinorVersion;
return supported;
}
Bool
XkbSelectEvents(Display *dpy,
unsigned int deviceSpec,
unsigned int affect,
unsigned int selectAll)
{
register xkbSelectEventsReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
xkbi->selected_events &= ~affect;
xkbi->selected_events |= (affect & selectAll);
GetReq(kbSelectEvents, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSelectEvents;
req->deviceSpec = deviceSpec;
req->affectWhich = (CARD16) affect;
req->clear = affect & (~selectAll);
req->selectAll = affect & selectAll;
if (affect & XkbMapNotifyMask) {
req->affectMap = XkbAllMapComponentsMask;
/* the implicit support needs the client info */
/* even if the client itself doesn't want it */
if (selectAll & XkbMapNotifyMask)
req->map = XkbAllMapEventsMask;
else
req->map = XkbAllClientInfoMask;
if (selectAll & XkbMapNotifyMask)
xkbi->selected_map_details = XkbAllMapEventsMask;
else
xkbi->selected_map_details = 0;
}
if (affect & XkbNewKeyboardNotifyMask) {
if (selectAll & XkbNewKeyboardNotifyMask)
xkbi->selected_nkn_details = XkbAllNewKeyboardEventsMask;
else
xkbi->selected_nkn_details = 0;
if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) {
/* we want it, even if the client doesn't. Don't mess */
/* around with details -- ask for all of them and throw */
/* away the ones we don't need */
req->selectAll |= XkbNewKeyboardNotifyMask;
}
}
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbSelectEventDetails(Display *dpy,
unsigned deviceSpec,
unsigned eventType,
unsigned long int affect,
unsigned long int details)
{
register xkbSelectEventsReq *req;
XkbInfoPtr xkbi;
int size = 0;
char *out;
union {
CARD8 *c8;
CARD16 *c16;
CARD32 *c32;
} u;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
if (affect & details)
xkbi->selected_events |= (1 << eventType);
else
xkbi->selected_events &= ~(1 << eventType);
GetReq(kbSelectEvents, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSelectEvents;
req->deviceSpec = deviceSpec;
req->clear = req->selectAll = 0;
if (eventType == XkbMapNotify) {
/* we need all of the client info, even if the application */
/* doesn't. Make sure that we always request the stuff */
/* that the implicit support needs, and just filter out anything */
/* the client doesn't want later */
req->affectMap = (CARD16) affect;
req->map = (CARD16) details | (XkbAllClientInfoMask & affect);
req->affectWhich = XkbMapNotifyMask;
xkbi->selected_map_details &= ~affect;
xkbi->selected_map_details |= (details & affect);
}
else {
req->affectMap = req->map = 0;
req->affectWhich = (1 << eventType);
switch (eventType) {
case XkbNewKeyboardNotify:
xkbi->selected_nkn_details &= ~affect;
xkbi->selected_nkn_details |= (details & affect);
if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards))
details = (affect & XkbAllNewKeyboardEventsMask);
case XkbStateNotify:
case XkbNamesNotify:
case XkbAccessXNotify:
case XkbExtensionDeviceNotify:
size = 2;
req->length += 1;
break;
case XkbControlsNotify:
case XkbIndicatorStateNotify:
case XkbIndicatorMapNotify:
size = 4;
req->length += 2;
break;
case XkbBellNotify:
case XkbActionMessage:
case XkbCompatMapNotify:
size = 1;
req->length += 1;
break;
}
BufAlloc(char *, out, (((size * 2) + (unsigned) 3) / 4) * 4);
u.c8 = (CARD8 *) out;
if (size == 2) {
u.c16[0] = (CARD16) affect;
u.c16[1] = (CARD16) details;
}
else if (size == 4) {
u.c32[0] = (CARD32) affect;
u.c32[1] = (CARD32) details;
}
else {
u.c8[0] = (CARD8) affect;
u.c8[1] = (CARD8) details;
}
}
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbLockModifiers(Display *dpy,
unsigned int deviceSpec,
unsigned int affect,
unsigned int values)
{
register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec;
req->affectModLocks = affect;
req->modLocks = values;
req->lockGroup = False;
req->groupLock = 0;
req->affectModLatches = req->modLatches = 0;
req->latchGroup = False;
req->groupLatch = 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbLatchModifiers(Display *dpy,
unsigned int deviceSpec,
unsigned int affect,
unsigned int values)
{
register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec;
req->affectModLatches = affect;
req->modLatches = values;
req->latchGroup = False;
req->groupLatch = 0;
req->affectModLocks = req->modLocks = 0;
req->lockGroup = False;
req->groupLock = 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbLockGroup(Display *dpy, unsigned int deviceSpec, unsigned int group)
{
register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec;
req->affectModLocks = 0;
req->modLocks = 0;
req->lockGroup = True;
req->groupLock = group;
req->affectModLatches = req->modLatches = 0;
req->latchGroup = False;
req->groupLatch = 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbLatchGroup(Display *dpy, unsigned int deviceSpec, unsigned int group)
{
register xkbLatchLockStateReq *req;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbLatchLockState, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbLatchLockState;
req->deviceSpec = deviceSpec;
req->affectModLatches = 0;
req->modLatches = 0;
req->latchGroup = True;
req->groupLatch = group;
req->affectModLocks = req->modLocks = 0;
req->lockGroup = False;
req->groupLock = 0;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
unsigned
XkbSetXlibControls(Display *dpy, unsigned affect, unsigned values)
{
if (!dpy->xkb_info)
XkbUseExtension(dpy, NULL, NULL);
if (!dpy->xkb_info)
return 0;
affect &= XkbLC_AllControls;
dpy->xkb_info->xlib_ctrls &= ~affect;
dpy->xkb_info->xlib_ctrls |= (affect & values);
return dpy->xkb_info->xlib_ctrls;
}
unsigned
XkbGetXlibControls(Display *dpy)
{
if (!dpy->xkb_info)
XkbUseExtension(dpy, NULL, NULL);
if (!dpy->xkb_info)
return 0;
return dpy->xkb_info->xlib_ctrls;
}
unsigned int
XkbXlibControlsImplemented(void)
{
return XkbLC_AllControls & ~XkbLC_AllComposeControls;
}
Bool
XkbSetDebuggingFlags(Display *dpy,
unsigned int mask,
unsigned int flags,
char *msg,
unsigned int ctrls_mask,
unsigned int ctrls,
unsigned int *rtrn_flags,
unsigned int *rtrn_ctrls)
{
register xkbSetDebuggingFlagsReq *req;
xkbSetDebuggingFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbSetDebuggingFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbSetDebuggingFlags;
req->affectFlags = mask;
req->flags = flags;
req->affectCtrls = ctrls_mask;
req->ctrls = ctrls;
if (msg) {
char *out;
req->msgLength = (CARD16) (strlen(msg) + 1);
req->length += (req->msgLength + (unsigned) 3) >> 2;
BufAlloc(char *, out, ((req->msgLength + (unsigned) 3) / 4) * 4);
memcpy(out, msg, req->msgLength);
}
else
req->msgLength = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
if (rtrn_flags)
*rtrn_flags = rep.currentFlags;
if (rtrn_ctrls)
*rtrn_ctrls = rep.currentCtrls;
UnlockDisplay(dpy);
SyncHandle();
return True;
}
Bool
XkbComputeEffectiveMap(XkbDescPtr xkb,
XkbKeyTypePtr type,
unsigned char *map_rtrn)
{
register int i;
unsigned tmp;
XkbKTMapEntryPtr entry = NULL;
if ((!xkb) || (!type) || (!xkb->server))
return False;
if (type->mods.vmods != 0) {
if (!XkbVirtualModsToReal(xkb, type->mods.vmods, &tmp))
return False;
type->mods.mask = tmp | type->mods.real_mods;
entry = type->map;
for (i = 0; i < type->map_count; i++, entry++) {
tmp = 0;
if (entry->mods.vmods != 0) {
if (!XkbVirtualModsToReal(xkb, entry->mods.vmods, &tmp))
return False;
if (tmp == 0) {
entry->active = False;
continue;
}
}
entry->active = True;
entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
}
}
else {
type->mods.mask = type->mods.real_mods;
}
if (map_rtrn != NULL) {
bzero(map_rtrn, type->mods.mask + 1);
for (i = 0; i < type->map_count; i++) {
if (entry && entry->active) {
map_rtrn[type->map[i].mods.mask] = type->map[i].level;
}
}
}
return True;
}
Status
XkbGetState(Display *dpy, unsigned deviceSpec, XkbStatePtr rtrn)
{
register xkbGetStateReq *req;
xkbGetStateReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return BadAccess;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbGetState, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbGetState;
req->deviceSpec = deviceSpec;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return BadImplementation;
}
rtrn->mods = rep.mods;
rtrn->base_mods = rep.baseMods;
rtrn->latched_mods = rep.latchedMods;
rtrn->locked_mods = rep.lockedMods;
rtrn->group = rep.group;
rtrn->base_group = rep.baseGroup;
rtrn->latched_group = rep.latchedGroup;
rtrn->locked_group = rep.lockedGroup;
rtrn->compat_state = rep.compatState;
rtrn->grab_mods = rep.grabMods;
rtrn->compat_grab_mods = rep.compatGrabMods;
rtrn->lookup_mods = rep.lookupMods;
rtrn->compat_lookup_mods = rep.compatLookupMods;
rtrn->ptr_buttons = rep.ptrBtnState;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
Bool
XkbSetDetectableAutoRepeat(Display *dpy, Bool detectable, Bool *supported)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->deviceSpec = XkbUseCoreKbd;
req->change = XkbPCF_DetectableAutoRepeatMask;
if (detectable)
req->value = XkbPCF_DetectableAutoRepeatMask;
else
req->value = 0;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
if (supported != NULL)
*supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0);
return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0);
}
Bool
XkbGetDetectableAutoRepeat(Display *dpy, Bool *supported)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->deviceSpec = XkbUseCoreKbd;
req->change = 0;
req->value = 0;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
if (supported != NULL)
*supported = ((rep.supported & XkbPCF_DetectableAutoRepeatMask) != 0);
return ((rep.value & XkbPCF_DetectableAutoRepeatMask) != 0);
}
Bool
XkbSetAutoResetControls(Display *dpy,
unsigned changes,
unsigned *auto_ctrls,
unsigned *auto_values)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->change = XkbPCF_AutoResetControlsMask;
req->deviceSpec = XkbUseCoreKbd;
req->value = XkbPCF_AutoResetControlsMask;
req->ctrlsToChange = changes;
req->autoCtrls = *auto_ctrls;
req->autoCtrlValues = *auto_values;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
*auto_ctrls = rep.autoCtrls;
*auto_values = rep.autoCtrlValues;
return ((rep.value & XkbPCF_AutoResetControlsMask) != 0);
}
Bool
XkbGetAutoResetControls(Display *dpy,
unsigned *auto_ctrls,
unsigned *auto_ctrl_values)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->deviceSpec = XkbUseCoreKbd;
req->change = 0;
req->value = 0;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
if (auto_ctrls)
*auto_ctrls = rep.autoCtrls;
if (auto_ctrl_values)
*auto_ctrl_values = rep.autoCtrlValues;
return ((rep.value & XkbPCF_AutoResetControlsMask) != 0);
}
Bool
XkbSetPerClientControls(Display *dpy, unsigned change, unsigned *values)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
unsigned value_hold = *values;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(change & ~(XkbPCF_GrabsUseXKBStateMask |
XkbPCF_LookupStateWhenGrabbed |
XkbPCF_SendEventUsesXKBState)))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->change = change;
req->deviceSpec = XkbUseCoreKbd;
req->value = *values;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
*values = rep.value;
return ((rep.value & value_hold) != 0);
}
Bool
XkbGetPerClientControls(Display *dpy, unsigned *ctrls)
{
register xkbPerClientFlagsReq *req;
xkbPerClientFlagsReply rep;
XkbInfoPtr xkbi;
if ((dpy->flags & XlibDisplayNoXkb) ||
(!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL)) ||
(ctrls == NULL))
return False;
LockDisplay(dpy);
xkbi = dpy->xkb_info;
GetReq(kbPerClientFlags, req);
req->reqType = xkbi->codes->major_opcode;
req->xkbReqType = X_kbPerClientFlags;
req->deviceSpec = XkbUseCoreKbd;
req->change = 0;
req->value = 0;
req->ctrlsToChange = req->autoCtrls = req->autoCtrlValues = 0;
if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return False;
}
UnlockDisplay(dpy);
SyncHandle();
*ctrls = (rep.value & (XkbPCF_GrabsUseXKBStateMask |
XkbPCF_LookupStateWhenGrabbed |
XkbPCF_SendEventUsesXKBState));
return (True);
}
Display *
XkbOpenDisplay(char *name,
int *ev_rtrn,
int *err_rtrn,
int *major_rtrn,
int *minor_rtrn,
int *reason)
{
Display *dpy;
int major_num, minor_num;
if ((major_rtrn != NULL) && (minor_rtrn != NULL)) {
if (!XkbLibraryVersion(major_rtrn, minor_rtrn)) {
if (reason != NULL)
*reason = XkbOD_BadLibraryVersion;
return NULL;
}
}
else {
major_num = XkbMajorVersion;
minor_num = XkbMinorVersion;
major_rtrn = &major_num;
minor_rtrn = &minor_num;
}
dpy = XOpenDisplay(name);
if (dpy == NULL) {
if (reason != NULL)
*reason = XkbOD_ConnectionRefused;
return NULL;
}
if (!XkbQueryExtension(dpy, NULL, ev_rtrn, err_rtrn,
major_rtrn, minor_rtrn)) {
if (reason != NULL) {
if ((*major_rtrn != 0) || (*minor_rtrn != 0))
*reason = XkbOD_BadServerVersion;
else
*reason = XkbOD_NonXkbServer;
}
XCloseDisplay(dpy);
return NULL;
}
if (reason != NULL)
*reason = XkbOD_Success;
return dpy;
}
void
XkbSetAtomFuncs(XkbInternAtomFunc getAtom, XkbGetAtomNameFunc getName)
{
_XkbInternAtomFunc = (getAtom ? getAtom : XInternAtom);
_XkbGetAtomNameFunc = (getName ? getName : XGetAtomName);
return;
}
|