2 Copyright 1985, 1987, 1990, 1998 The Open Group
3 Copyright 2008 Dan Nicholson
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the names of the authors or their
23 institutions shall not be used in advertising or otherwise to promote the
24 sale, use or other dealings in this Software without prior written
25 authorization from the authors.
28 /************************************************************
29 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
31 Permission to use, copy, modify, and distribute this
32 software and its documentation for any purpose and without
33 fee is hereby granted, provided that the above copyright
34 notice appear in all copies and that both that copyright
35 notice and this permission notice appear in supporting
36 documentation, and that the name of Silicon Graphics not be
37 used in advertising or publicity pertaining to distribution
38 of the software without specific prior written permission.
39 Silicon Graphics makes no representation about the suitability
40 of this software for any purpose. It is provided "as is"
41 without any express or implied warranty.
43 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
44 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
46 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
47 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
48 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
49 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
50 THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 ********************************************************/
60 #include <X11/Xfuncproto.h>
61 #include <X11/extensions/XKB.h>
63 typedef uint32_t xkb_keycode_t;
65 #define XKB_KEYCODE_MAX (0xffffffff - 1)
66 #define xkb_keycode_is_legal_ext(kc) (kc <= XKB_KEYCODE_MAX)
67 #define xkb_keycode_is_legal_x11(kc) (kc <= XKB_KEYCODE_MAX)
68 #define xkb_keymap_keycode_range_is_legal(xkb) \
69 (xkb->max_key_code > 0 && \
70 xkb->max_key_code > xkb->min_key_code && \
71 xkb_keycode_is_legal_ext(xkb->min_key_code) && \
72 xkb_keycode_is_legal_ext(xkb->max_key_code))
74 /* Duplicate the modifier mask defines so libxkcommon can be used
76 #define XKB_COMMON_SHIFT_MASK (1<<0)
77 #define XKB_COMMON_LOCK_MASK (1<<1)
78 #define XKB_COMMON_CONTROL_MASK (1<<2)
79 #define XKB_COMMON_MOD1_MASK (1<<3)
80 #define XKB_COMMON_MOD2_MASK (1<<4)
81 #define XKB_COMMON_MOD3_MASK (1<<5)
82 #define XKB_COMMON_MOD4_MASK (1<<6)
83 #define XKB_COMMON_MOD5_MASK (1<<7)
86 struct xkb_rule_names {
94 struct xkb_any_action {
99 struct xkb_mod_action {
107 struct xkb_group_action {
113 struct xkb_iso_action {
123 struct xkb_controls_action {
129 struct xkb_device_button_action {
137 struct xkb_device_valuator_action {
148 struct xkb_pointer_default_action {
155 struct xkb_switch_screen_action {
161 struct xkb_redirect_key_action {
163 xkb_keycode_t new_key;
170 struct xkb_pointer_action {
177 struct xkb_message_action {
183 struct xkb_pointer_button_action {
191 struct xkb_any_action any;
192 struct xkb_mod_action mods;
193 struct xkb_group_action group;
194 struct xkb_iso_action iso;
195 struct xkb_controls_action ctrls;
196 struct xkb_device_button_action devbtn;
197 struct xkb_device_valuator_action devval;
198 struct xkb_pointer_default_action dflt;
199 struct xkb_switch_screen_action screen;
200 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
201 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
202 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
203 struct xkb_message_action msg; /* XXX just delete */
208 uint32_t mask; /* effective mods */
213 struct xkb_kt_map_entry {
216 struct xkb_mods mods;
219 struct xkb_key_type {
220 struct xkb_mods mods;
222 unsigned char map_count;
223 struct xkb_kt_map_entry * map;
224 struct xkb_mods * preserve;
226 const char **level_names;
229 struct xkb_sym_interpret {
233 uint8_t mods; /* XXX real or virt? */
234 uint32_t virtual_mod;
235 struct xkb_any_action act;
238 struct xkb_compat_map {
239 struct xkb_sym_interpret * sym_interpret;
240 struct xkb_mods groups[XkbNumKbdGroups];
241 unsigned short num_si;
242 unsigned short size_si;
246 unsigned char kt_index[XkbNumKbdGroups];
247 unsigned char group_info;
249 unsigned short offset;
252 #define XkbNumGroups(g) ((g)&0x0f)
253 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
254 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
255 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
256 #define XkbSetGroupInfo(g,w,n) (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
257 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
259 struct xkb_client_map {
260 unsigned char size_types;
261 unsigned char num_types;
262 struct xkb_key_type * types;
267 struct xkb_sym_map * key_sym_map;
269 unsigned char *modmap;
272 #define XkbCMKeyGroupInfo(m,k) ((m)->key_sym_map[k].group_info)
273 #define XkbCMKeyNumGroups(m,k) (XkbNumGroups((m)->key_sym_map[k].group_info))
274 #define XkbCMKeyGroupWidth(m,k,g) (XkbCMKeyType(m,k,g)->num_levels)
275 #define XkbCMKeyGroupsWidth(m,k) ((m)->key_sym_map[k].width)
276 #define XkbCMKeyTypeIndex(m,k,g) ((m)->key_sym_map[k].kt_index[g&0x3])
277 #define XkbCMKeyType(m,k,g) (&(m)->types[XkbCMKeyTypeIndex(m,k,g)])
278 #define XkbCMKeyNumSyms(m,k) (XkbCMKeyGroupsWidth(m,k)*XkbCMKeyNumGroups(m,k))
279 #define XkbCMKeySymsOffset(m,k) ((m)->key_sym_map[k].offset)
280 #define XkbCMKeySymsPtr(m,k) (&(m)->syms[XkbCMKeySymsOffset(m,k)])
282 struct xkb_behavior {
287 struct xkb_server_map {
288 unsigned short num_acts;
289 unsigned short size_acts;
291 #if defined(__cplusplus) || defined(c_plusplus)
292 /* explicit is a C++ reserved word */
293 unsigned char * c_explicit;
295 unsigned char * explicit;
298 union xkb_action *acts;
299 struct xkb_behavior *behaviors;
300 unsigned short *key_acts;
301 unsigned char *explicits;
302 uint32_t vmods[XkbNumVirtualMods];
306 #define XkbSMKeyActionsPtr(m,k) (&(m)->acts[(m)->key_acts[k]])
308 struct xkb_indicator_map {
310 unsigned char which_groups;
311 unsigned char groups;
312 unsigned char which_mods;
313 struct xkb_mods mods;
317 struct xkb_indicator {
318 unsigned long phys_indicators;
319 struct xkb_indicator_map maps[XkbNumIndicators];
322 struct xkb_key_name {
323 char name[XkbKeyNameLength];
326 struct xkb_key_alias {
327 char real[XkbKeyNameLength];
328 char alias[XkbKeyNameLength];
332 const char *vmods[XkbNumVirtualMods];
333 const char *indicators[XkbNumIndicators];
334 const char *groups[XkbNumKbdGroups];
335 struct xkb_key_name * keys;
336 struct xkb_key_alias * key_aliases;
338 xkb_keycode_t num_keys;
339 xkb_keycode_t num_key_aliases;
340 unsigned short num_rg;
343 struct xkb_controls {
344 unsigned char mk_dflt_btn;
345 unsigned char num_groups;
346 unsigned char groups_wrap;
347 struct xkb_mods internal;
348 struct xkb_mods ignore_lock;
349 unsigned int enabled_ctrls;
350 unsigned short repeat_delay;
351 unsigned short repeat_interval;
352 unsigned short slow_keys_delay;
353 unsigned short debounce_delay;
354 unsigned short mk_delay;
355 unsigned short mk_interval;
356 unsigned short mk_time_to_max;
357 unsigned short mk_max_speed;
359 unsigned short ax_options;
360 unsigned short ax_timeout;
361 unsigned short axt_opts_mask;
362 unsigned short axt_opts_values;
363 unsigned int axt_ctrls_mask;
364 unsigned int axt_ctrls_values;
365 unsigned char *per_key_repeat;
368 /* Common keyboard description structure */
370 unsigned int defined;
371 unsigned short flags;
372 unsigned short device_spec;
373 xkb_keycode_t min_key_code;
374 xkb_keycode_t max_key_code;
376 struct xkb_controls * ctrls;
377 struct xkb_server_map * server;
378 struct xkb_client_map * map;
379 struct xkb_indicator * indicators;
380 struct xkb_names * names;
381 struct xkb_compat_map * compat;
384 #define XkbKeyKeyTypeIndex(d,k,g) (XkbCMKeyTypeIndex((d)->map,k,g))
385 #define XkbKeyKeyType(d,k,g) (XkbCMKeyType((d)->map,k,g))
386 #define XkbKeyGroupWidth(d,k,g) (XkbCMKeyGroupWidth((d)->map,k,g))
387 #define XkbKeyGroupsWidth(d,k) (XkbCMKeyGroupsWidth((d)->map,k))
388 #define XkbKeyGroupInfo(d,k) (XkbCMKeyGroupInfo((d)->map,(k)))
389 #define XkbKeyNumGroups(d,k) (XkbCMKeyNumGroups((d)->map,(k)))
390 #define XkbKeyNumSyms(d,k) (XkbCMKeyNumSyms((d)->map,(k)))
391 #define XkbKeySymsPtr(d,k) (XkbCMKeySymsPtr((d)->map,(k)))
392 #define XkbKeySym(d,k,n) (XkbKeySymsPtr(d,k)[n])
393 #define XkbKeySymEntry(d,k,sl,g) \
394 (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
395 #define XkbKeyAction(d,k,n) \
396 (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
397 #define XkbKeyActionEntry(d,k,sl,g) \
398 (XkbKeyHasActions(d,k)?\
399 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
401 #define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0)
402 #define XkbKeyNumActions(d,k) (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
403 #define XkbKeyActionsPtr(d,k) (XkbSMKeyActionsPtr((d)->server,k))
404 #define XkbKeycodeInRange(d,k) (((k)>=(d)->min_key_code)&&\
405 ((k)<=(d)->max_key_code))
406 #define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
408 struct xkb_map_changes {
409 unsigned short changed;
410 xkb_keycode_t min_key_code;
411 xkb_keycode_t max_key_code;
412 unsigned char first_type;
413 unsigned char num_types;
414 xkb_keycode_t first_key_sym;
415 xkb_keycode_t num_key_syms;
416 xkb_keycode_t first_key_act;
417 xkb_keycode_t num_key_acts;
418 xkb_keycode_t first_key_behavior;
419 xkb_keycode_t num_key_behaviors;
420 xkb_keycode_t first_key_explicit;
421 xkb_keycode_t num_key_explicit;
422 xkb_keycode_t first_modmap_key;
423 xkb_keycode_t num_modmap_keys;
424 xkb_keycode_t first_vmodmap_key;
425 xkb_keycode_t num_vmodmap_keys;
426 unsigned short vmods;
429 struct xkb_controls_changes {
430 unsigned int changed_ctrls;
431 unsigned int enabled_ctrls_changes;
432 int num_groups_changed;
435 struct xkb_indicator_changes {
436 unsigned int state_changes;
437 unsigned int map_changes;
440 struct xkb_name_changes {
441 unsigned int changed;
442 unsigned char first_type;
443 unsigned char num_types;
444 unsigned char first_lvl;
445 unsigned char num_lvls;
446 xkb_keycode_t num_aliases;
447 unsigned char num_rg;
448 xkb_keycode_t first_key;
449 xkb_keycode_t num_keys;
450 unsigned short changed_vmods;
451 unsigned long changed_indicators;
452 unsigned char changed_groups;
455 struct xkb_compat_changes {
456 unsigned char changed_groups;
457 unsigned short first_si;
458 unsigned short num_si;
462 unsigned short device_spec;
463 unsigned short state_changes;
464 struct xkb_map_changes map;
465 struct xkb_controls_changes ctrls;
466 struct xkb_indicator_changes indicators;
467 struct xkb_name_changes names;
468 struct xkb_compat_changes compat;
471 struct xkb_component_names {
479 struct xkb_component_name {
480 unsigned short flags;
484 struct xkb_component_list {
490 struct xkb_component_name * keymaps;
491 struct xkb_component_name * keycodes;
492 struct xkb_component_name * types;
493 struct xkb_component_name * compat;
494 struct xkb_component_name * symbols;
498 unsigned char group; /* base + latched + locked */
499 /* FIXME: Why are base + latched short and not char?? */
500 unsigned short base_group; /* physically ... down? */
501 unsigned short latched_group;
502 unsigned char locked_group;
504 unsigned char mods; /* base + latched + locked */
505 unsigned char base_mods; /* physically down */
506 unsigned char latched_mods;
507 unsigned char locked_mods;
509 unsigned char compat_state; /* mods + group for core state */
511 /* grab mods = all depressed and latched mods, _not_ locked mods */
512 unsigned char grab_mods; /* grab mods minus internal mods */
513 unsigned char compat_grab_mods; /* grab mods + group for core state,
514 but not locked groups if
515 IgnoreGroupLocks set */
517 /* effective mods = all mods (depressed, latched, locked) */
518 unsigned char lookup_mods; /* effective mods minus internal mods */
519 unsigned char compat_lookup_mods; /* effective mods + group */
521 unsigned short ptr_buttons; /* core pointer buttons */
524 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
525 #define XkbGrabStateFromRec(s) XkbBuildCoreState((s)->grab_mods,(s)->group)
527 #define XkbNumGroups(g) ((g)&0x0f)
528 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
529 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
530 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
531 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
535 typedef uint32_t (*InternAtomFuncPtr)(const char *val);
536 typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
538 _X_EXPORT extern void
539 xkb_init_atoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
541 _X_EXPORT extern uint32_t
542 xkb_intern_atom(const char *name);
544 _X_EXPORT extern struct xkb_desc *
545 xkb_compile_keymap_from_rules(const struct xkb_rule_names *rules);
547 _X_EXPORT extern struct xkb_desc *
548 xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg);
550 _X_EXPORT extern struct xkb_desc *
551 xkb_compile_keymap_from_file(FILE *inputFile, const char *mapName);
553 _X_EXPORT extern struct xkb_desc *
554 xkb_compile_keymap_from_string(const char *string, const char *mapName);
556 _X_EXPORT extern void
557 xkb_free_keymap(struct xkb_desc *xkb);
559 _X_EXPORT extern struct xkb_component_list *
560 xkb_list_components(struct xkb_component_names * ptrns, int *maxMatch);
563 * Canonicalises component names by prepending the relevant component from
564 * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
565 * by replacing a '%' with the relevant component, e.g.:
568 * ------------------------------------------
571 * foo+%|baz bar foo+bar|baz
573 * If a component in names needs to be modified, the existing value will be
574 * free()d, and a new one allocated with malloc().
576 _X_EXPORT extern void
577 xkb_canonicalise_components(struct xkb_component_names * names,
578 const struct xkb_component_names * old);
581 * Converts a keysym to a string; will return unknown Unicode codepoints
582 * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
584 * This is uint32_t rather than KeySym, as KeySym changes size between
585 * client and server (no, really).
587 _X_EXPORT extern void
588 xkb_keysym_to_string(uint32_t ks, char *buffer, size_t size);
591 * See xkb_keysym_to_string comments: this function will accept any string
592 * from that function.
594 _X_EXPORT extern uint32_t
595 xkb_string_to_keysym(const char *s);
599 #endif /* _XKBCOMMON_H_ */