libxkbcommon  0.3.1
xkbcommon.h
Go to the documentation of this file.
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 
89 #include <xkbcommon/xkbcommon-keysyms.h>
90 
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
111 struct xkb_context;
112 
123 struct xkb_keymap;
124 
134 struct xkb_state;
135 
161 typedef uint32_t xkb_keycode_t;
162 
191 typedef uint32_t xkb_keysym_t;
192 
211 typedef uint32_t xkb_layout_index_t;
213 typedef uint32_t xkb_layout_mask_t;
214 
220 typedef uint32_t xkb_level_index_t;
221 
245 typedef uint32_t xkb_mod_index_t;
247 typedef uint32_t xkb_mod_mask_t;
248 
272 typedef uint32_t xkb_led_index_t;
274 typedef uint32_t xkb_led_mask_t;
275 
276 #define XKB_KEYCODE_INVALID (0xffffffff)
277 #define XKB_LAYOUT_INVALID (0xffffffff)
278 #define XKB_LEVEL_INVALID (0xffffffff)
279 #define XKB_MOD_INVALID (0xffffffff)
280 #define XKB_LED_INVALID (0xffffffff)
281 
282 #define XKB_KEYCODE_MAX (0xffffffff - 1)
283 
288 #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
289 
294 #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
295 
307  const char *rules;
309  const char *model;
312  const char *layout;
315  const char *variant;
319  const char *options;
320 };
321 
349 int
350 xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
351 
356 };
357 
378 xkb_keysym_t
379 xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
380 
392 int
393 xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
394 
402 uint32_t
403 xkb_keysym_to_utf32(xkb_keysym_t keysym);
404 
423 };
424 
438 struct xkb_context *
440 
448 struct xkb_context *
449 xkb_context_ref(struct xkb_context *context);
450 
458 void
459 xkb_context_unref(struct xkb_context *context);
460 
469 void
470 xkb_context_set_user_data(struct xkb_context *context, void *user_data);
471 
483 void *
484 xkb_context_get_user_data(struct xkb_context *context);
485 
507 int
508 xkb_context_include_path_append(struct xkb_context *context, const char *path);
509 
517 int
519 
530 int
532 
538 void
540 
546 unsigned int
548 
557 const char *
558 xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
559 
576 };
577 
591 void
592 xkb_context_set_log_level(struct xkb_context *context,
593  enum xkb_log_level level);
594 
600 enum xkb_log_level
601 xkb_context_get_log_level(struct xkb_context *context);
602 
622 void
623 xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
624 
630 int
632 
653 void
654 xkb_context_set_log_fn(struct xkb_context *context,
655  void (*log_fn)(struct xkb_context *context,
656  enum xkb_log_level level,
657  const char *format, va_list args));
658 
672 };
673 
695 struct xkb_keymap *
696 xkb_keymap_new_from_names(struct xkb_context *context,
697  const struct xkb_rule_names *names,
698  enum xkb_keymap_compile_flags flags);
699 
704 };
705 
724 struct xkb_keymap *
725 xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
726  enum xkb_keymap_format format,
727  enum xkb_keymap_compile_flags flags);
728 
738 struct xkb_keymap *
739 xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
740  enum xkb_keymap_format format,
741  enum xkb_keymap_compile_flags flags);
742 
752 struct xkb_keymap *
753 xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
754  size_t length, enum xkb_keymap_format format,
755  enum xkb_keymap_compile_flags flags);
756 
764 struct xkb_keymap *
765 xkb_keymap_ref(struct xkb_keymap *keymap);
766 
774 void
775 xkb_keymap_unref(struct xkb_keymap *keymap);
776 
781 #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
782 
801 char *
802 xkb_keymap_get_as_string(struct xkb_keymap *keymap,
803  enum xkb_keymap_format format);
804 
820 xkb_keycode_t
821 xkb_keymap_min_keycode(struct xkb_keymap *keymap);
822 
829 xkb_keycode_t
830 xkb_keymap_max_keycode(struct xkb_keymap *keymap);
831 
838 typedef void
839 (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
840  void *data);
841 
850 void
852  void *data);
853 
860 xkb_mod_index_t
861 xkb_keymap_num_mods(struct xkb_keymap *keymap);
862 
871 const char *
872 xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
873 
883 xkb_mod_index_t
884 xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
885 
892 xkb_layout_index_t
893 xkb_keymap_num_layouts(struct xkb_keymap *keymap);
894 
904 const char *
905 xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
906 
916 xkb_layout_index_t
917 xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
918 
929 xkb_layout_index_t
930 xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
931 
942 xkb_level_index_t
943 xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
944  xkb_layout_index_t layout);
945 
974 int
976  xkb_keycode_t key,
977  xkb_layout_index_t layout,
978  xkb_level_index_t level,
979  const xkb_keysym_t **syms_out);
980 
992 xkb_led_index_t
993 xkb_keymap_num_leds(struct xkb_keymap *keymap);
994 
1002 const char *
1003 xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
1004 
1013 xkb_led_index_t
1014 xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
1015 
1031 int
1032 xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
1033 
1052 struct xkb_state *
1053 xkb_state_new(struct xkb_keymap *keymap);
1054 
1062 struct xkb_state *
1063 xkb_state_ref(struct xkb_state *state);
1064 
1072 void
1073 xkb_state_unref(struct xkb_state *state);
1074 
1087 struct xkb_keymap *
1088 xkb_state_get_keymap(struct xkb_state *state);
1089 
1094 };
1095 
1127  XKB_STATE_LEDS = (1 << 8)
1128 };
1129 
1140 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
1141  enum xkb_key_direction direction);
1142 
1166 int
1167 xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
1168  const xkb_keysym_t **syms_out);
1169 
1184 xkb_keysym_t
1185 xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
1186 
1201 xkb_layout_index_t
1202 xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
1203 
1226 xkb_level_index_t
1227 xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
1228  xkb_layout_index_t layout);
1229 
1244 };
1245 
1271 xkb_state_update_mask(struct xkb_state *state,
1272  xkb_mod_mask_t depressed_mods,
1273  xkb_mod_mask_t latched_mods,
1274  xkb_mod_mask_t locked_mods,
1275  xkb_layout_index_t depressed_layout,
1276  xkb_layout_index_t latched_layout,
1277  xkb_layout_index_t locked_layout);
1278 
1297 xkb_mod_mask_t
1298 xkb_state_serialize_mods(struct xkb_state *state,
1299  enum xkb_state_component components);
1300 
1319 xkb_layout_index_t
1321  enum xkb_state_component components);
1322 
1331 int
1332 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
1333  enum xkb_state_component type);
1334 
1352 int
1354  enum xkb_state_component type,
1355  enum xkb_state_match match,
1356  ...);
1357 
1366 int
1367 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
1368  enum xkb_state_component type);
1369 
1387 int
1389  enum xkb_state_component type,
1390  enum xkb_state_match match,
1391  ...);
1392 
1455 int
1456 xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
1457  xkb_mod_index_t idx);
1458 
1468 xkb_mod_mask_t
1469 xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
1470  xkb_mod_mask_t mask);
1471 
1484 int
1485 xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
1486  enum xkb_state_component type);
1487 
1497 int
1499  xkb_layout_index_t idx,
1500  enum xkb_state_component type);
1501 
1511 int
1512 xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
1513 
1523 int
1524 xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
1525 
1528 /* Leave this include last, so it can pick up our types, etc. */
1529 #include <xkbcommon/xkbcommon-compat.h>
1530 
1531 #ifdef __cplusplus
1532 } /* extern "C" */
1533 #endif
1534 
1535 #endif /* _XKBCOMMON_H_ */