doc: extend xkb_rule_names default-value description
[platform/upstream/libxkbcommon.git] / 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  * @code
156  * xkb_keycode_t keycode_A = KEY_A + 8;
157  * @endcode
158  *
159  * @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()
160  */
161 typedef uint32_t xkb_keycode_t;
162
163 /**
164  * A number used to represent the symbols generated from a key on a keyboard.
165  *
166  * A key, represented by a keycode, may generate different symbols according
167  * to keyboard state.  For example, on a QWERTY keyboard, pressing the key
168  * labled \<A\> generates the symbol 'a'.  If the Shift key is held, it
169  * generates the symbol 'A'.  If a different layout is used, say Greek,
170  * it generates the symbol 'α'.  And so on.
171  *
172  * Each such symbol is represented by a keysym.  Note that keysyms are
173  * somewhat more general, in that they can also represent some "function",
174  * such as "Left" or "Right" for the arrow keys.  For more information,
175  * see:
176  * http://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#keysym_encoding
177  *
178  * Specifically named keysyms can be found in the
179  * xkbcommon/xkbcommon-keysyms.h header file.  Their name does not include
180  * the XKB_KEY_ prefix.
181  *
182  * Besides those, any Unicode/ISO 10646 character in the range U0100 to
183  * U10FFFF can be represented by a keysym value in the range 0x01000100 to
184  * 0x0110FFFF.  The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".
185  *
186  * The name of other unnamed keysyms is the hexadecimal representation of
187  * their value, e.g. "0xabcd1234".
188  *
189  * Keysym names are case-sensitive.
190  */
191 typedef uint32_t xkb_keysym_t;
192
193 /**
194  * Index of a keyboard layout.
195  *
196  * The layout index is a state component which detemines which <em>keyboard
197  * layout</em> is active.  These may be different alphabets, different key
198  * arrangements, etc.
199  *
200  * Layout indices are consecutive.  The first layout has index 0.
201  *
202  * Each layout is not required to have a name, and the names are not
203  * guaranteed to be unique (though they are usually provided and unique).
204  * Therefore, it is not safe to use the name as a unique identifier for a
205  * layout.  Layout names are case-sensitive.
206  *
207  * Layouts are also called "groups" by XKB.
208  *
209  * @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()
210  */
211 typedef uint32_t xkb_layout_index_t;
212 /** A mask of layout indices. */
213 typedef uint32_t xkb_layout_mask_t;
214
215 /**
216  * Index of a shift level.
217  *
218  * Any key, in any layout, can have several <em>shift levels</em>.  Each
219  * shift level can assign different keysyms to the key.  The shift level
220  * to use is chosen according to the current keyboard state; for example,
221  * if no keys are pressed, the first level may be used; if the Left Shift
222  * key is pressed, the second; if Num Lock is pressed, the third; and
223  * many such combinations are possible (see xkb_mod_index_t).
224  *
225  * Level indices are consecutive.  The first level has index 0.
226  */
227 typedef uint32_t xkb_level_index_t;
228
229 /**
230  * Index of a modifier.
231  *
232  * A @e modifier is a state component which changes the way keys are
233  * interpreted.  A keymap defines a set of modifiers, such as Alt, Shift,
234  * Num Lock or Meta, and specifies which keys may @e activate which
235  * modifiers (in a many-to-many relationship, i.e. a key can activate
236  * several modifiers, and a modifier may be activated by several keys.
237  * Different keymaps do this differently).
238  *
239  * When retrieving the keysyms for a key, the active modifier set is
240  * consulted; this detemines the correct shift level to use within the
241  * currently active layout (see xkb_level_index_t).
242  *
243  * Modifier indices are consecutive.  The first modifier has index 0.
244  *
245  * Each modifier must have a name, and the names are unique.  Therefore, it
246  * is safe to use the name as a unique identifier for a modifier.  The names
247  * of some common modifiers are provided in the xkbcommon/xkbcommon-names.h
248  * header file.  Modifier names are case-sensitive.
249  *
250  * @sa xkb_keymap_num_mods()
251  */
252 typedef uint32_t xkb_mod_index_t;
253 /** A mask of modifier indices. */
254 typedef uint32_t xkb_mod_mask_t;
255
256 /**
257  * Index of a keyboard LED.
258  *
259  * LEDs are logical objects which may be @e active or @e inactive.  They
260  * typically correspond to the lights on the keyboard. Their state is
261  * determined by the current keyboard state.
262  *
263  * LED indices are non-consecutive.  The first LED has index 0.
264  *
265  * Each LED must have a name, and the names are unique. Therefore,
266  * it is safe to use the name as a unique identifier for a LED.  The names
267  * of some common LEDs are provided in the xkbcommon/xkbcommon-names.h
268  * header file.  LED names are case-sensitive.
269  *
270  * @warning A given keymap may specify an exact index for a given LED.
271  * Therefore, LED indexing is not necessarily sequential, as opposed to
272  * modifiers and layouts.  This means that when iterating over the LEDs
273  * in a keymap using e.g. xkb_keymap_num_leds(), some indices might be
274  * invalid.  Given such an index, functions like xkb_keymap_led_get_name()
275  * will return NULL, and xkb_state_led_index_is_active() will return -1.
276  *
277  * LEDs are also called "indicators" by XKB.
278  *
279  * @sa xkb_keymap_num_leds()
280  */
281 typedef uint32_t xkb_led_index_t;
282 /** A mask of LED indices. */
283 typedef uint32_t xkb_led_mask_t;
284
285 #define XKB_KEYCODE_INVALID (0xffffffff)
286 #define XKB_LAYOUT_INVALID  (0xffffffff)
287 #define XKB_LEVEL_INVALID   (0xffffffff)
288 #define XKB_MOD_INVALID     (0xffffffff)
289 #define XKB_LED_INVALID     (0xffffffff)
290
291 #define XKB_KEYCODE_MAX     (0xffffffff - 1)
292
293 /**
294  * Test whether a value is a valid extended keycode.
295  * @sa xkb_keycode_t
296  **/
297 #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
298
299 /**
300  * Test whether a value is a valid X11 keycode.
301  * @sa xkb_keycode_t
302  */
303 #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
304
305 /**
306  * Names to compile a keymap with, also known as RMLVO.
307  *
308  * The names are the common configuration values by which a user picks
309  * a keymap.
310  *
311  * If the entire struct is NULL, then each field is taken to be NULL.
312  * You should prefer passing NULL instead of choosing your own defaults.
313  */
314 struct xkb_rule_names {
315     /**
316      * The rules file to use. The rules file describes how to interpret
317      * the values of the model, layout, variant and options fields.
318      *
319      * If NULL or the empty string "", a default value is used.
320      * If the XKB_DEFAULT_RULES environment variable is set, it is used
321      * as the default.  Otherwise the system default is used.
322      */
323     const char *rules;
324     /**
325      * The keyboard model by which to interpret keycodes and LEDs.
326      *
327      * If NULL or the empty string "", a default value is used.
328      * If the XKB_DEFAULT_MODEL environment variable is set, it is used
329      * as the default.  Otherwise the system default is used.
330      */
331     const char *model;
332     /**
333      * A comma separated list of layouts (languages) to include in the
334      * keymap.
335      *
336      * If NULL or the empty string "", a default value is used.
337      * If the XKB_DEFAULT_LAYOUT environment variable is set, it is used
338      * as the default.  Otherwise the system default is used.
339      */
340     const char *layout;
341     /**
342      * A comma separated list of variants, one per layout, which may
343      * modify or augment the respective layout in various ways.
344      *
345      * If NULL or the empty string "", and a default value is also used
346      * for the layout, a default value is used.  Otherwise no variant is
347      * used.
348      * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
349      * as the default.  Otherwise the system default is used.
350      */
351     const char *variant;
352     /**
353      * A comma separated list of options, through which the user specifies
354      * non-layout related preferences, like which key combinations are used
355      * for switching layouts, or which key is the Compose key.
356      *
357      * If NULL, a default value is used.  If the empty string "", no
358      * options are used.
359      * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
360      * as the default.  Otherwise the system default is used.
361      */
362     const char *options;
363 };
364
365 /**
366  * @defgroup keysyms Keysyms
367  * Utility functions related to keysyms.
368  *
369  * @{
370  */
371
372 /**
373  * Get the name of a keysym.
374  *
375  * For a description of how keysyms are named, see @ref xkb_keysym_t.
376  *
377  * @param[in]  keysym The keysym.
378  * @param[out] buffer A string buffer to write the name into.
379  * @param[in]  size   Size of the buffer.
380  *
381  * @warning If the buffer passed is too small, the string is truncated
382  * (though still NUL-terminated); a size of at least 64 bytes is recommended.
383  *
384  * @returns The number of bytes in the name, excluding the NUL byte. If
385  * the keysym is invalid, returns -1.
386  *
387  * You may check if truncation has occurred by comparing the return value
388  * with the length of buffer, similarly to the snprintf(3) function.
389  *
390  * @sa xkb_keysym_t
391  */
392 int
393 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
394
395 /** Flags for xkb_keysym_from_name(). */
396 enum xkb_keysym_flags {
397     /** Do not apply any flags. */
398     XKB_KEYSYM_NO_FLAGS = 0,
399     /** Find keysym by case-insensitive search. */
400     XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
401 };
402
403 /**
404  * Get a keysym from its name.
405  *
406  * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
407  * this function will accept any name returned by that function.
408  * @param flags A set of flags controlling how the search is done. If
409  * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
410  *
411  * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
412  * differ only by case, then the lower-case keysym is returned.  For
413  * instance, for KEY_a and KEY_A, this function would return KEY_a for the
414  * case-insensitive search.  If this functionality is needed, it is
415  * recommended to first call this function without this flag; and if that
416  * fails, only then to try with this flag, while possibly warning the user
417  * he had misspelled the name, and might get wrong results.
418  *
419  * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
420  *
421  * @sa xkb_keysym_t
422  */
423 xkb_keysym_t
424 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
425
426 /**
427  * Get the Unicode/UTF-8 representation of a keysym.
428  *
429  * @param[in]  keysym The keysym.
430  * @param[out] buffer A buffer to write the UTF-8 string into.
431  * @param[in]  size   The size of buffer.  Must be at least 7.
432  *
433  * @returns The number of bytes written to the buffer (including the
434  * terminating byte).  If the keysym does not have a Unicode
435  * representation, returns 0.  If the buffer is too small, returns -1.
436  */
437 int
438 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
439
440 /**
441  * Get the Unicode/UTF-32 representation of a keysym.
442  *
443  * @returns The Unicode/UTF-32 representation of keysym, which is also
444  * compatible with UCS-4.  If the keysym does not have a Unicode
445  * representation, returns 0.
446  */
447 uint32_t
448 xkb_keysym_to_utf32(xkb_keysym_t keysym);
449
450 /** @} */
451
452 /**
453  * @defgroup context Library Context
454  * Creating, destroying and using library contexts.
455  *
456  * Every keymap compilation request must have a context associated with
457  * it.  The context keeps around state such as the include path.
458  *
459  * @{
460  */
461
462 /** Flags for context creation. */
463 enum xkb_context_flags {
464     /** Do not apply any context flags. */
465     XKB_CONTEXT_NO_FLAGS = 0,
466     /** Create this context with an empty include path. */
467     XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
468     /** Don't take RMLVO names from the environment. */
469     XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1),
470 };
471
472 /**
473  * Create a new context.
474  *
475  * @param flags Optional flags for the context, or 0.
476  *
477  * @returns A new context, or NULL on failure.
478  *
479  * The user may set some environment variables to affect default values in
480  * the context. See e.g. xkb_context_set_log_level() and
481  * xkb_context_set_log_verbosity().
482  *
483  * @memberof xkb_context
484  */
485 struct xkb_context *
486 xkb_context_new(enum xkb_context_flags flags);
487
488 /**
489  * Take a new reference on a context.
490  *
491  * @returns The passed in context.
492  *
493  * @memberof xkb_context
494  */
495 struct xkb_context *
496 xkb_context_ref(struct xkb_context *context);
497
498 /**
499  * Release a reference on a context, and possibly free it.
500  *
501  * @param context The context.  If it is NULL, this function does nothing.
502  *
503  * @memberof xkb_context
504  */
505 void
506 xkb_context_unref(struct xkb_context *context);
507
508 /**
509  * Store custom user data in the context.
510  *
511  * This may be useful in conjunction with xkb_context_set_log_fn() or other
512  * callbacks.
513  *
514  * @memberof xkb_context
515  */
516 void
517 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
518
519 /**
520  * Retrieves stored user data from the context.
521  *
522  * @returns The stored user data.  If the user data wasn't set, or the
523  * passed in context is NULL, returns NULL.
524  *
525  * This may be useful to access private user data from callbacks like a
526  * custom logging function.
527  *
528  * @memberof xkb_context
529  **/
530 void *
531 xkb_context_get_user_data(struct xkb_context *context);
532
533 /** @} */
534
535 /**
536  * @defgroup include-path Include Paths
537  * Manipulating the include paths in a context.
538  *
539  * The include paths are the file-system paths that are searched when an
540  * include statement is encountered during keymap compilation.
541  * In most cases, the default include paths are sufficient.
542  *
543  * @{
544  */
545
546 /**
547  * Append a new entry to the context's include path.
548  *
549  * @returns 1 on success, or 0 if the include path could not be added or is
550  * inaccessible.
551  *
552  * @memberof xkb_context
553  */
554 int
555 xkb_context_include_path_append(struct xkb_context *context, const char *path);
556
557 /**
558  * Append the default include paths to the context's include path.
559  *
560  * @returns 1 on success, or 0 if the primary include path could not be added.
561  *
562  * @memberof xkb_context
563  */
564 int
565 xkb_context_include_path_append_default(struct xkb_context *context);
566
567 /**
568  * Reset the context's include path to the default.
569  *
570  * Removes all entries from the context's include path, and inserts the
571  * default paths.
572  *
573  * @returns 1 on success, or 0 if the primary include path could not be added.
574  *
575  * @memberof xkb_context
576  */
577 int
578 xkb_context_include_path_reset_defaults(struct xkb_context *context);
579
580 /**
581  * Remove all entries from the context's include path.
582  *
583  * @memberof xkb_context
584  */
585 void
586 xkb_context_include_path_clear(struct xkb_context *context);
587
588 /**
589  * Get the number of paths in the context's include path.
590  *
591  * @memberof xkb_context
592  */
593 unsigned int
594 xkb_context_num_include_paths(struct xkb_context *context);
595
596 /**
597  * Get a specific include path from the context's include path.
598  *
599  * @returns The include path at the specified index.  If the index is
600  * invalid, returns NULL.
601  *
602  * @memberof xkb_context
603  */
604 const char *
605 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
606
607 /** @} */
608
609 /**
610  * @defgroup logging Logging Handling
611  * Manipulating how logging from this library is handled.
612  *
613  * @{
614  */
615
616 /** Specifies a logging level. */
617 enum xkb_log_level {
618     XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
619     XKB_LOG_LEVEL_ERROR = 20,    /**< Log all errors. */
620     XKB_LOG_LEVEL_WARNING = 30,  /**< Log warnings and errors. */
621     XKB_LOG_LEVEL_INFO = 40,     /**< Log information, warnings, and errors. */
622     XKB_LOG_LEVEL_DEBUG = 50     /**< Log everything. */
623 };
624
625 /**
626  * Set the current logging level.
627  *
628  * @param context The context in which to set the logging level.
629  * @param level   The logging level to use.  Only messages from this level
630  * and below will be logged.
631  *
632  * The default level is XKB_LOG_LEVEL_ERROR.  The environment variable
633  * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
634  * default value.  It may be specified as a level number or name.
635  *
636  * @memberof xkb_context
637  */
638 void
639 xkb_context_set_log_level(struct xkb_context *context,
640                           enum xkb_log_level level);
641
642 /**
643  * Get the current logging level.
644  *
645  * @memberof xkb_context
646  */
647 enum xkb_log_level
648 xkb_context_get_log_level(struct xkb_context *context);
649
650 /**
651  * Sets the current logging verbosity.
652  *
653  * The library can generate a number of warnings which are not helpful to
654  * ordinary users of the library.  The verbosity may be increased if more
655  * information is desired (e.g. when developing a new keymap).
656  *
657  * The default verbosity is 0.  The environment variable XKB_LOG_VERBOSITY,
658  * if set in the time the context was created, overrides the default value.
659  *
660  * @param context   The context in which to use the set verbosity.
661  * @param verbosity The verbosity to use.  Currently used values are
662  * 1 to 10, higher values being more verbose.  0 would result in no verbose
663  * messages being logged.
664  *
665  * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
666  *
667  * @memberof xkb_context
668  */
669 void
670 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
671
672 /**
673  * Get the current logging verbosity of the context.
674  *
675  * @memberof xkb_context
676  */
677 int
678 xkb_context_get_log_verbosity(struct xkb_context *context);
679
680 /**
681  * Set a custom function to handle logging messages.
682  *
683  * @param context The context in which to use the set logging function.
684  * @param log_fn  The function that will be called for logging messages.
685  * Passing NULL restores the default function, which logs to stderr.
686  *
687  * By default, log messages from this library are printed to stderr.  This
688  * function allows you to replace the default behavior with a custom
689  * handler.  The handler is only called with messages which match the
690  * current logging level and verbosity settings for the context.
691  * level is the logging level of the message.  @a format and @a args are
692  * the same as in the vprintf(3) function.
693  *
694  * You may use xkb_context_set_user_data() on the context, and then call
695  * xkb_context_get_user_data() from within the logging function to provide
696  * it with additional private context.
697  *
698  * @memberof xkb_context
699  */
700 void
701 xkb_context_set_log_fn(struct xkb_context *context,
702                        void (*log_fn)(struct xkb_context *context,
703                                       enum xkb_log_level level,
704                                       const char *format, va_list args));
705
706 /** @} */
707
708 /**
709  * @defgroup keymap Keymap Creation
710  * Creating and destroying keymaps.
711  *
712  * @{
713  */
714
715 /** Flags for keymap compilation. */
716 enum xkb_keymap_compile_flags {
717     /** Do not apply any flags. */
718     XKB_KEYMAP_COMPILE_NO_FLAGS = 0
719 };
720
721 /**
722  * Create a keymap from RMLVO names.
723  *
724  * The primary keymap entry point: creates a new XKB keymap from a set of
725  * RMLVO (Rules + Model + Layouts + Variants + Options) names.
726  *
727  * @param context The context in which to create the keymap.
728  * @param names   The RMLVO names to use.  See xkb_rule_names.
729  * @param flags   Optional flags for the keymap, or 0.
730  *
731  * @returns A keymap compiled according to the RMLVO names, or NULL if
732  * the compilation failed.
733  *
734  * @sa xkb_rule_names
735  * @memberof xkb_keymap
736  */
737 struct xkb_keymap *
738 xkb_keymap_new_from_names(struct xkb_context *context,
739                           const struct xkb_rule_names *names,
740                           enum xkb_keymap_compile_flags flags);
741
742 /** The possible keymap formats. */
743 enum xkb_keymap_format {
744     /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
745     XKB_KEYMAP_FORMAT_TEXT_V1 = 1
746 };
747
748 /**
749  * Create a keymap from a keymap file.
750  *
751  * @param context The context in which to create the keymap.
752  * @param file    The keymap file to compile.
753  * @param format  The text format of the keymap file to compile.
754  * @param flags   Optional flags for the keymap, or 0.
755  *
756  * @returns A keymap compiled from the given XKB keymap file, or NULL if
757  * the compilation failed.
758  *
759  * The file must contain a complete keymap.  For example, in the
760  * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
761  * top level '%xkb_keymap' section, which in turn contains other required
762  * sections.
763  *
764  * @memberof xkb_keymap
765  */
766 struct xkb_keymap *
767 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
768                          enum xkb_keymap_format format,
769                          enum xkb_keymap_compile_flags flags);
770
771 /**
772  * Create a keymap from a keymap string.
773  *
774  * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
775  * the keymap as one enormous string.
776  *
777  * @see xkb_keymap_new_from_string()
778  * @memberof xkb_keymap
779  */
780 struct xkb_keymap *
781 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
782                            enum xkb_keymap_format format,
783                            enum xkb_keymap_compile_flags flags);
784
785 /**
786  * Create a keymap from a memory buffer.
787  *
788  * This is just like xkb_keymap_new_from_string(), but takes a length argument
789  * so the input string does not have to be zero-terminated.
790  *
791  * @see xkb_keymap_new_from_string()
792  * @memberof xkb_keymap
793  */
794 struct xkb_keymap *
795 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
796                            size_t length, enum xkb_keymap_format format,
797                            enum xkb_keymap_compile_flags flags);
798
799 /**
800  * Take a new reference on a keymap.
801  *
802  * @returns The passed in keymap.
803  *
804  * @memberof xkb_keymap
805  */
806 struct xkb_keymap *
807 xkb_keymap_ref(struct xkb_keymap *keymap);
808
809 /**
810  * Release a reference on a keymap, and possibly free it.
811  *
812  * @param keymap The keymap.  If it is NULL, this function does nothing.
813  *
814  * @memberof xkb_keymap
815  */
816 void
817 xkb_keymap_unref(struct xkb_keymap *keymap);
818
819 /**
820  * Get the keymap as a string in the format from which it was created.
821  * @sa xkb_keymap_get_as_string()
822  **/
823 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
824
825 /**
826  * Get the compiled keymap as a string.
827  *
828  * @param keymap The keymap to get as a string.
829  * @param format The keymap format to use for the string.  You can pass
830  * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
831  * from which the keymap was originally created.
832  *
833  * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
834  *
835  * The returned string may be fed back into xkb_map_new_from_string() to get
836  * the exact same keymap (possibly in another process, etc.).
837  *
838  * The returned string is dynamically allocated and should be freed by the
839  * caller.
840  *
841  * @memberof xkb_keymap
842  */
843 char *
844 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
845                          enum xkb_keymap_format format);
846
847 /** @} */
848
849 /**
850  * @defgroup components Keymap Components
851  * Enumeration of state components in a keymap.
852  *
853  * @{
854  */
855
856 /**
857  * Get the minimum keycode in the keymap.
858  *
859  * @sa xkb_keycode_t
860  * @memberof xkb_keymap
861  */
862 xkb_keycode_t
863 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
864
865 /**
866  * Get the maximum keycode in the keymap.
867  *
868  * @sa xkb_keycode_t
869  * @memberof xkb_keymap
870  */
871 xkb_keycode_t
872 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
873
874 /**
875  * The iterator used by xkb_keymap_key_for_each().
876  *
877  * @sa xkb_keymap_key_for_each
878  * @memberof xkb_keymap
879  */
880 typedef void
881 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
882                          void *data);
883
884 /**
885  * Run a specified function for every valid keycode in the keymap.  If a
886  * keymap is sparse, this function may be called fewer than
887  * (max_keycode - min_keycode + 1) times.
888  *
889  * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
890  * @memberof xkb_keymap
891  */
892 void
893 xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
894                         void *data);
895
896 /**
897  * Get the number of modifiers in the keymap.
898  *
899  * @sa xkb_mod_index_t
900  * @memberof xkb_keymap
901  */
902 xkb_mod_index_t
903 xkb_keymap_num_mods(struct xkb_keymap *keymap);
904
905 /**
906  * Get the name of a modifier by index.
907  *
908  * @returns The name.  If the index is invalid, returns NULL.
909  *
910  * @sa xkb_mod_index_t
911  * @memberof xkb_keymap
912  */
913 const char *
914 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
915
916 /**
917  * Get the index of a modifier by name.
918  *
919  * @returns The index.  If no modifier with this name exists, returns
920  * XKB_MOD_INVALID.
921  *
922  * @sa xkb_mod_index_t
923  * @memberof xkb_keymap
924  */
925 xkb_mod_index_t
926 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
927
928 /**
929  * Get the number of layouts in the keymap.
930  *
931  * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
932  * @memberof xkb_keymap
933  */
934 xkb_layout_index_t
935 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
936
937 /**
938  * Get the name of a layout by index.
939  *
940  * @returns The name.  If the index is invalid, or the layout does not have
941  * a name, returns NULL.
942  *
943  * @sa xkb_layout_index_t
944  * @memberof xkb_keymap
945  */
946 const char *
947 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
948
949 /**
950  * Get the index of a layout by name.
951  *
952  * @returns The index.  If no layout exists with this name, returns
953  * XKB_LAYOUT_INVALID.  If more than one layout in the keymap has this name,
954  * returns the lowest index among them.
955  *
956  * @memberof xkb_keymap
957  */
958 xkb_layout_index_t
959 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
960
961 /**
962  * Get the number of layouts for a specific key.
963  *
964  * This number can be different from xkb_keymap_num_layouts(), but is always
965  * smaller.  It is the appropriate value to use when iterating over the
966  * layouts of a key.
967  *
968  * @sa xkb_layout_index_t
969  * @memberof xkb_keymap
970  */
971 xkb_layout_index_t
972 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
973
974 /**
975  * Get the number of shift levels for a specific key and layout.
976  *
977  * If @c layout is out of range for this key (that is, larger or equal to
978  * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
979  * back into range in a manner consistent with xkb_state_key_get_layout().
980  *
981  * @sa xkb_level_index_t
982  * @memberof xkb_keymap
983  */
984 xkb_level_index_t
985 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
986                               xkb_layout_index_t layout);
987
988 /**
989  * Get the keysyms obtained from pressing a key in a given layout and
990  * shift level.
991  *
992  * This function is like xkb_state_key_get_syms(), only the layout and
993  * shift level are not derived from the keyboard state but are instead
994  * specified explicitly.
995  *
996  * @param[in] keymap    The keymap.
997  * @param[in] key       The keycode of the key.
998  * @param[in] layout    The layout for which to get the keysyms.
999  * @param[in] level     The shift level in the layout for which to get the
1000  * keysyms. This must be smaller than:
1001  * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1002  * @param[out] syms_out An immutible array of keysyms corresponding to the
1003  * key in the given layout and shift level.
1004  *
1005  * If @c layout is out of range for this key (that is, larger or equal to
1006  * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
1007  * back into range in a manner consistent with xkb_state_key_get_layout().
1008  *
1009  * @returns The number of keysyms in the syms_out array.  If no keysyms
1010  * are produced by the key in the given layout and shift level, returns 0
1011  * and sets syms_out to NULL.
1012  *
1013  * @sa xkb_state_key_get_syms()
1014  * @memberof xkb_keymap
1015  */
1016 int
1017 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
1018                                  xkb_keycode_t key,
1019                                  xkb_layout_index_t layout,
1020                                  xkb_level_index_t level,
1021                                  const xkb_keysym_t **syms_out);
1022
1023 /**
1024  * Get the number of LEDs in the keymap.
1025  *
1026  * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
1027  * in the keymap, but may also contain inactive LEDs.  When iterating over
1028  * this range, you need the handle this case when calling functions such as
1029  * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
1030  *
1031  * @sa xkb_led_index_t
1032  * @memberof xkb_keymap
1033  */
1034 xkb_led_index_t
1035 xkb_keymap_num_leds(struct xkb_keymap *keymap);
1036
1037 /**
1038  * Get the name of a LED by index.
1039  *
1040  * @returns The name.  If the index is invalid, returns NULL.
1041  *
1042  * @memberof xkb_keymap
1043  */
1044 const char *
1045 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1046
1047 /**
1048  * Get the index of a LED by name.
1049  *
1050  * @returns The index.  If no LED with this name exists, returns
1051  * XKB_LED_INVALID.
1052  *
1053  * @memberof xkb_keymap
1054  */
1055 xkb_led_index_t
1056 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1057
1058 /**
1059  * Determine whether a key should repeat or not.
1060  *
1061  * A keymap may specify different repeat behaviors for different keys.
1062  * Most keys should generally exhibit repeat behavior; for example, holding
1063  * the 'a' key down in a text editor should normally insert a single 'a'
1064  * character every few milliseconds, until the key is released.  However,
1065  * there are keys which should not or do not need to be repeated.  For
1066  * example, repeating modifier keys such as Left/Right Shift or Caps Lock
1067  * is not generally useful or desired.
1068  *
1069  * @returns 1 if the key should repeat, 0 otherwise.
1070  *
1071  * @memberof xkb_keymap
1072  */
1073 int
1074 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1075
1076 /** @} */
1077
1078 /**
1079  * @defgroup state Keyboard State
1080  * Creating, destroying and manipulating keyboard state objects.
1081  *
1082  * @{
1083  */
1084
1085 /**
1086  * Create a new keyboard state object.
1087  *
1088  * @param keymap The keymap which the state will use.
1089  *
1090  * @returns A new keyboard state object, or NULL on failure.
1091  *
1092  * @memberof xkb_state
1093  */
1094 struct xkb_state *
1095 xkb_state_new(struct xkb_keymap *keymap);
1096
1097 /**
1098  * Take a new reference on a keyboard state object.
1099  *
1100  * @returns The passed in object.
1101  *
1102  * @memberof xkb_state
1103  */
1104 struct xkb_state *
1105 xkb_state_ref(struct xkb_state *state);
1106
1107 /**
1108  * Release a reference on a keybaord state object, and possibly free it.
1109  *
1110  * @param state The state.  If it is NULL, this function does nothing.
1111  *
1112  * @memberof xkb_state
1113  */
1114 void
1115 xkb_state_unref(struct xkb_state *state);
1116
1117 /**
1118  * Get the keymap which a keyboard state object is using.
1119  *
1120  * @returns The keymap which was passed to xkb_state_new() when creating
1121  * this state object.
1122  *
1123  * This function does not take a new reference on the keymap; you must
1124  * explicitly reference it yourself if you plan to use it beyond the
1125  * lifetime of the state.
1126  *
1127  * @memberof xkb_state
1128  */
1129 struct xkb_keymap *
1130 xkb_state_get_keymap(struct xkb_state *state);
1131
1132 /** Specifies the direction of the key (press / release). */
1133 enum xkb_key_direction {
1134     XKB_KEY_UP,   /**< The key was released. */
1135     XKB_KEY_DOWN  /**< The key was pressed. */
1136 };
1137
1138 /**
1139  * Modifier and layout types for state objects.  This enum is bitmaskable,
1140  * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
1141  * exclude locked modifiers.
1142  *
1143  * In XKB, the DEPRESSED components are also known as 'base'.
1144  */
1145 enum xkb_state_component {
1146     /** Depressed modifiers, i.e. a key is physically holding them. */
1147     XKB_STATE_MODS_DEPRESSED = (1 << 0),
1148     /** Latched modifiers, i.e. will be unset after the next non-modifier
1149      *  key press. */
1150     XKB_STATE_MODS_LATCHED = (1 << 1),
1151     /** Locked modifiers, i.e. will be unset after the key provoking the
1152      *  lock has been pressed again. */
1153     XKB_STATE_MODS_LOCKED = (1 << 2),
1154     /** Effective modifiers, i.e. currently active and affect key
1155      *  processing (derived from the other state components).
1156      *  Use this unless you explictly care how the state came about. */
1157     XKB_STATE_MODS_EFFECTIVE = (1 << 3),
1158     /** Depressed layout, i.e. a key is physically holding it. */
1159     XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
1160     /** Latched layout, i.e. will be unset after the next non-modifier
1161      *  key press. */
1162     XKB_STATE_LAYOUT_LATCHED = (1 << 5),
1163     /** Locked layout, i.e. will be unset after the key provoking the lock
1164      *  has been pressed again. */
1165     XKB_STATE_LAYOUT_LOCKED = (1 << 6),
1166     /** Effective layout, i.e. currently active and affects key processing
1167      *  (derived from the other state components).
1168      *  Use this unless you explictly care how the state came about. */
1169     XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
1170     /** LEDs (derived from the other state components). */
1171     XKB_STATE_LEDS = (1 << 8)
1172 };
1173
1174 /**
1175  * Update the keyboard state to reflect a given key being pressed or
1176  * released.
1177  *
1178  * This entry point is intended for programs which track the keyboard state
1179  * explictly (like an evdev client).  If the state is serialized to you by
1180  * a master process (like a Wayland compositor) using functions like
1181  * xkb_state_serialize_mods(), you should use xkb_state_update_mask() instead.
1182  * The two functins should not generally be used together.
1183  *
1184  * A series of calls to this function should be consistent; that is, a call
1185  * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
1186  * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
1187  * to missed input events), situations like "stuck modifiers" may occur.
1188  *
1189  * This function is often used in conjunction with the function
1190  * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
1191  * when handling a key event.  In this case, you should prefer to get the
1192  * keysyms *before* updating the key, such that the keysyms reported for
1193  * the key event are not affected by the event itself.  This is the
1194  * conventional behavior.
1195  *
1196  * @returns A mask of state components that have changed as a result of
1197  * the update.  If nothing in the state has changed, returns 0.
1198  *
1199  * @memberof xkb_state
1200  *
1201  * @sa xkb_state_update_mask()
1202  */
1203 enum xkb_state_component
1204 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1205                      enum xkb_key_direction direction);
1206
1207 /**
1208  * Update a keyboard state from a set of explicit masks.
1209  *
1210  * This entry point is intended for window systems and the like, where a
1211  * master process holds an xkb_state, then serializes it over a wire
1212  * protocol, and clients then use the serialization to feed in to their own
1213  * xkb_state.
1214  *
1215  * All parameters must always be passed, or the resulting state may be
1216  * incoherent.
1217  *
1218  * The serialization is lossy and will not survive round trips; it must only
1219  * be used to feed slave state objects, and must not be used to update the
1220  * master state.
1221  *
1222  * If you do not fit the description above, you should use
1223  * xkb_state_update_key() instead.  The two functions should not generally be
1224  * used together.
1225  *
1226  * @returns A mask of state components that have changed as a result of
1227  * the update.  If nothing in the state has changed, returns 0.
1228  *
1229  * @memberof xkb_state
1230  *
1231  * @sa xkb_state_component
1232  * @sa xkb_state_update_key
1233  */
1234 enum xkb_state_component
1235 xkb_state_update_mask(struct xkb_state *state,
1236                       xkb_mod_mask_t depressed_mods,
1237                       xkb_mod_mask_t latched_mods,
1238                       xkb_mod_mask_t locked_mods,
1239                       xkb_layout_index_t depressed_layout,
1240                       xkb_layout_index_t latched_layout,
1241                       xkb_layout_index_t locked_layout);
1242
1243 /**
1244  * Get the keysyms obtained from pressing a particular key in a given
1245  * keyboard state.
1246  *
1247  * Get the keysyms for a key according to the current active layout,
1248  * modifiers and shift level for the key, as determined by a keyboard
1249  * state.
1250  *
1251  * @param[in]  state    The keyboard state object.
1252  * @param[in]  key      The keycode of the key.
1253  * @param[out] syms_out An immutable array of keysyms corresponding the
1254  * key in the given keyboard state.
1255  *
1256  * As an extension to XKB, this function can return more than one keysym.
1257  * If you do not want to handle this case, you should use
1258  * xkb_state_key_get_one_sym(), which additionally performs transformations
1259  * which are specific to the one-keysym case.
1260  *
1261  * @returns The number of keysyms in the syms_out array.  If no keysyms
1262  * are produced by the key in the given keyboard state, returns 0 and sets
1263  * syms_out to NULL.
1264  *
1265  * @memberof xkb_state
1266  */
1267 int
1268 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1269                        const xkb_keysym_t **syms_out);
1270
1271 /**
1272  * Get the single keysym obtained from pressing a particular key in a
1273  * given keyboard state.
1274  *
1275  * This function is similar to xkb_state_key_get_syms(), but intended
1276  * for users which cannot or do not want to handle the case where
1277  * multiple keysyms are returned (in which case this function is
1278  * preferred).
1279  *
1280  * @returns The keysym.  If the key does not have exactly one keysym,
1281  * returns XKB_KEY_NoSymbol
1282  *
1283  * @sa xkb_state_key_get_syms()
1284  * @memberof xkb_state
1285  */
1286 xkb_keysym_t
1287 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1288
1289 /**
1290  * Get the effective layout index for a key in a given keyboard state.
1291  *
1292  * @returns The layout index for the key in the given keyboard state.  If
1293  * the given keycode is invalid, or if the key is not included in any
1294  * layout at all, returns XKB_LAYOUT_INVALID.
1295  *
1296  * @invariant If the returned layout is valid, the following always holds:
1297  * @code
1298  * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
1299  * @endcode
1300  *
1301  * @memberof xkb_state
1302  */
1303 xkb_layout_index_t
1304 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1305
1306 /**
1307  * Get the effective shift level for a key in a given keyboard state and
1308  * layout.
1309  *
1310  * @param state The keyboard state.
1311  * @param key The keycode of the key.
1312  * @param layout The layout for which to get the shift level.  This must be
1313  * smaller than:
1314  * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
1315  * usually it would be:
1316  * @code xkb_state_key_get_layout(state, key) @endcode
1317  *
1318  * @return The shift level index.  If the key or layout are invalid,
1319  * returns XKB_LEVEL_INVALID.
1320  *
1321  * @invariant If the returned level is valid, the following always holds:
1322  * @code
1323  * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
1324  * @endcode
1325  *
1326  * @memberof xkb_state
1327  */
1328 xkb_level_index_t
1329 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1330                         xkb_layout_index_t layout);
1331
1332 /**
1333  * Match flags for xkb_state_mod_indices_are_active and
1334  * xkb_state_mod_names_are_active, specifying how the conditions for a
1335  * successful match.  XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
1336  * the other modes.
1337  */
1338 enum xkb_state_match {
1339     /** Returns true if any of the modifiers are active. */
1340     XKB_STATE_MATCH_ANY = (1 << 0),
1341     /** Returns true if all of the modifiers are active. */
1342     XKB_STATE_MATCH_ALL = (1 << 1),
1343     /** Makes matching non-exclusive, i.e. will not return false if a
1344      *  modifier not specified in the arguments is active. */
1345     XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
1346 };
1347
1348 /**
1349  * The counterpart to xkb_state_update_mask for modifiers, to be used on
1350  * the server side of serialization.
1351  *
1352  * @param state      The keyboard state.
1353  * @param components A mask of the modifier state components to serialize.
1354  * State components other than XKB_STATE_MODS_* are ignored.
1355  * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
1356  * ignored.
1357  *
1358  * @returns A xkb_mod_mask_t representing the given components of the
1359  * modifier state.
1360  *
1361  * This function should not be used in regular clients; please use the
1362  * xkb_state_mod_*_is_active API instead.
1363  *
1364  * @memberof xkb_state
1365  */
1366 xkb_mod_mask_t
1367 xkb_state_serialize_mods(struct xkb_state *state,
1368                          enum xkb_state_component components);
1369
1370 /**
1371  * The counterpart to xkb_state_update_mask for layouts, to be used on
1372  * the server side of serialization.
1373  *
1374  * @param state      The keyboard state.
1375  * @param components A mask of the layout state components to serialize.
1376  * State components other than XKB_STATE_LAYOUT_* are ignored.
1377  * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
1378  * ignored.
1379  *
1380  * @returns A layout index representing the given components of the
1381  * layout state.
1382  *
1383  * This function should not be used in regular clients; please use the
1384  * xkb_state_layout_*_is_active API instead.
1385  *
1386  * @memberof xkb_state
1387  */
1388 xkb_layout_index_t
1389 xkb_state_serialize_layout(struct xkb_state *state,
1390                            enum xkb_state_component components);
1391
1392 /**
1393  * Test whether a modifier is active in a given keyboard state by name.
1394  *
1395  * @returns 1 if the modifier is active, 0 if it is not.  If the modifier
1396  * name does not exist in the keymap, returns -1.
1397  *
1398  * @memberof xkb_state
1399  */
1400 int
1401 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1402                              enum xkb_state_component type);
1403
1404 /**
1405  * Test whether a set of modifiers are active in a given keyboard state by
1406  * name.
1407  *
1408  * @param state The keyboard state.
1409  * @param type  The component of the state against which to match the
1410  * given modifiers.
1411  * @param match The manner by which to match the state against the
1412  * given modifiers.
1413  * @param ...   The set of of modifier names to test, terminated by a NULL
1414  * argument (sentinel).
1415  *
1416  * @returns 1 if the modifiers are active, 0 if they are not.  If any of
1417  * the modifier names do not exist in the keymap, returns -1.
1418  *
1419  * @memberof xkb_state
1420  */
1421 int
1422 xkb_state_mod_names_are_active(struct xkb_state *state,
1423                                enum xkb_state_component type,
1424                                enum xkb_state_match match,
1425                                ...);
1426
1427 /**
1428  * Test whether a modifier is active in a given keyboard state by index.
1429  *
1430  * @returns 1 if the modifier is active, 0 if it is not.  If the modifier
1431  * index is invalid in the keymap, returns -1.
1432  *
1433  * @memberof xkb_state
1434  */
1435 int
1436 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1437                               enum xkb_state_component type);
1438
1439 /**
1440  * Test whether a set of modifiers are active in a given keyboard state by
1441  * index.
1442  *
1443  * @param state The keyboard state.
1444  * @param type  The component of the state against which to match the
1445  * given modifiers.
1446  * @param match The manner by which to match the state against the
1447  * given modifiers.
1448  * @param ...   The set of of modifier indices to test, terminated by a
1449  * XKB_MOD_INVALID argument (sentinel).
1450  *
1451  * @returns 1 if the modifiers are active, 0 if they are not.  If any of
1452  * the modifier indices are invalid in the keymap, returns -1.
1453  *
1454  * @memberof xkb_state
1455  */
1456 int
1457 xkb_state_mod_indices_are_active(struct xkb_state *state,
1458                                  enum xkb_state_component type,
1459                                  enum xkb_state_match match,
1460                                  ...);
1461
1462 /**
1463  * Test whether a modifier is consumed by keyboard state translation for
1464  * a key.
1465  *
1466  * Some functions, like xkb_state_key_get_syms(), look at the state of
1467  * the modifiers in the keymap and derive from it the correct shift level
1468  * to use for the key.  For example, in a US layout, pressing the key
1469  * labeled \<A\> while the Shift modifier is active, generates the keysym 'A'.
1470  * In this case, the Shift modifier is said to be consumed.  However, the
1471  * Num Lock modifier does not affect this translation at all, even if it
1472  * active, so it is not consumed by this translation.
1473  *
1474  * It may be desirable for some application to not reuse consumed modifiers
1475  * for further processing, e.g. for hotkeys or keyboard shortcuts. To
1476  * understand why, consider some requirements from a standard shortcut
1477  * mechanism, and how they are implemented:
1478  *
1479  * 1. The shortcut's modifiers must match exactly to the state. For example,
1480  *    it is possible to bind separate actions to \<Alt\>\<Tab\> and to
1481  *    \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is bound to
1482  *    an action, pressing \<Alt\>\<Shift\>\<Tab\> should not trigger the
1483  *    shortcut.
1484  *    Effectively, this means that the modifiers are compared using the
1485  *    equality operator (==).
1486  * 2. Only relevant modifiers are considered for the matching. For example,
1487  *    Caps Lock and Num Lock should not generally affect the matching, e.g.
1488  *    when matching \<Alt\>\<Tab\> against the state, it does not matter
1489  *    whether Num Lock is active or not. These relevant, or significant,
1490  *    modifiers usually include Alt, Control, Shift, Super and similar.
1491  *    Effectively, this means that non-significant modifiers are masked out,
1492  *    before doing the comparison as described above.
1493  * 3. The matching must be independent of the layout/keymap. For example,
1494  *    the \<Plus\> (+) symbol is found on the first level on some layouts,
1495  *    and requires holding Shift on others. If you simply bind the action
1496  *    to the \<Plus\> keysym, it would work for the unshifted kind, but
1497  *    not for the others, because the match against Shift would fail. If
1498  *    you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
1499  *    work. So what is needed is to recognize that Shift is used up in the
1500  *    translation of the keysym itself, and therefore should not be included
1501  *    in the matching.
1502  *    Effectively, this means that consumed modifiers (Shift in this example)
1503  *    are masked out as well, before doing the comparison.
1504  *
1505  * To summarize, this is how the matching would be performed:
1506  * @code
1507  *   (keysym == shortcut_keysym) &&
1508  *   ((state_modifiers & ~consumed_modifiers & significant_modifiers) == shortcut_modifiers)
1509  * @endcode
1510  *
1511  * @c state_modifiers are the modifiers reported by
1512  * xkb_state_mod_index_is_active() and similar functions.
1513  * @c consumed_modifiers are the modifiers reported by
1514  * xkb_state_mod_index_is_consumed().
1515  * @c significant_modifiers are decided upon by the application/toolkit/user;
1516  * it is up to them to decide whether these are configurable or hard-coded.
1517  *
1518  * @returns 1 if the modifier is consumed, 0 if it is not.  If the modifier
1519  * index is not valid in the keymap, returns -1.
1520  *
1521  * @sa xkb_state_mod_mask_remove_consumed()
1522  * @sa xkb_state_key_get_consumed_mods()
1523  * @memberof xkb_state
1524  */
1525 int
1526 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1527                                 xkb_mod_index_t idx);
1528
1529 /**
1530  * Remove consumed modifiers from a modifier mask for a key.
1531  *
1532  * Takes the given modifier mask, and removes all modifiers which are
1533  * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
1534  *
1535  * @sa xkb_state_mod_index_is_consumed()
1536  * @memberof xkb_state
1537  */
1538 xkb_mod_mask_t
1539 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1540                                    xkb_mod_mask_t mask);
1541
1542 /**
1543  * Get the mask of modifiers consumed by translating a given key.
1544  *
1545  * @returns a mask of the consumed modifiers.
1546  *
1547  * @sa xkb_state_mod_index_is_consumed()
1548  * @memberof xkb_state
1549  */
1550 xkb_mod_mask_t
1551 xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
1552
1553 /**
1554  * Test whether a layout is active in a given keyboard state by name.
1555  *
1556  * @returns 1 if the layout is active, 0 if it is not.  If no layout with
1557  * this name exists in the keymap, return -1.
1558  *
1559  * If multiple layouts in the keymap have this name, the one with the lowest
1560  * index is tested.
1561  *
1562  * @sa xkb_layout_index_t
1563  * @memberof xkb_state
1564  */
1565 int
1566 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1567                                 enum xkb_state_component type);
1568
1569 /**
1570  * Test whether a layout is active in a given keyboard state by index.
1571  *
1572  * @returns 1 if the layout is active, 0 if it is not.  If the layout index
1573  * is not valid in the keymap, returns -1.
1574  *
1575  * @sa xkb_layout_index_t
1576  * @memberof xkb_state
1577  */
1578 int
1579 xkb_state_layout_index_is_active(struct xkb_state *state,
1580                                  xkb_layout_index_t idx,
1581                                  enum xkb_state_component type);
1582
1583 /**
1584  * Test whether a LED is active in a given keyboard state by name.
1585  *
1586  * @returns 1 if the LED is active, 0 if it not.  If no LED with this name
1587  * exists in the keymap, returns -1.
1588  *
1589  * @sa xkb_led_index_t
1590  * @memberof xkb_state
1591  */
1592 int
1593 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1594
1595 /**
1596  * Test whether a LED is active in a given keyboard state by index.
1597  *
1598  * @returns 1 if the LED is active, 0 if it not.  If the LED index is not
1599  * valid in the keymap, returns -1.
1600  *
1601  * @sa xkb_led_index_t
1602  * @memberof xkb_state
1603  */
1604 int
1605 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1606
1607 /** @} */
1608
1609 /* Leave this include last, so it can pick up our types, etc. */
1610 #include <xkbcommon/xkbcommon-compat.h>
1611
1612 #ifdef __cplusplus
1613 } /* extern "C" */
1614 #endif
1615
1616 #endif /* _XKBCOMMON_H_ */