2 * Copyright 1985, 1987, 1990, 1998 The Open Group
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the names of the authors or their
22 * institutions shall not be used in advertising or otherwise to promote the
23 * sale, use or other dealings in this Software without prior written
24 * authorization from the authors.
27 /************************************************************
28 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
30 * Permission to use, copy, modify, and distribute this
31 * software and its documentation for any purpose and without
32 * fee is hereby granted, provided that the above copyright
33 * notice appear in all copies and that both that copyright
34 * notice and this permission notice appear in supporting
35 * documentation, and that the name of Silicon Graphics not be
36 * used in advertising or publicity pertaining to distribution
37 * of the software without specific prior written permission.
38 * Silicon Graphics makes no representation about the suitability
39 * of this software for any purpose. It is provided "as is"
40 * without any express or implied warranty.
42 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
43 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
44 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
45 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
46 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
47 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
48 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
49 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
51 ********************************************************/
54 * Copyright © 2009 Dan Nicholson
55 * Copyright © 2012 Intel Corporation
56 * Copyright © 2012 Ran Benita
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:
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
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.
77 * Author: Daniel Stone <daniel@fooishbar.org>
78 * Dan Nicholson <dbn.lists@gmail.com>
84 /* Don't use compat names in internal code. */
85 #define _XKBCOMMON_COMPAT_H
86 #include "xkbcommon/xkbcommon.h"
91 /* This limit is artificially enforced, we do not depend on it any where.
92 * The reason it's still here is that the rules file format does not
93 * support multiple groups very well, and the rules shipped with
94 * xkeyboard-config (see rules/evdev) depend on this limit extensively.
95 * So just lifting this limit would cause problems for people who will use
96 * more than 4 layouts.
97 * TODO: Fix the group index syntax in the rules format, preferably in a
98 * backwards compatible way.
99 * See e.g. https://bugs.freedesktop.org/show_bug.cgi?id=14372
100 * Note: A limit on the number of groups we *do* depend on is imposed by
101 * the size of the xkb_layout_mask_t type (32). This is more than enough
104 #define XKB_MAX_GROUPS 4
106 /* Don't allow more modifiers than we can hold in xkb_mod_mask_t. */
107 #define XKB_MAX_MODS ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * 8))
109 /* Don't allow more leds than we can hold in xkb_led_mask_t. */
110 #define XKB_MAX_LEDS ((xkb_led_index_t) (sizeof(xkb_led_mask_t) * 8))
112 /* These should all go away. */
116 MOD_BOTH = (MOD_REAL | MOD_VIRT),
118 #define MOD_REAL_MASK_ALL ((xkb_mod_mask_t) 0x000000ff)
120 enum xkb_action_type {
121 ACTION_TYPE_NONE = 0,
123 ACTION_TYPE_MOD_LATCH,
124 ACTION_TYPE_MOD_LOCK,
125 ACTION_TYPE_GROUP_SET,
126 ACTION_TYPE_GROUP_LATCH,
127 ACTION_TYPE_GROUP_LOCK,
128 ACTION_TYPE_PTR_MOVE,
129 ACTION_TYPE_PTR_BUTTON,
130 ACTION_TYPE_PTR_LOCK,
131 ACTION_TYPE_PTR_DEFAULT,
132 ACTION_TYPE_TERMINATE,
133 ACTION_TYPE_SWITCH_VT,
134 ACTION_TYPE_CTRL_SET,
135 ACTION_TYPE_CTRL_LOCK,
136 ACTION_TYPE_KEY_REDIRECT,
138 _ACTION_TYPE_NUM_ENTRIES
141 enum xkb_action_flags {
142 ACTION_LOCK_CLEAR = (1 << 0),
143 ACTION_LATCH_TO_LOCK = (1 << 1),
144 ACTION_LOCK_NO_LOCK = (1 << 2),
145 ACTION_LOCK_NO_UNLOCK = (1 << 3),
146 ACTION_MODS_LOOKUP_MODMAP = (1 << 4),
147 ACTION_ABSOLUTE_SWITCH = (1 << 5),
148 ACTION_ABSOLUTE_X = (1 << 6),
149 ACTION_ABSOLUTE_Y = (1 << 7),
150 ACTION_NO_ACCEL = (1 << 8),
151 ACTION_SAME_SCREEN = (1 << 9),
154 enum xkb_action_controls {
155 CONTROL_REPEAT = (1 << 0),
156 CONTROL_SLOW = (1 << 1),
157 CONTROL_DEBOUNCE = (1 << 2),
158 CONTROL_STICKY = (1 << 3),
159 CONTROL_MOUSEKEYS = (1 << 4),
160 CONTROL_MOUSEKEYS_ACCEL = (1 << 5),
161 CONTROL_AX = (1 << 6),
162 CONTROL_AX_TIMEOUT = (1 << 7),
163 CONTROL_AX_FEEDBACK = (1 << 8),
164 CONTROL_BELL = (1 << 9),
165 CONTROL_IGNORE_GROUP_LOCK = (1 << 10),
167 (CONTROL_REPEAT | CONTROL_SLOW | CONTROL_DEBOUNCE | CONTROL_STICKY | \
168 CONTROL_MOUSEKEYS | CONTROL_MOUSEKEYS_ACCEL | CONTROL_AX | \
169 CONTROL_AX_TIMEOUT | CONTROL_AX_FEEDBACK | CONTROL_BELL | \
170 CONTROL_IGNORE_GROUP_LOCK)
173 enum xkb_match_operation {
182 xkb_mod_mask_t mods; /* original real+virtual mods in definition */
183 xkb_mod_mask_t mask; /* computed effective mask */
186 struct xkb_mod_action {
187 enum xkb_action_type type;
188 enum xkb_action_flags flags;
189 struct xkb_mods mods;
192 struct xkb_group_action {
193 enum xkb_action_type type;
194 enum xkb_action_flags flags;
198 struct xkb_controls_action {
199 enum xkb_action_type type;
200 enum xkb_action_flags flags;
201 enum xkb_action_controls ctrls;
204 struct xkb_pointer_default_action {
205 enum xkb_action_type type;
206 enum xkb_action_flags flags;
210 struct xkb_switch_screen_action {
211 enum xkb_action_type type;
212 enum xkb_action_flags flags;
216 struct xkb_redirect_key_action {
217 enum xkb_action_type type;
218 enum xkb_action_flags flags;
219 xkb_keycode_t new_kc;
226 struct xkb_pointer_action {
227 enum xkb_action_type type;
228 enum xkb_action_flags flags;
233 struct xkb_pointer_button_action {
234 enum xkb_action_type type;
235 enum xkb_action_flags flags;
240 struct xkb_private_action {
241 enum xkb_action_type type;
242 enum xkb_action_flags flags;
247 enum xkb_action_type type;
248 struct xkb_mod_action mods;
249 struct xkb_group_action group;
250 struct xkb_controls_action ctrls;
251 struct xkb_pointer_default_action dflt;
252 struct xkb_switch_screen_action screen;
253 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
254 struct xkb_pointer_action ptr;
255 struct xkb_pointer_button_action btn;
256 struct xkb_private_action priv;
259 struct xkb_kt_map_entry {
260 xkb_level_index_t level;
261 struct xkb_mods mods;
262 struct xkb_mods preserve;
265 struct xkb_key_type {
266 struct xkb_mods mods;
267 xkb_level_index_t num_levels;
268 struct xkb_kt_map_entry *map;
269 unsigned int num_entries;
271 xkb_atom_t *level_names;
274 struct xkb_sym_interpret {
276 enum xkb_match_operation match;
279 xkb_mod_index_t virtual_mod;
280 union xkb_action action;
284 struct xkb_indicator_map {
286 enum xkb_state_component which_groups;
287 xkb_layout_mask_t groups;
288 enum xkb_state_component which_mods;
289 struct xkb_mods mods;
290 enum xkb_action_controls ctrls;
293 struct xkb_key_alias {
298 struct xkb_controls {
299 unsigned char groups_wrap;
300 struct xkb_mods internal;
301 struct xkb_mods ignore_lock;
302 unsigned short repeat_delay;
303 unsigned short repeat_interval;
304 unsigned short slow_keys_delay;
305 unsigned short debounce_delay;
306 unsigned short ax_options;
307 unsigned short ax_timeout;
308 unsigned short axt_opts_mask;
309 unsigned short axt_opts_values;
310 unsigned int axt_ctrls_mask;
311 unsigned int axt_ctrls_values;
314 /* Such an awkward name. Oh well. */
315 enum xkb_range_exceed_type {
321 enum xkb_explicit_components {
322 EXPLICIT_INTERP = (1 << 0),
323 EXPLICIT_VMODMAP = (1 << 1),
324 EXPLICIT_REPEAT = (1 << 2),
328 union xkb_action action;
329 unsigned int num_syms;
331 xkb_keysym_t sym; /* num_syms == 1 */
332 xkb_keysym_t *syms; /* num_syms > 1 */
338 /* Points to a type in keymap->types. */
339 const struct xkb_key_type *type;
340 /* Use XkbKeyGroupWidth for the number of levels. */
341 struct xkb_level *levels;
345 xkb_keycode_t keycode;
348 enum xkb_explicit_components explicit;
350 xkb_mod_mask_t modmap;
351 xkb_mod_mask_t vmodmap;
355 enum xkb_range_exceed_type out_of_range_group_action;
356 xkb_layout_index_t out_of_range_group_number;
358 xkb_layout_index_t num_groups;
359 struct xkb_group *groups;
365 xkb_mod_mask_t mapping; /* vmod -> real mod mapping */
368 /* Common keyboard description structure */
370 struct xkb_context *ctx;
373 enum xkb_keymap_compile_flags flags;
374 enum xkb_keymap_format format;
376 enum xkb_action_controls enabled_ctrls;
378 xkb_keycode_t min_key_code;
379 xkb_keycode_t max_key_code;
380 struct xkb_key *keys;
382 /* aliases in no particular order */
383 darray(struct xkb_key_alias) key_aliases;
385 struct xkb_key_type *types;
386 unsigned int num_types;
388 darray(struct xkb_sym_interpret) sym_interprets;
390 darray(struct xkb_mod) mods;
392 /* Number of groups in the key with the most groups. */
393 xkb_layout_index_t num_groups;
394 /* Not all groups must have names. */
395 xkb_layout_index_t num_group_names;
396 xkb_atom_t *group_names;
398 darray(struct xkb_indicator_map) indicators;
400 char *keycodes_section_name;
401 char *symbols_section_name;
402 char *types_section_name;
403 char *compat_section_name;
406 static inline const struct xkb_key *
407 XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
409 if (kc < keymap->min_key_code || kc > keymap->max_key_code)
411 return &keymap->keys[kc];
414 #define xkb_foreach_key(iter, keymap) \
415 for (iter = keymap->keys + keymap->min_key_code; \
416 iter <= keymap->keys + keymap->max_key_code; \
419 static inline xkb_level_index_t
420 XkbKeyGroupWidth(const struct xkb_key *key, xkb_layout_index_t layout)
422 return key->groups[layout].type->num_levels;
426 xkb_keymap_new(struct xkb_context *ctx,
427 enum xkb_keymap_format format,
428 enum xkb_keymap_compile_flags);
431 wrap_group_into_range(int32_t group,
432 xkb_layout_index_t num_groups,
433 enum xkb_range_exceed_type out_of_range_group_action,
434 xkb_layout_index_t out_of_range_group_number);