Debian Codegraph @

include/xkbcommon/xkbcommon.h

raw
1 /*
2 * For MIT-open-group:
3 * Copyright 1985, 1987, 1990, 1998 The Open Group
4 * Copyright 2008 Dan Nicholson
5 *
6 * For HPND:
7 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
8 * SPDX-License-Identifier: HPND
9 *
10 * For MIT:
11 * Copyright © 2009-2012 Daniel Stone
12 * Copyright © 2012 Intel Corporation
13 * Copyright © 2012 Ran Benita
14 *
15 * SPDX-License-Identifier: MIT-open-group AND HPND AND MIT
16 *
17 * Author: Daniel Stone <[email protected]>
18 */
19
20 #ifndef _XKBCOMMON_H_
21 #define _XKBCOMMON_H_
22
23 #include <stdbool.h>
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <stdarg.h>
27
28 #include <xkbcommon/xkbcommon-names.h>
29 #include <xkbcommon/xkbcommon-keysyms.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #if defined(__GNUC__) && !defined(__CYGWIN__)
36 # define XKB_EXPORT __attribute__((visibility("default")))
37 #elif defined(_WIN32)
38 # define XKB_EXPORT __declspec(dllexport)
39 #else
40 # define XKB_EXPORT
41 #endif
42
43 /**
44 * @file
45 * Main libxkbcommon API.
46 */
47
48 /**
49 * @struct xkb_context
50 * Opaque top level library context object.
51 *
52 * The context contains various general library data and state, like
53 * logging level and include paths.
54 *
55 * Objects are created in a specific context, and multiple contexts may
56 * coexist simultaneously. Objects from different contexts are completely
57 * separated and do not share any memory or state.
58 */
59 struct xkb_context;
60
61 /**
62 * @struct xkb_keymap
63 * Opaque compiled keymap object.
64 *
65 * The keymap object holds all of the static keyboard information obtained
66 * from compiling XKB files.
67 *
68 * A keymap is immutable after it is created (besides reference counts, etc.);
69 * if you need to change it, you must create a new one.
70 */
71 struct xkb_keymap;
72
73 /**
74 * @struct xkb_state
75 * Opaque keyboard state object.
76 *
77 * State objects contain the active state of a keyboard (or keyboards), such
78 * as the currently effective layout and the active modifiers. It acts as a
79 * simple state machine, wherein key presses and releases are the input, and
80 * key symbols (keysyms) are the output.
81 */
82 struct xkb_state;
83
84 /**
85 * A number used to represent a physical key on a keyboard.
86 *
87 * A standard PC-compatible keyboard might have 102 keys. An appropriate
88 * keymap would assign each of them a keycode, by which the user should
89 * refer to the key throughout the library.
90 *
91 * Historically, the X11 protocol, and consequentially the XKB protocol,
92 * assign only 8 bits for keycodes. This limits the number of different
93 * keys that can be used simultaneously in a single keymap to 256
94 * (disregarding other limitations). This library does not share this limit;
95 * keycodes beyond 255 (*extended* keycodes) are not treated specially.
96 * Keymaps and applications which are compatible with X11 should not use
97 * these keycodes.
98 *
99 * The values of specific keycodes are determined by the keymap and the
100 * underlying input system. For example, with an X11-compatible keymap
101 * and Linux evdev scan codes (see `linux/input.h`), a fixed offset is used:
102 *
103 * The keymap defines a canonical name for each key, plus possible aliases.
104 * Historically, the XKB protocol restricts these names to at most 4 (ASCII)
105 * characters, but this library does not share this limit.
106 *
107 * @code
108 * xkb_keycode_t keycode_A = KEY_A + 8;
109 * @endcode
110 *
111 * @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()
112 */
113 typedef uint32_t xkb_keycode_t;
114
115 /**
116 * A number used to represent the symbols generated from a key on a keyboard.
117 *
118 * A key, represented by a keycode, may generate different symbols according
119 * to keyboard state. For example, on a QWERTY keyboard, pressing the key
120 * labled \<A\> generates the symbol ‘a’. If the Shift key is held, it
121 * generates the symbol ‘A’. If a different layout is used, say Greek,
122 * it generates the symbol ‘α’. And so on.
123 *
124 * Each such symbol is represented by a *keysym* (short for “key symbol”).
125 * Note that keysyms are somewhat more general, in that they can also represent
126 * some “function”, such as “Left” or “Right” for the arrow keys. For more
127 * information, see: Appendix A [“KEYSYM Encoding”][encoding] of the X Window
128 * System Protocol.
129 *
130 * Specifically named keysyms can be found in the
131 * xkbcommon/xkbcommon-keysyms.h header file. Their name does not include
132 * the `XKB_KEY_` prefix.
133 *
134 * Besides those, any Unicode/ISO&nbsp;10646 character in the range U+0100 to
135 * U+10FFFF can be represented by a keysym value in the range 0x01000100 to
136 * 0x0110FFFF. The name of Unicode keysyms is `U<codepoint>`, e.g. `UA1B2`.
137 *
138 * The name of other unnamed keysyms is the hexadecimal representation of
139 * their value, e.g. `0xabcd1234`.
140 *
141 * Keysym names are case-sensitive.
142 *
143 * @note **Encoding:** Keysyms are 32-bit integers with the 3 most significant
144 * bits always set to zero. Thus valid keysyms are in the range
145 * `0 .. 0x1fffffff` = @ref XKB_KEYSYM_MAX.
146 * See: Appendix A [“KEYSYM Encoding”][encoding] of the X Window System Protocol.
147 *
148 * [encoding]: https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding
149 *
150 * @ingroup keysyms
151 * @sa `::XKB_KEYSYM_MAX`
152 */
153 typedef uint32_t xkb_keysym_t;
154
155 /**
156 * Index of a keyboard layout.
157 *
158 * The layout index is a state component which determines which <em>keyboard
159 * layout</em> is active. These may be different alphabets, different key
160 * arrangements, etc.
161 *
162 * Layout indices are consecutive. The first layout has index 0.
163 *
164 * Each layout is not required to have a name, and the names are not
165 * guaranteed to be unique (though they are usually provided and unique).
166 * Therefore, it is not safe to use the name as a unique identifier for a
167 * layout. Layout names are case-sensitive.
168 *
169 * Layout names are specified in the layout’s definition, for example
170 * “English (US)”. These are different from the (conventionally) short names
171 * which are used to locate the layout, for example `us` or `us(intl)`. These
172 * names are not present in a compiled keymap.
173 *
174 * If the user selects layouts from a list generated from the XKB registry
175 * (using libxkbregistry or directly), and this metadata is needed later on, it
176 * is recommended to store it along with the keymap.
177 *
178 * Layouts are also called *groups* by XKB.
179 *
180 * @sa xkb_keymap::xkb_keymap_num_layouts()
181 * @sa xkb_keymap::xkb_keymap_num_layouts_for_key()
182 */
183 typedef uint32_t xkb_layout_index_t;
184 /** A mask of layout indices. */
185 typedef uint32_t xkb_layout_mask_t;
186
187 /**
188 * Index of a shift level.
189 *
190 * Any key, in any layout, can have several <em>shift levels</em>. Each
191 * shift level can assign different keysyms to the key. The shift level
192 * to use is chosen according to the current keyboard state; for example,
193 * if no keys are pressed, the first level may be used; if the Left Shift
194 * key is pressed, the second; if Num Lock is pressed, the third; and
195 * many such combinations are possible (see `xkb_mod_index_t`).
196 *
197 * Level indices are consecutive. The first level has index 0.
198 */
199 typedef uint32_t xkb_level_index_t;
200
201 /**
202 * Index of a modifier.
203 *
204 * A @e modifier is a state component which changes the way keys are
205 * interpreted. A keymap defines a set of modifiers, such as Alt, Shift,
206 * Num Lock or Meta, and specifies which keys may @e activate which
207 * modifiers (in a many-to-many relationship, i.e. a key can activate
208 * several modifiers, and a modifier may be activated by several keys.
209 * Different keymaps do this differently).
210 *
211 * When retrieving the keysyms for a key, the active modifier set is
212 * consulted; this determines the correct shift level to use within the
213 * currently active layout (see `xkb_level_index_t`).
214 *
215 * Modifier indices are consecutive. The first modifier has index 0.
216 *
217 * Each modifier must have a name, and the names are unique. Therefore, it
218 * is safe to use the name as a unique identifier for a modifier. The names
219 * of some common modifiers are provided in the `xkbcommon/xkbcommon-names.h`
220 * header file. Modifier names are case-sensitive.
221 *
222 * @sa xkb_keymap_num_mods()
223 */
224 typedef uint32_t xkb_mod_index_t;
225 /** A mask of modifier indices. */
226 typedef uint32_t xkb_mod_mask_t;
227
228 /**
229 * Index of a keyboard LED.
230 *
231 * LEDs are logical objects which may be @e active or @e inactive. They
232 * typically correspond to the lights on the keyboard. Their state is
233 * determined by the current keyboard state.
234 *
235 * LED indices are non-consecutive. The first LED has index 0.
236 *
237 * Each LED must have a name, and the names are unique. Therefore,
238 * it is safe to use the name as a unique identifier for a LED. The names
239 * of some common LEDs are provided in the `xkbcommon/xkbcommon-names.h`
240 * header file. LED names are case-sensitive.
241 *
242 * @warning A given keymap may specify an exact index for a given LED.
243 * Therefore, LED indexing is not necessarily sequential, as opposed to
244 * modifiers and layouts. This means that when iterating over the LEDs
245 * in a keymap using e.g. xkb_keymap::xkb_keymap_num_leds(), some indices might
246 * be invalid.
247 * Given such an index, functions like xkb_keymap::xkb_keymap_led_get_name()
248 * will return `NULL`, and `xkb_state::xkb_state_led_index_is_active()` will
249 * return -1.
250 *
251 * LEDs are also called *indicators* by XKB.
252 *
253 * @sa `xkb_keymap::xkb_keymap_num_leds()`
254 */
255 typedef uint32_t xkb_led_index_t;
256 /** A mask of LED indices. */
257 typedef uint32_t xkb_led_mask_t;
258
259 /** Invalid keycode */
260 #define XKB_KEYCODE_INVALID (0xffffffff)
261 /** Invalid layout index */
262 #define XKB_LAYOUT_INVALID (0xffffffff)
263 /** Invalid level index */
264 #define XKB_LEVEL_INVALID (0xffffffff)
265 /** Invalid modifier index */
266 #define XKB_MOD_INVALID (0xffffffff)
267 /** Invalid LED index */
268 #define XKB_LED_INVALID (0xffffffff)
269
270 /** Maximum legal keycode */
271 #define XKB_KEYCODE_MAX (0xffffffff - 1)
272
273 /**
274 * Maximum keysym value
275 *
276 * @since 1.6.0
277 * @sa xkb_keysym_t
278 * @ingroup keysyms
279 */
280 #define XKB_KEYSYM_MAX 0x1fffffff
281
282 /**
283 * Test whether a value is a valid extended keycode.
284 * @sa xkb_keycode_t
285 **/
286 #define xkb_keycode_is_legal_ext(key) ((key) <= XKB_KEYCODE_MAX)
287
288 /**
289 * Test whether a value is a valid X11 keycode.
290 * @sa xkb_keycode_t
291 */
292 #define xkb_keycode_is_legal_x11(key) ((key) >= 8 && (key) <= 255)
293
294 /**
295 * @defgroup rules-api Rules
296 * Utility functions related to *rules*, whose purpose is introduced in:
297 * @ref xkb-the-config "".
298 *
299 * @{
300 */
301
302 /**
303 * @struct xkb_rmlvo_builder
304 * Opaque [RMLVO] configuration object.
305 *
306 * It denotes the configuration values by which a user picks a keymap.
307 *
308 * @see [Introduction to RMLVO][RMLVO]
309 * @see @ref rules-api ""
310 * @since 1.11.0
311 *
312 * [RMLVO]: @ref RMLVO-intro
313 */
314 struct xkb_rmlvo_builder;
315
316 enum xkb_rmlvo_builder_flags {
317 XKB_RMLVO_BUILDER_NO_FLAGS = 0
318 };
319
320 /**
321 * Create a new [RMLVO] builder.
322 *
323 * @param context The context in which to create the builder.
324 * @param rules The ruleset.
325 * If `NULL` or the empty string `""`, a default value is used.
326 * If the `XKB_DEFAULT_RULES` environment variable is set, it is used
327 * as the default. Otherwise the system default is used.
328 * @param model The keyboard model.
329 * If `NULL` or the empty string `""`, a default value is used.
330 * If the `XKB_DEFAULT_MODEL` environment variable is set, it is used
331 * as the default. Otherwise the system default is used.
332 * @param flags Optional flags for the builder, or 0.
333 *
334 * @returns A `xkb_rmlvo_builder`, or `NULL` if the compilation failed.
335 *
336 * @see `xkb_rule_names` for a detailed description of `rules` and `model`.
337 * @since 1.11.0
338 * @memberof xkb_rmlvo_builder
339 *
340 * [RMLVO]: @ref RMLVO-intro
341 */
342 XKB_EXPORT struct xkb_rmlvo_builder*
343 xkb_rmlvo_builder_new(struct xkb_context *context,
344 const char *rules, const char *model,
345 enum xkb_rmlvo_builder_flags flags);
346
347 /**
348 * Append a layout to the given [RMLVO] builder.
349 *
350 * @param rmlvo The builder to modify.
351 * @param layout The name of the layout.
352 * @param variant The name of the layout variant, or `NULL` to
353 * select the default variant.
354 * @param options An array of options to apply only to this layout, or
355 * `NULL` if there is no such options.
356 * @param options_len The length of @p options.
357 *
358 * @note The options are only effectual if the corresponding ruleset has the
359 * proper rules to handle them as *layout-specific* options.
360 * @note See `rxkb_option_is_layout_specific()` to query whether an option
361 * supports the layout-specific feature.
362 *
363 * @returns `true` if the call succeeded, otherwise `false`.
364 *
365 * @since 1.11.0
366 * @memberof xkb_rmlvo_builder
367 *
368 * [RMLVO]: @ref RMLVO-intro
369 */
370 XKB_EXPORT bool
371 xkb_rmlvo_builder_append_layout(struct xkb_rmlvo_builder *rmlvo,
372 const char *layout, const char *variant,
373 const char* const* options, size_t options_len);
374
375 /**
376 * Append an option to the given [RMLVO] builder.
377 *
378 * @param rmlvo The builder to modify.
379 * @param option The name of the option.
380 *
381 * @returns `true` if the call succeeded, otherwise `false`.
382 *
383 * @since 1.11.0
384 * @memberof xkb_rmlvo_builder
385 *
386 * [RMLVO]: @ref RMLVO-intro
387 */
388 XKB_EXPORT bool
389 xkb_rmlvo_builder_append_option(struct xkb_rmlvo_builder *rmlvo,
390 const char *option);
391
392 /**
393 * Take a new reference on a [RMLVO] builder.
394 *
395 * @param rmlvo The builder to reference.
396 *
397 * @returns The passed in builder.
398 *
399 * @since 1.11.0
400 * @memberof xkb_rmlvo_builder
401 *
402 * [RMLVO]: @ref RMLVO-intro
403 */
404 XKB_EXPORT struct xkb_rmlvo_builder *
405 xkb_rmlvo_builder_ref(struct xkb_rmlvo_builder *rmlvo);
406
407 /**
408 * Release a reference on a [RMLVO] builder, and possibly free it.
409 *
410 * @param rmlvo The builder. If it is `NULL`, this function does nothing.
411 *
412 * @since 1.11.0
413 * @memberof xkb_rmlvo_builder
414 *
415 * [RMLVO]: @ref RMLVO-intro
416 */
417 XKB_EXPORT void
418 xkb_rmlvo_builder_unref(struct xkb_rmlvo_builder *rmlvo);
419
420 /**
421 * Names to compile a keymap with, also known as [RMLVO].
422 *
423 * The names are the common configuration values by which a user picks
424 * a keymap.
425 *
426 * If the entire struct is `NULL`, then each field is taken to be `NULL`.
427 * You should prefer passing `NULL` instead of choosing your own defaults.
428 *
429 * @see [Introduction to RMLVO][RMLVO]
430 * @see @ref rules-api ""
431 *
432 * [RMLVO]: @ref RMLVO-intro
433 */
434 struct xkb_rule_names {
435 /**
436 * The rules file to use. The rules file describes how to interpret
437 * the values of the model, layout, variant and options fields.
438 *
439 * If `NULL` or the empty string `""`, a default value is used.
440 * If the `XKB_DEFAULT_RULES` environment variable is set, it is used
441 * as the default. Otherwise the system default is used.
442 */
443 const char *rules;
444 /**
445 * The keyboard model by which to interpret keycodes and LEDs.
446 *
447 * If `NULL` or the empty string `""`, a default value is used.
448 * If the `XKB_DEFAULT_MODEL` environment variable is set, it is used
449 * as the default. Otherwise the system default is used.
450 */
451 const char *model;
452 /**
453 * A comma separated list of layouts (languages) to include in the
454 * keymap.
455 *
456 * If `NULL` or the empty string `""`, a default value is used.
457 * If the `XKB_DEFAULT_LAYOUT` environment variable is set, it is used
458 * as the default. Otherwise the system default is used.
459 */
460 const char *layout;
461 /**
462 * A comma separated list of variants, one per layout, which may
463 * modify or augment the respective layout in various ways.
464 *
465 * Generally, should either be empty or have the same number of values
466 * as the number of layouts. You may use empty values as in `intl,,neo`.
467 *
468 * If `NULL` or the empty string `""`, and a default value is also used
469 * for the layout, a default value is used. Otherwise no variant is
470 * used.
471 * If the `XKB_DEFAULT_VARIANT` environment variable is set, it is used
472 * as the default. Otherwise the system default is used.
473 */
474 const char *variant;
475 /**
476 * A comma separated list of options, through which the user specifies
477 * non-layout related preferences, like which key combinations are used
478 * for switching layouts, or which key is the Compose key.
479 *
480 * If `NULL`, a default value is used. If the empty string `""`, no
481 * options are used.
482 * If the `XKB_DEFAULT_OPTIONS` environment variable is set, it is used
483 * as the default. Otherwise the system default is used.
484 *
485 * Each option can additionally have a *layout index specifier*, so that it
486 * applies only if matching the given layout. The index is specified by
487 * appending `!` immediately after the option name, then the 1-indexed
488 * target layout in decimal format: e.g. `ns:option!2`. When no layout is
489 * specified, it matches any layout.
490 *
491 * @note The layout index specifier is only effectual if the corresponding
492 * ruleset has the proper rules to handle the option as *layout-specific*.
493 * @note See `rxkb_option_is_layout_specific()` to query whether an option
494 * supports the layout-specific feature.
495 *
496 * @since 1.11.0: Layout index specifier using `!`.
497 */
498 const char *options;
499 };
500
501 /**
502 * Keymap components, also known as [KcCGST].
503 *
504 * The components are the result of the [RMLVO] resolution.
505 *
506 * @see [Introduction to RMLVO][RMLVO]
507 * @see [Introduction to KcCGST][KcCGST]
508 * @see @ref rules-api ""
509 *
510 * [RMLVO]: @ref RMLVO-intro
511 * [KcCGST]: @ref KcCGST-intro
512 */
513 struct xkb_component_names {
514 char *keycodes;
515 char *compatibility;
516 char *geometry;
517 char *symbols;
518 char *types;
519 };
520
521 /**
522 * Resolve [RMLVO] names to [KcCGST] components.
523 *
524 * This function is used primarily for *debugging*. See
525 * `xkb_keymap::xkb_keymap_new_from_names2()` for creating keymaps from
526 * [RMLVO] names.
527 *
528 * @param[in] context The context in which to resolve the names.
529 * @param[in] rmlvo_in The [RMLVO] names to use.
530 * @param[out] rmlvo_out The [RMLVO] names actually used after resolving
531 * missing values.
532 * @param[out] components_out The [KcCGST] components resulting of the [RMLVO]
533 * resolution.
534 *
535 * @c rmlvo_out and @c components can be omitted by using `NULL`, but not both.
536 *
537 * If @c components is not `NULL`, it is filled with dynamically-allocated
538 * strings that should be freed by the caller.
539 *
540 * @returns `true` if the [RMLVO] names could be resolved, `false` otherwise.
541 *
542 * @see [Introduction to RMLVO][RMLVO]
543 * @see [Introduction to KcCGST][KcCGST]
544 * @see xkb_rule_names
545 * @see xkb_component_names
546 * @see xkb_keymap::xkb_keymap_new_from_names2()
547 *
548 * @since 1.9.0
549 * @memberof xkb_component_names
550 *
551 * [RMLVO]: @ref RMLVO-intro
552 * [KcCGST]: @ref KcCGST-intro
553 */
554 XKB_EXPORT bool
555 xkb_components_names_from_rules(struct xkb_context *context,
556 const struct xkb_rule_names *rmlvo_in,
557 struct xkb_rule_names *rmlvo_out,
558 struct xkb_component_names *components_out);
559
560 /** @} */
561
562 /**
563 * @defgroup keysyms Keysyms
564 * Utility functions related to *keysyms* (short for “key symbols”).
565 *
566 * @{
567 */
568
569 /**
570 * @page keysym-transformations Keysym Transformations
571 *
572 * Keysym translation is subject to several *keysym transformations*,
573 * as described in the XKB specification. These are:
574 *
575 * <dl>
576 * <dt>Capitalization transformation</dt>
577 * <dd>
578 * If the Caps Lock modifier is
579 * active and was not consumed by the translation process, keysyms
580 * are transformed to their upper-case form (if applicable).
581 * Similarly, the UTF-8/UTF-32 string produced is capitalized.
582 *
583 * This is described in:
584 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
585 * </dd>
586 * <dt>Control transformation</dt>
587 * <dd>
588 * If the Control modifier is active and
589 * was not consumed by the translation process, the string produced
590 * is transformed to its matching ASCII control character (if
591 * applicable). Keysyms are not affected.
592 *
593 * This is described in:
594 * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
595 * </dd>
596 * </dl>
597 *
598 * Each relevant function discusses which transformations it performs.
599 *
600 * These transformations are not applicable when a key produces multiple
601 * keysyms.
602 */
603
604
605 /**
606 * Get the name of a keysym.
607 *
608 * For a description of how keysyms are named, see @ref xkb_keysym_t.
609 *
610 * @param[in] keysym The keysym.
611 * @param[out] buffer A string buffer to write the name into.
612 * @param[in] size Size of the buffer.
613 *
614 * @warning If the buffer passed is too small, the string is truncated
615 * (though still `NULL`-terminated); a size of at least 64 bytes is recommended.
616 *
617 * @returns The number of bytes in the name, excluding the `NULL` byte. If
618 * the keysym is invalid, returns -1.
619 *
620 * You may check if truncation has occurred by comparing the return value
621 * with the length of buffer, similarly to the `snprintf(3)` function.
622 *
623 * @sa `xkb_keysym_t`
624 */
625 XKB_EXPORT int
626 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
627
628 /** Flags for xkb_keysym_from_name(). */
629 enum xkb_keysym_flags {
630 /** Do not apply any flags. */
631 XKB_KEYSYM_NO_FLAGS = 0,
632 /** Find keysym by case-insensitive search. */
633 XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
634 };
635
636 /**
637 * Get a keysym from its name.
638 *
639 * @param name The name of a keysym. See remarks in `xkb_keysym_get_name()`;
640 * this function will accept any name returned by that function.
641 * @param flags A set of flags controlling how the search is done. If
642 * invalid flags are passed, this will fail with `XKB_KEY_NoSymbol`.
643 *
644 * If you use the `::XKB_KEYSYM_CASE_INSENSITIVE` flag and two keysym names
645 * differ only by case, then the lower-case keysym name is returned. For
646 * instance, for KEY_a and KEY_A, this function would return KEY_a for the
647 * case-insensitive search. If this functionality is needed, it is
648 * recommended to first call this function without this flag; and if that
649 * fails, only then to try with this flag, while possibly warning the user
650 * he had misspelled the name, and might get wrong results.
651 *
652 * Case folding is done according to the C locale; the current locale is not
653 * consulted.
654 *
655 * @returns The keysym. If the name is invalid, returns `XKB_KEY_NoSymbol`.
656 *
657 * @sa xkb_keysym_t
658 * @since 1.9.0: Enable support for C0 and C1 control characters in the Unicode
659 * notation.
660 */
661 XKB_EXPORT xkb_keysym_t
662 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
663
664 /**
665 * Get the Unicode/UTF-8 representation of a keysym.
666 *
667 * @param[in] keysym The keysym.
668 * @param[out] buffer A buffer to write the UTF-8 string into.
669 * @param[in] size The size of buffer. Must be at least 5.
670 *
671 * @returns The number of bytes written to the buffer (including the
672 * terminating byte). If the keysym does not have a Unicode
673 * representation, returns 0. If the buffer is too small, returns -1.
674 *
675 * This function does not perform any @ref keysym-transformations.
676 * Therefore, prefer to use `xkb_state::xkb_state_key_get_utf8()` if possible.
677 *
678 * @sa `xkb_state::xkb_state_key_get_utf8()`
679 */
680 XKB_EXPORT int
681 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
682
683 /**
684 * Get the Unicode/UTF-32 representation of a keysym.
685 *
686 * @returns The Unicode/UTF-32 representation of keysym, which is also
687 * compatible with UCS-4. If the keysym does not have a Unicode
688 * representation, returns 0.
689 *
690 * This function does not perform any @ref keysym-transformations.
691 * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
692 *
693 * @sa `xkb_state::xkb_state_key_get_utf32()`
694 */
695 XKB_EXPORT uint32_t
696 xkb_keysym_to_utf32(xkb_keysym_t keysym);
697
698 /**
699 * Get the keysym corresponding to a Unicode/UTF-32 codepoint.
700 *
701 * @returns The keysym corresponding to the specified Unicode
702 * codepoint, or XKB_KEY_NoSymbol if there is none.
703 *
704 * This function is the inverse of @ref xkb_keysym_to_utf32. In cases
705 * where a single codepoint corresponds to multiple keysyms, returns
706 * the keysym with the lowest value.
707 *
708 * Unicode codepoints which do not have a special (legacy) keysym
709 * encoding use a direct encoding scheme. These keysyms don’t usually
710 * have an associated keysym constant (`XKB_KEY_*`).
711 *
712 * @sa `xkb_keysym_to_utf32()`
713 * @since 1.0.0
714 * @since 1.9.0: Enable support for all noncharacters.
715 */
716 XKB_EXPORT xkb_keysym_t
717 xkb_utf32_to_keysym(uint32_t ucs);
718
719 /**
720 * Convert a keysym to its uppercase form.
721 *
722 * If there is no such form, the keysym is returned unchanged.
723 *
724 * The conversion rules are the *simple* (i.e. one-to-one) Unicode case
725 * mappings (with some exceptions, see hereinafter) and do not depend
726 * on the locale. If you need the special case mappings (i.e. not
727 * one-to-one or locale-dependent), prefer to work with the Unicode
728 * representation instead, when possible.
729 *
730 * Exceptions to the Unicode mappings:
731 *
732 * | Lower keysym | Lower letter | Upper keysym | Upper letter | Comment |
733 * | ------------ | ------------ | ------------ | ------------ | ------- |
734 * | `ssharp` | `U+00DF`: ß | `U1E9E` | `U+1E9E`: ẞ | [Council for German Orthography] |
735 *
736 * [Council for German Orthography]: https://www.rechtschreibrat.com/regeln-und-woerterverzeichnis/
737 *
738 * @since 0.8.0: Initial implementation, based on `libX11`.
739 * @since 1.8.0: Use Unicode 16.0 mappings for complete Unicode coverage.
740 * @since 1.12.0: Update to Unicode 17.0.
741 */
742 XKB_EXPORT xkb_keysym_t
743 xkb_keysym_to_upper(xkb_keysym_t ks);
744
745 /**
746 * Convert a keysym to its lowercase form.
747 *
748 * If there is no such form, the keysym is returned unchanged.
749 *
750 * The conversion rules are the *simple* (i.e. one-to-one) Unicode case
751 * mappings and do not depend on the locale. If you need the special
752 * case mappings (i.e. not one-to-one or locale-dependent), prefer to
753 * work with the Unicode representation instead, when possible.
754 *
755 * @since 0.8.0: Initial implementation, based on `libX11`.
756 * @since 1.8.0: Use Unicode 16.0 mappings for complete Unicode coverage.
757 * @since 1.12.0: Update to Unicode 17.0.
758 */
759 XKB_EXPORT xkb_keysym_t
760 xkb_keysym_to_lower(xkb_keysym_t ks);
761
762 /** @} */
763
764 /**
765 * @defgroup context Library Context
766 * Creating, destroying and using library contexts.
767 *
768 * Every keymap compilation request must have a context associated with
769 * it. The context keeps around state such as the include path.
770 *
771 * @{
772 */
773
774 /**
775 * @page envvars Environment Variables
776 *
777 * The user may set some environment variables which affect the library:
778 *
779 * - `XKB_CONFIG_ROOT`, `XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH`,
780 * `XKB_CONFIG_VERSIONED_EXTENSIONS_PATH`, `XKB_CONFIG_EXTRA_PATH`,
781 * `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.
782 * - `XKB_LOG_LEVEL` - see `xkb_context::xkb_context_set_log_level()`.
783 * - `XKB_LOG_VERBOSITY` - see `xkb_context::xkb_context_set_log_verbosity()`.
784 * - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,
785 * `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see `xkb_rule_names`.
786 */
787
788 /** Flags for context creation. */
789 enum xkb_context_flags {
790 /** Do not apply any context flags. */
791 XKB_CONTEXT_NO_FLAGS = 0,
792 /**
793 * Create this context with an empty include path.
794 *
795 * This may be useful e.g.:
796 * - to have full control over the included paths;
797 * - for clients that do not need to access the XKB directories, e.g.
798 * if only retrieving keymap from the Wayland or X server. It avoids
799 * potential issues with directory access permissions.
800 */
801 XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
802 /**
803 * Don’t take RMLVO names from the environment.
804 *
805 * @since 0.3.0
806 */
807 XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1),
808 /**
809 * Disable the use of secure_getenv for this context, so that privileged
810 * processes can use environment variables. Client uses at their own risk.
811 *
812 * @since 1.5.0
813 */
814 XKB_CONTEXT_NO_SECURE_GETENV = (1 << 2)
815 };
816
817 /**
818 * Create a new context.
819 *
820 * @param flags Optional flags for the context, or 0.
821 *
822 * @returns A new context, or `NULL` on failure.
823 *
824 * @memberof xkb_context
825 */
826 XKB_EXPORT struct xkb_context *
827 xkb_context_new(enum xkb_context_flags flags);
828
829 /**
830 * Take a new reference on a context.
831 *
832 * @returns The passed in context.
833 *
834 * @memberof xkb_context
835 */
836 XKB_EXPORT struct xkb_context *
837 xkb_context_ref(struct xkb_context *context);
838
839 /**
840 * Release a reference on a context, and possibly free it.
841 *
842 * @param context The context. If it is `NULL`, this function does nothing.
843 *
844 * @memberof xkb_context
845 */
846 XKB_EXPORT void
847 xkb_context_unref(struct xkb_context *context);
848
849 /**
850 * Store custom user data in the context.
851 *
852 * This may be useful in conjunction with `xkb_context::xkb_context_set_log_fn()`
853 * or other callbacks.
854 *
855 * @memberof xkb_context
856 */
857 XKB_EXPORT void
858 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
859
860 /**
861 * Retrieves stored user data from the context.
862 *
863 * @returns The stored user data. If the user data wasn’t set, or the
864 * passed in context is `NULL`, returns `NULL`.
865 *
866 * This may be useful to access private user data from callbacks like a
867 * custom logging function.
868 *
869 * @memberof xkb_context
870 **/
871 XKB_EXPORT void *
872 xkb_context_get_user_data(struct xkb_context *context);
873
874 /** @} */
875
876 /**
877 * @defgroup include-path Include Paths
878 * Manipulating the include paths in a context.
879 *
880 * The include paths are the file-system paths that are searched when an
881 * include statement is encountered during keymap compilation.
882 *
883 * The default include paths are, in that lookup order:
884 * - The path `$XDG_CONFIG_HOME/xkb`, where `$XDG_CONFIG_HOME` is the value of
885 the environment variable `XDG_CONFIG_HOME`, with the usual fallback to
886 `$HOME/.config/` if unset.
887 * - The path `$HOME/.xkb`, where `$HOME` is the value of the environment
888 * variable `HOME`.
889 * - The `XKB_CONFIG_EXTRA_PATH` environment variable, if defined, otherwise the
890 * system configuration directory, defined at library configuration time
891 * (usually `/etc/xkb`).
892 * - Each subdirectory of each XKB extensions directory (versioned, then
893 * unversioned if no corresponding versioned subdirectory), listed in
894 * lexicographic order. The extensions directories are defined by the
895 * environment variables `XKB_CONFIG_VERSIONED_EXTENSIONS_PATH` and
896 * `XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH` and default to the system XKB
897 * root extensions directories, defined at library configuration time (usually
898 * `/usr/share/xkeyboard-config-<VERSION>.d` and
899 * `/usr/share/xkeyboard-config.d`).
900 * - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise
901 * the system XKB root, defined at library configuration time
902 * (usually `/usr/share/xkeyboard-config-<VERSION>` or `/usr/share/X11/xkb`).
903 *
904 * @{
905 */
906
907 /**
908 * Append a new entry to the context’s include path.
909 *
910 * @returns 1 on success, or 0 if the include path could not be added or is
911 * inaccessible.
912 *
913 * @memberof xkb_context
914 */
915 XKB_EXPORT int
916 xkb_context_include_path_append(struct xkb_context *context, const char *path);
917
918 /**
919 * Append the default include paths to the context’s include path.
920 *
921 * @returns 1 on success, or 0 if no default include path could be added.
922 *
923 * @memberof xkb_context
924 */
925 XKB_EXPORT int
926 xkb_context_include_path_append_default(struct xkb_context *context);
927
928 /**
929 * Reset the context’s include path to the default.
930 *
931 * Removes all entries from the context’s include path, and inserts the
932 * default paths.
933 *
934 * @returns 1 on success, or 0 if the primary include path could not be added.
935 *
936 * @memberof xkb_context
937 */
938 XKB_EXPORT int
939 xkb_context_include_path_reset_defaults(struct xkb_context *context);
940
941 /**
942 * Remove all entries from the context’s include path.
943 *
944 * @memberof xkb_context
945 */
946 XKB_EXPORT void
947 xkb_context_include_path_clear(struct xkb_context *context);
948
949 /**
950 * Get the number of paths in the context’s include path.
951 *
952 * @memberof xkb_context
953 */
954 XKB_EXPORT unsigned int
955 xkb_context_num_include_paths(struct xkb_context *context);
956
957 /**
958 * Get a specific include path from the context’s include path.
959 *
960 * @returns The include path at the specified index. If the index is
961 * invalid, returns NULL.
962 *
963 * @memberof xkb_context
964 */
965 XKB_EXPORT const char *
966 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
967
968 /** @} */
969
970 /**
971 * @defgroup logging Logging Handling
972 * Manipulating how logging from this library is handled.
973 *
974 * @{
975 */
976
977 /** Specifies a logging level. */
978 enum xkb_log_level {
979 XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
980 XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
981 XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
982 XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
983 XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
984 };
985
986 /**
987 * Set the current logging level.
988 *
989 * @param context The context in which to set the logging level.
990 * @param level The logging level to use. Only messages from this level
991 * and below will be logged.
992 *
993 * The default level is `::XKB_LOG_LEVEL_ERROR`. The environment variable
994 * `XKB_LOG_LEVEL`, if set in the time the context was created, overrides the
995 * default value. It may be specified as a level number or name.
996 *
997 * @memberof xkb_context
998 */
999 XKB_EXPORT void
1000 xkb_context_set_log_level(struct xkb_context *context,
1001 enum xkb_log_level level);
1002
1003 /**
1004 * Get the current logging level.
1005 *
1006 * @memberof xkb_context
1007 */
1008 XKB_EXPORT enum xkb_log_level
1009 xkb_context_get_log_level(struct xkb_context *context);
1010
1011 /**
1012 * Sets the current logging verbosity.
1013 *
1014 * The library can generate a number of warnings which are not helpful to
1015 * ordinary users of the library. The verbosity may be increased if more
1016 * information is desired (e.g. when developing a new keymap).
1017 *
1018 * The default verbosity is 0. The environment variable `XKB_LOG_VERBOSITY`,
1019 * if set in the time the context was created, overrides the default value.
1020 *
1021 * @param context The context in which to use the set verbosity.
1022 * @param verbosity The verbosity to use. Currently used values are
1023 * 1 to 10, higher values being more verbose. 0 would result in no verbose
1024 * messages being logged.
1025 *
1026 * Most verbose messages are of level `::XKB_LOG_LEVEL_WARNING` or lower.
1027 *
1028 * @memberof xkb_context
1029 */
1030 XKB_EXPORT void
1031 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
1032
1033 /**
1034 * Get the current logging verbosity of the context.
1035 *
1036 * @memberof xkb_context
1037 */
1038 XKB_EXPORT int
1039 xkb_context_get_log_verbosity(struct xkb_context *context);
1040
1041 /**
1042 * Set a custom function to handle logging messages.
1043 *
1044 * @param context The context in which to use the set logging function.
1045 * @param log_fn The function that will be called for logging messages.
1046 * Passing `NULL` restores the default function, which logs to stderr.
1047 *
1048 * By default, log messages from this library are printed to stderr. This
1049 * function allows you to replace the default behavior with a custom
1050 * handler. The handler is only called with messages which match the
1051 * current logging level and verbosity settings for the context.
1052 * level is the logging level of the message. @a format and @a args are
1053 * the same as in the `vprintf(3)` function.
1054 *
1055 * You may use `xkb_context::xkb_context_set_user_data()` on the context, and
1056 * then call `xkb_context::xkb_context_get_user_data()` from within the logging
1057 * function to provide it with additional private context.
1058 *
1059 * @memberof xkb_context
1060 */
1061 XKB_EXPORT void
1062 xkb_context_set_log_fn(struct xkb_context *context,
1063 void (*log_fn)(struct xkb_context *context,
1064 enum xkb_log_level level,
1065 const char *format, va_list args));
1066
1067 /** @} */
1068
1069 /**
1070 * @defgroup keymap Keymap Creation
1071 * Creating and destroying keymaps.
1072 *
1073 * @{
1074 */
1075
1076 /** Flags for keymap compilation. */
1077 enum xkb_keymap_compile_flags {
1078 /** Do not apply any flags. */
1079 XKB_KEYMAP_COMPILE_NO_FLAGS = 0
1080 };
1081
1082 /**
1083 * The possible keymap formats.
1084 *
1085 * See @ref keymap-text-format-v1-v2 "" for the complete description of the
1086 * formats and @ref keymap-support "" for detailed differences between the
1087 * formats.
1088 *
1089 * @remark A keymap can be parsed in one format and serialized in another,
1090 * thanks to automatic fallback mechanisms.
1091 *
1092 * <table>
1093 * <caption>
1094 * Keymap format to use depending on the target protocol
1095 * </caption>
1096 * <thead>
1097 * <tr>
1098 * <th colspan="2">Protocol</th>
1099 * <th colspan="2">libxkbcommon keymap format</th>
1100 * </tr>
1101 * <tr>
1102 * <th>Name</th>
1103 * <th>Keymap format</th>
1104 * <th>Parsing</th>
1105 * <th>Serialization</th>
1106 * </tr>
1107 * </thead>
1108 * <tbody>
1109 * <tr>
1110 * <th>X11</th>
1111 * <td>XKB</td>
1112 * <td>
1113 * `::XKB_KEYMAP_FORMAT_TEXT_V1`
1114 * </td>
1115 * <td>
1116 * *Always* use `::XKB_KEYMAP_FORMAT_TEXT_V1`, since the other formats are
1117 * incompatible.
1118 * </td>
1119 * </tr>
1120 * <tr>
1121 * <th>Wayland</th>
1122 * <td><code>[xkb_v1]</code></td>
1123 * <td>
1124 * <dl>
1125 * <dt>Wayland compositors<dt>
1126 * <dd>
1127 * The format depends on the keyboard layout database (usually [xkeyboard-config]).
1128 * Note that since v2 is a superset of v1, compositors are encouraged to use
1129 * `::XKB_KEYMAP_FORMAT_TEXT_V2` whenever possible.
1130 * </dd>
1131 * <dt>Client apps</dt>
1132 * <dd>
1133 * Clients should use `::XKB_KEYMAP_FORMAT_TEXT_V1` to parse the keymap sent
1134 * by a Wayland compositor, at least until `::XKB_KEYMAP_FORMAT_TEXT_V2`
1135 * stabilizes.
1136 * </dd>
1137 * </td>
1138 * <td>
1139 * At the time of writing (July 2025), the Wayland <code>[xkb_v1]</code> keymap
1140 * format is only defined as “libxkbcommon compatible”. In theory it enables
1141 * flexibility, but the set of supported features varies depending on the
1142 * libxkbcommon version and libxkbcommon keymap format used. Unfortunately there
1143 * is currently no Wayland API for keymap format *negotiation*.
1144 *
1145 * Therefore the **recommended** serialization format is
1146 * `::XKB_KEYMAP_FORMAT_TEXT_V1`, in order to ensure maximum compatibility for
1147 * interchange.
1148 *
1149 * Serializing using `::XKB_KEYMAP_FORMAT_TEXT_V2` should be considered
1150 * **experimental**, as some clients may fail to parse the resulting string.
1151 * </td>
1152 * </tr>
1153 * </tbody>
1154 * </table>
1155 *
1156 * [xkb_v1]: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard-enum-keymap_format
1157 * [xkeyboard-config]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config
1158 */
1159 enum xkb_keymap_format {
1160 /**
1161 * The classic XKB text format, as generated by `xkbcomp -xkb`.
1162 *
1163 * @important This format should *always* be used when *serializing* a
1164 * keymap for **X11**.
1165 *
1166 * @important For the **Wayland** <code>[xkb_v1]</code> format, it is
1167 * advised to use this format as well for serializing, in order to ensure
1168 * maximum compatibility for interchange.
1169 *
1170 * [xkb_v1]: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard-enum-keymap_format
1171 */
1172 XKB_KEYMAP_FORMAT_TEXT_V1 = 1,
1173 /**
1174 * Xkbcommon extensions of the classic XKB text format, **incompatible with
1175 * X11**.
1176 *
1177 * @important Do *not* use when *serializing* a keymap for **X11**
1178 * (incompatible).
1179 *
1180 * @important Considered *experimental* when *serializing* for **Wayland**:
1181 * at the time of writing (July 2025), there is only one XKB keymap format
1182 * <code>[xkb_v1]</code> in Wayland and no Wayland API for keymap format
1183 * *negotiation*, so the clients may not be able to parse the keymap if it
1184 * uses v2-specific features. Therefore a compositor may *parse* keymaps
1185 * using `::XKB_KEYMAP_FORMAT_TEXT_V2` but it should serialize them using
1186 * `::XKB_KEYMAP_FORMAT_TEXT_V1` and rely on the automatic *fallback*
1187 * mechanisms.
1188 *
1189 * @since 1.11.0
1190 *
1191 * [xkb_v1]: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard-enum-keymap_format
1192 */
1193 XKB_KEYMAP_FORMAT_TEXT_V2 = 2
1194 };
1195
1196 /**
1197 * Create a keymap from a [RMLVO] builder.
1198 *
1199 * The primary keymap entry point: creates a new XKB keymap from a set of
1200 * [RMLVO] \(Rules + Model + Layouts + Variants + Options) names.
1201 *
1202 * @param rmlvo The [RMLVO] builder to use. See `xkb_rmlvo_builder`.
1203 * @param format The text format of the keymap file to compile.
1204 * @param flags Optional flags for the keymap, or 0.
1205 *
1206 * @returns A keymap compiled according to the [RMLVO] names, or `NULL` if
1207 * the compilation failed.
1208 *
1209 * @since 1.11.0
1210 * @sa `xkb_keymap_new_from_names2()`
1211 * @sa `xkb_rmlvo_builder`
1212 * @memberof xkb_keymap
1213 *
1214 * [RMLVO]: @ref RMLVO-intro
1215 */
1216 XKB_EXPORT struct xkb_keymap *
1217 xkb_keymap_new_from_rmlvo(const struct xkb_rmlvo_builder *rmlvo,
1218 enum xkb_keymap_format format,
1219 enum xkb_keymap_compile_flags flags);
1220
1221 /**
1222 * Create a keymap from [RMLVO] names.
1223 *
1224 * Same as `xkb_keymap_new_from_names2()`, but with the keymap format fixed to:
1225 * `::XKB_KEYMAP_FORMAT_TEXT_V2`.
1226 *
1227 * @deprecated Use `xkb_keymap_new_from_names2()` instead.
1228 * @since 1.11.0: Deprecated
1229 * @since 1.11.0: Use internally `::XKB_KEYMAP_FORMAT_TEXT_V2` instead of
1230 * `::XKB_KEYMAP_FORMAT_TEXT_V1`
1231 * @sa `xkb_keymap_new_from_names2()`
1232 * @sa `xkb_rule_names`
1233 * @sa `xkb_keymap_new_from_rmlvo()`
1234 * @memberof xkb_keymap
1235 *
1236 * [RMLVO]: @ref RMLVO-intro
1237 */
1238 XKB_EXPORT struct xkb_keymap *
1239 xkb_keymap_new_from_names(struct xkb_context *context,
1240 const struct xkb_rule_names *names,
1241 enum xkb_keymap_compile_flags flags);
1242
1243 /**
1244 * Create a keymap from [RMLVO] names.
1245 *
1246 * The primary keymap entry point: creates a new XKB keymap from a set of
1247 * [RMLVO] \(Rules + Model + Layouts + Variants + Options) names.
1248 *
1249 * @param context The context in which to create the keymap.
1250 * @param names The [RMLVO] names to use. See xkb_rule_names.
1251 * @param format The text format of the keymap file to compile.
1252 * @param flags Optional flags for the keymap, or 0.
1253 *
1254 * @returns A keymap compiled according to the [RMLVO] names, or `NULL` if
1255 * the compilation failed.
1256 *
1257 * @sa `xkb_rule_names`
1258 * @sa `xkb_keymap_new_from_rmlvo()`
1259 * @memberof xkb_keymap
1260 * @since 1.11.0
1261 *
1262 * [RMLVO]: @ref RMLVO-intro
1263 */
1264 XKB_EXPORT struct xkb_keymap *
1265 xkb_keymap_new_from_names2(struct xkb_context *context,
1266 const struct xkb_rule_names *names,
1267 enum xkb_keymap_format format,
1268 enum xkb_keymap_compile_flags flags);
1269
1270 /**
1271 * Create a keymap from a keymap file.
1272 *
1273 * @param context The context in which to create the keymap.
1274 * @param file The keymap file to compile.
1275 * @param format The text format of the keymap file to compile.
1276 * @param flags Optional flags for the keymap, or 0.
1277 *
1278 * @returns A keymap compiled from the given XKB keymap file, or `NULL` if
1279 * the compilation failed.
1280 *
1281 * The file must contain a complete keymap. For example, in the
1282 * `::XKB_KEYMAP_FORMAT_TEXT_V1` format, this means the file must contain one
1283 * top level `%xkb_keymap` section, which in turn contains other required
1284 * sections.
1285 *
1286 * @memberof xkb_keymap
1287 */
1288 XKB_EXPORT struct xkb_keymap *
1289 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
1290 enum xkb_keymap_format format,
1291 enum xkb_keymap_compile_flags flags);
1292
1293 /**
1294 * Create a keymap from a keymap string.
1295 *
1296 * This is just like `xkb_keymap_new_from_file()`, but instead of a file, gets
1297 * the keymap as one enormous string.
1298 *
1299 * @see `xkb_keymap_new_from_file()`
1300 * @memberof xkb_keymap
1301 */
1302 XKB_EXPORT struct xkb_keymap *
1303 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
1304 enum xkb_keymap_format format,
1305 enum xkb_keymap_compile_flags flags);
1306
1307 /**
1308 * Create a keymap from a memory buffer.
1309 *
1310 * This is just like `xkb_keymap_new_from_string()`, but takes a length argument
1311 * so the input string does not have to be zero-terminated.
1312 *
1313 * @see `xkb_keymap_new_from_string()`
1314 * @memberof xkb_keymap
1315 * @since 0.3.0
1316 */
1317 XKB_EXPORT struct xkb_keymap *
1318 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
1319 size_t length, enum xkb_keymap_format format,
1320 enum xkb_keymap_compile_flags flags);
1321
1322 /**
1323 * Take a new reference on a keymap.
1324 *
1325 * @returns The passed in keymap.
1326 *
1327 * @memberof xkb_keymap
1328 */
1329 XKB_EXPORT struct xkb_keymap *
1330 xkb_keymap_ref(struct xkb_keymap *keymap);
1331
1332 /**
1333 * Release a reference on a keymap, and possibly free it.
1334 *
1335 * @param keymap The keymap. If it is `NULL`, this function does nothing.
1336 *
1337 * @memberof xkb_keymap
1338 */
1339 XKB_EXPORT void
1340 xkb_keymap_unref(struct xkb_keymap *keymap);
1341
1342 /**
1343 * Get the keymap as a string in the format from which it was created.
1344 * @sa `xkb_keymap::xkb_keymap_get_as_string()`
1345 **/
1346 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
1347
1348 /**
1349 * Flags to control keymap serialization.
1350 *
1351 * @since 1.12.0
1352 */
1353 enum xkb_keymap_serialize_flags {
1354 /** Do not apply any flags. */
1355 XKB_KEYMAP_SERIALIZE_NO_FLAGS = 0,
1356 /** Enable pretty-printing */
1357 XKB_KEYMAP_SERIALIZE_PRETTY = (1 << 0),
1358 /** Do not drop unused bits (key types, compatibility entries) */
1359 XKB_KEYMAP_SERIALIZE_KEEP_UNUSED = (1 << 1),
1360 };
1361
1362 /**
1363 * Get the compiled keymap as a string.
1364 *
1365 * Same as `xkb_keymap::xkb_keymap_get_as_string2()` using
1366 * `::XKB_KEYMAP_SERIALIZE_NO_FLAGS`.
1367 *
1368 * @since 1.12.0: Drop unused types and compatibility entries and do not
1369 * pretty-print.
1370 *
1371 * @sa `xkb_keymap::xkb_keymap_get_as_string2()`
1372 * @memberof xkb_keymap
1373 */
1374 XKB_EXPORT char *
1375 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
1376 enum xkb_keymap_format format);
1377
1378 /**
1379 * Get the compiled keymap as a string.
1380 *
1381 * @param keymap The keymap to get as a string.
1382 * @param format The keymap format to use for the string. You can pass
1383 * in the special value `::XKB_KEYMAP_USE_ORIGINAL_FORMAT` to use the format
1384 * from which the keymap was originally created. When used as an *interchange*
1385 * format such as Wayland <code>[xkb_v1]</code>, the format should be explicit.
1386 * @param flags Optional flags to control the serialization, or 0.
1387 *
1388 * @returns The keymap as a `NULL`-terminated string, or `NULL` if unsuccessful.
1389 *
1390 * The returned string may be fed back into `xkb_keymap_new_from_string()`
1391 * to get the exact same keymap (possibly in another process, etc.).
1392 *
1393 * The returned string is *dynamically allocated* and should be freed by the
1394 * caller.
1395 *
1396 * @since 1.12.0
1397 *
1398 * @sa `xkb_keymap_get_as_string()`
1399 * @sa `xkb_keymap_new_from_string()`
1400 * @memberof xkb_keymap
1401 *
1402 * [xkb_v1]: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard-enum-keymap_format
1403 */
1404 XKB_EXPORT char *
1405 xkb_keymap_get_as_string2(struct xkb_keymap *keymap,
1406 enum xkb_keymap_format format,
1407 enum xkb_keymap_serialize_flags flags);
1408
1409 /** @} */
1410
1411 /**
1412 * @defgroup components Keymap Components
1413 * Enumeration of state components in a keymap.
1414 *
1415 * @{
1416 */
1417
1418 /**
1419 * Get the minimum keycode in the keymap.
1420 *
1421 * @sa xkb_keycode_t
1422 * @memberof xkb_keymap
1423 * @since 0.3.1
1424 */
1425 XKB_EXPORT xkb_keycode_t
1426 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
1427
1428 /**
1429 * Get the maximum keycode in the keymap.
1430 *
1431 * @sa xkb_keycode_t
1432 * @memberof xkb_keymap
1433 * @since 0.3.1
1434 */
1435 XKB_EXPORT xkb_keycode_t
1436 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
1437
1438 /**
1439 * The iterator used by `xkb_keymap_key_for_each()`.
1440 *
1441 * @sa xkb_keymap_key_for_each
1442 * @memberof xkb_keymap
1443 * @since 0.3.1
1444 */
1445 typedef void
1446 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
1447 void *data);
1448
1449 /**
1450 * Run a specified function for every valid keycode in the keymap. If a
1451 * keymap is sparse, this function may be called fewer than
1452 * (max_keycode - min_keycode + 1) times.
1453 *
1454 * @sa xkb_keymap_min_keycode()
1455 * @sa xkb_keymap_max_keycode()
1456 * @sa xkb_keycode_t
1457 * @memberof xkb_keymap
1458 * @since 0.3.1
1459 */
1460 XKB_EXPORT void
1461 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
1462 void *data);
1463
1464 /**
1465 * Find the name of the key with the given keycode.
1466 *
1467 * This function always returns the canonical name of the key (see
1468 * description in `xkb_keycode_t`).
1469 *
1470 * @returns The key name. If no key with this keycode exists,
1471 * returns `NULL`.
1472 *
1473 * @sa xkb_keycode_t
1474 * @memberof xkb_keymap
1475 * @since 0.6.0
1476 */
1477 XKB_EXPORT const char *
1478 xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
1479
1480 /**
1481 * Find the keycode of the key with the given name.
1482 *
1483 * The name can be either a canonical name or an alias.
1484 *
1485 * @returns The keycode. If no key with this name exists,
1486 * returns `::XKB_KEYCODE_INVALID`.
1487 *
1488 * @sa xkb_keycode_t
1489 * @memberof xkb_keymap
1490 * @since 0.6.0
1491 */
1492 XKB_EXPORT xkb_keycode_t
1493 xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
1494
1495 /**
1496 * Get the number of modifiers in the keymap.
1497 *
1498 * @sa xkb_mod_index_t
1499 * @memberof xkb_keymap
1500 */
1501 XKB_EXPORT xkb_mod_index_t
1502 xkb_keymap_num_mods(struct xkb_keymap *keymap);
1503
1504 /**
1505 * Get the name of a modifier by index.
1506 *
1507 * @returns The name. If the index is invalid, returns `NULL`.
1508 *
1509 * @sa xkb_mod_index_t
1510 * @memberof xkb_keymap
1511 */
1512 XKB_EXPORT const char *
1513 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
1514
1515 /**
1516 * Get the index of a modifier by name.
1517 *
1518 * @returns The index. If no modifier with this name exists, returns
1519 * `::XKB_MOD_INVALID`.
1520 *
1521 * @sa xkb_mod_index_t
1522 * @memberof xkb_keymap
1523 */
1524 XKB_EXPORT xkb_mod_index_t
1525 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
1526
1527 /**
1528 * Get the encoding of a modifier by name.
1529 *
1530 * In X11 terminology it corresponds to the mapping to the *[real modifiers]*.
1531 *
1532 * @returns The encoding of a modifier. Note that it may be 0 if the name does
1533 * not exist or if the modifier is not mapped.
1534 *
1535 * @since 1.10.0
1536 * @sa `xkb_keymap_mod_get_mask2()`
1537 * @memberof xkb_keymap
1538 *
1539 * [real modifiers]: @ref real-modifier-def
1540 */
1541 XKB_EXPORT xkb_mod_mask_t
1542 xkb_keymap_mod_get_mask(struct xkb_keymap *keymap, const char *name);
1543
1544 /**
1545 * Get the encoding of a modifier by index.
1546 *
1547 * In X11 terminology it corresponds to the mapping to the *[real modifiers]*.
1548 *
1549 * @returns The encoding of a modifier. Note that it may be 0 if the modifier is
1550 * not mapped.
1551 *
1552 * @since 1.11.0
1553 * @sa `xkb_keymap_mod_get_mask()`
1554 * @memberof xkb_keymap
1555 *
1556 * [real modifiers]: @ref real-modifier-def
1557 */
1558 XKB_EXPORT xkb_mod_mask_t
1559 xkb_keymap_mod_get_mask2(struct xkb_keymap *keymap, xkb_mod_index_t idx);
1560
1561 /**
1562 * Get the number of layouts in the keymap.
1563 *
1564 * @sa `xkb_layout_index_t`
1565 * @sa `xkb_rule_names`
1566 * @sa `xkb_keymap_num_layouts_for_key()`
1567 * @memberof xkb_keymap
1568 */
1569 XKB_EXPORT xkb_layout_index_t
1570 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
1571
1572 /**
1573 * Get the name of a layout by index.
1574 *
1575 * @returns The name. If the index is invalid, or the layout does not have
1576 * a name, returns `NULL`.
1577 *
1578 * @sa xkb_layout_index_t
1579 * For notes on layout names.
1580 * @memberof xkb_keymap
1581 */
1582 XKB_EXPORT const char *
1583 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
1584
1585 /**
1586 * Get the index of a layout by name.
1587 *
1588 * @returns The index. If no layout exists with this name, returns
1589 * `::XKB_LAYOUT_INVALID`. If more than one layout in the keymap has this name,
1590 * returns the lowest index among them.
1591 *
1592 * @sa `xkb_layout_index_t` for notes on layout names.
1593 * @memberof xkb_keymap
1594 */
1595 XKB_EXPORT xkb_layout_index_t
1596 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
1597
1598 /**
1599 * Get the number of LEDs in the keymap.
1600 *
1601 * @warning The range [ 0...`xkb_keymap_num_leds()` ) includes all of the LEDs
1602 * in the keymap, but may also contain inactive LEDs. When iterating over
1603 * this range, you need the handle this case when calling functions such as
1604 * `xkb_keymap_led_get_name()` or `xkb_state::xkb_state_led_index_is_active()`.
1605 *
1606 * @sa xkb_led_index_t
1607 * @memberof xkb_keymap
1608 */
1609 XKB_EXPORT xkb_led_index_t
1610 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1611
1612 /**
1613 * Get the name of a LED by index.
1614 *
1615 * @returns The name. If the index is invalid, returns `NULL`.
1616 *
1617 * @memberof xkb_keymap
1618 */
1619 XKB_EXPORT const char *
1620 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1621
1622 /**
1623 * Get the index of a LED by name.
1624 *
1625 * @returns The index. If no LED with this name exists, returns
1626 * `::XKB_LED_INVALID`.
1627 *
1628 * @memberof xkb_keymap
1629 */
1630 XKB_EXPORT xkb_led_index_t
1631 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1632
1633 /**
1634 * Get the number of layouts for a specific key.
1635 *
1636 * This number can be different from `xkb_keymap_num_layouts()`, but is always
1637 * smaller. It is the appropriate value to use when iterating over the
1638 * layouts of a key.
1639 *
1640 * @sa xkb_layout_index_t
1641 * @memberof xkb_keymap
1642 */
1643 XKB_EXPORT xkb_layout_index_t
1644 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
1645
1646 /**
1647 * Get the number of shift levels for a specific key and layout.
1648 *
1649 * If @c layout is out of range for this key (that is, larger or equal to
1650 * the value returned by `xkb_keymap_num_layouts_for_key()`), it is brought
1651 * back into range in a manner consistent with
1652 * `xkb_state::xkb_state_key_get_layout()`.
1653 *
1654 * @sa xkb_level_index_t
1655 * @memberof xkb_keymap
1656 */
1657 XKB_EXPORT xkb_level_index_t
1658 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
1659 xkb_layout_index_t layout);
1660
1661 /**
1662 * Retrieves every possible modifier mask that produces the specified
1663 * shift level for a specific key and layout.
1664 *
1665 * This API is useful for inverse key transformation; i.e. finding out
1666 * which modifiers need to be active in order to be able to type the
1667 * keysym(s) corresponding to the specific key code, layout and level.
1668 *
1669 * @warning It returns only up to masks_size modifier masks. If the
1670 * buffer passed is too small, some of the possible modifier combinations
1671 * will not be returned.
1672 *
1673 * @param[in] keymap The keymap.
1674 * @param[in] key The keycode of the key.
1675 * @param[in] layout The layout for which to get modifiers.
1676 * @param[in] level The shift level in the layout for which to get the
1677 * modifiers. This should be smaller than:
1678 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1679 * @param[out] masks_out A buffer in which the requested masks should be
1680 * stored.
1681 * @param[out] masks_size The number of elements in the buffer pointed to by
1682 * masks_out.
1683 *
1684 * If @c layout is out of range for this key (that is, larger or equal to
1685 * the value returned by `xkb_keymap_num_layouts_for_key()`), it is brought
1686 * back into range in a manner consistent with
1687 * `xkb_state::xkb_state_key_get_layout()`.
1688 *
1689 * @returns The number of modifier masks stored in the masks_out array.
1690 * If the key is not in the keymap or if the specified shift level cannot
1691 * be reached it returns 0 and does not modify the masks_out buffer.
1692 *
1693 * @sa xkb_level_index_t
1694 * @sa xkb_mod_mask_t
1695 * @memberof xkb_keymap
1696 * @since 1.0.0
1697 */
1698 XKB_EXPORT size_t
1699 xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,
1700 xkb_keycode_t key,
1701 xkb_layout_index_t layout,
1702 xkb_level_index_t level,
1703 xkb_mod_mask_t *masks_out,
1704 size_t masks_size);
1705
1706 /**
1707 * Get the keysyms obtained from pressing a key in a given layout and
1708 * shift level.
1709 *
1710 * This function is like `xkb_state::xkb_state_key_get_syms()`, only the layout
1711 * and shift level are not derived from the keyboard state but are instead
1712 * specified explicitly.
1713 *
1714 * @param[in] keymap The keymap.
1715 * @param[in] key The keycode of the key.
1716 * @param[in] layout The layout for which to get the keysyms.
1717 * @param[in] level The shift level in the layout for which to get the
1718 * keysyms. This should be smaller than:
1719 * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1720 * @param[out] syms_out An immutable array of keysyms corresponding to the
1721 * key in the given layout and shift level.
1722 *
1723 * If @c layout is out of range for this key (that is, larger or equal to
1724 * the value returned by `xkb_keymap_num_layouts_for_key()`), it is brought
1725 * back into range in a manner consistent with
1726 * `xkb_state::xkb_state_key_get_layout()`.
1727 *
1728 * @returns The number of keysyms in the syms_out array. If no keysyms
1729 * are produced by the key in the given layout and shift level, returns 0
1730 * and sets @p syms_out to `NULL`.
1731 *
1732 * @sa `xkb_state::xkb_state_key_get_syms()`
1733 * @memberof xkb_keymap
1734 */
1735 XKB_EXPORT int
1736 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1737 xkb_keycode_t key,
1738 xkb_layout_index_t layout,
1739 xkb_level_index_t level,
1740 const xkb_keysym_t **syms_out);
1741
1742 /**
1743 * Determine whether a key should repeat or not.
1744 *
1745 * A keymap may specify different repeat behaviors for different keys.
1746 * Most keys should generally exhibit repeat behavior; for example, holding
1747 * the `a` key down in a text editor should normally insert a single ‘a’
1748 * character every few milliseconds, until the key is released. However,
1749 * there are keys which should not or do not need to be repeated. For
1750 * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1751 * is not generally useful or desired.
1752 *
1753 * @returns 1 if the key should repeat, 0 otherwise.
1754 *
1755 * @memberof xkb_keymap
1756 */
1757 XKB_EXPORT int
1758 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1759
1760 /** @} */
1761
1762 /**
1763 * @defgroup state Keyboard State
1764 * Creating, destroying and manipulating keyboard state objects.
1765 *
1766 * @{
1767 */
1768
1769 /**
1770 * Create a new keyboard state object.
1771 *
1772 * @param keymap The keymap which the state will use.
1773 *
1774 * @returns A new keyboard state object, or `NULL` on failure.
1775 *
1776 * @memberof xkb_state
1777 */
1778 XKB_EXPORT struct xkb_state *
1779 xkb_state_new(struct xkb_keymap *keymap);
1780
1781 /**
1782 * Take a new reference on a keyboard state object.
1783 *
1784 * @returns The passed in object.
1785 *
1786 * @memberof xkb_state
1787 */
1788 XKB_EXPORT struct xkb_state *
1789 xkb_state_ref(struct xkb_state *state);
1790
1791 /**
1792 * Release a reference on a keyboard state object, and possibly free it.
1793 *
1794 * @param state The state. If it is `NULL`, this function does nothing.
1795 *
1796 * @memberof xkb_state
1797 */
1798 XKB_EXPORT void
1799 xkb_state_unref(struct xkb_state *state);
1800
1801 /**
1802 * Get the keymap which a keyboard state object is using.
1803 *
1804 * @returns The keymap which was passed to `xkb_state_new()` when creating
1805 * this state object.
1806 *
1807 * This function does not take a new reference on the keymap; you must
1808 * explicitly reference it yourself if you plan to use it beyond the
1809 * lifetime of the state.
1810 *
1811 * @memberof xkb_state
1812 */
1813 XKB_EXPORT struct xkb_keymap *
1814 xkb_state_get_keymap(struct xkb_state *state);
1815
1816 /**
1817 * @page server-client-state Server State and Client State
1818 * @parblock
1819 *
1820 * The xkb_state API is used by two distinct actors in most window-system
1821 * architectures:
1822 *
1823 * 1. A *server* - for example, a Wayland compositor, an X11 server, an evdev
1824 * listener.
1825 *
1826 * Servers maintain the XKB state for a device according to input events from
1827 * the device, such as key presses and releases, and out-of-band events from
1828 * the user, like UI layout switchers.
1829 *
1830 * 2. A *client* - for example, a Wayland client, an X11 client.
1831 *
1832 * Clients do not listen to input from the device; instead, whenever the
1833 * server state changes, the server serializes the state and notifies the
1834 * clients that the state has changed; the clients then update the state
1835 * from the serialization.
1836 *
1837 * Some entry points in the xkb_state API are only meant for servers and some
1838 * are only meant for clients, and the two should generally not be mixed.
1839 *
1840 * @endparblock
1841 */
1842
1843 /** Specifies the direction of the key (press / release). */
1844 enum xkb_key_direction {
1845 XKB_KEY_UP, /**< The key was released. */
1846 XKB_KEY_DOWN /**< The key was pressed. */
1847 };
1848
1849 /**
1850 * Modifier and layout types for state objects. This enum is bitmaskable,
1851 * e.g. (`::XKB_STATE_MODS_DEPRESSED` | `::XKB_STATE_MODS_LATCHED`) is valid to
1852 * exclude locked modifiers.
1853 *
1854 * In XKB, the `DEPRESSED` components are also known as *base*.
1855 */
1856 enum xkb_state_component {
1857 /** Depressed modifiers, i.e. a key is physically holding them. */
1858 XKB_STATE_MODS_DEPRESSED = (1 << 0),
1859 /** Latched modifiers, i.e. will be unset after the next non-modifier
1860 * key press. */
1861 XKB_STATE_MODS_LATCHED = (1 << 1),
1862 /** Locked modifiers, i.e. will be unset after the key provoking the
1863 * lock has been pressed again. */
1864 XKB_STATE_MODS_LOCKED = (1 << 2),
1865 /** Effective modifiers, i.e. currently active and affect key
1866 * processing (derived from the other state components).
1867 * Use this unless you explicitly care how the state came about. */
1868 XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1869 /** Depressed layout, i.e. a key is physically holding it. */
1870 XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1871 /** Latched layout, i.e. will be unset after the next non-modifier
1872 * key press. */
1873 XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1874 /** Locked layout, i.e. will be unset after the key provoking the lock
1875 * has been pressed again. */
1876 XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1877 /** Effective layout, i.e. currently active and affects key processing
1878 * (derived from the other state components).
1879 * Use this unless you explicitly care how the state came about. */
1880 XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1881 /** LEDs (derived from the other state components). */
1882 XKB_STATE_LEDS = (1 << 8)
1883 };
1884
1885 /**
1886 * Update the keyboard state to reflect a given key being pressed or
1887 * released.
1888 *
1889 * This entry point is intended for *server* applications and should not be used
1890 * by *client* applications; see @ref server-client-state for details.
1891 *
1892 * A series of calls to this function should be consistent; that is, a call
1893 * with `::XKB_KEY_DOWN` for a key should be matched by an `::XKB_KEY_UP`; if a
1894 * key is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1895 * to missed input events), situations like “stuck modifiers” may occur.
1896 *
1897 * This function is often used in conjunction with the function
1898 * `xkb_state_key_get_syms()` (or `xkb_state_key_get_one_sym()`), for example,
1899 * when handling a key event. In this case, you should prefer to get the
1900 * keysyms *before* updating the key, such that the keysyms reported for
1901 * the key event are not affected by the event itself. This is the
1902 * conventional behavior.
1903 *
1904 * @returns A mask of state components that have changed as a result of
1905 * the update. If nothing in the state has changed, returns 0.
1906 *
1907 * @memberof xkb_state
1908 *
1909 * @sa `xkb_state_update_mask()`
1910 */
1911 XKB_EXPORT enum xkb_state_component
1912 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1913 enum xkb_key_direction direction);
1914
1915 /**
1916 * Update the keyboard state to change the latched and locked state of
1917 * the modifiers and layout.
1918 *
1919 * This entry point is intended for *server* applications and should not be used
1920 * by *client* applications; see @ref server-client-state for details.
1921 *
1922 * Use this function to update the latched and locked state according to
1923 * “out of band” (non-device) inputs, such as UI layout switchers.
1924 *
1925 * @par Layout out of range
1926 * @parblock
1927 *
1928 * If the effective layout, after taking into account the depressed, latched and
1929 * locked layout, is out of range (negative or greater than the maximum layout),
1930 * it is brought into range. Currently, the layout is wrapped using integer
1931 * modulus (with negative values wrapping from the end). The wrapping behavior
1932 * may be made configurable in the future.
1933 *
1934 * @endparblock
1935 *
1936 * @param state The keyboard state object.
1937 * @param affect_latched_mods
1938 * @param latched_mods
1939 * Modifiers to set as latched or unlatched. Only modifiers in
1940 * @p affect_latched_mods are considered.
1941 * @param affect_latched_layout
1942 * @param latched_layout
1943 * Layout to latch. Only considered if @p affect_latched_layout is true.
1944 * Maybe be out of range (including negative) -- see note above.
1945 * @param affect_locked_mods
1946 * @param locked_mods
1947 * Modifiers to set as locked or unlocked. Only modifiers in
1948 * @p affect_locked_mods are considered.
1949 * @param affect_locked_layout
1950 * @param locked_layout
1951 * Layout to lock. Only considered if @p affect_locked_layout is true.
1952 * Maybe be out of range (including negative) -- see note above.
1953 *
1954 * @returns A mask of state components that have changed as a result of
1955 * the update. If nothing in the state has changed, returns 0.
1956 *
1957 * @memberof xkb_state
1958 *
1959 * @sa xkb_state_update_mask()
1960 */
1961 XKB_EXPORT enum xkb_state_component
1962 xkb_state_update_latched_locked(struct xkb_state *state,
1963 xkb_mod_mask_t affect_latched_mods,
1964 xkb_mod_mask_t latched_mods,
1965 bool affect_latched_layout,
1966 int32_t latched_layout,
1967 xkb_mod_mask_t affect_locked_mods,
1968 xkb_mod_mask_t locked_mods,
1969 bool affect_locked_layout,
1970 int32_t locked_layout);
1971
1972 /**
1973 * Update a keyboard state from a set of explicit masks.
1974 *
1975 * This entry point is intended for *client* applications; see @ref
1976 * server-client-state for details. *Server* applications should use
1977 * `xkb_state_update_key()` instead.
1978 *
1979 * All parameters must always be passed, or the resulting state may be
1980 * incoherent.
1981 *
1982 * @warning The serialization is lossy and will not survive round trips; it must
1983 * only be used to feed client state objects, and must not be used to update the
1984 * server state.
1985 *
1986 * @returns A mask of state components that have changed as a result of
1987 * the update. If nothing in the state has changed, returns 0.
1988 *
1989 * @memberof xkb_state
1990 *
1991 * @sa `xkb_state_component`
1992 * @sa `xkb_state_update_key()`
1993 */
1994 XKB_EXPORT enum xkb_state_component
1995 xkb_state_update_mask(struct xkb_state *state,
1996 xkb_mod_mask_t depressed_mods,
1997 xkb_mod_mask_t latched_mods,
1998 xkb_mod_mask_t locked_mods,
1999 xkb_layout_index_t depressed_layout,
2000 xkb_layout_index_t latched_layout,
2001 xkb_layout_index_t locked_layout);
2002
2003 /**
2004 * Get the keysyms obtained from pressing a particular key in a given
2005 * keyboard state.
2006 *
2007 * Get the keysyms for a key according to the current active layout,
2008 * modifiers and shift level for the key, as determined by a keyboard
2009 * state.
2010 *
2011 * @param[in] state The keyboard state object.
2012 * @param[in] key The keycode of the key.
2013 * @param[out] syms_out An immutable array of keysyms corresponding the
2014 * key in the given keyboard state.
2015 *
2016 * As an extension to XKB, this function can return more than one keysym.
2017 * If you do not want to handle this case, you can use
2018 * `xkb_state_key_get_one_sym()` for a simpler interface.
2019 *
2020 * @returns The number of keysyms in the syms_out array. If no keysyms
2021 * are produced by the key in the given keyboard state, returns 0 and sets
2022 * syms_out to `NULL`.
2023 *
2024 * This function performs Capitalization @ref keysym-transformations.
2025 *
2026 * @memberof xkb_state
2027 *
2028 * @since 1.9.0 This function now performs @ref keysym-transformations.
2029 */
2030 XKB_EXPORT int
2031 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
2032 const xkb_keysym_t **syms_out);
2033
2034 /**
2035 * Get the Unicode/UTF-8 string obtained from pressing a particular key
2036 * in a given keyboard state.
2037 *
2038 * @param[in] state The keyboard state object.
2039 * @param[in] key The keycode of the key.
2040 * @param[out] buffer A buffer to write the string into.
2041 * @param[in] size Size of the buffer.
2042 *
2043 * @warning If the buffer passed is too small, the string is truncated
2044 * (though still `NULL`-terminated).
2045 *
2046 * @returns The number of bytes required for the string, excluding the
2047 * `NULL` byte. If there is nothing to write, returns 0.
2048 *
2049 * You may check if truncation has occurred by comparing the return value
2050 * with the size of @p buffer, similarly to the `snprintf(3)` function.
2051 * You may safely pass `NULL` and 0 to @p buffer and @p size to find the
2052 * required size (without the `NULL`-byte).
2053 *
2054 * This function performs Capitalization and Control @ref
2055 * keysym-transformations.
2056 *
2057 * @memberof xkb_state
2058 * @since 0.4.1
2059 */
2060 XKB_EXPORT int
2061 xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
2062 char *buffer, size_t size);
2063
2064 /**
2065 * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
2066 * key in a a given keyboard state.
2067 *
2068 * @returns The UTF-32 representation for the key, if it consists of only
2069 * a single codepoint. Otherwise, returns 0.
2070 *
2071 * This function performs Capitalization and Control @ref
2072 * keysym-transformations.
2073 *
2074 * @memberof xkb_state
2075 * @since 0.4.1
2076 */
2077 XKB_EXPORT uint32_t
2078 xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
2079
2080 /**
2081 * Get the single keysym obtained from pressing a particular key in a
2082 * given keyboard state.
2083 *
2084 * This function is similar to `xkb_state_key_get_syms()`, but intended
2085 * for users which cannot or do not want to handle the case where
2086 * multiple keysyms are returned (in which case this function is
2087 * preferred).
2088 *
2089 * @returns The keysym. If the key does not have exactly one keysym,
2090 * returns `XKB_KEY_NoSymbol`.
2091 *
2092 * This function performs Capitalization @ref keysym-transformations.
2093 *
2094 * @sa xkb_state_key_get_syms()
2095 * @memberof xkb_state
2096 */
2097 XKB_EXPORT xkb_keysym_t
2098 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
2099
2100 /**
2101 * Get the effective layout index for a key in a given keyboard state.
2102 *
2103 * @returns The layout index for the key in the given keyboard state. If
2104 * the given keycode is invalid, or if the key is not included in any
2105 * layout at all, returns `::XKB_LAYOUT_INVALID`.
2106 *
2107 * @invariant If the returned layout is valid, the following always holds:
2108 * @code
2109 * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
2110 * @endcode
2111 *
2112 * @memberof xkb_state
2113 */
2114 XKB_EXPORT xkb_layout_index_t
2115 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
2116
2117 /**
2118 * Get the effective shift level for a key in a given keyboard state and
2119 * layout.
2120 *
2121 * @param state The keyboard state.
2122 * @param key The keycode of the key.
2123 * @param layout The layout for which to get the shift level. This must be
2124 * smaller than:
2125 * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
2126 * usually it would be:
2127 * @code xkb_state_key_get_layout(state, key) @endcode
2128 *
2129 * @return The shift level index. If the key or layout are invalid,
2130 * returns `::XKB_LEVEL_INVALID`.
2131 *
2132 * @invariant If the returned level is valid, the following always holds:
2133 * @code
2134 * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
2135 * @endcode
2136 *
2137 * @memberof xkb_state
2138 */
2139 XKB_EXPORT xkb_level_index_t
2140 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
2141 xkb_layout_index_t layout);
2142
2143 /**
2144 * Match flags for `xkb_state::xkb_state_mod_indices_are_active()` and
2145 * `xkb_state::xkb_state_mod_names_are_active()`, specifying the conditions for a
2146 * successful match. `::XKB_STATE_MATCH_NON_EXCLUSIVE` is bitmaskable with
2147 * the other modes.
2148 */
2149 enum xkb_state_match {
2150 /** Returns true if any of the modifiers are active. */
2151 XKB_STATE_MATCH_ANY = (1 << 0),
2152 /** Returns true if all of the modifiers are active. */
2153 XKB_STATE_MATCH_ALL = (1 << 1),
2154 /** Makes matching non-exclusive, i.e. will not return false if a
2155 * modifier not specified in the arguments is active. */
2156 XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
2157 };
2158
2159 /**
2160 * The counterpart to `xkb_state::xkb_state_update_mask()` for modifiers, to be
2161 * used on the server side of serialization.
2162 *
2163 * This entry point is intended for *server* applications; see @ref
2164 * server-client-state for details. *Client* applications should use the
2165 * `xkb_state_mod_*_is_active` API.
2166 *
2167 * @param state The keyboard state.
2168 * @param components A mask of the modifier state components to serialize.
2169 * State components other than `XKB_STATE_MODS_*` are ignored.
2170 * If `::XKB_STATE_MODS_EFFECTIVE` is included, all other state components are
2171 * ignored.
2172 *
2173 * @returns A `xkb_mod_mask_t` representing the given components of the
2174 * modifier state.
2175 *
2176 * @memberof xkb_state
2177 */
2178 XKB_EXPORT xkb_mod_mask_t
2179 xkb_state_serialize_mods(struct xkb_state *state,
2180 enum xkb_state_component components);
2181
2182 /**
2183 * The counterpart to `xkb_state::xkb_state_update_mask()` for layouts, to be
2184 * used on the server side of serialization.
2185 *
2186 * This entry point is intended for *server* applications; see @ref
2187 * server-client-state for details. *Client* applications should use the
2188 * xkb_state_layout_*_is_active API.
2189 *
2190 * @param state The keyboard state.
2191 * @param components A mask of the layout state components to serialize.
2192 * State components other than `XKB_STATE_LAYOUT_*` are ignored.
2193 * If `::XKB_STATE_LAYOUT_EFFECTIVE` is included, all other state components are
2194 * ignored.
2195 *
2196 * @returns A layout index representing the given components of the
2197 * layout state.
2198 *
2199 * @memberof xkb_state
2200 */
2201 XKB_EXPORT xkb_layout_index_t
2202 xkb_state_serialize_layout(struct xkb_state *state,
2203 enum xkb_state_component components);
2204
2205 /**
2206 * Test whether a modifier is active in a given keyboard state by name.
2207 *
2208 * @warning For [virtual modifiers], this function may *overmatch* in case
2209 * there are virtual modifiers with overlapping mappings to [real modifiers].
2210 *
2211 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
2212 * name does not exist in the keymap, returns -1.
2213 *
2214 * @memberof xkb_state
2215 *
2216 * @since 0.1.0: Works only with *real* modifiers
2217 * @since 1.8.0: Works also with *virtual* modifiers
2218 *
2219 * [virtual modifiers]: @ref virtual-modifier-def
2220 * [real modifiers]: @ref real-modifier-def
2221 */
2222 XKB_EXPORT int
2223 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
2224 enum xkb_state_component type);
2225
2226 /**
2227 * Test whether a set of modifiers are active in a given keyboard state by
2228 * name.
2229 *
2230 * @warning For [virtual modifiers], this function may *overmatch* in case
2231 * there are virtual modifiers with overlapping mappings to [real modifiers].
2232 *
2233 * @param state The keyboard state.
2234 * @param type The component of the state against which to match the
2235 * given modifiers.
2236 * @param match The manner by which to match the state against the
2237 * given modifiers.
2238 * @param ... The set of of modifier names to test, terminated by a NULL
2239 * argument (sentinel).
2240 *
2241 * @returns 1 if the modifiers are active, 0 if they are not. If any of
2242 * the modifier names do not exist in the keymap, returns -1.
2243 *
2244 * @memberof xkb_state
2245 *
2246 * @since 0.1.0: Works only with *real* modifiers
2247 * @since 1.8.0: Works also with *virtual* modifiers
2248 *
2249 * [virtual modifiers]: @ref virtual-modifier-def
2250 * [real modifiers]: @ref real-modifier-def
2251 */
2252 XKB_EXPORT int
2253 xkb_state_mod_names_are_active(struct xkb_state *state,
2254 enum xkb_state_component type,
2255 enum xkb_state_match match,
2256 ...);
2257
2258 /**
2259 * Test whether a modifier is active in a given keyboard state by index.
2260 *
2261 * @warning For [virtual modifiers], this function may *overmatch* in case
2262 * there are virtual modifiers with overlapping mappings to [real modifiers].
2263 *
2264 * @returns 1 if the modifier is active, 0 if it is not. If the modifier
2265 * index is invalid in the keymap, returns -1.
2266 *
2267 * @memberof xkb_state
2268 *
2269 * @since 0.1.0: Works only with *real* modifiers
2270 * @since 1.8.0: Works also with *virtual* modifiers
2271 *
2272 * [virtual modifiers]: @ref virtual-modifier-def
2273 * [real modifiers]: @ref real-modifier-def
2274 */
2275 XKB_EXPORT int
2276 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
2277 enum xkb_state_component type);
2278
2279 /**
2280 * Test whether a set of modifiers are active in a given keyboard state by
2281 * index.
2282 *
2283 * @warning For [virtual modifiers], this function may *overmatch* in case
2284 * there are virtual modifiers with overlapping mappings to [real modifiers].
2285 *
2286 * @param state The keyboard state.
2287 * @param type The component of the state against which to match the
2288 * given modifiers.
2289 * @param match The manner by which to match the state against the
2290 * given modifiers.
2291 * @param ... The set of of modifier indices to test, terminated by a
2292 * `::XKB_MOD_INVALID` argument (sentinel).
2293 *
2294 * @returns 1 if the modifiers are active, 0 if they are not. If any of
2295 * the modifier indices are invalid in the keymap, returns -1.
2296 *
2297 * @memberof xkb_state
2298 *
2299 * @since 0.1.0: Works only with *real* modifiers
2300 * @since 1.8.0: Works also with *virtual* modifiers
2301 *
2302 * [virtual modifiers]: @ref virtual-modifier-def
2303 * [real modifiers]: @ref real-modifier-def
2304 */
2305 XKB_EXPORT int
2306 xkb_state_mod_indices_are_active(struct xkb_state *state,
2307 enum xkb_state_component type,
2308 enum xkb_state_match match,
2309 ...);
2310
2311 /**
2312 * @page consumed-modifiers Consumed Modifiers
2313 * @parblock
2314 *
2315 * Some functions, like `xkb_state::xkb_state_key_get_syms()`, look at the state
2316 * of the modifiers in the keymap and derive from it the correct shift level
2317 * to use for the key. For example, in a US layout, pressing the key
2318 * labeled `<A>` while the Shift modifier is active, generates the keysym
2319 * `A`. In this case, the Shift modifier is said to be *consumed*.
2320 * However, the Num Lock modifier does not affect this translation at all,
2321 * even if it is active, so it is not consumed by this translation.
2322 *
2323 * It may be desirable for some application to not reuse consumed modifiers
2324 * for further processing, e.g. for hotkeys or keyboard shortcuts. To
2325 * understand why, consider some requirements from a standard shortcut
2326 * mechanism, and how they are implemented:
2327 *
2328 * 1. The shortcut’s modifiers must match exactly to the state. For
2329 * example, it is possible to bind separate actions to `<Alt><Tab>`
2330 * and to `<Alt><Shift><Tab>`. Further, if only `<Alt><Tab>` is
2331 * bound to an action, pressing `<Alt><Shift><Tab>` should not
2332 * trigger the shortcut.
2333 * Effectively, this means that the modifiers are compared using the
2334 * equality operator (`==`).
2335 *
2336 * 2. Only relevant modifiers are considered for the matching. For example,
2337 * Caps Lock and Num Lock should not generally affect the matching, e.g.
2338 * when matching `<Alt><Tab>` against the state, it does not matter
2339 * whether Num Lock is active or not. These relevant, or *significant*,
2340 * modifiers usually include Alt, Control, Shift, Super and similar.
2341 * Effectively, this means that non-significant modifiers are masked out,
2342 * before doing the comparison as described above.
2343 *
2344 * 3. The matching must be independent of the layout/keymap. For example,
2345 * the `<Plus>` (+) symbol is found on the first level on some layouts,
2346 * but requires holding Shift on others. If you simply bind the action
2347 * to the `<Plus>` keysym, it would work for the unshifted kind, but
2348 * not for the others, because the match against Shift would fail. If
2349 * you bind the action to `<Shift><Plus>`, only the shifted kind would
2350 * work. So what is needed is to recognize that Shift is used up in the
2351 * translation of the keysym itself, and therefore should not be included
2352 * in the matching.
2353 * Effectively, this means that consumed modifiers (Shift in this example)
2354 * are masked out as well, before doing the comparison.
2355 *
2356 * In summary, this is approximately how the matching would be performed:
2357 *
2358 * ```c
2359 * (keysym == shortcut_keysym) &&
2360 * ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
2361 * ```
2362 *
2363 * @c state_mods are the modifiers reported by
2364 * `xkb_state::xkb_state_mod_index_is_active()` and similar functions.
2365 * @c consumed_mods are the modifiers reported by
2366 * `xkb_state::xkb_state_mod_index_is_consumed()` and similar functions.
2367 * @c significant_mods are decided upon by the application/toolkit/user;
2368 * it is up to them to decide whether these are configurable or hard-coded.
2369 *
2370 * @endparblock
2371 */
2372
2373 /**
2374 * Consumed modifiers mode.
2375 *
2376 * There are several possible methods for deciding which modifiers are
2377 * consumed and which are not, each applicable for different systems or
2378 * situations. The mode selects the method to use.
2379 *
2380 * Keep in mind that in all methods, the keymap may decide to *preserve*
2381 * a modifier, meaning it is not reported as consumed even if it would
2382 * have otherwise.
2383 */
2384 enum xkb_consumed_mode {
2385 /**
2386 * This is the mode defined in the XKB specification and used by libX11.
2387 *
2388 * A modifier is consumed if and only if it *may affect* key translation.
2389 *
2390 * For example, if `Control+Alt+<Backspace>` produces some assigned keysym,
2391 * then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,
2392 * even though they are not active, since if they *were* active they would
2393 * have affected key translation.
2394 */
2395 XKB_CONSUMED_MODE_XKB,
2396 /**
2397 * This is the mode used by the GTK+ toolkit.
2398 *
2399 * The mode consists of the following two independent heuristics:
2400 *
2401 * - The currently active set of modifiers, excluding modifiers which do
2402 * not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are
2403 * considered consumed, if the keysyms produced when all of them are
2404 * active are different from the keysyms produced when no modifiers are
2405 * active.
2406 *
2407 * - A single modifier is considered consumed if the keysyms produced for
2408 * the key when it is the only active modifier are different from the
2409 * keysyms produced when no modifiers are active.
2410 */
2411 XKB_CONSUMED_MODE_GTK
2412 };
2413
2414 /**
2415 * Get the mask of modifiers consumed by translating a given key.
2416 *
2417 * @param state The keyboard state.
2418 * @param key The keycode of the key.
2419 * @param mode The consumed modifiers mode to use; see enum description.
2420 *
2421 * @returns a mask of the consumed [real modifiers] modifiers.
2422 *
2423 * @memberof xkb_state
2424 * @since 0.7.0
2425 *
2426 * [real modifiers]: @ref real-modifier-def
2427 */
2428 XKB_EXPORT xkb_mod_mask_t
2429 xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,
2430 enum xkb_consumed_mode mode);
2431
2432 /**
2433 * Same as `xkb_state_key_get_consumed_mods2()` with mode `::XKB_CONSUMED_MODE_XKB`.
2434 *
2435 * @memberof xkb_state
2436 * @since 0.4.1
2437 */
2438 XKB_EXPORT xkb_mod_mask_t
2439 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
2440
2441 /**
2442 * Test whether a modifier is consumed by keyboard state translation for
2443 * a key.
2444 *
2445 * @warning For [virtual modifiers], this function may *overmatch* in case
2446 * there are virtual modifiers with overlapping mappings to [real modifiers].
2447 *
2448 * @param state The keyboard state.
2449 * @param key The keycode of the key.
2450 * @param idx The index of the modifier to check.
2451 * @param mode The consumed modifiers mode to use; see enum description.
2452 *
2453 * @returns 1 if the modifier is consumed, 0 if it is not. If the modifier
2454 * index is not valid in the keymap, returns -1.
2455 *
2456 * @sa xkb_state_mod_mask_remove_consumed()
2457 * @sa xkb_state_key_get_consumed_mods()
2458 * @memberof xkb_state
2459 * @since 0.7.0: Works only with *real* modifiers
2460 * @since 1.8.0: Works also with *virtual* modifiers
2461 *
2462 * [virtual modifiers]: @ref virtual-modifier-def
2463 * [real modifiers]: @ref real-modifier-def
2464 */
2465 XKB_EXPORT int
2466 xkb_state_mod_index_is_consumed2(struct xkb_state *state,
2467 xkb_keycode_t key,
2468 xkb_mod_index_t idx,
2469 enum xkb_consumed_mode mode);
2470
2471 /**
2472 * Same as `xkb_state_mod_index_is_consumed2()` with mode `::XKB_CONSUMED_MOD_XKB`.
2473 *
2474 * @warning For [virtual modifiers], this function may *overmatch* in case
2475 * there are virtual modifiers with overlapping mappings to [real modifiers].
2476 *
2477 * @memberof xkb_state
2478 * @since 0.4.1: Works only with *real* modifiers
2479 * @since 1.8.0: Works also with *virtual* modifiers
2480 *
2481 * [virtual modifiers]: @ref virtual-modifier-def
2482 * [real modifiers]: @ref real-modifier-def
2483 */
2484 XKB_EXPORT int
2485 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
2486 xkb_mod_index_t idx);
2487
2488 /**
2489 * Remove consumed modifiers from a modifier mask for a key.
2490 *
2491 * @deprecated Use `xkb_state_key_get_consumed_mods2()` instead.
2492 *
2493 * Takes the given modifier mask, and removes all modifiers which are
2494 * consumed for that particular key (as in `xkb_state_mod_index_is_consumed()`).
2495 *
2496 * @returns a mask of [real modifiers] modifiers.
2497 *
2498 * @sa xkb_state_mod_index_is_consumed()
2499 * @memberof xkb_state
2500 * @since 0.5.0: Works only with *real* modifiers
2501 * @since 1.8.0: Works also with *virtual* modifiers
2502 *
2503 * [real modifiers]: @ref real-modifier-def
2504 */
2505 XKB_EXPORT xkb_mod_mask_t
2506 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
2507 xkb_mod_mask_t mask);
2508
2509 /**
2510 * Test whether a layout is active in a given keyboard state by name.
2511 *
2512 * @returns 1 if the layout is active, 0 if it is not. If no layout with
2513 * this name exists in the keymap, return -1.
2514 *
2515 * If multiple layouts in the keymap have this name, the one with the lowest
2516 * index is tested.
2517 *
2518 * @sa xkb_layout_index_t
2519 * @memberof xkb_state
2520 */
2521 XKB_EXPORT int
2522 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
2523 enum xkb_state_component type);
2524
2525 /**
2526 * Test whether a layout is active in a given keyboard state by index.
2527 *
2528 * @returns 1 if the layout is active, 0 if it is not. If the layout index
2529 * is not valid in the keymap, returns -1.
2530 *
2531 * @sa xkb_layout_index_t
2532 * @memberof xkb_state
2533 */
2534 XKB_EXPORT int
2535 xkb_state_layout_index_is_active(struct xkb_state *state,
2536 xkb_layout_index_t idx,
2537 enum xkb_state_component type);
2538
2539 /**
2540 * Test whether a LED is active in a given keyboard state by name.
2541 *
2542 * @returns 1 if the LED is active, 0 if it not. If no LED with this name
2543 * exists in the keymap, returns -1.
2544 *
2545 * @sa xkb_led_index_t
2546 * @memberof xkb_state
2547 */
2548 XKB_EXPORT int
2549 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
2550
2551 /**
2552 * Test whether a LED is active in a given keyboard state by index.
2553 *
2554 * @returns 1 if the LED is active, 0 if it not. If the LED index is not
2555 * valid in the keymap, returns -1.
2556 *
2557 * @sa xkb_led_index_t
2558 * @memberof xkb_state
2559 */
2560 XKB_EXPORT int
2561 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
2562
2563 /** @} */
2564
2565 /* Leave this include last, so it can pick up our types, etc. */
2566 #include <xkbcommon/xkbcommon-compat.h>
2567
2568 #ifdef __cplusplus
2569 } /* extern "C" */
2570 #endif
2571
2572 #endif /* _XKBCOMMON_H_ */