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 ********************************************************/
55 * Copyright © 2009 Daniel Stone
57 * Permission is hereby granted, free of charge, to any person obtaining a
58 * copy of this software and associated documentation files (the "Software"),
59 * to deal in the Software without restriction, including without limitation
60 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
61 * and/or sell copies of the Software, and to permit persons to whom the
62 * Software is furnished to do so, subject to the following conditions:
64 * The above copyright notice and this permission notice (including the next
65 * paragraph) shall be included in all copies or substantial portions of the
68 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
71 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
73 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
74 * DEALINGS IN THE SOFTWARE.
76 * Author: Daniel Stone <daniel@fooishbar.org>
87 #include <xkbcommon/xkbcommon-names.h>
88 #include <xkbcommon/xkbcommon-keysyms.h>
90 #define XKB_KEY_NoSymbol 0L /* special KeySym */
92 typedef uint32_t xkb_keycode_t;
93 typedef uint32_t xkb_keysym_t;
94 typedef uint32_t xkb_mod_index_t;
95 typedef uint32_t xkb_mod_mask_t;
96 typedef uint32_t xkb_group_index_t;
97 typedef uint32_t xkb_led_index_t;
99 #define XKB_MOD_INVALID (0xffffffff)
100 #define XKB_GROUP_INVALID (0xffffffff)
101 #define XKB_KEYCODE_INVALID (0xffffffff)
102 #define XKB_LED_INVALID (0xffffffff)
104 #define XKB_KEYCODE_MAX (0xffffffff - 1)
105 #define xkb_keycode_is_legal_ext(kc) (kc <= XKB_KEYCODE_MAX)
106 #define xkb_keycode_is_legal_x11(kc) (kc >= 8 && kc <= 255)
109 * Names to compile a keymap with, also known as RMLVO. These names together
110 * should be the primary identifier for a keymap.
112 struct xkb_rule_names {
121 * Opaque context object; may only be created, accessed, manipulated and
122 * destroyed through the xkb_context_*() API.
127 * Opaque keymap object; may only be created, accessed, manipulated and
128 * destroyed through the xkb_state_*() API.
133 * Opaque state object; may only be created, accessed, manipulated and
134 * destroyed through the xkb_state_*() API.
143 * Returns the name for a keysym as a string; will return unknown Unicode
144 * codepoints as "Ua1b2", and other unknown keysyms as "0xabcd1234".
147 xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size);
150 * See xkb_keysym_to_string comments: this function will accept any string
151 * from that function.
154 xkb_keysym_from_name(const char *s);
157 * @defgroup context XKB contexts
158 * Every keymap compilation request must have an XKB context associated with
159 * it. The context keeps around state such as the include path.
164 enum xkb_context_flags {
165 /** Create this context with an empty include path. */
166 XKB_CONTEXT_NO_DEFAULT_INCLUDES = 1,
170 * Returns a new XKB context, or NULL on failure. If successful, the caller
171 * holds a reference on the context, and must free it when finished with
172 * xkb_context_unref().
175 xkb_context_new(enum xkb_context_flags flags);
178 * Appends a new entry to the include path used for keymap compilation.
179 * Returns 1 on success, or 0 if the include path could not be added or is
183 xkb_context_include_path_append(struct xkb_context *context, const char *path);
186 * Appends the default include paths to the context's current include path.
187 * Returns 1 on success, or 0 if the primary include path could not be
191 xkb_context_include_path_append_default(struct xkb_context *context);
194 * Removes all entries from the context's include path, and inserts the
195 * default paths. Returns 1 on success, or 0 if the primary include path
196 * could not be added.
199 xkb_context_include_path_reset_defaults(struct xkb_context *context);
202 * Removes all entries from the context's include path.
205 xkb_context_include_path_clear(struct xkb_context *context);
208 * Returns the number of include paths currently active in the context.
211 xkb_context_num_include_paths(struct xkb_context *context);
214 * Returns the include path at the specified index within the context.
217 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
220 * Takes a new reference on an XKB context.
223 xkb_context_ref(struct xkb_context *context);
226 * Releases a reference on an XKB context, and possibly frees it.
229 xkb_context_unref(struct xkb_context *context);
234 * @defgroup map Keymap management
235 * These utility functions allow you to create and deallocate XKB keymaps.
240 enum xkb_map_compile_flags {
241 /** Apparently you can't have empty enums. What a drag. */
242 XKB_MAP_COMPILE_PLACEHOLDER = 0,
246 * The primary keymap entry point: creates a new XKB keymap from a set of
247 * RMLVO (Rules + Model + Layout + Variant + Option) names.
249 * You should almost certainly be using this and nothing else to create
253 xkb_map_new_from_names(struct xkb_context *context,
254 const struct xkb_rule_names *names,
255 enum xkb_map_compile_flags flags);
257 enum xkb_keymap_format {
258 /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
259 XKB_KEYMAP_FORMAT_TEXT_V1 = 1,
263 * Creates an XKB keymap from a full text XKB keymap passed into the
267 xkb_map_new_from_file(struct xkb_context *context,
268 FILE *file, enum xkb_keymap_format format,
269 enum xkb_map_compile_flags flags);
272 * Creates an XKB keymap from a full text XKB keymap serialized into one
276 xkb_map_new_from_string(struct xkb_context *context,
278 enum xkb_keymap_format format,
279 enum xkb_map_compile_flags flags);
282 * Takes a new reference on a keymap.
285 xkb_map_ref(struct xkb_keymap *keymap);
288 * Releases a reference on a keymap.
291 xkb_map_unref(struct xkb_keymap *keymap);
296 * @defgroup components XKB state components
297 * Allows enumeration of state components such as modifiers and groups within
298 * the current keymap.
304 * Returns the number of modifiers active in the keymap.
307 xkb_map_num_mods(struct xkb_keymap *keymap);
310 * Returns the name of the modifier specified by 'idx', or NULL if invalid.
313 xkb_map_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
316 * Returns the index of the modifier specified by 'name', or XKB_MOD_INVALID.
319 xkb_map_mod_get_index(struct xkb_keymap *keymap, const char *name);
322 * Returns the number of groups active in the keymap.
325 xkb_map_num_groups(struct xkb_keymap *keymap);
328 * Returns the name of the group specified by 'idx', or NULL if invalid.
331 xkb_map_group_get_name(struct xkb_keymap *keymap, xkb_group_index_t idx);
334 * Returns the index of the group specified by 'name', or XKB_GROUP_INVALID.
337 xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name);
340 * Returns the number of groups active for the specified key.
343 xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t key);
346 * Returns the number of LEDs in the given map.
349 xkb_map_num_leds(struct xkb_keymap *keymap);
352 * Returns the name of the LED specified by 'idx', or NULL if invalid.
355 xkb_map_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
358 * Returns the index of the LED specified by 'name', or XKB_LED_INVALID.
361 xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name);
366 * @defgroup state XKB state objects
367 * Creation, destruction and manipulation of keyboard state objects,
368 * representing modifier and group state.
374 * Returns a new XKB state object for use with the given keymap, or NULL on
378 xkb_state_new(struct xkb_keymap *keymap);
381 * Takes a new reference on a state object.
384 xkb_state_ref(struct xkb_state *state);
387 * Unrefs and potentially deallocates a state object; the caller must not
388 * use the state object after calling this.
391 xkb_state_unref(struct xkb_state *state);
394 * Get the keymap from which the state object was created. Does not take
395 * a new reference on the map; you must explicitly reference it yourself
396 * if you plan to use it beyond the lifetime of the state.
399 xkb_state_get_map(struct xkb_state *state);
401 enum xkb_key_direction {
407 * Updates a state object to reflect the given key being pressed or released.
410 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
411 enum xkb_key_direction direction);
414 * Gives the symbols obtained from pressing a particular key with the given
415 * state. *syms_out will be set to point to an array of keysyms, with the
416 * return value being the number of symbols in *syms_out. If the return
417 * value is 0, *syms_out will be set to NULL, as there are no symbols produced
420 * This should be called before xkb_state_update_key.
423 xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
424 const xkb_keysym_t **syms_out);
427 * Modifier and group types for state objects. This enum is bitmaskable,
428 * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
431 enum xkb_state_component {
432 /** A key holding this modifier or group is currently physically
433 * depressed; also known as 'base'. */
434 XKB_STATE_DEPRESSED = (1 << 0),
435 /** Modifier or group is latched, i.e. will be unset after the next
436 * non-modifier key press. */
437 XKB_STATE_LATCHED = (1 << 1),
438 /** Modifier or group is locked, i.e. will be unset after the key
439 * provoking the lock has been pressed again. */
440 XKB_STATE_LOCKED = (1 << 2),
441 /** Combinatination of depressed, latched, and locked. */
442 XKB_STATE_EFFECTIVE =
443 (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
447 * Match flags for xkb_state_mod_indices_are_active and
448 * xkb_state_mod_names_are_active, specifying how the conditions for a
449 * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
452 enum xkb_state_match {
453 /** Returns true if any of the modifiers are active. */
454 XKB_STATE_MATCH_ANY = (1 << 0),
455 /** Returns true if all of the modifiers are active. */
456 XKB_STATE_MATCH_ALL = (1 << 1),
457 /** Makes matching non-exclusive, i.e. will not return false if a
458 * modifier not specified in the arguments is active. */
459 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16),
463 * Updates a state object from a set of explicit masks. This entrypoint is
464 * really only for window systems and the like, where a master process
465 * holds an xkb_state, then serializes it over a wire protocol, and clients
466 * then use the serialization to feed in to their own xkb_state.
468 * All parameters must always be passed, or the resulting state may be
471 * The serialization is lossy and will not survive round trips; it must only
472 * be used to feed slave state objects, and must not be used to update the
475 * Please do not use this unless you fit the description above.
478 xkb_state_update_mask(struct xkb_state *state,
479 xkb_mod_mask_t base_mods,
480 xkb_mod_mask_t latched_mods,
481 xkb_mod_mask_t locked_mods,
482 xkb_group_index_t base_group,
483 xkb_group_index_t latched_group,
484 xkb_group_index_t locked_group);
487 * The counterpart to xkb_state_update_mask, to be used on the server side
488 * of serialization. Returns a xkb_mod_mask_t representing the given
489 * component(s) of the state.
491 * This function should not be used in regular clients; please use the
492 * xkb_state_mod_*_is_active or xkb_state_foreach_active_mod API instead.
494 * Can return NULL on failure.
497 xkb_state_serialize_mods(struct xkb_state *state,
498 enum xkb_state_component component);
501 * The group equivalent of xkb_state_serialize_mods: please see its
505 xkb_state_serialize_group(struct xkb_state *state,
506 enum xkb_state_component component);
509 * Returns 1 if the modifier specified by 'name' is active in the manner
510 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
514 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
515 enum xkb_state_component type);
518 * Returns 1 if the modifiers specified by the varargs (treated as
519 * NULL-terminated pointers to strings) are active in the manner
520 * specified by 'match', 0 otherwise, or -1 if any of the modifiers
521 * do not exist in the map.
524 xkb_state_mod_names_are_active(struct xkb_state *state,
525 enum xkb_state_component type,
526 enum xkb_state_match match,
530 * Returns 1 if the modifier specified by 'idx' is active in the manner
531 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
532 * exist in the current map.
535 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
536 enum xkb_state_component type);
539 * Returns 1 if the modifiers specified by the varargs (treated as
540 * xkb_mod_index_t, terminated with XKB_MOD_INVALID) are active in the manner
541 * specified by 'match' and 'type', 0 otherwise, or -1 if the modifier does not
542 * exist in the current map.
545 xkb_state_mod_indices_are_active(struct xkb_state *state,
546 enum xkb_state_component type,
547 enum xkb_state_match match,
551 * Returns 1 if the group specified by 'name' is active in the manner
552 * specified by 'type', 0 if it is unset, or -1 if the group does not
553 * exist in the current map.
556 xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
557 enum xkb_state_component type);
560 * Returns 1 if the group specified by 'idx' is active in the manner
561 * specified by 'type', 0 if it is unset, or -1 if the group does not
562 * exist in the current map.
565 xkb_state_group_index_is_active(struct xkb_state *state, xkb_group_index_t idx,
566 enum xkb_state_component type);
569 * Returns 1 if the LED specified by 'name' is active, 0 if it is unset, or
570 * -1 if the LED does not exist in the current map.
573 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
576 * Returns 1 if the LED specified by 'idx' is active, 0 if it is unset, or
577 * -1 if the LED does not exist in the current map.
580 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
588 #endif /* _XKBCOMMON_H_ */