doc: use JAVADOC_AUTOBRIEF
[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  *
58  * Permission is hereby granted, free of charge, to any person obtaining a
59  * copy of this software and associated documentation files (the "Software"),
60  * to deal in the Software without restriction, including without limitation
61  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
62  * and/or sell copies of the Software, and to permit persons to whom the
63  * Software is furnished to do so, subject to the following conditions:
64  *
65  * The above copyright notice and this permission notice (including the next
66  * paragraph) shall be included in all copies or substantial portions of the
67  * Software.
68  *
69  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
70  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
71  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
72  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
73  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
74  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
75  * DEALINGS IN THE SOFTWARE.
76  *
77  * Author: Daniel Stone <daniel@fooishbar.org>
78  */
79
80 #ifndef _XKBCOMMON_H_
81 #define _XKBCOMMON_H_
82
83 #include <stdint.h>
84 #include <stdio.h>
85 #include <stdarg.h>
86
87 #include <xkbcommon/xkbcommon-names.h>
88 #include <xkbcommon/xkbcommon-keysyms.h>
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 /**
95  * @file
96  * Main libxkbcommon API.
97  */
98
99 /**
100  * @struct xkb_context
101  * Opaque top level library context object.
102  *
103  * The context contains various general library data and state, like
104  * logging level and include paths.
105  * Objects are created in a specific context, and multiple contexts may
106  * coexist simultaneously. Objects from different contexts are completely
107  * separated and do not share any memory or state.
108  * A context is created, accessed, manipulated and destroyed through the
109  * xkb_context_*() API.
110  */
111 struct xkb_context;
112
113 /**
114  * @struct xkb_keymap
115  * Opaque compiled XKB keymap object.
116  *
117  * The keymap object holds all of the static keyboard information obtained
118  * from compiling XKB files.
119  * A keymap is immutable after it is created (besides reference counts, etc.);
120  * if you need to change it, you must create a new one.
121  * A keymap object is created, accessed and destroyed through the
122  * xkb_keymap_*() API.
123  */
124 struct xkb_keymap;
125
126 /**
127  * @struct xkb_state
128  * Opaque XKB keyboard state object.
129  *
130  * State objects contain the active state of a keyboard (or keyboards), such
131  * as the currently effective layout and the active modifiers. It acts as a
132  * simple state machine, wherein key presses and releases are the input, and
133  * key symbols (keysyms) are the output.
134  * A state object is created, accessed, manipulated and destroyed through the
135  * xkb_state_*() API.
136  */
137 struct xkb_state;
138
139 typedef uint32_t xkb_keycode_t;
140 typedef uint32_t xkb_keysym_t;
141 typedef uint32_t xkb_mod_index_t;
142 typedef uint32_t xkb_mod_mask_t;
143 typedef uint32_t xkb_layout_index_t;
144 typedef uint32_t xkb_layout_mask_t;
145 typedef uint32_t xkb_level_index_t;
146 typedef uint32_t xkb_led_index_t;
147 typedef uint32_t xkb_led_mask_t;
148
149 #define XKB_MOD_INVALID     (0xffffffff)
150 #define XKB_LAYOUT_INVALID  (0xffffffff)
151 #define XKB_KEYCODE_INVALID (0xffffffff)
152 #define XKB_LEVEL_INVALID   (0xffffffff)
153 #define XKB_LED_INVALID     (0xffffffff)
154
155 #define XKB_KEYCODE_MAX     (0xffffffff - 1)
156 #define xkb_keycode_is_legal_ext(kc) (kc <= XKB_KEYCODE_MAX)
157 #define xkb_keycode_is_legal_x11(kc) (kc >= 8 && kc <= 255)
158
159 /**
160  * Names to compile a keymap with, also known as RMLVO.
161  *
162  * These names together are the primary identifier for a keymap.
163  * If any of the members is NULL or an empty string (""), a default value is
164  * used.
165  */
166 struct xkb_rule_names {
167     /** The rules file to use. The rules file describes how to interpret
168      *  the values of the model, layout, variant and options fields. */
169     const char *rules;
170     /** The keyboard model by which to interpret keycodes and LEDs. */
171     const char *model;
172     /** A comma seperated list of layouts (languages) to include in the
173      *  keymap. */
174     const char *layout;
175     /** A comma seperated list of variants, one per layout, which may
176      *  modify or augment the respective layout in various ways. */
177     const char *variant;
178     /** A comma seprated list of options, through which the user specifies
179      *  non-layout related preferences, like which key combinations are used
180      *  for switching layouts, or which key is the Compose key. */
181     const char *options;
182 };
183
184 /**
185  * @defgroup keysyms Keysyms
186  * Utility functions related to keysyms.
187  *
188  * @{
189  */
190
191 /**
192  * Get the name of a keysym.
193  *
194  * @param[in]  keysym The keysym.
195  * @param[out] buffer A string buffer to write the name into.
196  * @param[in]  size   Size of the buffer.
197  *
198  * @remark Named keysyms are found in the xkbcommon/xkbcommon-keysyms.h
199  * header file. Their name does not include the XKB_KEY_ prefix.
200  * The name of Unicode keysyms is "U<codepoint>", e.g. "Ua1b2".
201  * The name of other unnamed keysyms is the hexadecimal representation of
202  * their value, e.g. "0xabcd1234".
203  * An invalid keysym is returned as "Invalid".
204  *
205  * @warning If the buffer passed is too small, the string is truncated
206  * (though still NUL-terminated); a size of at least 32 bytes is recommended.
207  *
208  * @returns The number of bytes in the name, excluding the NUL byte, if
209  * keysym is valid.  Otherwise, -1 is returned.
210  *
211  * @remark You may check if truncation has occured by comparing the return
212  * value with the length of buffer, similarly to the snprintf(3) function.
213  */
214 int
215 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
216
217 /**
218  * Get a keysym from its name.
219  *
220  * @param name The name of a keysym. See remarks in
221  * xkb_keysym_get_name(); this function will accept any name returned by that
222  * function.
223  *
224  * @remark The lookup is case-sensitive.
225  *
226  * @returns The keysym, if name is valid.  Otherwise, XKB_KEY_NoSymbol is
227  * returned.
228  */
229 xkb_keysym_t
230 xkb_keysym_from_name(const char *name);
231
232 /**
233  * Get the Unicode/UTF-8 representation of a keysym.
234  *
235  * @param[in]  keysym The keysym.
236  * @param[out] buffer A buffer to write the UTF-8 string into.
237  * @param[in]  size   The size of buffer.  Must be at least 7.
238  *
239  * @returns The number of bytes written to the buffer.  A return value of
240  * 0 means that the keysym does not have a known printable Unicode
241  * representation.  A return value of -1 means that the buffer was too small.
242  */
243 int
244 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
245
246 /**
247  * Get the Unicode/UTF-32 representation of a keysym.
248  *
249  * @param keysym The keysym.
250  *
251  * @returns The Unicode/UTF-32 representation of keysym, which is also
252  * compatible with UCS-4.  A return value of 0 means the keysym does not
253  * have a known printable Unicode representation.
254  */
255 uint32_t
256 xkb_keysym_to_utf32(xkb_keysym_t keysym);
257
258 /** @} */
259
260 /**
261  * @defgroup context Library Context
262  * Creating, destroying and using library contexts.
263  *
264  * Every keymap compilation request must have a context associated with
265  * it.  The context keeps around state such as the include path.
266  *
267  * @{
268  */
269
270 /** Flags for context creation. */
271 enum xkb_context_flags {
272     /** Create this context with an empty include path. */
273     XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
274 };
275
276 /**
277  * Create a new context.
278  *
279  * @param flags Optional flags for the context, or 0.
280  *
281  * @returns A new context, or NULL on failure.
282  *
283  * @remark If successful, the caller holds a reference on the context, and
284  * must call xkb_context_unref() when finished.
285  *
286  * @remark The user may set some environment variables to affect default
287  * values in the context. See e.g. xkb_context_set_log_level() and
288  * xkb_context_set_log_verbosity().
289  */
290 struct xkb_context *
291 xkb_context_new(enum xkb_context_flags flags);
292
293 /**
294  * Take a new reference on a context.
295  * @param context The context to reference.
296  * @returns The passed in context.
297  */
298 struct xkb_context *
299 xkb_context_ref(struct xkb_context *context);
300
301 /**
302  * Release a reference on a context, and possibly free it.
303  * @param context The context to unreference.
304  */
305 void
306 xkb_context_unref(struct xkb_context *context);
307
308 /**
309  * Append a new entry to the context's include path.
310  * @returns 1 on success, or 0 if the include path could not be added or is
311  * inaccessible.
312  */
313 int
314 xkb_context_include_path_append(struct xkb_context *context, const char *path);
315
316 /**
317  * Append the default include paths to the context's include path.
318  * @returns 1 on success, or 0 if the primary include path could not be added.
319  */
320 int
321 xkb_context_include_path_append_default(struct xkb_context *context);
322
323 /**
324  * Reset the context's include path to the default.
325  *
326  * Removes all entries from the context's include path, and inserts the
327  * default paths.
328  *
329  * @returns 1 on success, or 0 if the primary include path could not be added.
330  */
331 int
332 xkb_context_include_path_reset_defaults(struct xkb_context *context);
333
334 /**
335  * Remove all entries from the context's include path.
336  */
337 void
338 xkb_context_include_path_clear(struct xkb_context *context);
339
340 /**
341  * Get the number of paths in the context's include path.
342  * @returns The number of paths in the context's include path.
343  */
344 unsigned int
345 xkb_context_num_include_paths(struct xkb_context *context);
346
347 /**
348  * Get a specific include path from the context's include path.
349  * @returns The include path at the specified index within the context, or
350  * NULL if the index is invalid.
351  */
352 const char *
353 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
354
355 /**
356  * Store custom user data in the context.
357  *
358  * This may be useful in conjuction with xkb_context_set_log_fn() or other
359  * callbacks.
360  */
361 void
362 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
363
364 /**
365  * Retrieves stored user data from the context.
366  *
367  * @returns The stored user data.  If the user data wasn't set, or the
368  * passed in context is NULL, returns NULL.
369  *
370  * This may be useful to access private user data from callbacks like a
371  * custom logging function.
372  **/
373 void *
374 xkb_context_get_user_data(struct xkb_context *context);
375
376 /** @} */
377
378 /**
379  * @defgroup logging Logging Handling
380  * Manipulating how logging from this library is handled.
381  *
382  * @{
383  */
384
385 /** Specifies a logging level. */
386 enum xkb_log_level {
387     XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
388     XKB_LOG_LEVEL_ERROR = 20,    /**< Log all errors. */
389     XKB_LOG_LEVEL_WARNING = 30,  /**< Log warnings and errors. */
390     XKB_LOG_LEVEL_INFO = 40,     /**< Log information, warnings, and errors. */
391     XKB_LOG_LEVEL_DEBUG = 50,    /**< Log everything. */
392 };
393
394 /**
395  * Set the current logging level.
396  *
397  * @param context The context in which to set the logging level.
398  * @param level   The logging level to use.  Only messages from this level
399  * and below will be logged.
400  *
401  * The default level is XKB_LOG_LEVEL_ERROR.  The environment variable
402  * XKB_LOG, if set in the time the context was created, overrides the default
403  * value.  It may be specified as a level number or name.
404  */
405 void
406 xkb_context_set_log_level(struct xkb_context *context,
407                           enum xkb_log_level level);
408
409 /**
410  * Get the current logging level.
411  * @returns The current logging level.
412  */
413 enum xkb_log_level
414 xkb_context_get_log_level(struct xkb_context *context);
415
416 /**
417  * Sets the current logging verbosity.
418  *
419  * The library can generate a number of warnings which are not helpful to
420  * ordinary users of the library.  The verbosity may be increased if more
421  * information is desired (e.g. when developing a new keymap).
422  *
423  * The default verbosity is 0.  The environment variable XKB_VERBOSITY, if
424  * set in the time the context was created, overrdies the default value.
425  *
426  * @param context   The context in which to use the set verbosity.
427  * @param verbosity The verbosity to use.  Currently used values are
428  * 1 to 10, higher values being more verbose.  0 would result in no verbose
429  * messages being logged.
430  *
431  * @remark Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
432  */
433 void
434 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
435
436 /**
437  * Get the current logging verbosity of the context.
438  * @returns The current logging verbosity.
439  */
440 int
441 xkb_context_get_log_verbosity(struct xkb_context *context);
442
443 /**
444  * Set a custom function to handle logging messages.
445  *
446  * @param context The context in which to use the set logging function.
447  * @param log_fn  The function that will be called for logging messages.
448  * Passing NULL restores the default function, which logs to stderr.
449  *
450  * By default, log messages from this library are printed to stderr.  This
451  * function allows you to replace the default behavior with a custom
452  * handler.  The handler is only called with messages which match the
453  * current logging level and verbosity settings for the context.
454  * level is the logging level of the message.  format and args are the
455  * same as in the vprintf(3) function.
456  *
457  * You may use xkb_context_set_user_data() on the context, and then call
458  * xkb_context_get_user_data() from within the logging function to provide
459  * it with additional private context.
460  */
461 void
462 xkb_context_set_log_fn(struct xkb_context *context,
463                        void (*log_fn)(struct xkb_context *context,
464                                       enum xkb_log_level level,
465                                       const char *format, va_list args));
466
467 /** @} */
468
469 /**
470  * @defgroup keymap Keymap Creation
471  * Creating and destroying XKB keymaps.
472  *
473  * @{
474  */
475
476 /** Flags for keymap compilation. */
477 enum xkb_keymap_compile_flags {
478     /** Apparently you can't have empty enums.  What a drag. */
479     XKB_MAP_COMPILE_PLACEHOLDER = 0,
480 };
481
482 /**
483  * Create a keymap from RMLVO names.
484  *
485  * The primary keymap entry point: creates a new XKB keymap from a set of
486  * RMLVO (Rules + Model + Layouts + Variants + Options) names.
487  *
488  * You should almost certainly be using this and nothing else to create
489  * keymaps.
490  *
491  * @param context The context in which to create the keymap.
492  * @param names   The RMLVO names to use.
493  * @param flags   Optional flags for the keymap, or 0.
494  *
495  * @returns A keymap compiled according to the RMLVO names, or NULL if
496  * the compilation failed.
497  *
498  * @sa xkb_rule_names
499  */
500 struct xkb_keymap *
501 xkb_keymap_new_from_names(struct xkb_context *context,
502                           const struct xkb_rule_names *names,
503                           enum xkb_keymap_compile_flags flags);
504
505 /** The possible keymap text formats. */
506 enum xkb_keymap_format {
507     /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
508     XKB_KEYMAP_FORMAT_TEXT_V1 = 1,
509 };
510
511 /**
512  * Create a keymap from an XKB keymap file.
513  *
514  * @param context The context in which to create the keymap.
515  * @param file    The XKB keymap file to compile.
516  * @param format  The text format of the XKB keymap file to compile.
517  * @param flags   Optional flags for the keymap, or 0.
518  *
519  * @returns A keymap compiled from the given XKB keymap file, or NULL of
520  * the compilation failed.
521  *
522  * @remark The file must contain an entire XKB keymap.  For example, in the
523  * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
524  * top level '%xkb_keymap' section, which in turn contains other required
525  * sections.
526  */
527 struct xkb_keymap *
528 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
529                          enum xkb_keymap_format format,
530                          enum xkb_keymap_compile_flags flags);
531
532 /**
533  * Create a keymap from an XKB keymap given as a string.
534  *
535  * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
536  * the XKB keymap as one enormous string.
537  *
538  * @see xkb_keymap_new_from_string()
539  */
540 struct xkb_keymap *
541 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
542                            enum xkb_keymap_format format,
543                            enum xkb_keymap_compile_flags flags);
544
545 /**
546  * Take a new reference on a keymap.
547  * @param keymap The keymap to reference.
548  * @returns The passed in keymap.
549  */
550 struct xkb_keymap *
551 xkb_keymap_ref(struct xkb_keymap *keymap);
552
553 /**
554  * Release a reference on a keymap, and possibly free it.
555  * @param keymap The keymap to unreference. If the reference count reaches
556  * zero, the keymap is freed.
557  */
558 void
559 xkb_keymap_unref(struct xkb_keymap *keymap);
560
561 /* See xkb_keymap_get_as_string(). */
562 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
563
564 /**
565  * Get the compiled keymap as a string.
566  *
567  * @param keymap The keymap to get as a string.
568  * @param format The keymap format to use for the string.  You can pass
569  * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
570  * from which the keymap was originally created.
571  *
572  * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
573  *
574  * The returned string may be fed back into xkb_map_new_from_string() to get
575  * the exact same keymap (possibly in another process, etc.).
576  *
577  * @remark The returned string is dynamically allocated and should be freed
578  * by the caller.
579  */
580 char *
581 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
582                          enum xkb_keymap_format format);
583
584 /** @} */
585
586 /**
587  * @defgroup components XKB State Components
588  * Enumeration of state components in a keymap.
589  *
590  * @{
591  */
592
593 /**
594  * Returns the number of modifiers active in the keymap.
595  */
596 xkb_mod_index_t
597 xkb_keymap_num_mods(struct xkb_keymap *keymap);
598
599 /**
600  * Returns the name of the modifier specified by 'idx', or NULL if invalid.
601  */
602 const char *
603 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
604
605 /**
606  * Returns the index of the modifier specified by 'name', or XKB_MOD_INVALID.
607  */
608 xkb_mod_index_t
609 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
610
611 /**
612  * Returns the number of groups active in the keymap.
613  */
614 xkb_layout_index_t
615 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
616
617 /**
618  * Returns the name of the group specified by 'idx', or NULL if invalid.
619  */
620 const char *
621 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
622
623 /**
624  * Returns the index of the layout specified by 'name', or XKB_LAYOUT_INVALID.
625  */
626 xkb_layout_index_t
627 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
628
629 /**
630  * Returns the number of layouts active for the specified key.
631  */
632 xkb_layout_index_t
633 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
634
635 /**
636  * Returns the number of levels active for the specified key and layout.
637  */
638 xkb_level_index_t
639 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
640                               xkb_layout_index_t layout);
641
642 /**
643  * Returns the number of LEDs in the given map.
644  * Note that LED indexes are not necessarily consecutive in the keymap.
645  * This means that some LEDs in the range between 0 and the return value
646  * might not be valid.  Given such an index, xkb_keymap_led_get_name()
647  * will return NULL, and xkb_state_led_index_is_active() will return -1.
648  */
649 xkb_led_index_t
650 xkb_keymap_num_leds(struct xkb_keymap *keymap);
651
652 /**
653  * Returns the name of the LED specified by 'idx', or NULL if invalid.
654  */
655 const char *
656 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
657
658 /**
659  * Returns the index of the LED specified by 'name', or XKB_LED_INVALID.
660  */
661 xkb_led_index_t
662 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
663
664 /**
665  * Returns 1 if the key should repeat, or 0 otherwise.
666  */
667 int
668 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
669
670 /** @} */
671
672 /**
673  * @defgroup state XKB State Objects
674  * Creating, destroying and manipulating keyboard state objects.
675  *
676  * @{
677  */
678
679 /**
680  * Returns a new XKB state object for use with the given keymap, or NULL on
681  * failure.
682  */
683 struct xkb_state *
684 xkb_state_new(struct xkb_keymap *keymap);
685
686 /**
687  * Takes a new reference on a state object.
688  */
689 struct xkb_state *
690 xkb_state_ref(struct xkb_state *state);
691
692 /**
693  * Unrefs and potentially deallocates a state object; the caller must not
694  * use the state object after calling this.
695  */
696 void
697 xkb_state_unref(struct xkb_state *state);
698
699 /**
700  * Get the keymap from which the state object was created.  Does not take
701  * a new reference on the map; you must explicitly reference it yourself
702  * if you plan to use it beyond the lifetime of the state.
703  */
704 struct xkb_keymap *
705 xkb_state_get_keymap(struct xkb_state *state);
706
707 /** Specifies the direction of the key (press / release). */
708 enum xkb_key_direction {
709     XKB_KEY_UP,   /**< The key was released. */
710     XKB_KEY_DOWN, /**< The key was pressed. */
711 };
712
713 /**
714  * Updates a state object to reflect the given key being pressed or released.
715  */
716 void
717 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
718                      enum xkb_key_direction direction);
719
720 /**
721  * Gives the symbols obtained from pressing a particular key with the given
722  * state.  *syms_out will be set to point to an array of keysyms, with the
723  * return value being the number of symbols in *syms_out.  If the return
724  * value is 0, *syms_out will be set to NULL, as there are no symbols produced
725  * by this event.
726  */
727 int
728 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
729                        const xkb_keysym_t **syms_out);
730
731 /**
732  * As with xkb_state_key_get_syms, but either returns exactly keysym, or
733  * XKB_KEY_NoSymbol if there are either zero or more than one symbols.
734  */
735 xkb_keysym_t
736 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
737
738 /**
739  * Returns the layout number that would be active for a particular key with
740  * the given state.
741  */
742 xkb_layout_index_t
743 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
744
745 /**
746  * Returns the level number that would be active for a particular key with
747  * the given state and layout number, usually obtained from
748  * xkb_state_key_get_layout.
749  */
750 xkb_level_index_t
751 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
752                         xkb_layout_index_t layout);
753
754 /**
755  * Gives the symbols obtained from pressing a particular key with the given
756  * layout and level.  *syms_out will be set to point to an array of keysyms,
757  * with the return value being the number of symbols in *syms_out.  If the
758  * return value is 0, *syms_out will be set to NULL, as there are no symbols
759  * produced by this event.
760  */
761 int
762 xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
763                                  xkb_keycode_t key,
764                                  xkb_layout_index_t layout,
765                                  xkb_level_index_t level,
766                                  const xkb_keysym_t **syms_out);
767
768 /**
769  * Modifier and group types for state objects.  This enum is bitmaskable,
770  * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
771  * locked modifiers.
772  */
773 enum xkb_state_component {
774     /** A key holding this modifier or group is currently physically
775      *  depressed; also known as 'base'. */
776     XKB_STATE_DEPRESSED = (1 << 0),
777     /** Modifier or group is latched, i.e. will be unset after the next
778      *  non-modifier key press. */
779     XKB_STATE_LATCHED = (1 << 1),
780     /** Modifier or group is locked, i.e. will be unset after the key
781      *  provoking the lock has been pressed again. */
782     XKB_STATE_LOCKED = (1 << 2),
783     /** Combinatination of depressed, latched, and locked. */
784     XKB_STATE_EFFECTIVE =
785         (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
786 };
787
788 /**
789  * Match flags for xkb_state_mod_indices_are_active and
790  * xkb_state_mod_names_are_active, specifying how the conditions for a
791  * successful match.  XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
792  * the other modes.
793  */
794 enum xkb_state_match {
795     /** Returns true if any of the modifiers are active. */
796     XKB_STATE_MATCH_ANY = (1 << 0),
797     /** Returns true if all of the modifiers are active. */
798     XKB_STATE_MATCH_ALL = (1 << 1),
799     /** Makes matching non-exclusive, i.e. will not return false if a
800      *  modifier not specified in the arguments is active. */
801     XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16),
802 };
803
804 /**
805  * Updates a state object from a set of explicit masks.  This entrypoint is
806  * really only for window systems and the like, where a master process
807  * holds an xkb_state, then serializes it over a wire protocol, and clients
808  * then use the serialization to feed in to their own xkb_state.
809  *
810  * All parameters must always be passed, or the resulting state may be
811  * incoherent.
812  *
813  * The serialization is lossy and will not survive round trips; it must only
814  * be used to feed slave state objects, and must not be used to update the
815  * master state.
816  *
817  * Please do not use this unless you fit the description above.
818  */
819 void
820 xkb_state_update_mask(struct xkb_state *state, xkb_mod_mask_t base_mods,
821                       xkb_mod_mask_t latched_mods, xkb_mod_mask_t locked_mods,
822                       xkb_layout_index_t base_group,
823                       xkb_layout_index_t latched_group,
824                       xkb_layout_index_t locked_group);
825
826 /**
827  * The counterpart to xkb_state_update_mask, to be used on the server side
828  * of serialization.  Returns a xkb_mod_mask_t representing the given
829  * component(s) of the state.
830  *
831  * This function should not be used in regular clients; please use the
832  * xkb_state_mod_*_is_active or xkb_state_foreach_active_mod API instead.
833  *
834  * Can return NULL on failure.
835  */
836 xkb_mod_mask_t
837 xkb_state_serialize_mods(struct xkb_state *state,
838                          enum xkb_state_component component);
839
840 /**
841  * The group equivalent of xkb_state_serialize_mods: please see its
842  * documentation.
843  */
844 xkb_layout_index_t
845 xkb_state_serialize_layout(struct xkb_state *state,
846                            enum xkb_state_component component);
847
848 /**
849  * Returns 1 if the modifier specified by 'name' is active in the manner
850  * specified by 'type', 0 if it is unset, or -1 if the modifier does not
851  * exist in the map.
852  */
853 int
854 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
855                              enum xkb_state_component type);
856
857 /**
858  * Returns 1 if the modifiers specified by the varargs (NULL-terminated
859  * strings, with a NULL sentinel) are active in the manner specified by
860  * 'match', 0 otherwise, or -1 if any of the modifiers do not exist in
861  * the map.
862  */
863 int
864 xkb_state_mod_names_are_active(struct xkb_state *state,
865                                enum xkb_state_component type,
866                                enum xkb_state_match match,
867                                ...);
868
869 /**
870  * Returns 1 if the modifier specified by 'idx' is active in the manner
871  * specified by 'type', 0 if it is unset, or -1 if the modifier does not
872  * exist in the current map.
873  */
874 int
875 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
876                               enum xkb_state_component type);
877
878 /**
879  * Returns 1 if the modifiers specified by the varargs (of type
880  * xkb_mod_index_t, with a XKB_MOD_INVALID sentinel) are active in the
881  * manner specified by 'match' and 'type', 0 otherwise, or -1 if any of
882  * the modifiers do not exist in the map.
883  */
884 int
885 xkb_state_mod_indices_are_active(struct xkb_state *state,
886                                  enum xkb_state_component type,
887                                  enum xkb_state_match match,
888                                  ...);
889
890 /**
891  * Returns 1 if the modifier specified by 'idx' is used in the
892  * translation of the keycode 'key' to the key symbols obtained by
893  * pressing it (as in xkb_key_get_syms), given the current state.
894  * Returns 0 otherwise.
895  */
896 int
897 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
898                                 xkb_mod_index_t idx);
899
900 /**
901  * Takes the given modifier mask, and removes all modifiers which are
902  * marked as 'consumed' (see xkb_key_mod_index_is_consumed definition)
903  * for that particular key.
904  */
905 xkb_mod_mask_t
906 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
907                                    xkb_mod_mask_t mask);
908
909 /**
910  * Returns 1 if the group specified by 'name' is active in the manner
911  * specified by 'type', 0 if it is unset, or -1 if the group does not
912  * exist in the current map.
913  */
914 int
915 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
916                                 enum xkb_state_component type);
917
918 /**
919  * Returns 1 if the group specified by 'idx' is active in the manner
920  * specified by 'type', 0 if it is unset, or -1 if the group does not
921  * exist in the current map.
922  */
923 int
924 xkb_state_layout_index_is_active(struct xkb_state *state,
925                                  xkb_layout_index_t idx,
926                                  enum xkb_state_component type);
927
928 /**
929  * Returns 1 if the LED specified by 'name' is active, 0 if it is unset, or
930  * -1 if the LED does not exist in the current map.
931  */
932 int
933 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
934
935 /**
936  * Returns 1 if the LED specified by 'idx' is active, 0 if it is unset, or
937  * -1 if the LED does not exist in the current map.
938  */
939 int
940 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
941
942 /** @} */
943
944 /* Leave this include last, so it can pick up our types, etc. */
945 #include <xkbcommon/xkbcommon-compat.h>
946
947 #ifdef __cplusplus
948 } /* extern "C" */
949 #endif
950
951 #endif /* _XKBCOMMON_H_ */