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>
86 typedef uint32_t xkb_keycode_t;
87 typedef uint32_t xkb_keysym_t;
88 typedef uint32_t xkb_mod_index_t;
89 typedef uint32_t xkb_mod_mask_t;
90 typedef uint32_t xkb_group_index_t;
91 typedef uint32_t xkb_led_index_t;
93 #define XKB_MOD_INVALID (0xffffffff)
94 #define XKB_GROUP_INVALID (0xffffffff)
95 #define XKB_KEYCODE_INVALID (0xffffffff)
96 #define XKB_LED_INVALID (0xffffffff)
98 #define XKB_KEYSYM_NO_SYMBOL 0
100 #define XKB_KEYCODE_MAX (0xffffffff - 1)
101 #define xkb_keycode_is_legal_ext(kc) (kc <= XKB_KEYCODE_MAX)
102 #define xkb_keycode_is_legal_x11(kc) (kc <= XKB_KEYCODE_MAX)
103 #define xkb_keymap_keycode_range_is_legal(xkb) \
104 (xkb->max_key_code > 0 && \
105 xkb->max_key_code > xkb->min_key_code && \
106 xkb_keycode_is_legal_ext(xkb->min_key_code) && \
107 xkb_keycode_is_legal_ext(xkb->max_key_code))
110 * Names to compile a keymap with, also known as RMLVO. These names together
111 * should be the primary identifier for a keymap.
113 struct xkb_rule_names {
122 * Legacy names for the components of an XKB keymap, also known as KcCGST.
123 * This is only used in deprecated entrypoints which might be removed or
124 * shuffled off to a support library.
126 struct xkb_component_names {
135 * Opaque context object; may only be created, accessed, manipulated and
136 * destroyed through the xkb_context_*() API.
141 * Opaque keymap object; may only be created, accessed, manipulated and
142 * destroyed through the xkb_state_*() API.
147 * Opaque state object; may only be created, accessed, manipulated and
148 * destroyed through the xkb_state_*() API.
157 * Canonicalises component names by prepending the relevant component from
158 * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
159 * by replacing a '%' with the relevant component, e.g.:
162 * ------------------------------------------
165 * foo+%|baz bar foo+bar|baz
167 * If a component in names needs to be modified, the existing value will be
168 * free()d, and a new one allocated with malloc().
171 xkb_canonicalise_components(struct xkb_component_names *names,
172 const struct xkb_component_names *old);
175 * Converts a keysym to a string; will return unknown Unicode codepoints
176 * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
179 xkb_keysym_to_string(xkb_keysym_t ks, char *buffer, size_t size);
182 * See xkb_keysym_to_string comments: this function will accept any string
183 * from that function.
186 xkb_string_to_keysym(const char *s);
189 * @defgroup ctx XKB contexts
190 * Every keymap compilation request must have an XKB context associated with
191 * it. The context keeps around state such as the include path.
196 enum xkb_context_flags {
197 /** Apparently you can't have empty enums. What a drag. */
198 XKB_CONTEXT_PLACEHOLDER = 0,
202 * Returns a new XKB context, or NULL on failure. If successful, the caller
203 * holds a reference on the context, and must free it when finished with
204 * xkb_context_unref().
207 xkb_context_new(enum xkb_context_flags flags);
210 * Appends a new entry to the include path used for keymap compilation.
211 * Returns 1 on success, or 0 if the include path could not be added or is
215 xkb_context_include_path_append(struct xkb_context *context, const char *path);
218 * Appends the default include paths to the context's current include path.
219 * Returns 1 on success, or 0 if the primary include path could not be
223 xkb_context_include_path_append_default(struct xkb_context *context);
226 * Removes all entries from the context's include path, and inserts the
227 * default paths. Returns 1 on success, or 0 if the primary include path
228 * could not be added.
231 xkb_context_include_path_reset_defaults(struct xkb_context *context);
234 * Removes all entries from the context's include path.
237 xkb_context_include_path_clear(struct xkb_context *context);
240 * Returns the number of include paths currently active in the context.
243 xkb_context_num_include_paths(struct xkb_context *context);
246 * Returns the include path at the specified index within the context.
249 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
252 * Takes a new reference on an XKB context.
255 xkb_context_ref(struct xkb_context *context);
258 * Releases a reference on an XKB context, and possibly frees it.
261 xkb_context_unref(struct xkb_context *context);
266 * @defgroup map Keymap management
267 * These utility functions allow you to create and deallocate XKB keymaps.
272 enum xkb_map_compile_flags {
273 /** Apparently you can't have empty enums. What a drag. */
274 XKB_MAP_COMPILE_PLACEHOLDER = 0,
278 * The primary keymap entry point: creates a new XKB keymap from a set of
279 * RMLVO (Rules + Model + Layout + Variant + Option) names.
281 * You should almost certainly be using this and nothing else to create
285 xkb_map_new_from_names(struct xkb_context *context,
286 const struct xkb_rule_names *names,
287 enum xkb_map_compile_flags flags);
290 * Deprecated entrypoint for legacy users who need to be able to compile
291 * XKB keymaps by KcCGST (Keycodes + Compat + Geometry + Symbols + Types)
294 * You should not use this unless you are the X server. This entrypoint
295 * may well disappear in future releases. Please, please, don't use it.
297 * Geometry will be ignored since xkbcommon does not support it in any way.
300 xkb_map_new_from_kccgst(struct xkb_context *context,
301 const struct xkb_component_names *kccgst,
302 enum xkb_map_compile_flags flags);
304 enum xkb_keymap_format {
305 /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
306 XKB_KEYMAP_FORMAT_TEXT_V1 = 1,
310 * Creates an XKB keymap from a full text XKB keymap passed into the
314 xkb_map_new_from_fd(struct xkb_context *context,
315 int fd, enum xkb_keymap_format format,
316 enum xkb_map_compile_flags flags);
319 * Creates an XKB keymap from a full text XKB keymap serialised into one
323 xkb_map_new_from_string(struct xkb_context *context,
325 enum xkb_keymap_format format,
326 enum xkb_map_compile_flags flags);
329 * Takes a new reference on a keymap.
332 xkb_map_ref(struct xkb_keymap *xkb);
335 * Releases a reference on a keymap.
338 xkb_map_unref(struct xkb_keymap *xkb);
343 * @defgroup components XKB state components
344 * Allows enumeration of state components such as modifiers and groups within
345 * the current keymap.
351 * Returns the number of modifiers active in the keymap.
354 xkb_map_num_mods(struct xkb_keymap *xkb);
357 * Returns the name of the modifier specified by 'idx', or NULL if invalid.
360 xkb_map_mod_get_name(struct xkb_keymap *xkb, xkb_mod_index_t idx);
363 * Returns the index of the modifier specified by 'name', or XKB_MOD_INVALID.
366 xkb_map_mod_get_index(struct xkb_keymap *xkb, const char *name);
369 * Returns the number of groups active in the keymap.
372 xkb_map_num_groups(struct xkb_keymap *xkb);
375 * Returns the name of the group specified by 'idx', or NULL if invalid.
378 xkb_map_group_get_name(struct xkb_keymap *xkb, xkb_group_index_t idx);
381 * Returns the index of the group specified by 'name', or XKB_GROUP_INVALID.
384 xkb_map_group_get_index(struct xkb_keymap *xkb, const char *name);
387 * Returns the number of groups active for the specified key.
390 xkb_key_num_groups(struct xkb_keymap *xkb, xkb_keycode_t key);
393 * Returns the number of LEDs in the given map.
396 xkb_map_num_leds(struct xkb_keymap *xkb);
399 * Returns the name of the LED specified by 'idx', or NULL if invalid.
402 xkb_map_led_get_name(struct xkb_keymap *xkb, xkb_led_index_t idx);
405 * Returns the index of the LED specified by 'name', or XKB_LED_INVALID.
408 xkb_map_led_get_index(struct xkb_keymap *xkb, const char *name);
413 * @defgroup state XKB state objects
414 * Creation, destruction and manipulation of keyboard state objects,
415 * representing modifier and group state.
421 * Returns a new XKB state object for use with the given keymap, or NULL on
425 xkb_state_new(struct xkb_keymap *xkb);
428 * Takes a new reference on a state object.
431 xkb_state_ref(struct xkb_state *state);
434 * Unrefs and potentially deallocates a state object; the caller must not
435 * use the state object after calling this.
438 xkb_state_unref(struct xkb_state *state);
441 * Get the keymap from which the state object was created.
444 xkb_state_get_map(struct xkb_state *state);
446 enum xkb_key_direction {
452 * Updates a state object to reflect the given key being pressed or released.
455 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
456 enum xkb_key_direction direction);
459 * Gives the symbols obtained from pressing a particular key with the given
460 * state. *syms_out will be set to point to an array of keysyms, with the
461 * return value being the number of symbols in *syms_out. If the return
462 * value is 0, *syms_out will be set to NULL, as there are no symbols produced
465 * This should be called before xkb_state_update_key.
468 xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
469 const xkb_keysym_t **syms_out);
472 * Modifier and group types for state objects. This enum is bitmaskable,
473 * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
476 enum xkb_state_component {
477 /** A key holding this modifier or group is currently physically
478 * depressed; also known as 'base'. */
479 XKB_STATE_DEPRESSED = (1 << 0),
480 /** Modifier or group is latched, i.e. will be unset after the next
481 * non-modifier key press. */
482 XKB_STATE_LATCHED = (1 << 1),
483 /** Modifier or group is locked, i.e. will be unset after the key
484 * provoking the lock has been pressed again. */
485 XKB_STATE_LOCKED = (1 << 2),
486 /** Combinatination of depressed, latched, and locked. */
487 XKB_STATE_EFFECTIVE =
488 (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
492 * Updates a state object from a set of explicit masks. This entrypoint is
493 * really only for window systems and the like, where a master process
494 * holds an xkb_state, then serialises it over a wire protocol, and clients
495 * then use the serialisation to feed in to their own xkb_state.
497 * All parameters must always be passed, or the resulting state may be
500 * The serialisation is lossy and will not survive round trips; it must only
501 * be used to feed slave state objects, and must not be used to update the
504 * Please do not use this unless you fit the description above.
507 xkb_state_update_mask(struct xkb_state *state,
508 xkb_mod_mask_t base_mods,
509 xkb_mod_mask_t latched_mods,
510 xkb_mod_mask_t locked_mods,
511 xkb_group_index_t base_group,
512 xkb_group_index_t latched_group,
513 xkb_group_index_t locked_group);
516 * The counterpart to xkb_state_update_mask, to be used on the server side
517 * of serialisation. Returns a xkb_mod_mask_t representing the given
518 * component(s) of the state.
520 * This function should not be used in regular clients; please use the
521 * xkb_state_mod_*_is_active or xkb_state_foreach_active_mod API instead.
523 * Can return NULL on failure.
526 xkb_state_serialise_mods(struct xkb_state *state,
527 enum xkb_state_component component);
530 * The group equivalent of xkb_state_serialise_mods: please see its
534 xkb_state_serialise_group(struct xkb_state *state,
535 enum xkb_state_component component);
538 * Returns 1 if the modifier specified by 'name' is active in the manner
539 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
540 * exist in the current map.
543 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
544 enum xkb_state_component type);
547 * Returns 1 if the modifier specified by 'idx' is active in the manner
548 * specified by 'type', 0 if it is unset, or -1 if the modifier does not
549 * exist in the current map.
552 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
553 enum xkb_state_component type);
556 * Returns 1 if the group specified by 'name' is active in the manner
557 * specified by 'type', 0 if it is unset, or -1 if the group does not
558 * exist in the current map.
561 xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
562 enum xkb_state_component type);
565 * Returns 1 if the group specified by 'idx' is active in the manner
566 * specified by 'type', 0 if it is unset, or -1 if the group does not
567 * exist in the current map.
570 xkb_state_group_index_is_active(struct xkb_state *state, xkb_group_index_t idx,
571 enum xkb_state_component type);
574 * Returns 1 if the LED specified by 'name' is active, 0 if it is unset, or
575 * -1 if the LED does not exist in the current map.
578 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
581 * Returns 1 if the LED specified by 'idx' is active, 0 if it is unset, or
582 * -1 if the LED does not exist in the current map.
585 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
593 #endif /* _XKBCOMMON_H_ */