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 * Returns the compiled XKB map as a string which can later be fed back into
283 * xkb_map_new_from_string to return the exact same keymap.
286 xkb_map_get_as_string(struct xkb_keymap *keymap);
289 * Takes a new reference on a keymap.
292 xkb_map_ref(struct xkb_keymap *keymap);
295 * Releases a reference on a keymap.
298 xkb_map_unref(struct xkb_keymap *keymap);
303 * @defgroup components XKB state components
304 * Allows enumeration of state components such as modifiers and groups within
305 * the current keymap.
311 * Returns the number of modifiers active in the keymap.
314 xkb_map_num_mods(struct xkb_keymap *keymap);
317 * Returns the name of the modifier specified by 'idx', or NULL if invalid.
320 xkb_map_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
323 * Returns the index of the modifier specified by 'name', or XKB_MOD_INVALID.
326 xkb_map_mod_get_index(struct xkb_keymap *keymap, const char *name);
329 * Returns the number of groups active in the keymap.
332 xkb_map_num_groups(struct xkb_keymap *keymap);
335 * Returns the name of the group specified by 'idx', or NULL if invalid.
338 xkb_map_group_get_name(struct xkb_keymap *keymap, xkb_group_index_t idx);
341 * Returns the index of the group specified by 'name', or XKB_GROUP_INVALID.
344 xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name);
347 * Returns the number of groups active for the specified key.
350 xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t key);
353 * Returns the number of LEDs in the given map.
356 xkb_map_num_leds(struct xkb_keymap *keymap);
359 * Returns the name of the LED specified by 'idx', or NULL if invalid.
362 xkb_map_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
365 * Returns the index of the LED specified by 'name', or XKB_LED_INVALID.
368 xkb_map_led_get_index(struct xkb_keymap *keymap, const char *name);
373 * @defgroup state XKB state objects
374 * Creation, destruction and manipulation of keyboard state objects,
375 * representing modifier and group state.
381 * Returns a new XKB state object for use with the given keymap, or NULL on
385 xkb_state_new(struct xkb_keymap *keymap);
388 * Takes a new reference on a state object.
391 xkb_state_ref(struct xkb_state *state);
394 * Unrefs and potentially deallocates a state object; the caller must not
395 * use the state object after calling this.
398 xkb_state_unref(struct xkb_state *state);
401 * Get the keymap from which the state object was created. Does not take
402 * a new reference on the map; you must explicitly reference it yourself
403 * if you plan to use it beyond the lifetime of the state.
406 xkb_state_get_map(struct xkb_state *state);
408 enum xkb_key_direction {
414 * Updates a state object to reflect the given key being pressed or released.
417 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
418 enum xkb_key_direction direction);
421 * Gives the symbols obtained from pressing a particular key with the given
422 * state. *syms_out will be set to point to an array of keysyms, with the
423 * return value being the number of symbols in *syms_out. If the return
424 * value is 0, *syms_out will be set to NULL, as there are no symbols produced
427 * This should be called before xkb_state_update_key.
430 xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
431 const xkb_keysym_t **syms_out);
434 * Modifier and group types for state objects. This enum is bitmaskable,
435 * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
438 enum xkb_state_component {
439 /** A key holding this modifier or group is currently physically
440 * depressed; also known as 'base'. */
441 XKB_STATE_DEPRESSED = (1 << 0),
442 /** Modifier or group is latched, i.e. will be unset after the next
443 * non-modifier key press. */
444 XKB_STATE_LATCHED = (1 << 1),
445 /** Modifier or group is locked, i.e. will be unset after the key
446 * provoking the lock has been pressed again. */
447 XKB_STATE_LOCKED = (1 << 2),
448 /** Combinatination of depressed, latched, and locked. */
449 XKB_STATE_EFFECTIVE =
450 (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
454 * Match flags for xkb_state_mod_indices_are_active and
455 * xkb_state_mod_names_are_active, specifying how the conditions for a
456 * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
459 enum xkb_state_match {
460 /** Returns true if any of the modifiers are active. */
461 XKB_STATE_MATCH_ANY = (1 << 0),
462 /** Returns true if all of the modifiers are active. */
463 XKB_STATE_MATCH_ALL = (1 << 1),
464 /** Makes matching non-exclusive, i.e. will not return false if a
465 * modifier not specified in the arguments is active. */
466 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16),
470 * Updates a state object from a set of explicit masks. This entrypoint is
471 * really only for window systems and the like, where a master process
472 * holds an xkb_state, then serializes it over a wire protocol, and clients
473 * then use the serialization to feed in to their own xkb_state.
475 * All parameters must always be passed, or the resulting state may be
478 * The serialization is lossy and will not survive round trips; it must only
479 * be used to feed slave state objects, and must not be used to update the
482 * Please do not use this unless you fit the description above.
485 xkb_state_update_mask(struct xkb_state *state,
486 xkb_mod_mask_t base_mods,
487 xkb_mod_mask_t latched_mods,
488 xkb_mod_mask_t locked_mods,
489 xkb_group_index_t base_group,
490 xkb_group_index_t latched_group,
491 xkb_group_index_t locked_group);
494 * The counterpart to xkb_state_update_mask, to be used on the server side
495 * of serialization. Returns a xkb_mod_mask_t representing the given
496 * component(s) of the state.
498 * This function should not be used in regular clients; please use the
499 * xkb_state_mod_*_is_active or xkb_state_foreach_active_mod API instead.
501 * Can return NULL on failure.
504 xkb_state_serialize_mods(struct xkb_state *state,
505 enum xkb_state_component component);
508 * The group equivalent of xkb_state_serialize_mods: please see its
512 xkb_state_serialize_group(struct xkb_state *state,
513 enum xkb_state_component component);
516 * Returns 1 if the modifier specified by 'name' is active in the manner
517 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
521 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
522 enum xkb_state_component type);
525 * Returns 1 if the modifiers specified by the varargs (treated as
526 * NULL-terminated pointers to strings) are active in the manner
527 * specified by 'match', 0 otherwise, or -1 if any of the modifiers
528 * do not exist in the map.
531 xkb_state_mod_names_are_active(struct xkb_state *state,
532 enum xkb_state_component type,
533 enum xkb_state_match match,
537 * Returns 1 if the modifier specified by 'idx' is active in the manner
538 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
539 * exist in the current map.
542 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
543 enum xkb_state_component type);
546 * Returns 1 if the modifiers specified by the varargs (treated as
547 * xkb_mod_index_t, terminated with XKB_MOD_INVALID) are active in the manner
548 * specified by 'match' and 'type', 0 otherwise, or -1 if the modifier does not
549 * exist in the current map.
552 xkb_state_mod_indices_are_active(struct xkb_state *state,
553 enum xkb_state_component type,
554 enum xkb_state_match match,
558 * Returns 1 if the group specified by 'name' is active in the manner
559 * specified by 'type', 0 if it is unset, or -1 if the group does not
560 * exist in the current map.
563 xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
564 enum xkb_state_component type);
567 * Returns 1 if the group specified by 'idx' is active in the manner
568 * specified by 'type', 0 if it is unset, or -1 if the group does not
569 * exist in the current map.
572 xkb_state_group_index_is_active(struct xkb_state *state, xkb_group_index_t idx,
573 enum xkb_state_component type);
576 * Returns 1 if the LED specified by 'name' is active, 0 if it is unset, or
577 * -1 if the LED does not exist in the current map.
580 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
583 * Returns 1 if the LED specified by 'idx' is active, 0 if it is unset, or
584 * -1 if the LED does not exist in the current map.
587 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
595 #endif /* _XKBCOMMON_H_ */