Add XKB_KEYSYM_MIN and XKB_KEYSYM_MAX
[platform/upstream/libxkbcommon.git] / include / xkbcommon / xkbcommon.h
1 /*
2  * Copyright 1985, 1987, 1990, 1998  The Open Group
3  * Copyright 2008  Dan Nicholson
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Except as contained in this notice, the names of the authors or their
23  * institutions shall not be used in advertising or otherwise to promote the
24  * sale, use or other dealings in this Software without prior written
25  * authorization from the authors.
26  */
27
28 /************************************************************
29  * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
30  *
31  * Permission to use, copy, modify, and distribute this
32  * software and its documentation for any purpose and without
33  * fee is hereby granted, provided that the above copyright
34  * notice appear in all copies and that both that copyright
35  * notice and this permission notice appear in supporting
36  * documentation, and that the name of Silicon Graphics not be
37  * used in advertising or publicity pertaining to distribution
38  * of the software without specific prior written permission.
39  * Silicon Graphics makes no representation about the suitability
40  * of this software for any purpose. It is provided "as is"
41  * without any express or implied warranty.
42  *
43  * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
44  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
46  * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
47  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
48  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
49  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
50  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
51  *
52  ********************************************************/
53
54 /*
55  * Copyright © 2009-2012 Daniel Stone
56  * Copyright © 2012 Intel Corporation
57  * Copyright © 2012 Ran Benita
58  *
59  * Permission is hereby granted, free of charge, to any person obtaining a
60  * copy of this software and associated documentation files (the "Software"),
61  * to deal in the Software without restriction, including without limitation
62  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
63  * and/or sell copies of the Software, and to permit persons to whom the
64  * Software is furnished to do so, subject to the following conditions:
65  *
66  * The above copyright notice and this permission notice (including the next
67  * paragraph) shall be included in all copies or substantial portions of the
68  * Software.
69  *
70  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
71  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
72  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
73  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
74  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
75  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
76  * DEALINGS IN THE SOFTWARE.
77  *
78  * Author: Daniel Stone <daniel@fooishbar.org>
79  */
80
81 #ifndef _XKBCOMMON_H_
82 #define _XKBCOMMON_H_
83
84 #include <stdint.h>
85 #include <stdio.h>
86 #include <stdarg.h>
87
88 #include <xkbcommon/xkbcommon-names.h>
89 #include <xkbcommon/xkbcommon-keysyms.h>
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 /**
96  * @file
97  * Main libxkbcommon API.
98  */
99
100 /**
101  * @struct xkb_context
102  * Opaque top level library context object.
103  *
104  * The context contains various general library data and state, like
105  * logging level and include paths.
106  *
107  * Objects are created in a specific context, and multiple contexts may
108  * coexist simultaneously.  Objects from different contexts are completely
109  * separated and do not share any memory or state.
110  */
111 struct xkb_context;
112
113 /**
114  * @struct xkb_keymap
115  * Opaque compiled keymap object.
116  *
117  * The keymap object holds all of the static keyboard information obtained
118  * from compiling XKB files.
119  *
120  * A keymap is immutable after it is created (besides reference counts, etc.);
121  * if you need to change it, you must create a new one.
122  */
123 struct xkb_keymap;
124
125 /**
126  * @struct xkb_state
127  * Opaque keyboard state object.
128  *
129  * State objects contain the active state of a keyboard (or keyboards), such
130  * as the currently effective layout and the active modifiers.  It acts as a
131  * simple state machine, wherein key presses and releases are the input, and
132  * key symbols (keysyms) are the output.
133  */
134 struct xkb_state;
135
136 /**
137  * A number used to represent a physical key on a keyboard.
138  *
139  * A standard PC-compatible keyboard might have 102 keys.  An appropriate
140  * keymap would assign each of them a keycode, by which the user should
141  * refer to the key throughout the library.
142  *
143  * Historically, the X11 protocol, and consequentially the XKB protocol,
144  * assign only 8 bits for keycodes.  This limits the number of different
145  * keys that can be used simultaneously in a single keymap to 256
146  * (disregarding other limitations).  This library does not share this limit;
147  * keycodes beyond 255 ('extended keycodes') are not treated specially.
148  * Keymaps and applications which are compatible with X11 should not use
149  * these keycodes.
150  *
151  * The values of specific keycodes are determined by the keymap and the
152  * underlying input system.  For example, with an X11-compatible keymap
153  * and Linux evdev scan codes (see linux/input.h), a fixed offset is used:
154  *
155  * The keymap defines a canonical name for each key, plus possible aliases.
156  * Historically, the XKB protocol restricts these names to at most 4 (ASCII)
157  * characters, but this library does not share this limit.
158  *
159  * @code
160  * xkb_keycode_t keycode_A = KEY_A + 8;
161  * @endcode
162  *
163  * @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()
164  */
165 typedef uint32_t xkb_keycode_t;
166
167 /**
168  * A number used to represent the symbols generated from a key on a keyboard.
169  *
170  * A key, represented by a keycode, may generate different symbols according
171  * to keyboard state.  For example, on a QWERTY keyboard, pressing the key
172  * labled \<A\> generates the symbol 'a'.  If the Shift key is held, it
173  * generates the symbol 'A'.  If a different layout is used, say Greek,
174  * it generates the symbol 'α'.  And so on.
175  *
176  * Each such symbol is represented by a keysym.  Note that keysyms are
177  * somewhat more general, in that they can also represent some "function",
178  * such as "Left" or "Right" for the arrow keys.  For more information,
179  * see:
180  * https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding
181  *
182  * Specifically named keysyms can be found in the
183  * xkbcommon/xkbcommon-keysyms.h header file.  Their name does not include
184  * the XKB_KEY_ prefix.
185  *
186  * Besides those, any Unicode/ISO 10646 character in the range U0100 to
187  * U10FFFF can be represented by a keysym value in the range 0x01000100 to
188  * 0x0110FFFF.  The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".
189  *
190  * The name of other unnamed keysyms is the hexadecimal representation of
191  * their value, e.g. "0xabcd1234".
192  *
193  * Keysym names are case-sensitive.
194  */
195 typedef uint32_t xkb_keysym_t;
196
197 /**
198  * Index of a keyboard layout.
199  *
200  * The layout index is a state component which detemines which <em>keyboard
201  * layout</em> is active.  These may be different alphabets, different key
202  * arrangements, etc.
203  *
204  * Layout indices are consecutive.  The first layout has index 0.
205  *
206  * Each layout is not required to have a name, and the names are not
207  * guaranteed to be unique (though they are usually provided and unique).
208  * Therefore, it is not safe to use the name as a unique identifier for a
209  * layout.  Layout names are case-sensitive.
210  *
211  * Layout names are specified in the layout's definition, for example
212  * "English (US)".  These are different from the (conventionally) short names
213  * which are used to locate the layout, for example "us" or "us(intl)".  These
214  * names are not present in a compiled keymap.
215  *
216  * If the user selects layouts from a list generated from the XKB registry
217  * (using libxkbregistry or directly), and this metadata is needed later on, it
218  * is recommended to store it along with the keymap.
219  *
220  * Layouts are also called "groups" by XKB.
221  *
222  * @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()
223  */
224 typedef uint32_t xkb_layout_index_t;
225 /** A mask of layout indices. */
226 typedef uint32_t xkb_layout_mask_t;
227
228 /**
229  * Index of a shift level.
230  *
231  * Any key, in any layout, can have several <em>shift levels</em>.  Each
232  * shift level can assign different keysyms to the key.  The shift level
233  * to use is chosen according to the current keyboard state; for example,
234  * if no keys are pressed, the first level may be used; if the Left Shift
235  * key is pressed, the second; if Num Lock is pressed, the third; and
236  * many such combinations are possible (see xkb_mod_index_t).
237  *
238  * Level indices are consecutive.  The first level has index 0.
239  */
240 typedef uint32_t xkb_level_index_t;
241
242 /**
243  * Index of a modifier.
244  *
245  * A @e modifier is a state component which changes the way keys are
246  * interpreted.  A keymap defines a set of modifiers, such as Alt, Shift,
247  * Num Lock or Meta, and specifies which keys may @e activate which
248  * modifiers (in a many-to-many relationship, i.e. a key can activate
249  * several modifiers, and a modifier may be activated by several keys.
250  * Different keymaps do this differently).
251  *
252  * When retrieving the keysyms for a key, the active modifier set is
253  * consulted; this detemines the correct shift level to use within the
254  * currently active layout (see xkb_level_index_t).
255  *
256  * Modifier indices are consecutive.  The first modifier has index 0.
257  *
258  * Each modifier must have a name, and the names are unique.  Therefore, it
259  * is safe to use the name as a unique identifier for a modifier.  The names
260  * of some common modifiers are provided in the xkbcommon/xkbcommon-names.h
261  * header file.  Modifier names are case-sensitive.
262  *
263  * @sa xkb_keymap_num_mods()
264  */
265 typedef uint32_t xkb_mod_index_t;
266 /** A mask of modifier indices. */
267 typedef uint32_t xkb_mod_mask_t;
268
269 /**
270  * Index of a keyboard LED.
271  *
272  * LEDs are logical objects which may be @e active or @e inactive.  They
273  * typically correspond to the lights on the keyboard. Their state is
274  * determined by the current keyboard state.
275  *
276  * LED indices are non-consecutive.  The first LED has index 0.
277  *
278  * Each LED must have a name, and the names are unique. Therefore,
279  * it is safe to use the name as a unique identifier for a LED.  The names
280  * of some common LEDs are provided in the xkbcommon/xkbcommon-names.h
281  * header file.  LED names are case-sensitive.
282  *
283  * @warning A given keymap may specify an exact index for a given LED.
284  * Therefore, LED indexing is not necessarily sequential, as opposed to
285  * modifiers and layouts.  This means that when iterating over the LEDs
286  * in a keymap using e.g. xkb_keymap_num_leds(), some indices might be
287  * invalid.  Given such an index, functions like xkb_keymap_led_get_name()
288  * will return NULL, and xkb_state_led_index_is_active() will return -1.
289  *
290  * LEDs are also called "indicators" by XKB.
291  *
292  * @sa xkb_keymap_num_leds()
293  */
294 typedef uint32_t xkb_led_index_t;
295 /** A mask of LED indices. */
296 typedef uint32_t xkb_led_mask_t;
297
298 #define XKB_KEYCODE_INVALID (0xffffffff)
299 #define XKB_LAYOUT_INVALID  (0xffffffff)
300 #define XKB_LEVEL_INVALID   (0xffffffff)
301 #define XKB_MOD_INVALID     (0xffffffff)
302 #define XKB_LED_INVALID     (0xffffffff)
303
304 #define XKB_KEYCODE_MAX     (0xffffffff - 1)
305
306 /**
307  * Maximum keysym value
308  *
309  * @since 1.6.0
310  * @sa xkb_keysym_t
311  * @ingroup keysyms
312  */
313 #define XKB_KEYSYM_MAX      0x1fffffff
314
315 /**
316  * Test whether a value is a valid extended keycode.
317  * @sa xkb_keycode_t
318  **/
319 #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
320
321 /**
322  * Test whether a value is a valid X11 keycode.
323  * @sa xkb_keycode_t
324  */
325 #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
326
327 /**
328  * Names to compile a keymap with, also known as RMLVO.
329  *
330  * The names are the common configuration values by which a user picks
331  * a keymap.
332  *
333  * If the entire struct is NULL, then each field is taken to be NULL.
334  * You should prefer passing NULL instead of choosing your own defaults.
335  */
336 struct xkb_rule_names {
337     /**
338      * The rules file to use. The rules file describes how to interpret
339      * the values of the model, layout, variant and options fields.
340      *
341      * If NULL or the empty string "", a default value is used.
342      * If the XKB_DEFAULT_RULES environment variable is set, it is used
343      * as the default.  Otherwise the system default is used.
344      */
345     const char *rules;
346     /**
347      * The keyboard model by which to interpret keycodes and LEDs.
348      *
349      * If NULL or the empty string "", a default value is used.
350      * If the XKB_DEFAULT_MODEL environment variable is set, it is used
351      * as the default.  Otherwise the system default is used.
352      */
353     const char *model;
354     /**
355      * A comma separated list of layouts (languages) to include in the
356      * keymap.
357      *
358      * If NULL or the empty string "", a default value is used.
359      * If the XKB_DEFAULT_LAYOUT environment variable is set, it is used
360      * as the default.  Otherwise the system default is used.
361      */
362     const char *layout;
363     /**
364      * A comma separated list of variants, one per layout, which may
365      * modify or augment the respective layout in various ways.
366      *
367      * Generally, should either be empty or have the same number of values
368      * as the number of layouts. You may use empty values as in "intl,,neo".
369      *
370      * If NULL or the empty string "", and a default value is also used
371      * for the layout, a default value is used.  Otherwise no variant is
372      * used.
373      * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
374      * as the default.  Otherwise the system default is used.
375      */
376     const char *variant;
377     /**
378      * A comma separated list of options, through which the user specifies
379      * non-layout related preferences, like which key combinations are used
380      * for switching layouts, or which key is the Compose key.
381      *
382      * If NULL, a default value is used.  If the empty string "", no
383      * options are used.
384      * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
385      * as the default.  Otherwise the system default is used.
386      */
387     const char *options;
388 };
389
390 /**
391  * @defgroup keysyms Keysyms
392  * Utility functions related to keysyms.
393  *
394  * @{
395  */
396
397 /**
398  * @page keysym-transformations Keysym Transformations
399  *
400  * Keysym translation is subject to several "keysym transformations",
401  * as described in the XKB specification.  These are:
402  *
403  * - Capitalization transformation.  If the Caps Lock modifier is
404  *   active and was not consumed by the translation process, a single
405  *   keysym is transformed to its upper-case form (if applicable).
406  *   Similarly, the UTF-8/UTF-32 string produced is capitalized.
407  *
408  *   This is described in:
409  *   https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
410  *
411  * - Control transformation.  If the Control modifier is active and
412  *   was not consumed by the translation process, the string produced
413  *   is transformed to its matching ASCII control character (if
414  *   applicable).  Keysyms are not affected.
415  *
416  *   This is described in:
417  *   https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
418  *
419  * Each relevant function discusses which transformations it performs.
420  *
421  * These transformations are not applicable when a key produces multiple
422  * keysyms.
423  */
424
425
426 /**
427  * Get the name of a keysym.
428  *
429  * For a description of how keysyms are named, see @ref xkb_keysym_t.
430  *
431  * @param[in]  keysym The keysym.
432  * @param[out] buffer A string buffer to write the name into.
433  * @param[in]  size   Size of the buffer.
434  *
435  * @warning If the buffer passed is too small, the string is truncated
436  * (though still NUL-terminated); a size of at least 64 bytes is recommended.
437  *
438  * @returns The number of bytes in the name, excluding the NUL byte. If
439  * the keysym is invalid, returns -1.
440  *
441  * You may check if truncation has occurred by comparing the return value
442  * with the length of buffer, similarly to the snprintf(3) function.
443  *
444  * @sa xkb_keysym_t
445  */
446 int
447 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
448
449 /** Flags for xkb_keysym_from_name(). */
450 enum xkb_keysym_flags {
451     /** Do not apply any flags. */
452     XKB_KEYSYM_NO_FLAGS = 0,
453     /** Find keysym by case-insensitive search. */
454     XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
455 };
456
457 /**
458  * Get a keysym from its name.
459  *
460  * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
461  * this function will accept any name returned by that function.
462  * @param flags A set of flags controlling how the search is done. If
463  * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
464  *
465  * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
466  * differ only by case, then the lower-case keysym is returned.  For
467  * instance, for KEY_a and KEY_A, this function would return KEY_a for the
468  * case-insensitive search.  If this functionality is needed, it is
469  * recommended to first call this function without this flag; and if that
470  * fails, only then to try with this flag, while possibly warning the user
471  * he had misspelled the name, and might get wrong results.
472  *
473  * Case folding is done according to the C locale; the current locale is not
474  * consulted.
475  *
476  * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
477  *
478  * @sa xkb_keysym_t
479  */
480 xkb_keysym_t
481 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
482
483 /**
484  * Get the Unicode/UTF-8 representation of a keysym.
485  *
486  * @param[in]  keysym The keysym.
487  * @param[out] buffer A buffer to write the UTF-8 string into.
488  * @param[in]  size   The size of buffer.  Must be at least 7.
489  *
490  * @returns The number of bytes written to the buffer (including the
491  * terminating byte).  If the keysym does not have a Unicode
492  * representation, returns 0.  If the buffer is too small, returns -1.
493  *
494  * This function does not perform any @ref keysym-transformations.
495  * Therefore, prefer to use xkb_state_key_get_utf8() if possible.
496  *
497  * @sa xkb_state_key_get_utf8()
498  */
499 int
500 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
501
502 /**
503  * Get the Unicode/UTF-32 representation of a keysym.
504  *
505  * @returns The Unicode/UTF-32 representation of keysym, which is also
506  * compatible with UCS-4.  If the keysym does not have a Unicode
507  * representation, returns 0.
508  *
509  * This function does not perform any @ref keysym-transformations.
510  * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
511  *
512  * @sa xkb_state_key_get_utf32()
513  */
514 uint32_t
515 xkb_keysym_to_utf32(xkb_keysym_t keysym);
516
517 /**
518  * Get the keysym corresponding to a Unicode/UTF-32 codepoint.
519  *
520  * @returns The keysym corresponding to the specified Unicode
521  * codepoint, or XKB_KEY_NoSymbol if there is none.
522  *
523  * This function is the inverse of @ref xkb_keysym_to_utf32. In cases
524  * where a single codepoint corresponds to multiple keysyms, returns
525  * the keysym with the lowest value.
526  *
527  * Unicode codepoints which do not have a special (legacy) keysym
528  * encoding use a direct encoding scheme. These keysyms don't usually
529  * have an associated keysym constant (XKB_KEY_*).
530  *
531  * For noncharacter Unicode codepoints and codepoints outside of the
532  * defined Unicode planes this function returns XKB_KEY_NoSymbol.
533  *
534  * @sa xkb_keysym_to_utf32()
535  * @since 1.0.0
536  */
537 xkb_keysym_t
538 xkb_utf32_to_keysym(uint32_t ucs);
539
540 /**
541  * Convert a keysym to its uppercase form.
542  *
543  * If there is no such form, the keysym is returned unchanged.
544  *
545  * The conversion rules may be incomplete; prefer to work with the Unicode
546  * representation instead, when possible.
547  */
548 xkb_keysym_t
549 xkb_keysym_to_upper(xkb_keysym_t ks);
550
551 /**
552  * Convert a keysym to its lowercase form.
553  *
554  * The conversion rules may be incomplete; prefer to work with the Unicode
555  * representation instead, when possible.
556  */
557 xkb_keysym_t
558 xkb_keysym_to_lower(xkb_keysym_t ks);
559
560 /** @} */
561
562 /**
563  * @defgroup context Library Context
564  * Creating, destroying and using library contexts.
565  *
566  * Every keymap compilation request must have a context associated with
567  * it.  The context keeps around state such as the include path.
568  *
569  * @{
570  */
571
572 /**
573  * @page envvars Environment Variables
574  *
575  * The user may set some environment variables which affect the library:
576  *
577  * - `XKB_CONFIG_ROOT`, `XKB_CONFIG_EXTRA_PATH`, `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.
578  * - `XKB_LOG_LEVEL` - see xkb_context_set_log_level().
579  * - `XKB_LOG_VERBOSITY` - see xkb_context_set_log_verbosity().
580  * - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,
581  *   `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see xkb_rule_names.
582  */
583
584 /** Flags for context creation. */
585 enum xkb_context_flags {
586     /** Do not apply any context flags. */
587     XKB_CONTEXT_NO_FLAGS = 0,
588     /** Create this context with an empty include path. */
589     XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
590     /**
591      * Don't take RMLVO names from the environment.
592      *
593      * @since 0.3.0
594      */
595     XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1),
596     /**
597      * Disable the use of secure_getenv for this context, so that privileged
598      * processes can use environment variables. Client uses at their own risk.
599      *
600      * @since 1.5.0
601      */
602     XKB_CONTEXT_NO_SECURE_GETENV = (1 << 2)
603 };
604
605 /**
606  * Create a new context.
607  *
608  * @param flags Optional flags for the context, or 0.
609  *
610  * @returns A new context, or NULL on failure.
611  *
612  * @memberof xkb_context
613  */
614 struct xkb_context *
615 xkb_context_new(enum xkb_context_flags flags);
616
617 /**
618  * Take a new reference on a context.
619  *
620  * @returns The passed in context.
621  *
622  * @memberof xkb_context
623  */
624 struct xkb_context *
625 xkb_context_ref(struct xkb_context *context);
626
627 /**
628  * Release a reference on a context, and possibly free it.
629  *
630  * @param context The context.  If it is NULL, this function does nothing.
631  *
632  * @memberof xkb_context
633  */
634 void
635 xkb_context_unref(struct xkb_context *context);
636
637 /**
638  * Store custom user data in the context.
639  *
640  * This may be useful in conjunction with xkb_context_set_log_fn() or other
641  * callbacks.
642  *
643  * @memberof xkb_context
644  */
645 void
646 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
647
648 /**
649  * Retrieves stored user data from the context.
650  *
651  * @returns The stored user data.  If the user data wasn't set, or the
652  * passed in context is NULL, returns NULL.
653  *
654  * This may be useful to access private user data from callbacks like a
655  * custom logging function.
656  *
657  * @memberof xkb_context
658  **/
659 void *
660 xkb_context_get_user_data(struct xkb_context *context);
661
662 /** @} */
663
664 /**
665  * @defgroup include-path Include Paths
666  * Manipulating the include paths in a context.
667  *
668  * The include paths are the file-system paths that are searched when an
669  * include statement is encountered during keymap compilation.
670  *
671  * The default include paths are, in that lookup order:
672  * - The path `$XDG_CONFIG_HOME/xkb`, with the usual `XDG_CONFIG_HOME`
673  *   fallback to `$HOME/.config/` if unset.
674  * - The path `$HOME/.xkb`, where $HOME is the value of the environment
675  *   variable `HOME`.
676  * - The `XKB_CONFIG_EXTRA_PATH` environment variable, if defined, otherwise the
677  *   system configuration directory, defined at library configuration time
678  *   (usually `/etc/xkb`).
679  * - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise
680  *   the system XKB root, defined at library configuration time.
681  *
682  * @{
683  */
684
685 /**
686  * Append a new entry to the context's include path.
687  *
688  * @returns 1 on success, or 0 if the include path could not be added or is
689  * inaccessible.
690  *
691  * @memberof xkb_context
692  */
693 int
694 xkb_context_include_path_append(struct xkb_context *context, const char *path);
695
696 /**
697  * Append the default include paths to the context's include path.
698  *
699  * @returns 1 on success, or 0 if the primary include path could not be added.
700  *
701  * @memberof xkb_context
702  */
703 int
704 xkb_context_include_path_append_default(struct xkb_context *context);
705
706 /**
707  * Reset the context's include path to the default.
708  *
709  * Removes all entries from the context's include path, and inserts the
710  * default paths.
711  *
712  * @returns 1 on success, or 0 if the primary include path could not be added.
713  *
714  * @memberof xkb_context
715  */
716 int
717 xkb_context_include_path_reset_defaults(struct xkb_context *context);
718
719 /**
720  * Remove all entries from the context's include path.
721  *
722  * @memberof xkb_context
723  */
724 void
725 xkb_context_include_path_clear(struct xkb_context *context);
726
727 /**
728  * Get the number of paths in the context's include path.
729  *
730  * @memberof xkb_context
731  */
732 unsigned int
733 xkb_context_num_include_paths(struct xkb_context *context);
734
735 /**
736  * Get a specific include path from the context's include path.
737  *
738  * @returns The include path at the specified index.  If the index is
739  * invalid, returns NULL.
740  *
741  * @memberof xkb_context
742  */
743 const char *
744 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
745
746 /** @} */
747
748 /**
749  * @defgroup logging Logging Handling
750  * Manipulating how logging from this library is handled.
751  *
752  * @{
753  */
754
755 /** Specifies a logging level. */
756 enum xkb_log_level {
757     XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
758     XKB_LOG_LEVEL_ERROR = 20,    /**< Log all errors. */
759     XKB_LOG_LEVEL_WARNING = 30,  /**< Log warnings and errors. */
760     XKB_LOG_LEVEL_INFO = 40,     /**< Log information, warnings, and errors. */
761     XKB_LOG_LEVEL_DEBUG = 50     /**< Log everything. */
762 };
763
764 /**
765  * Set the current logging level.
766  *
767  * @param context The context in which to set the logging level.
768  * @param level   The logging level to use.  Only messages from this level
769  * and below will be logged.
770  *
771  * The default level is XKB_LOG_LEVEL_ERROR.  The environment variable
772  * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
773  * default value.  It may be specified as a level number or name.
774  *
775  * @memberof xkb_context
776  */
777 void
778 xkb_context_set_log_level(struct xkb_context *context,
779                           enum xkb_log_level level);
780
781 /**
782  * Get the current logging level.
783  *
784  * @memberof xkb_context
785  */
786 enum xkb_log_level
787 xkb_context_get_log_level(struct xkb_context *context);
788
789 /**
790  * Sets the current logging verbosity.
791  *
792  * The library can generate a number of warnings which are not helpful to
793  * ordinary users of the library.  The verbosity may be increased if more
794  * information is desired (e.g. when developing a new keymap).
795  *
796  * The default verbosity is 0.  The environment variable XKB_LOG_VERBOSITY,
797  * if set in the time the context was created, overrides the default value.
798  *
799  * @param context   The context in which to use the set verbosity.
800  * @param verbosity The verbosity to use.  Currently used values are
801  * 1 to 10, higher values being more verbose.  0 would result in no verbose
802  * messages being logged.
803  *
804  * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
805  *
806  * @memberof xkb_context
807  */
808 void
809 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
810
811 /**
812  * Get the current logging verbosity of the context.
813  *
814  * @memberof xkb_context
815  */
816 int
817 xkb_context_get_log_verbosity(struct xkb_context *context);
818
819 /**
820  * Set a custom function to handle logging messages.
821  *
822  * @param context The context in which to use the set logging function.
823  * @param log_fn  The function that will be called for logging messages.
824  * Passing NULL restores the default function, which logs to stderr.
825  *
826  * By default, log messages from this library are printed to stderr.  This
827  * function allows you to replace the default behavior with a custom
828  * handler.  The handler is only called with messages which match the
829  * current logging level and verbosity settings for the context.
830  * level is the logging level of the message.  @a format and @a args are
831  * the same as in the vprintf(3) function.
832  *
833  * You may use xkb_context_set_user_data() on the context, and then call
834  * xkb_context_get_user_data() from within the logging function to provide
835  * it with additional private context.
836  *
837  * @memberof xkb_context
838  */
839 void
840 xkb_context_set_log_fn(struct xkb_context *context,
841                        void (*log_fn)(struct xkb_context *context,
842                                       enum xkb_log_level level,
843                                       const char *format, va_list args));
844
845 /** @} */
846
847 /**
848  * @defgroup keymap Keymap Creation
849  * Creating and destroying keymaps.
850  *
851  * @{
852  */
853
854 /** Flags for keymap compilation. */
855 enum xkb_keymap_compile_flags {
856     /** Do not apply any flags. */
857     XKB_KEYMAP_COMPILE_NO_FLAGS = 0
858 };
859
860 /**
861  * Create a keymap from RMLVO names.
862  *
863  * The primary keymap entry point: creates a new XKB keymap from a set of
864  * RMLVO (Rules + Model + Layouts + Variants + Options) names.
865  *
866  * @param context The context in which to create the keymap.
867  * @param names   The RMLVO names to use.  See xkb_rule_names.
868  * @param flags   Optional flags for the keymap, or 0.
869  *
870  * @returns A keymap compiled according to the RMLVO names, or NULL if
871  * the compilation failed.
872  *
873  * @sa xkb_rule_names
874  * @memberof xkb_keymap
875  */
876 struct xkb_keymap *
877 xkb_keymap_new_from_names(struct xkb_context *context,
878                           const struct xkb_rule_names *names,
879                           enum xkb_keymap_compile_flags flags);
880
881 /** The possible keymap formats. */
882 enum xkb_keymap_format {
883     /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
884     XKB_KEYMAP_FORMAT_TEXT_V1 = 1
885 };
886
887 /**
888  * Create a keymap from a keymap file.
889  *
890  * @param context The context in which to create the keymap.
891  * @param file    The keymap file to compile.
892  * @param format  The text format of the keymap file to compile.
893  * @param flags   Optional flags for the keymap, or 0.
894  *
895  * @returns A keymap compiled from the given XKB keymap file, or NULL if
896  * the compilation failed.
897  *
898  * The file must contain a complete keymap.  For example, in the
899  * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
900  * top level '%xkb_keymap' section, which in turn contains other required
901  * sections.
902  *
903  * @memberof xkb_keymap
904  */
905 struct xkb_keymap *
906 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
907                          enum xkb_keymap_format format,
908                          enum xkb_keymap_compile_flags flags);
909
910 /**
911  * Create a keymap from a keymap string.
912  *
913  * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
914  * the keymap as one enormous string.
915  *
916  * @see xkb_keymap_new_from_file()
917  * @memberof xkb_keymap
918  */
919 struct xkb_keymap *
920 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
921                            enum xkb_keymap_format format,
922                            enum xkb_keymap_compile_flags flags);
923
924 /**
925  * Create a keymap from a memory buffer.
926  *
927  * This is just like xkb_keymap_new_from_string(), but takes a length argument
928  * so the input string does not have to be zero-terminated.
929  *
930  * @see xkb_keymap_new_from_string()
931  * @memberof xkb_keymap
932  * @since 0.3.0
933  */
934 struct xkb_keymap *
935 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
936                            size_t length, enum xkb_keymap_format format,
937                            enum xkb_keymap_compile_flags flags);
938
939 /**
940  * Take a new reference on a keymap.
941  *
942  * @returns The passed in keymap.
943  *
944  * @memberof xkb_keymap
945  */
946 struct xkb_keymap *
947 xkb_keymap_ref(struct xkb_keymap *keymap);
948
949 /**
950  * Release a reference on a keymap, and possibly free it.
951  *
952  * @param keymap The keymap.  If it is NULL, this function does nothing.
953  *
954  * @memberof xkb_keymap
955  */
956 void
957 xkb_keymap_unref(struct xkb_keymap *keymap);
958
959 /**
960  * Get the keymap as a string in the format from which it was created.
961  * @sa xkb_keymap_get_as_string()
962  **/
963 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
964
965 /**
966  * Get the compiled keymap as a string.
967  *
968  * @param keymap The keymap to get as a string.
969  * @param format The keymap format to use for the string.  You can pass
970  * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
971  * from which the keymap was originally created.
972  *
973  * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
974  *
975  * The returned string may be fed back into xkb_keymap_new_from_string() to get
976  * the exact same keymap (possibly in another process, etc.).
977  *
978  * The returned string is dynamically allocated and should be freed by the
979  * caller.
980  *
981  * @memberof xkb_keymap
982  */
983 char *
984 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
985                          enum xkb_keymap_format format);
986
987 /** @} */
988
989 /**
990  * @defgroup components Keymap Components
991  * Enumeration of state components in a keymap.
992  *
993  * @{
994  */
995
996 /**
997  * Get the minimum keycode in the keymap.
998  *
999  * @sa xkb_keycode_t
1000  * @memberof xkb_keymap
1001  * @since 0.3.1
1002  */
1003 xkb_keycode_t
1004 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
1005
1006 /**
1007  * Get the maximum keycode in the keymap.
1008  *
1009  * @sa xkb_keycode_t
1010  * @memberof xkb_keymap
1011  * @since 0.3.1
1012  */
1013 xkb_keycode_t
1014 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
1015
1016 /**
1017  * The iterator used by xkb_keymap_key_for_each().
1018  *
1019  * @sa xkb_keymap_key_for_each
1020  * @memberof xkb_keymap
1021  * @since 0.3.1
1022  */
1023 typedef void
1024 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
1025                          void *data);
1026
1027 /**
1028  * Run a specified function for every valid keycode in the keymap.  If a
1029  * keymap is sparse, this function may be called fewer than
1030  * (max_keycode - min_keycode + 1) times.
1031  *
1032  * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
1033  * @memberof xkb_keymap
1034  * @since 0.3.1
1035  */
1036 void
1037 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
1038                         void *data);
1039
1040 /**
1041  * Find the name of the key with the given keycode.
1042  *
1043  * This function always returns the canonical name of the key (see
1044  * description in xkb_keycode_t).
1045  *
1046  * @returns The key name. If no key with this keycode exists,
1047  * returns NULL.
1048  *
1049  * @sa xkb_keycode_t
1050  * @memberof xkb_keymap
1051  * @since 0.6.0
1052  */
1053 const char *
1054 xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
1055
1056 /**
1057  * Find the keycode of the key with the given name.
1058  *
1059  * The name can be either a canonical name or an alias.
1060  *
1061  * @returns The keycode. If no key with this name exists,
1062  * returns XKB_KEYCODE_INVALID.
1063  *
1064  * @sa xkb_keycode_t
1065  * @memberof xkb_keymap
1066  * @since 0.6.0
1067  */
1068 xkb_keycode_t
1069 xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
1070
1071 /**
1072  * Get the number of modifiers in the keymap.
1073  *
1074  * @sa xkb_mod_index_t
1075  * @memberof xkb_keymap
1076  */
1077 xkb_mod_index_t
1078 xkb_keymap_num_mods(struct xkb_keymap *keymap);
1079
1080 /**
1081  * Get the name of a modifier by index.
1082  *
1083  * @returns The name.  If the index is invalid, returns NULL.
1084  *
1085  * @sa xkb_mod_index_t
1086  * @memberof xkb_keymap
1087  */
1088 const char *
1089 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
1090
1091 /**
1092  * Get the index of a modifier by name.
1093  *
1094  * @returns The index.  If no modifier with this name exists, returns
1095  * XKB_MOD_INVALID.
1096  *
1097  * @sa xkb_mod_index_t
1098  * @memberof xkb_keymap
1099  */
1100 xkb_mod_index_t
1101 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
1102
1103 /**
1104  * Get the number of layouts in the keymap.
1105  *
1106  * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
1107  * @memberof xkb_keymap
1108  */
1109 xkb_layout_index_t
1110 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
1111
1112 /**
1113  * Get the name of a layout by index.
1114  *
1115  * @returns The name.  If the index is invalid, or the layout does not have
1116  * a name, returns NULL.
1117  *
1118  * @sa xkb_layout_index_t
1119  *     For notes on layout names.
1120  * @memberof xkb_keymap
1121  */
1122 const char *
1123 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
1124
1125 /**
1126  * Get the index of a layout by name.
1127  *
1128  * @returns The index.  If no layout exists with this name, returns
1129  * XKB_LAYOUT_INVALID.  If more than one layout in the keymap has this name,
1130  * returns the lowest index among them.
1131  *
1132  * @sa xkb_layout_index_t
1133  *     For notes on layout names.
1134  * @memberof xkb_keymap
1135  */
1136 xkb_layout_index_t
1137 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
1138
1139 /**
1140  * Get the number of LEDs in the keymap.
1141  *
1142  * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
1143  * in the keymap, but may also contain inactive LEDs.  When iterating over
1144  * this range, you need the handle this case when calling functions such as
1145  * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
1146  *
1147  * @sa xkb_led_index_t
1148  * @memberof xkb_keymap
1149  */
1150 xkb_led_index_t
1151 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1152
1153 /**
1154  * Get the name of a LED by index.
1155  *
1156  * @returns The name.  If the index is invalid, returns NULL.
1157  *
1158  * @memberof xkb_keymap
1159  */
1160 const char *
1161 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1162
1163 /**
1164  * Get the index of a LED by name.
1165  *
1166  * @returns The index.  If no LED with this name exists, returns
1167  * XKB_LED_INVALID.
1168  *
1169  * @memberof xkb_keymap
1170  */
1171 xkb_led_index_t
1172 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1173
1174 /**
1175  * Get the number of layouts for a specific key.
1176  *
1177  * This number can be different from xkb_keymap_num_layouts(), but is always
1178  * smaller.  It is the appropriate value to use when iterating over the
1179  * layouts of a key.
1180  *
1181  * @sa xkb_layout_index_t
1182  * @memberof xkb_keymap
1183  */
1184 xkb_layout_index_t
1185 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
1186
1187 /**
1188  * Get the number of shift levels for a specific key and layout.
1189  *
1190  * If @c layout is out of range for this key (that is, larger or equal to
1191  * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1192  * back into range in a manner consistent with xkb_state_key_get_layout().
1193  *
1194  * @sa xkb_level_index_t
1195  * @memberof xkb_keymap
1196  */
1197 xkb_level_index_t
1198 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
1199                               xkb_layout_index_t layout);
1200
1201 /**
1202  * Retrieves every possible modifier mask that produces the specified
1203  * shift level for a specific key and layout.
1204  *
1205  * This API is useful for inverse key transformation; i.e. finding out
1206  * which modifiers need to be active in order to be able to type the
1207  * keysym(s) corresponding to the specific key code, layout and level.
1208  *
1209  * @warning It returns only up to masks_size modifier masks. If the
1210  * buffer passed is too small, some of the possible modifier combinations
1211  * will not be returned.
1212  *
1213  * @param[in] keymap      The keymap.
1214  * @param[in] key         The keycode of the key.
1215  * @param[in] layout      The layout for which to get modifiers.
1216  * @param[in] level       The shift level in the layout for which to get the
1217  * modifiers. This should be smaller than:
1218  * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1219  * @param[out] masks_out  A buffer in which the requested masks should be
1220  * stored.
1221  * @param[out] masks_size The number of elements in the buffer pointed to by
1222  * masks_out.
1223  *
1224  * If @c layout is out of range for this key (that is, larger or equal to
1225  * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1226  * back into range in a manner consistent with xkb_state_key_get_layout().
1227  *
1228  * @returns The number of modifier masks stored in the masks_out array.
1229  * If the key is not in the keymap or if the specified shift level cannot
1230  * be reached it returns 0 and does not modify the masks_out buffer.
1231  *
1232  * @sa xkb_level_index_t
1233  * @sa xkb_mod_mask_t
1234  * @memberof xkb_keymap
1235  * @since 1.0.0
1236  */
1237 size_t
1238 xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,
1239                                   xkb_keycode_t key,
1240                                   xkb_layout_index_t layout,
1241                                   xkb_level_index_t level,
1242                                   xkb_mod_mask_t *masks_out,
1243                                   size_t masks_size);
1244
1245 /**
1246  * Get the keysyms obtained from pressing a key in a given layout and
1247  * shift level.
1248  *
1249  * This function is like xkb_state_key_get_syms(), only the layout and
1250  * shift level are not derived from the keyboard state but are instead
1251  * specified explicitly.
1252  *
1253  * @param[in] keymap    The keymap.
1254  * @param[in] key       The keycode of the key.
1255  * @param[in] layout    The layout for which to get the keysyms.
1256  * @param[in] level     The shift level in the layout for which to get the
1257  * keysyms. This should be smaller than:
1258  * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
1259  * @param[out] syms_out An immutable array of keysyms corresponding to the
1260  * key in the given layout and shift level.
1261  *
1262  * If @c layout is out of range for this key (that is, larger or equal to
1263  * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1264  * back into range in a manner consistent with xkb_state_key_get_layout().
1265  *
1266  * @returns The number of keysyms in the syms_out array.  If no keysyms
1267  * are produced by the key in the given layout and shift level, returns 0
1268  * and sets syms_out to NULL.
1269  *
1270  * @sa xkb_state_key_get_syms()
1271  * @memberof xkb_keymap
1272  */
1273 int
1274 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1275                                  xkb_keycode_t key,
1276                                  xkb_layout_index_t layout,
1277                                  xkb_level_index_t level,
1278                                  const xkb_keysym_t **syms_out);
1279
1280 /**
1281  * Determine whether a key should repeat or not.
1282  *
1283  * A keymap may specify different repeat behaviors for different keys.
1284  * Most keys should generally exhibit repeat behavior; for example, holding
1285  * the 'a' key down in a text editor should normally insert a single 'a'
1286  * character every few milliseconds, until the key is released.  However,
1287  * there are keys which should not or do not need to be repeated.  For
1288  * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1289  * is not generally useful or desired.
1290  *
1291  * @returns 1 if the key should repeat, 0 otherwise.
1292  *
1293  * @memberof xkb_keymap
1294  */
1295 int
1296 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1297
1298 /** @} */
1299
1300 /**
1301  * @defgroup state Keyboard State
1302  * Creating, destroying and manipulating keyboard state objects.
1303  *
1304  * @{
1305  */
1306
1307 /**
1308  * Create a new keyboard state object.
1309  *
1310  * @param keymap The keymap which the state will use.
1311  *
1312  * @returns A new keyboard state object, or NULL on failure.
1313  *
1314  * @memberof xkb_state
1315  */
1316 struct xkb_state *
1317 xkb_state_new(struct xkb_keymap *keymap);
1318
1319 /**
1320  * Take a new reference on a keyboard state object.
1321  *
1322  * @returns The passed in object.
1323  *
1324  * @memberof xkb_state
1325  */
1326 struct xkb_state *
1327 xkb_state_ref(struct xkb_state *state);
1328
1329 /**
1330  * Release a reference on a keybaord state object, and possibly free it.
1331  *
1332  * @param state The state.  If it is NULL, this function does nothing.
1333  *
1334  * @memberof xkb_state
1335  */
1336 void
1337 xkb_state_unref(struct xkb_state *state);
1338
1339 /**
1340  * Get the keymap which a keyboard state object is using.
1341  *
1342  * @returns The keymap which was passed to xkb_state_new() when creating
1343  * this state object.
1344  *
1345  * This function does not take a new reference on the keymap; you must
1346  * explicitly reference it yourself if you plan to use it beyond the
1347  * lifetime of the state.
1348  *
1349  * @memberof xkb_state
1350  */
1351 struct xkb_keymap *
1352 xkb_state_get_keymap(struct xkb_state *state);
1353
1354 /**
1355  * @page server-client-state Server State and Client State
1356  * @parblock
1357  *
1358  * The xkb_state API is used by two distinct actors in most window-system
1359  * architectures:
1360  *
1361  * 1. A *server* - for example, a Wayland compositor, an X11 server, an evdev
1362  *    listener.
1363  *
1364  *    Servers maintain the XKB state for a device according to input events from
1365  *    the device, such as key presses and releases, and out-of-band events from
1366  *    the user, like UI layout switchers.
1367  *
1368  * 2. A *client* - for example, a Wayland client, an X11 client.
1369  *
1370  *    Clients do not listen to input from the device; instead, whenever the
1371  *    server state changes, the server serializes the state and notifies the
1372  *    clients that the state has changed; the clients then update the state
1373  *    from the serialization.
1374  *
1375  * Some entry points in the xkb_state API are only meant for servers and some
1376  * are only meant for clients, and the two should generally not be mixed.
1377  *
1378  * @endparblock
1379  */
1380
1381 /** Specifies the direction of the key (press / release). */
1382 enum xkb_key_direction {
1383     XKB_KEY_UP,   /**< The key was released. */
1384     XKB_KEY_DOWN  /**< The key was pressed. */
1385 };
1386
1387 /**
1388  * Modifier and layout types for state objects.  This enum is bitmaskable,
1389  * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
1390  * exclude locked modifiers.
1391  *
1392  * In XKB, the DEPRESSED components are also known as 'base'.
1393  */
1394 enum xkb_state_component {
1395     /** Depressed modifiers, i.e. a key is physically holding them. */
1396     XKB_STATE_MODS_DEPRESSED = (1 << 0),
1397     /** Latched modifiers, i.e. will be unset after the next non-modifier
1398      *  key press. */
1399     XKB_STATE_MODS_LATCHED = (1 << 1),
1400     /** Locked modifiers, i.e. will be unset after the key provoking the
1401      *  lock has been pressed again. */
1402     XKB_STATE_MODS_LOCKED = (1 << 2),
1403     /** Effective modifiers, i.e. currently active and affect key
1404      *  processing (derived from the other state components).
1405      *  Use this unless you explicitly care how the state came about. */
1406     XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1407     /** Depressed layout, i.e. a key is physically holding it. */
1408     XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1409     /** Latched layout, i.e. will be unset after the next non-modifier
1410      *  key press. */
1411     XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1412     /** Locked layout, i.e. will be unset after the key provoking the lock
1413      *  has been pressed again. */
1414     XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1415     /** Effective layout, i.e. currently active and affects key processing
1416      *  (derived from the other state components).
1417      *  Use this unless you explicitly care how the state came about. */
1418     XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1419     /** LEDs (derived from the other state components). */
1420     XKB_STATE_LEDS = (1 << 8)
1421 };
1422
1423 /**
1424  * Update the keyboard state to reflect a given key being pressed or
1425  * released.
1426  *
1427  * This entry point is intended for *server* applications and should not be used
1428  * by *client* applications; see @ref server-client-state for details.
1429  *
1430  * A series of calls to this function should be consistent; that is, a call
1431  * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
1432  * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1433  * to missed input events), situations like "stuck modifiers" may occur.
1434  *
1435  * This function is often used in conjunction with the function
1436  * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
1437  * when handling a key event.  In this case, you should prefer to get the
1438  * keysyms *before* updating the key, such that the keysyms reported for
1439  * the key event are not affected by the event itself.  This is the
1440  * conventional behavior.
1441  *
1442  * @returns A mask of state components that have changed as a result of
1443  * the update.  If nothing in the state has changed, returns 0.
1444  *
1445  * @memberof xkb_state
1446  *
1447  * @sa xkb_state_update_mask()
1448  */
1449 enum xkb_state_component
1450 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1451                      enum xkb_key_direction direction);
1452
1453 /**
1454  * Update a keyboard state from a set of explicit masks.
1455  *
1456  * This entry point is intended for *client* applications; see @ref
1457  * server-client-state for details. *Server* applications should use
1458  * xkb_state_update_key() instead.
1459  *
1460  * All parameters must always be passed, or the resulting state may be
1461  * incoherent.
1462  *
1463  * The serialization is lossy and will not survive round trips; it must only
1464  * be used to feed client state objects, and must not be used to update the
1465  * server state.
1466  *
1467  * @returns A mask of state components that have changed as a result of
1468  * the update.  If nothing in the state has changed, returns 0.
1469  *
1470  * @memberof xkb_state
1471  *
1472  * @sa xkb_state_component
1473  * @sa xkb_state_update_key
1474  */
1475 enum xkb_state_component
1476 xkb_state_update_mask(struct xkb_state *state,
1477                       xkb_mod_mask_t depressed_mods,
1478                       xkb_mod_mask_t latched_mods,
1479                       xkb_mod_mask_t locked_mods,
1480                       xkb_layout_index_t depressed_layout,
1481                       xkb_layout_index_t latched_layout,
1482                       xkb_layout_index_t locked_layout);
1483
1484 /**
1485  * Get the keysyms obtained from pressing a particular key in a given
1486  * keyboard state.
1487  *
1488  * Get the keysyms for a key according to the current active layout,
1489  * modifiers and shift level for the key, as determined by a keyboard
1490  * state.
1491  *
1492  * @param[in]  state    The keyboard state object.
1493  * @param[in]  key      The keycode of the key.
1494  * @param[out] syms_out An immutable array of keysyms corresponding the
1495  * key in the given keyboard state.
1496  *
1497  * As an extension to XKB, this function can return more than one keysym.
1498  * If you do not want to handle this case, you can use
1499  * xkb_state_key_get_one_sym() for a simpler interface.
1500  *
1501  * This function does not perform any @ref keysym-transformations.
1502  * (This might change).
1503  *
1504  * @returns The number of keysyms in the syms_out array.  If no keysyms
1505  * are produced by the key in the given keyboard state, returns 0 and sets
1506  * syms_out to NULL.
1507  *
1508  * @memberof xkb_state
1509  */
1510 int
1511 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1512                        const xkb_keysym_t **syms_out);
1513
1514 /**
1515  * Get the Unicode/UTF-8 string obtained from pressing a particular key
1516  * in a given keyboard state.
1517  *
1518  * @param[in]  state  The keyboard state object.
1519  * @param[in]  key    The keycode of the key.
1520  * @param[out] buffer A buffer to write the string into.
1521  * @param[in]  size   Size of the buffer.
1522  *
1523  * @warning If the buffer passed is too small, the string is truncated
1524  * (though still NUL-terminated).
1525  *
1526  * @returns The number of bytes required for the string, excluding the
1527  * NUL byte.  If there is nothing to write, returns 0.
1528  *
1529  * You may check if truncation has occurred by comparing the return value
1530  * with the size of @p buffer, similarly to the snprintf(3) function.
1531  * You may safely pass NULL and 0 to @p buffer and @p size to find the
1532  * required size (without the NUL-byte).
1533  *
1534  * This function performs Capitalization and Control @ref
1535  * keysym-transformations.
1536  *
1537  * @memberof xkb_state
1538  * @since 0.4.1
1539  */
1540 int
1541 xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
1542                        char *buffer, size_t size);
1543
1544 /**
1545  * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
1546  * key in a a given keyboard state.
1547  *
1548  * @returns The UTF-32 representation for the key, if it consists of only
1549  * a single codepoint.  Otherwise, returns 0.
1550  *
1551  * This function performs Capitalization and Control @ref
1552  * keysym-transformations.
1553  *
1554  * @memberof xkb_state
1555  * @since 0.4.1
1556  */
1557 uint32_t
1558 xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
1559
1560 /**
1561  * Get the single keysym obtained from pressing a particular key in a
1562  * given keyboard state.
1563  *
1564  * This function is similar to xkb_state_key_get_syms(), but intended
1565  * for users which cannot or do not want to handle the case where
1566  * multiple keysyms are returned (in which case this function is
1567  * preferred).
1568  *
1569  * @returns The keysym.  If the key does not have exactly one keysym,
1570  * returns XKB_KEY_NoSymbol
1571  *
1572  * This function performs Capitalization @ref keysym-transformations.
1573  *
1574  * @sa xkb_state_key_get_syms()
1575  * @memberof xkb_state
1576  */
1577 xkb_keysym_t
1578 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1579
1580 /**
1581  * Get the effective layout index for a key in a given keyboard state.
1582  *
1583  * @returns The layout index for the key in the given keyboard state.  If
1584  * the given keycode is invalid, or if the key is not included in any
1585  * layout at all, returns XKB_LAYOUT_INVALID.
1586  *
1587  * @invariant If the returned layout is valid, the following always holds:
1588  * @code
1589  * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
1590  * @endcode
1591  *
1592  * @memberof xkb_state
1593  */
1594 xkb_layout_index_t
1595 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1596
1597 /**
1598  * Get the effective shift level for a key in a given keyboard state and
1599  * layout.
1600  *
1601  * @param state The keyboard state.
1602  * @param key The keycode of the key.
1603  * @param layout The layout for which to get the shift level.  This must be
1604  * smaller than:
1605  * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1606  * usually it would be:
1607  * @code xkb_state_key_get_layout(state, key) @endcode
1608  *
1609  * @return The shift level index.  If the key or layout are invalid,
1610  * returns XKB_LEVEL_INVALID.
1611  *
1612  * @invariant If the returned level is valid, the following always holds:
1613  * @code
1614  * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
1615  * @endcode
1616  *
1617  * @memberof xkb_state
1618  */
1619 xkb_level_index_t
1620 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1621                         xkb_layout_index_t layout);
1622
1623 /**
1624  * Match flags for xkb_state_mod_indices_are_active() and
1625  * xkb_state_mod_names_are_active(), specifying the conditions for a
1626  * successful match.  XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
1627  * the other modes.
1628  */
1629 enum xkb_state_match {
1630     /** Returns true if any of the modifiers are active. */
1631     XKB_STATE_MATCH_ANY = (1 << 0),
1632     /** Returns true if all of the modifiers are active. */
1633     XKB_STATE_MATCH_ALL = (1 << 1),
1634     /** Makes matching non-exclusive, i.e. will not return false if a
1635      *  modifier not specified in the arguments is active. */
1636     XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
1637 };
1638
1639 /**
1640  * The counterpart to xkb_state_update_mask for modifiers, to be used on
1641  * the server side of serialization.
1642  *
1643  * This entry point is intended for *server* applications; see @ref
1644  * server-client-state for details. *Client* applications should use the
1645  * xkb_state_mod_*_is_active API.
1646  *
1647  * @param state      The keyboard state.
1648  * @param components A mask of the modifier state components to serialize.
1649  * State components other than XKB_STATE_MODS_* are ignored.
1650  * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
1651  * ignored.
1652  *
1653  * @returns A xkb_mod_mask_t representing the given components of the
1654  * modifier state.
1655  *
1656  * @memberof xkb_state
1657  */
1658 xkb_mod_mask_t
1659 xkb_state_serialize_mods(struct xkb_state *state,
1660                          enum xkb_state_component components);
1661
1662 /**
1663  * The counterpart to xkb_state_update_mask for layouts, to be used on
1664  * the server side of serialization.
1665  *
1666  * This entry point is intended for *server* applications; see @ref
1667  * server-client-state for details. *Client* applications should use the
1668  * xkb_state_layout_*_is_active API.
1669  *
1670  * @param state      The keyboard state.
1671  * @param components A mask of the layout state components to serialize.
1672  * State components other than XKB_STATE_LAYOUT_* are ignored.
1673  * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
1674  * ignored.
1675  *
1676  * @returns A layout index representing the given components of the
1677  * layout state.
1678  *
1679  * @memberof xkb_state
1680  */
1681 xkb_layout_index_t
1682 xkb_state_serialize_layout(struct xkb_state *state,
1683                            enum xkb_state_component components);
1684
1685 /**
1686  * Test whether a modifier is active in a given keyboard state by name.
1687  *
1688  * @returns 1 if the modifier is active, 0 if it is not.  If the modifier
1689  * name does not exist in the keymap, returns -1.
1690  *
1691  * @memberof xkb_state
1692  */
1693 int
1694 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1695                              enum xkb_state_component type);
1696
1697 /**
1698  * Test whether a set of modifiers are active in a given keyboard state by
1699  * name.
1700  *
1701  * @param state The keyboard state.
1702  * @param type  The component of the state against which to match the
1703  * given modifiers.
1704  * @param match The manner by which to match the state against the
1705  * given modifiers.
1706  * @param ...   The set of of modifier names to test, terminated by a NULL
1707  * argument (sentinel).
1708  *
1709  * @returns 1 if the modifiers are active, 0 if they are not.  If any of
1710  * the modifier names do not exist in the keymap, returns -1.
1711  *
1712  * @memberof xkb_state
1713  */
1714 int
1715 xkb_state_mod_names_are_active(struct xkb_state *state,
1716                                enum xkb_state_component type,
1717                                enum xkb_state_match match,
1718                                ...);
1719
1720 /**
1721  * Test whether a modifier is active in a given keyboard state by index.
1722  *
1723  * @returns 1 if the modifier is active, 0 if it is not.  If the modifier
1724  * index is invalid in the keymap, returns -1.
1725  *
1726  * @memberof xkb_state
1727  */
1728 int
1729 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1730                               enum xkb_state_component type);
1731
1732 /**
1733  * Test whether a set of modifiers are active in a given keyboard state by
1734  * index.
1735  *
1736  * @param state The keyboard state.
1737  * @param type  The component of the state against which to match the
1738  * given modifiers.
1739  * @param match The manner by which to match the state against the
1740  * given modifiers.
1741  * @param ...   The set of of modifier indices to test, terminated by a
1742  * XKB_MOD_INVALID argument (sentinel).
1743  *
1744  * @returns 1 if the modifiers are active, 0 if they are not.  If any of
1745  * the modifier indices are invalid in the keymap, returns -1.
1746  *
1747  * @memberof xkb_state
1748  */
1749 int
1750 xkb_state_mod_indices_are_active(struct xkb_state *state,
1751                                  enum xkb_state_component type,
1752                                  enum xkb_state_match match,
1753                                  ...);
1754
1755 /**
1756  * @page consumed-modifiers Consumed Modifiers
1757  * @parblock
1758  *
1759  * Some functions, like xkb_state_key_get_syms(), look at the state of
1760  * the modifiers in the keymap and derive from it the correct shift level
1761  * to use for the key.  For example, in a US layout, pressing the key
1762  * labeled \<A\> while the Shift modifier is active, generates the keysym
1763  * 'A'.  In this case, the Shift modifier is said to be "consumed".
1764  * However, the Num Lock modifier does not affect this translation at all,
1765  * even if it is active, so it is not consumed by this translation.
1766  *
1767  * It may be desirable for some application to not reuse consumed modifiers
1768  * for further processing, e.g. for hotkeys or keyboard shortcuts.  To
1769  * understand why, consider some requirements from a standard shortcut
1770  * mechanism, and how they are implemented:
1771  *
1772  * 1. The shortcut's modifiers must match exactly to the state.  For
1773  *    example, it is possible to bind separate actions to \<Alt\>\<Tab\>
1774  *    and to \<Alt\>\<Shift\>\<Tab\>.  Further, if only \<Alt\>\<Tab\> is
1775  *    bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not
1776  *    trigger the shortcut.
1777  *    Effectively, this means that the modifiers are compared using the
1778  *    equality operator (==).
1779  *
1780  * 2. Only relevant modifiers are considered for the matching.  For example,
1781  *    Caps Lock and Num Lock should not generally affect the matching, e.g.
1782  *    when matching \<Alt\>\<Tab\> against the state, it does not matter
1783  *    whether Num Lock is active or not.  These relevant, or "significant",
1784  *    modifiers usually include Alt, Control, Shift, Super and similar.
1785  *    Effectively, this means that non-significant modifiers are masked out,
1786  *    before doing the comparison as described above.
1787  *
1788  * 3. The matching must be independent of the layout/keymap.  For example,
1789  *    the \<Plus\> (+) symbol is found on the first level on some layouts,
1790  *    but requires holding Shift on others.  If you simply bind the action
1791  *    to the \<Plus\> keysym, it would work for the unshifted kind, but
1792  *    not for the others, because the match against Shift would fail.  If
1793  *    you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
1794  *    work.  So what is needed is to recognize that Shift is used up in the
1795  *    translation of the keysym itself, and therefore should not be included
1796  *    in the matching.
1797  *    Effectively, this means that consumed modifiers (Shift in this example)
1798  *    are masked out as well, before doing the comparison.
1799  *
1800  * In summary, this is approximately how the matching would be performed:
1801  * @code
1802  *   (keysym == shortcut_keysym) &&
1803  *   ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
1804  * @endcode
1805  *
1806  * @c state_mods are the modifiers reported by
1807  * xkb_state_mod_index_is_active() and similar functions.
1808  * @c consumed_mods are the modifiers reported by
1809  * xkb_state_mod_index_is_consumed() and similar functions.
1810  * @c significant_mods are decided upon by the application/toolkit/user;
1811  * it is up to them to decide whether these are configurable or hard-coded.
1812  *
1813  * @endparblock
1814  */
1815
1816 /**
1817  * Consumed modifiers mode.
1818  *
1819  * There are several possible methods for deciding which modifiers are
1820  * consumed and which are not, each applicable for different systems or
1821  * situations. The mode selects the method to use.
1822  *
1823  * Keep in mind that in all methods, the keymap may decide to "preserve"
1824  * a modifier, meaning it is not reported as consumed even if it would
1825  * have otherwise.
1826  */
1827 enum xkb_consumed_mode {
1828     /**
1829      * This is the mode defined in the XKB specification and used by libX11.
1830      *
1831      * A modifier is consumed if and only if it *may affect* key translation.
1832      *
1833      * For example, if `Control+Alt+<Backspace>` produces some assigned keysym,
1834      * then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,
1835      * even though they are not active, since if they *were* active they would
1836      * have affected key translation.
1837      */
1838     XKB_CONSUMED_MODE_XKB,
1839     /**
1840      * This is the mode used by the GTK+ toolkit.
1841      *
1842      * The mode consists of the following two independent heuristics:
1843      *
1844      * - The currently active set of modifiers, excluding modifiers which do
1845      *   not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are
1846      *   considered consumed, if the keysyms produced when all of them are
1847      *   active are different from the keysyms produced when no modifiers are
1848      *   active.
1849      *
1850      * - A single modifier is considered consumed if the keysyms produced for
1851      *   the key when it is the only active modifier are different from the
1852      *   keysyms produced when no modifiers are active.
1853      */
1854     XKB_CONSUMED_MODE_GTK
1855 };
1856
1857 /**
1858  * Get the mask of modifiers consumed by translating a given key.
1859  *
1860  * @param state The keyboard state.
1861  * @param key   The keycode of the key.
1862  * @param mode  The consumed modifiers mode to use; see enum description.
1863  *
1864  * @returns a mask of the consumed modifiers.
1865  *
1866  * @memberof xkb_state
1867  * @since 0.7.0
1868  */
1869 xkb_mod_mask_t
1870 xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,
1871                                  enum xkb_consumed_mode mode);
1872
1873 /**
1874  * Same as xkb_state_key_get_consumed_mods2() with mode XKB_CONSUMED_MODE_XKB.
1875  *
1876  * @memberof xkb_state
1877  * @since 0.4.1
1878  */
1879 xkb_mod_mask_t
1880 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
1881
1882 /**
1883  * Test whether a modifier is consumed by keyboard state translation for
1884  * a key.
1885  *
1886  * @param state The keyboard state.
1887  * @param key   The keycode of the key.
1888  * @param idx   The index of the modifier to check.
1889  * @param mode  The consumed modifiers mode to use; see enum description.
1890  *
1891  * @returns 1 if the modifier is consumed, 0 if it is not.  If the modifier
1892  * index is not valid in the keymap, returns -1.
1893  *
1894  * @sa xkb_state_mod_mask_remove_consumed()
1895  * @sa xkb_state_key_get_consumed_mods()
1896  * @memberof xkb_state
1897  * @since 0.7.0
1898  */
1899 int
1900 xkb_state_mod_index_is_consumed2(struct xkb_state *state,
1901                                  xkb_keycode_t key,
1902                                  xkb_mod_index_t idx,
1903                                  enum xkb_consumed_mode mode);
1904
1905 /**
1906  * Same as xkb_state_mod_index_is_consumed2() with mode XKB_CONSUMED_MOD_XKB.
1907  *
1908  * @memberof xkb_state
1909  * @since 0.4.1
1910  */
1911 int
1912 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1913                                 xkb_mod_index_t idx);
1914
1915 /**
1916  * Remove consumed modifiers from a modifier mask for a key.
1917  *
1918  * @deprecated Use xkb_state_key_get_consumed_mods2() instead.
1919  *
1920  * Takes the given modifier mask, and removes all modifiers which are
1921  * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
1922  *
1923  * @sa xkb_state_mod_index_is_consumed()
1924  * @memberof xkb_state
1925  */
1926 xkb_mod_mask_t
1927 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1928                                    xkb_mod_mask_t mask);
1929
1930 /**
1931  * Test whether a layout is active in a given keyboard state by name.
1932  *
1933  * @returns 1 if the layout is active, 0 if it is not.  If no layout with
1934  * this name exists in the keymap, return -1.
1935  *
1936  * If multiple layouts in the keymap have this name, the one with the lowest
1937  * index is tested.
1938  *
1939  * @sa xkb_layout_index_t
1940  * @memberof xkb_state
1941  */
1942 int
1943 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1944                                 enum xkb_state_component type);
1945
1946 /**
1947  * Test whether a layout is active in a given keyboard state by index.
1948  *
1949  * @returns 1 if the layout is active, 0 if it is not.  If the layout index
1950  * is not valid in the keymap, returns -1.
1951  *
1952  * @sa xkb_layout_index_t
1953  * @memberof xkb_state
1954  */
1955 int
1956 xkb_state_layout_index_is_active(struct xkb_state *state,
1957                                  xkb_layout_index_t idx,
1958                                  enum xkb_state_component type);
1959
1960 /**
1961  * Test whether a LED is active in a given keyboard state by name.
1962  *
1963  * @returns 1 if the LED is active, 0 if it not.  If no LED with this name
1964  * exists in the keymap, returns -1.
1965  *
1966  * @sa xkb_led_index_t
1967  * @memberof xkb_state
1968  */
1969 int
1970 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1971
1972 /**
1973  * Test whether a LED is active in a given keyboard state by index.
1974  *
1975  * @returns 1 if the LED is active, 0 if it not.  If the LED index is not
1976  * valid in the keymap, returns -1.
1977  *
1978  * @sa xkb_led_index_t
1979  * @memberof xkb_state
1980  */
1981 int
1982 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1983
1984 /** @} */
1985
1986 /* Leave this include last, so it can pick up our types, etc. */
1987 #include <xkbcommon/xkbcommon-compat.h>
1988
1989 #ifdef __cplusplus
1990 } /* extern "C" */
1991 #endif
1992
1993 #endif /* _XKBCOMMON_H_ */