1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
30 #include <X11/extensions/XKB.h>
32 #define XkbCharToInt(v) ((int) ((v) & 0x80 ? ((v) | (~0xff)) : ((v) & 0x7f)))
33 #define XkbIntTo2Chars(i, h, l) ((h) = (i >> 8) & 0xff, (l) = (i) & 0xff)
35 #if defined(WORD64) && defined(UNSIGNEDBITFIELDS)
36 #define Xkb2CharsToInt(h, l) ((int) ((h) & 0x80 ? \
37 (((h) << 8) | (l) | (~0xffff)) : \
38 (((h) << 8) | (l) & 0x7fff))
40 #define Xkb2CharsToInt(h,l) ((short)(((h)<<8)|(l)))
44 * Common data structures and access macros
47 typedef struct _XkbStateRec
{
48 unsigned char group
; /* base + latched + locked */
49 /* FIXME: Why are base + latched short and not char?? */
50 unsigned short base_group
; /* physically ... down? */
51 unsigned short latched_group
;
52 unsigned char locked_group
;
54 unsigned char mods
; /* base + latched + locked */
55 unsigned char base_mods
; /* physically down */
56 unsigned char latched_mods
;
57 unsigned char locked_mods
;
59 unsigned char compat_state
; /* mods + group for core state */
61 /* grab mods = all depressed and latched mods, _not_ locked mods */
62 unsigned char grab_mods
; /* grab mods minus internal mods */
63 unsigned char compat_grab_mods
; /* grab mods + group for core state,
64 but not locked groups if
65 IgnoreGroupLocks set */
67 /* effective mods = all mods (depressed, latched, locked) */
68 unsigned char lookup_mods
; /* effective mods minus internal mods */
69 unsigned char compat_lookup_mods
; /* effective mods + group */
71 unsigned short ptr_buttons
; /* core pointer buttons */
72 } XkbStateRec
, *XkbStatePtr
;
74 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
75 #define XkbGrabStateFromRec(s) XkbBuildCoreState((s)->grab_mods,(s)->group)
77 typedef struct _XkbMods
{
78 unsigned char mask
; /* effective mods */
79 unsigned char real_mods
;
81 } XkbModsRec
, *XkbModsPtr
;
83 typedef struct _XkbKTMapEntry
{
87 } XkbKTMapEntryRec
, *XkbKTMapEntryPtr
;
89 typedef struct _XkbKeyType
{
91 unsigned char num_levels
;
92 unsigned char map_count
;
97 } XkbKeyTypeRec
, *XkbKeyTypePtr
;
99 #define XkbNumGroups(g) ((g)&0x0f)
100 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
101 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
102 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
103 #define XkbSetGroupInfo(g, w, n) (((w) & 0xc0) | (((n) & 3) << 4) | \
105 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
108 * Structures and access macros used primarily by the server
111 typedef struct _XkbBehavior
{
116 #define XkbAnyActionDataSize 7
117 typedef struct _XkbAnyAction
{
119 unsigned char data
[XkbAnyActionDataSize
];
122 typedef struct _XkbModAction
{
126 unsigned char real_mods
;
127 /* FIXME: Make this an int. */
128 unsigned char vmods1
;
129 unsigned char vmods2
;
132 #define XkbModActionVMods(a) ((short) (((a)->vmods1 << 8) | (a)->vmods2))
133 #define XkbSetModActionVMods(a,v) \
134 ((a)->vmods1 = (((v) >> 8) & 0xff), \
135 (a)->vmods2 = (v) & 0xff)
137 typedef struct _XkbGroupAction
{
140 /* FIXME: Make this an int. */
144 #define XkbSAGroup(a) (XkbCharToInt((a)->group_XXX))
145 #define XkbSASetGroup(a,g) ((a)->group_XXX=(g))
147 typedef struct _XkbISOAction
{
151 unsigned char real_mods
;
152 /* FIXME: Make this an int. */
154 unsigned char affect
;
155 unsigned char vmods1
;
156 unsigned char vmods2
;
159 typedef struct _XkbPtrAction
{
162 /* FIXME: Make this an int. */
163 unsigned char high_XXX
;
164 unsigned char low_XXX
;
165 unsigned char high_YYY
;
166 unsigned char low_YYY
;
169 #define XkbPtrActionX(a) (Xkb2CharsToInt((a)->high_XXX,(a)->low_XXX))
170 #define XkbPtrActionY(a) (Xkb2CharsToInt((a)->high_YYY,(a)->low_YYY))
171 #define XkbSetPtrActionX(a,x) (XkbIntTo2Chars(x,(a)->high_XXX,(a)->low_XXX))
172 #define XkbSetPtrActionY(a,y) (XkbIntTo2Chars(y,(a)->high_YYY,(a)->low_YYY))
174 typedef struct _XkbPtrBtnAction
{
178 unsigned char button
;
181 typedef struct _XkbPtrDfltAction
{
184 unsigned char affect
;
188 #define XkbSAPtrDfltValue(a) (XkbCharToInt((a)->valueXXX))
189 #define XkbSASetPtrDfltValue(a, c) ((a)->valueXXX = (c) & 0xff)
191 typedef struct _XkbSwitchScreenAction
{
195 } XkbSwitchScreenAction
;
197 #define XkbSAScreen(a) (XkbCharToInt((a)->screenXXX))
198 #define XkbSASetScreen(a, s) ((a)->screenXXX = (s) & 0xff)
200 typedef struct _XkbCtrlsAction
{
203 /* FIXME: Make this an int. */
204 unsigned char ctrls3
;
205 unsigned char ctrls2
;
206 unsigned char ctrls1
;
207 unsigned char ctrls0
;
210 #define XkbActionSetCtrls(a, c) ((a)->ctrls3 = ((c) >> 24) & 0xff, \
211 (a)->ctrls2 = ((c) >> 16) & 0xff, \
212 (a)->ctrls1 = ((c) >> 8) & 0xff, \
213 (a)->ctrls0 = (c) & 0xff)
214 #define XkbActionCtrls(a) ((((unsigned int)(a)->ctrls3)<<24)|\
215 (((unsigned int)(a)->ctrls2)<<16)|\
216 (((unsigned int)(a)->ctrls1)<<8)|\
217 ((unsigned int) (a)->ctrls0))
219 typedef struct _XkbMessageAction
{
222 unsigned char message
[6];
225 typedef struct _XkbRedirectKeyAction
{
227 unsigned char new_key
;
228 unsigned char mods_mask
;
230 /* FIXME: Make this an int. */
231 unsigned char vmods_mask0
;
232 unsigned char vmods_mask1
;
233 unsigned char vmods0
;
234 unsigned char vmods1
;
235 } XkbRedirectKeyAction
;
237 #define XkbSARedirectVMods(a) ((((unsigned int)(a)->vmods1)<<8)|\
238 ((unsigned int)(a)->vmods0))
239 /* FIXME: This is blatantly not setting vmods. Yeesh. */
240 #define XkbSARedirectSetVMods(a,m) (((a)->vmods_mask1=(((m)>>8)&0xff)),\
241 ((a)->vmods_mask0=((m)&0xff)))
242 #define XkbSARedirectVModsMask(a) ((((unsigned int)(a)->vmods_mask1)<<8)|\
243 ((unsigned int)(a)->vmods_mask0))
244 #define XkbSARedirectSetVModsMask(a,m) (((a)->vmods_mask1=(((m)>>8)&0xff)),\
245 ((a)->vmods_mask0=((m)&0xff)))
247 typedef struct _XkbDeviceBtnAction
{
251 unsigned char button
;
252 unsigned char device
;
253 } XkbDeviceBtnAction
;
255 typedef struct _XkbDeviceValuatorAction
{
257 unsigned char device
;
258 unsigned char v1_what
;
259 unsigned char v1_ndx
;
260 unsigned char v1_value
;
261 unsigned char v2_what
;
262 unsigned char v2_ndx
;
263 unsigned char v2_value
;
264 } XkbDeviceValuatorAction
;
266 typedef union _XkbAction
{
269 XkbGroupAction group
;
273 XkbPtrDfltAction dflt
;
274 XkbSwitchScreenAction screen
;
275 XkbCtrlsAction ctrls
;
276 XkbMessageAction msg
;
277 XkbRedirectKeyAction redirect
;
278 XkbDeviceBtnAction devbtn
;
279 XkbDeviceValuatorAction devval
;
283 typedef struct _XkbControls
{
284 unsigned char mk_dflt_btn
;
285 unsigned char num_groups
;
286 unsigned char groups_wrap
;
288 XkbModsRec ignore_lock
;
289 unsigned int enabled_ctrls
;
290 unsigned short repeat_delay
;
291 unsigned short repeat_interval
;
292 unsigned short slow_keys_delay
;
293 unsigned short debounce_delay
;
294 unsigned short mk_delay
;
295 unsigned short mk_interval
;
296 unsigned short mk_time_to_max
;
297 unsigned short mk_max_speed
;
299 unsigned short ax_options
;
300 unsigned short ax_timeout
;
301 unsigned short axt_opts_mask
;
302 unsigned short axt_opts_values
;
303 unsigned int axt_ctrls_mask
;
304 unsigned int axt_ctrls_values
;
305 unsigned char per_key_repeat
[XkbPerKeyBitArraySize
];
306 } XkbControlsRec
, *XkbControlsPtr
;
308 #define XkbAX_AnyFeedback(c) ((c)->enabled_ctrls&XkbAccessXFeedbackMask)
309 #define XkbAX_NeedOption(c,w) ((c)->ax_options&(w))
310 #define XkbAX_NeedFeedback(c, w) (XkbAX_AnyFeedback((c)) && \
311 XkbAX_NeedOption((c), (w)))
313 typedef struct _XkbServerMapRec
{
314 unsigned short num_acts
;
315 unsigned short size_acts
;
318 XkbBehavior
*behaviors
;
319 unsigned short *key_acts
;
320 #if defined(__cplusplus) || defined(c_plusplus)
321 /* explicit is a C++ reserved word */
322 unsigned char *c_explicit
;
324 unsigned char *explicit;
326 unsigned char vmods
[XkbNumVirtualMods
];
327 unsigned short *vmodmap
;
328 } XkbServerMapRec
, *XkbServerMapPtr
;
330 #define XkbSMKeyActionsPtr(m, k) (&(m)->acts[(m)->key_acts[(k)]])
333 * Structures and access macros used primarily by clients
336 typedef struct _XkbSymMapRec
{
337 unsigned char kt_index
[XkbNumKbdGroups
];
338 unsigned char group_info
;
340 unsigned short offset
;
341 } XkbSymMapRec
, *XkbSymMapPtr
;
343 typedef struct _XkbClientMapRec
{
344 unsigned char size_types
;
345 unsigned char num_types
;
348 unsigned short size_syms
;
349 unsigned short num_syms
;
351 XkbSymMapPtr key_sym_map
;
353 unsigned char *modmap
;
354 } XkbClientMapRec
, *XkbClientMapPtr
;
356 #define XkbCMKeyGroupInfo(m, k) ((m)->key_sym_map[(k)].group_info)
357 #define XkbCMKeyNumGroups(m, k) (XkbNumGroups((m)->key_sym_map[(k)].group_info))
358 #define XkbCMKeyGroupWidth(m, k, g) (XkbCMKeyType((m), (k), (g))->num_levels)
359 #define XkbCMKeyGroupsWidth(m, k) ((m)->key_sym_map[(k)].width)
360 #define XkbCMKeyTypeIndex(m, k, g) ((m)->key_sym_map[(k)].kt_index[(g) & 0x3])
361 #define XkbCMKeyType(m, k, g) (&(m)->types[XkbCMKeyTypeIndex((m), (k), (g))])
362 #define XkbCMKeyNumSyms(m, k) (XkbCMKeyGroupsWidth((m), (k)) * \
363 XkbCMKeyNumGroups((m), (k)))
364 #define XkbCMKeySymsOffset(m, k) ((m)->key_sym_map[(k)].offset)
365 #define XkbCMKeySymsPtr(m, k) (&(m)->syms[XkbCMKeySymsOffset((m), (k))])
368 * Compatibility structures and access macros
371 typedef struct _XkbSymInterpretRec
{
376 unsigned char virtual_mod
;
378 } XkbSymInterpretRec
, *XkbSymInterpretPtr
;
380 typedef struct _XkbCompatMapRec
{
381 XkbSymInterpretPtr sym_interpret
;
382 XkbModsRec groups
[XkbNumKbdGroups
];
383 unsigned short num_si
;
384 unsigned short size_si
;
385 } XkbCompatMapRec
, *XkbCompatMapPtr
;
387 typedef struct _XkbIndicatorMapRec
{
389 /* FIXME: For some reason, interepretation of groups is wildly
390 * different between which being base/latched/locked. */
391 unsigned char which_groups
;
392 unsigned char groups
;
393 unsigned char which_mods
;
396 } XkbIndicatorMapRec
, *XkbIndicatorMapPtr
;
398 #define XkbIM_IsAuto(i) (!((i)->flags & XkbIM_NoAutomatic) && \
399 (((i)->which_groups&&(i)->groups)||\
400 ((i)->which_mods&&(i)->mods.mask)||\
402 #define XkbIM_InUse(i) ((i)->flags || (i)->which_groups || (i)->which_mods || \
405 typedef struct _XkbIndicatorRec
{
406 unsigned long phys_indicators
;
407 XkbIndicatorMapRec maps
[XkbNumIndicators
];
408 } XkbIndicatorRec
, *XkbIndicatorPtr
;
410 typedef struct _XkbKeyNameRec
{
411 char name
[XkbKeyNameLength
];
412 } XkbKeyNameRec
, *XkbKeyNamePtr
;
414 typedef struct _XkbKeyAliasRec
{
415 char real
[XkbKeyNameLength
];
416 char alias
[XkbKeyNameLength
];
417 } XkbKeyAliasRec
, *XkbKeyAliasPtr
;
420 * Names for everything
422 typedef struct _XkbNamesRec
{
428 Atom vmods
[XkbNumVirtualMods
];
429 Atom indicators
[XkbNumIndicators
];
430 Atom groups
[XkbNumKbdGroups
];
432 XkbKeyAliasPtr key_aliases
;
436 unsigned char num_keys
;
437 unsigned char num_key_aliases
;
438 unsigned short num_rg
;
439 } XkbNamesRec
, *XkbNamesPtr
;
441 typedef struct _XkbGeometry
*XkbGeometryPtr
;
444 * Tie it all together into one big keyboard description
446 typedef struct _XkbDesc
{
447 unsigned int defined
;
448 unsigned short flags
;
449 unsigned short device_spec
;
450 KeyCode min_key_code
;
451 KeyCode max_key_code
;
453 XkbControlsPtr ctrls
;
454 XkbServerMapPtr server
;
456 XkbIndicatorPtr indicators
;
458 XkbCompatMapPtr compat
;
460 } XkbDescRec
, *XkbDescPtr
;
462 #define XkbKeyKeyTypeIndex(d, k, g) (XkbCMKeyTypeIndex((d)->map, (k), (g)))
463 #define XkbKeyKeyType(d, k, g) (XkbCMKeyType((d)->map, (k), (g)))
464 #define XkbKeyGroupWidth(d, k, g) (XkbCMKeyGroupWidth((d)->map, (k), (g)))
465 #define XkbKeyGroupsWidth(d, k) (XkbCMKeyGroupsWidth((d)->map, (k)))
466 #define XkbKeyGroupInfo(d,k) (XkbCMKeyGroupInfo((d)->map,(k)))
467 #define XkbKeyNumGroups(d,k) (XkbCMKeyNumGroups((d)->map,(k)))
468 #define XkbKeyNumSyms(d,k) (XkbCMKeyNumSyms((d)->map,(k)))
469 #define XkbKeySymsPtr(d,k) (XkbCMKeySymsPtr((d)->map,(k)))
470 #define XkbKeySym(d, k, n) (XkbKeySymsPtr((d), (k))[(n)])
471 #define XkbKeySymEntry(d,k,sl,g) \
472 (XkbKeySym((d), (k), (XkbKeyGroupsWidth((d), (k)) * (g)) + (sl)))
473 #define XkbKeyAction(d,k,n) \
474 (XkbKeyHasActions((d), (k)) ? & XkbKeyActionsPtr((d), (k))[(n)] : NULL)
475 #define XkbKeyActionEntry(d,k,sl,g) \
476 (XkbKeyHasActions((d), (k)) ? \
477 XkbKeyAction((d), (k), ((XkbKeyGroupsWidth((d), (k)) * (g)) + (sl))) : \
480 #define XkbKeyHasActions(d, k) (!!(d)->server->key_acts[(k)])
481 #define XkbKeyNumActions(d, k) (XkbKeyHasActions((d), (k)) ? \
482 XkbKeyNumSyms((d), (k)) : 1)
483 #define XkbKeyActionsPtr(d, k) (XkbSMKeyActionsPtr((d)->server, (k)))
484 #define XkbKeycodeInRange(d, k) ((k) >= (d)->min_key_code && \
485 (k) <= (d)->max_key_code)
486 #define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
489 * The following structures can be used to track changes
490 * to a keyboard device
492 typedef struct _XkbMapChanges
{
493 unsigned short changed
;
494 KeyCode min_key_code
;
495 KeyCode max_key_code
;
496 unsigned char first_type
;
497 unsigned char num_types
;
498 KeyCode first_key_sym
;
499 unsigned char num_key_syms
;
500 KeyCode first_key_act
;
501 unsigned char num_key_acts
;
502 KeyCode first_key_behavior
;
503 unsigned char num_key_behaviors
;
504 KeyCode first_key_explicit
;
505 unsigned char num_key_explicit
;
506 KeyCode first_modmap_key
;
507 unsigned char num_modmap_keys
;
508 KeyCode first_vmodmap_key
;
509 unsigned char num_vmodmap_keys
;
511 unsigned short vmods
;
512 } XkbMapChangesRec
, *XkbMapChangesPtr
;
514 typedef struct _XkbControlsChanges
{
515 unsigned int changed_ctrls
;
516 unsigned int enabled_ctrls_changes
;
517 Bool num_groups_changed
;
518 } XkbControlsChangesRec
, *XkbControlsChangesPtr
;
520 typedef struct _XkbIndicatorChanges
{
521 unsigned int state_changes
;
522 unsigned int map_changes
;
523 } XkbIndicatorChangesRec
, *XkbIndicatorChangesPtr
;
525 typedef struct _XkbNameChanges
{
526 unsigned int changed
;
527 unsigned char first_type
;
528 unsigned char num_types
;
529 unsigned char first_lvl
;
530 unsigned char num_lvls
;
531 unsigned char num_aliases
;
532 unsigned char num_rg
;
533 unsigned char first_key
;
534 unsigned char num_keys
;
535 unsigned short changed_vmods
;
536 unsigned long changed_indicators
;
537 unsigned char changed_groups
;
538 } XkbNameChangesRec
, *XkbNameChangesPtr
;
540 typedef struct _XkbCompatChanges
{
541 unsigned char changed_groups
;
542 unsigned short first_si
;
543 unsigned short num_si
;
544 } XkbCompatChangesRec
, *XkbCompatChangesPtr
;
546 typedef struct _XkbChanges
{
547 unsigned short device_spec
;
548 unsigned short state_changes
;
549 XkbMapChangesRec map
;
550 XkbControlsChangesRec ctrls
;
551 XkbIndicatorChangesRec indicators
;
552 XkbNameChangesRec names
;
553 XkbCompatChangesRec compat
;
554 } XkbChangesRec
, *XkbChangesPtr
;
557 * These data structures are used to construct a keymap from
558 * a set of components or to list components in the server
561 typedef struct _XkbComponentNames
{
567 } XkbComponentNamesRec
, *XkbComponentNamesPtr
;
569 typedef struct _XkbComponentName
{
570 unsigned short flags
;
572 } XkbComponentNameRec
, *XkbComponentNamePtr
;
574 typedef struct _XkbComponentList
{
581 XkbComponentNamePtr keymaps
;
582 XkbComponentNamePtr keycodes
;
583 XkbComponentNamePtr types
;
584 XkbComponentNamePtr compat
;
585 XkbComponentNamePtr symbols
;
586 XkbComponentNamePtr geometry
;
587 } XkbComponentListRec
, *XkbComponentListPtr
;
590 * The following data structures describe and track changes to a
591 * non-keyboard extension device
593 typedef struct _XkbDeviceLedInfo
{
594 unsigned short led_class
;
595 unsigned short led_id
;
596 unsigned int phys_indicators
;
597 unsigned int maps_present
;
598 unsigned int names_present
;
600 Atom names
[XkbNumIndicators
];
601 XkbIndicatorMapRec maps
[XkbNumIndicators
];
602 } XkbDeviceLedInfoRec
, *XkbDeviceLedInfoPtr
;
604 typedef struct _XkbDeviceInfo
{
607 unsigned short device_spec
;
609 unsigned short supported
;
610 unsigned short unsupported
;
612 unsigned short num_btns
;
615 unsigned short sz_leds
;
616 unsigned short num_leds
;
617 unsigned short dflt_kbd_fb
;
618 unsigned short dflt_led_fb
;
619 XkbDeviceLedInfoPtr leds
;
620 } XkbDeviceInfoRec
, *XkbDeviceInfoPtr
;
622 #define XkbXI_DevHasBtnActs(d) ((d)->num_btns > 0 && (d)->btn_acts)
623 #define XkbXI_LegalDevBtn(d,b) (XkbXI_DevHasBtnActs(d) && (b) < (d)->num_btns)
624 #define XkbXI_DevHasLeds(d) ((d)->num_leds > 0 && (d)->leds)
626 typedef struct _XkbDeviceLedChanges
{
627 unsigned short led_class
;
628 unsigned short led_id
;
629 unsigned int defined
; /* names or maps changed */
630 struct _XkbDeviceLedChanges
*next
;
631 } XkbDeviceLedChangesRec
, *XkbDeviceLedChangesPtr
;
633 typedef struct _XkbDeviceChanges
{
634 unsigned int changed
;
635 unsigned short first_btn
;
636 unsigned short num_btns
;
637 XkbDeviceLedChangesRec leds
;
638 } XkbDeviceChangesRec
, *XkbDeviceChangesPtr
;
640 #endif /* _XKBSTR_H_ */