Debian Codegraph @

src/keymap.h

raw
1 /*
2 * For MIT-open-group:
3 * Copyright 1985, 1987, 1990, 1998 The Open Group
4 *
5 * For HPND
6 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
7 *
8 * For MIT:
9 * Copyright © 2009 Dan Nicholson
10 * Copyright © 2012 Intel Corporation
11 * Copyright © 2012 Ran Benita
12 *
13 * SPDX-License-Identifier: MIT-open-group AND HPND AND MIT
14 *
15 * Author: Daniel Stone <[email protected]>
16 * Author: Dan Nicholson <[email protected]>
17 */
18 #pragma once
19
20 /* Don't use compat names in internal code. */
21 #define _XKBCOMMON_COMPAT_H
22
23 #include "config.h"
24
25 #include <limits.h>
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #include "xkbcommon/xkbcommon.h"
30
31 #include "darray.h"
32 #include "rmlvo.h"
33 #include "context.h"
34 #include "utils.h"
35
36 /* Note: imposed by the size of the xkb_layout_mask_t type (32).
37 * This is more than enough though. */
38 #define XKB_MAX_GROUPS 32
39 #define XKB_ALL_GROUPS ((UINT64_C(1) << XKB_MAX_GROUPS) - UINT64_C(1))
40 /* Limit imposed by X11 */
41 #define XKB_MAX_GROUPS_X11 4
42
43 static inline xkb_layout_index_t
44 format_max_groups(enum xkb_keymap_format format)
45 {
46 return (format == XKB_KEYMAP_FORMAT_TEXT_V1)
47 ? XKB_MAX_GROUPS_X11
48 : XKB_MAX_GROUPS;
49 }
50
51 /* Don't allow more modifiers than we can hold in xkb_mod_mask_t. */
52 #define XKB_MAX_MODS ((xkb_mod_index_t) (sizeof(xkb_mod_mask_t) * CHAR_BIT))
53
54 /* Don't allow more leds than we can hold in xkb_led_mask_t. */
55 #define XKB_MAX_LEDS ((xkb_led_index_t) (sizeof(xkb_led_mask_t) * CHAR_BIT))
56
57 /* Special value to handle modMap None {…} */
58 #define XKB_MOD_NONE 0xffffffffU
59
60 enum mod_type {
61 /** X11 core modifier */
62 MOD_REAL = (1 << 0),
63 /** A non-X11 core modifier */
64 MOD_VIRT = (1 << 1),
65 /** Any modifier */
66 MOD_BOTH = (MOD_REAL | MOD_VIRT)
67 };
68 #define MOD_REAL_MASK_ALL ((xkb_mod_mask_t) 0x000000ff)
69
70 /** Predefined (AKA real, core, X11) modifiers. The order is important! */
71 enum real_mod_index {
72 XKB_MOD_INDEX_SHIFT = 0,
73 XKB_MOD_INDEX_CAPS,
74 XKB_MOD_INDEX_CTRL,
75 XKB_MOD_INDEX_MOD1,
76 XKB_MOD_INDEX_MOD2,
77 XKB_MOD_INDEX_MOD3,
78 XKB_MOD_INDEX_MOD4,
79 XKB_MOD_INDEX_MOD5,
80 _XKB_MOD_INDEX_NUM_ENTRIES
81 };
82 static_assert(_XKB_MOD_INDEX_NUM_ENTRIES == 8, "Invalid X11 core modifiers");
83
84 enum xkb_action_type {
85 ACTION_TYPE_NONE = 0,
86 ACTION_TYPE_VOID, /* libxkbcommon extension */
87 ACTION_TYPE_MOD_SET,
88 ACTION_TYPE_MOD_LATCH,
89 ACTION_TYPE_MOD_LOCK,
90 ACTION_TYPE_GROUP_SET,
91 ACTION_TYPE_GROUP_LATCH,
92 ACTION_TYPE_GROUP_LOCK,
93 ACTION_TYPE_PTR_MOVE,
94 ACTION_TYPE_PTR_BUTTON,
95 ACTION_TYPE_PTR_LOCK,
96 ACTION_TYPE_PTR_DEFAULT,
97 ACTION_TYPE_TERMINATE,
98 ACTION_TYPE_SWITCH_VT,
99 ACTION_TYPE_CTRL_SET,
100 ACTION_TYPE_CTRL_LOCK,
101 ACTION_TYPE_UNSUPPORTED_LEGACY,
102 ACTION_TYPE_PRIVATE,
103 ACTION_TYPE_INTERNAL, /* Action specific and internal to xkbcommon */
104 _ACTION_TYPE_NUM_ENTRIES
105 };
106
107 enum xkb_action_flags {
108 ACTION_LOCK_CLEAR = (1 << 0),
109 ACTION_LATCH_TO_LOCK = (1 << 1),
110 ACTION_LOCK_NO_LOCK = (1 << 2),
111 ACTION_LOCK_NO_UNLOCK = (1 << 3),
112 ACTION_MODS_LOOKUP_MODMAP = (1 << 4),
113 ACTION_ABSOLUTE_SWITCH = (1 << 5),
114 ACTION_ABSOLUTE_X = (1 << 6),
115 ACTION_ABSOLUTE_Y = (1 << 7),
116 ACTION_ACCEL = (1 << 8),
117 ACTION_SAME_SCREEN = (1 << 9),
118 ACTION_LOCK_ON_RELEASE = (1 << 10),
119 ACTION_UNLOCK_ON_PRESS = (1 << 11),
120 ACTION_LATCH_ON_PRESS = (1 << 12),
121 };
122
123 enum xkb_action_controls {
124 CONTROL_REPEAT = (1 << 0),
125 CONTROL_SLOW = (1 << 1),
126 CONTROL_DEBOUNCE = (1 << 2),
127 CONTROL_STICKY = (1 << 3),
128 CONTROL_MOUSEKEYS = (1 << 4),
129 CONTROL_MOUSEKEYS_ACCEL = (1 << 5),
130 CONTROL_AX = (1 << 6),
131 CONTROL_AX_TIMEOUT = (1 << 7),
132 CONTROL_AX_FEEDBACK = (1 << 8),
133 CONTROL_BELL = (1 << 9),
134 CONTROL_IGNORE_GROUP_LOCK = (1 << 10),
135 CONTROL_ALL = \
136 (CONTROL_REPEAT | CONTROL_SLOW | CONTROL_DEBOUNCE | CONTROL_STICKY | \
137 CONTROL_MOUSEKEYS | CONTROL_MOUSEKEYS_ACCEL | CONTROL_AX | \
138 CONTROL_AX_TIMEOUT | CONTROL_AX_FEEDBACK | CONTROL_BELL | \
139 CONTROL_IGNORE_GROUP_LOCK)
140 };
141
142 enum xkb_match_operation {
143 MATCH_NONE,
144 MATCH_ANY_OR_NONE,
145 MATCH_ANY,
146 MATCH_ALL,
147 MATCH_EXACTLY,
148 };
149
150 struct xkb_mods {
151 xkb_mod_mask_t mods; /* original real+virtual mods in definition */
152 xkb_mod_mask_t mask; /* computed effective mask */
153 };
154
155 struct xkb_mod_action {
156 enum xkb_action_type type;
157 enum xkb_action_flags flags;
158 struct xkb_mods mods;
159 };
160
161 struct xkb_group_action {
162 enum xkb_action_type type;
163 enum xkb_action_flags flags;
164 int32_t group;
165 };
166
167 struct xkb_controls_action {
168 enum xkb_action_type type;
169 enum xkb_action_flags flags;
170 enum xkb_action_controls ctrls;
171 };
172
173 struct xkb_pointer_default_action {
174 enum xkb_action_type type;
175 enum xkb_action_flags flags;
176 int8_t value;
177 };
178
179 struct xkb_switch_screen_action {
180 enum xkb_action_type type;
181 enum xkb_action_flags flags;
182 int8_t screen;
183 };
184
185 struct xkb_pointer_action {
186 enum xkb_action_type type;
187 enum xkb_action_flags flags;
188 int16_t x;
189 int16_t y;
190 };
191
192 struct xkb_pointer_button_action {
193 enum xkb_action_type type;
194 enum xkb_action_flags flags;
195 uint8_t count;
196 uint8_t button;
197 };
198
199 struct xkb_private_action {
200 enum xkb_action_type type;
201 uint8_t data[7];
202 };
203
204 enum xkb_internal_action_flags {
205 INTERNAL_BREAKS_GROUP_LATCH = (1 << 0),
206 INTERNAL_BREAKS_MOD_LATCH = (1 << 1),
207 };
208
209 /* Action specific and internal to xkbcommon */
210 struct xkb_internal_action {
211 enum xkb_action_type type;
212 enum xkb_internal_action_flags flags;
213 union {
214 /* flag == INTERNAL_BREAKS_MOD_LATCH */
215 xkb_mod_mask_t clear_latched_mods;
216 };
217 };
218
219 union xkb_action {
220 enum xkb_action_type type;
221 struct xkb_mod_action mods;
222 struct xkb_group_action group;
223 struct xkb_controls_action ctrls;
224 struct xkb_pointer_default_action dflt;
225 struct xkb_switch_screen_action screen;
226 struct xkb_pointer_action ptr;
227 struct xkb_pointer_button_action btn;
228 struct xkb_private_action priv;
229 struct xkb_internal_action internal;
230 };
231
232 struct xkb_key_type_entry {
233 xkb_level_index_t level;
234 struct xkb_mods mods;
235 struct xkb_mods preserve;
236 };
237
238 struct xkb_key_type {
239 xkb_atom_t name;
240 struct xkb_mods mods;
241 bool required;
242 xkb_level_index_t num_levels;
243 xkb_level_index_t num_level_names;
244 xkb_atom_t *level_names;
245 darray_size_t num_entries;
246 struct xkb_key_type_entry *entries;
247 };
248
249 typedef uint16_t xkb_action_count_t;
250 #define MAX_ACTIONS_PER_LEVEL UINT16_MAX
251
252 struct xkb_sym_interpret {
253 xkb_keysym_t sym;
254 enum xkb_match_operation match;
255 xkb_mod_mask_t mods;
256 xkb_mod_index_t virtual_mod;
257 bool level_one_only;
258 bool repeat:1;
259 bool required:1;
260 xkb_action_count_t num_actions;
261 union {
262 /* num_actions <= 1 */
263 union xkb_action action;
264 /* num_actions > 1 */
265 union xkb_action *actions;
266 } a;
267 };
268
269 struct xkb_led {
270 xkb_atom_t name;
271 enum xkb_state_component which_groups;
272 xkb_layout_mask_t groups;
273 enum xkb_state_component which_mods;
274 struct xkb_mods mods;
275 enum xkb_action_controls ctrls;
276 };
277
278 struct xkb_key_alias {
279 xkb_atom_t real;
280 xkb_atom_t alias;
281 };
282
283 struct xkb_controls {
284 unsigned char groups_wrap;
285 struct xkb_mods internal;
286 struct xkb_mods ignore_lock;
287 unsigned short repeat_delay;
288 unsigned short repeat_interval;
289 unsigned short slow_keys_delay;
290 unsigned short debounce_delay;
291 unsigned short ax_options;
292 unsigned short ax_timeout;
293 unsigned short axt_opts_mask;
294 unsigned short axt_opts_values;
295 unsigned int axt_ctrls_mask;
296 unsigned int axt_ctrls_values;
297 };
298
299 /* Such an awkward name. Oh well. */
300 enum xkb_range_exceed_type {
301 RANGE_WRAP = 0,
302 RANGE_SATURATE,
303 RANGE_REDIRECT,
304 };
305
306 enum xkb_explicit_components {
307 EXPLICIT_SYMBOLS = (1 << 0),
308 EXPLICIT_INTERP = (1 << 1),
309 EXPLICIT_TYPES = (1 << 2),
310 EXPLICIT_VMODMAP = (1 << 3),
311 EXPLICIT_REPEAT = (1 << 4),
312 };
313
314 typedef uint16_t xkb_keysym_count_t;
315 #define MAX_KEYSYMS_PER_LEVEL UINT16_MAX
316
317 /** A key level */
318 struct xkb_level {
319 /** Count of keysyms */
320 xkb_keysym_count_t num_syms;
321 /** Count of actions */
322 xkb_action_count_t num_actions;
323 /** Upper keysym */
324 union {
325 /** num_syms == 1: Upper keysym */
326 xkb_keysym_t upper;
327 /** num_syms > 1: Indicate if `syms` contains the upper case keysyms
328 * after the lower ones. */
329 bool has_upper;
330 };
331 /** Keysyms */
332 union {
333 xkb_keysym_t sym; /* num_syms == 1 */
334 xkb_keysym_t *syms; /* num_syms > 1 */
335 } s;
336 /** Actions */
337 union {
338 union xkb_action action; /* num_actions == 1 */
339 union xkb_action *actions; /* num_actions > 1 */
340 } a;
341 };
342
343 /**
344 * Group in a key
345 */
346 struct xkb_group {
347 /**
348 * Flag that indicates whether a group has explicit actions. In case it has,
349 * compatibility interpretations will not be used on it.
350 * See also EXPLICIT_INTERP flag at key level.
351 */
352 bool explicit_actions:1;
353 /**
354 * Flag that indicates whether a group has an explicit key type. In case it
355 * has, type detection will not be used on it.
356 */
357 bool explicit_type:1;
358 /**
359 * Key type of the group. Points to an entry in keymap->types.
360 */
361 const struct xkb_key_type *type;
362 /**
363 * Array of group levels. Use `XkbKeyNumLevels` for the number of levels.
364 */
365 struct xkb_level *levels;
366 };
367
368 struct xkb_key {
369 xkb_keycode_t keycode;
370 xkb_atom_t name;
371
372 enum xkb_explicit_components explicit;
373
374 xkb_mod_mask_t modmap;
375 xkb_mod_mask_t vmodmap;
376
377 bool repeats;
378
379 enum xkb_range_exceed_type out_of_range_group_action;
380 xkb_layout_index_t out_of_range_group_number;
381
382 xkb_layout_index_t num_groups;
383 struct xkb_group *groups;
384 };
385
386 struct xkb_mod {
387 xkb_atom_t name;
388 enum mod_type type;
389 xkb_mod_mask_t mapping; /* vmod -> real mod mapping */
390 };
391
392 struct xkb_mod_set {
393 struct xkb_mod mods[XKB_MAX_MODS];
394 xkb_mod_index_t num_mods;
395 xkb_mod_mask_t explicit_vmods;
396 };
397
398 /*
399 * Implementation with continuous arrays does not allow efficient mapping of
400 * sparse keycodes. Indeed, allowing the API max valid keycode XKB_KEYCODE_MAX
401 * could result in memory exhaustion or memory waste (sparse arrays) with huge
402 * enough valid values. However usual keycodes form a contiguous range with a
403 * that maximum that rarely exceeds 1000. In order to handle the whole keycode
404 * range, we define a threshold for the continuous array storage, above which we
405 * use a more space-efficient storage for sparse arrays.
406 *
407 * The current limit is arbitrary and serves as a minimal security.
408 */
409 #define XKB_KEYCODE_MAX_CONTIGUOUS 0xfff
410 static_assert(XKB_KEYCODE_MAX_CONTIGUOUS < XKB_KEYCODE_MAX,
411 "Valid keycodes");
412 static_assert(XKB_KEYCODE_MAX_CONTIGUOUS < darray_max_alloc(sizeof(xkb_atom_t)),
413 "Max keycodes names");
414 static_assert(XKB_KEYCODE_MAX_CONTIGUOUS < darray_max_alloc(sizeof(struct xkb_key)),
415 "Max keymap keys");
416
417 /*
418 * Our current implementation with continuous arrays does not allow efficient
419 * mapping of levels. Allowing the max valid level UINT32_MAX could result in
420 * memory exhaustion or memory waste (sparse arrays) with huge enough valid
421 * values. Let’s be more conservative for now. This value should be big enough
422 * to satisfy automatically generated keymaps.
423 */
424 #define XKB_LEVEL_MAX_IMPL 2048
425 static_assert(XKB_LEVEL_MAX_IMPL < XKB_LEVEL_INVALID,
426 "Valid levels");
427 static_assert(XKB_LEVEL_MAX_IMPL < darray_max_alloc(sizeof(xkb_atom_t)),
428 "Max key types level names");
429 static_assert(XKB_LEVEL_MAX_IMPL < darray_max_alloc(sizeof(struct xkb_level)),
430 "Max keys levels");
431
432 static_assert((1LLU << (DARRAY_SIZE_T_WIDTH - 3)) - 1 >=
433 XKB_KEYCODE_MAX_CONTIGUOUS,
434 "Cannot store low keycodes");
435
436 /** Keycode store lookup result */
437 typedef union {
438 struct {
439 /** If true, the index is valid */
440 bool found:1;
441 bool:1;
442 /** Whether the corresponding entry is an alias */
443 bool is_alias:1;
444 darray_size_t:(DARRAY_SIZE_T_WIDTH - 3);
445 };
446 /* Only if is_alias = false, for better semantics */
447 struct {
448 bool found:1;
449 /**
450 * Whether the corresponding entry is stored in the low or high table
451 * of the keycode store
452 */
453 bool low:1;
454 bool is_alias:1;
455 /**
456 * - xkb_keycodes: index of the entry in the keycode store
457 * - xkb_symbols: index of the entry in xkb_keymap::keys array
458 */
459 darray_size_t index:(DARRAY_SIZE_T_WIDTH - 3);
460 } key;
461 /* Only if is_alias = true, for better semantics */
462 struct {
463 bool found:1;
464 bool:1;
465 bool is_alias:1;
466 /** Real name of the target key */
467 xkb_atom_t real:(DARRAY_SIZE_T_WIDTH - 3);
468 } alias;
469 } KeycodeMatch;
470
471 /* Common keyboard description structure */
472 struct xkb_keymap {
473 struct xkb_context *ctx;
474
475 int refcnt;
476 enum xkb_keymap_compile_flags flags;
477 enum xkb_keymap_format format;
478
479 enum xkb_action_controls enabled_ctrls;
480
481 xkb_keycode_t min_key_code;
482 xkb_keycode_t max_key_code;
483 xkb_keycode_t num_keys;
484 /*
485 * Keys are divided into 2 ordered (possibly empty) lists:
486 *
487 * Low keycodes (≤ XKB_KEYCODE_MAX_CONTIGUOUS)
488 * Stored contiguously at indexes [0..num_keys_low).
489 * Fast O(1) access.
490 * High keycodes (> XKB_KEYCODE_MAX_CONTIGUOUS)
491 * Stored noncontiguously at indexes [num_keys_low..num_keys).
492 * Slow access via a binary search.
493 */
494 xkb_keycode_t num_keys_low;
495 struct xkb_key *keys;
496
497 union {
498 /**
499 * Keycode name atom -> key index lookup table
500 *
501 * ⚠️ Used only *during* compilation
502 *
503 * Given that:
504 * - the number of atoms is usually < 1k;
505 * - the keycode section usually appears first;
506 * then the first atoms will be mostly the keycodes and their aliases,
507 * so we can achieve O(1) lookup of the key names by using a simple array.
508 */
509 struct {
510 darray_size_t num_key_names;
511 KeycodeMatch *key_names;
512 };
513 /**
514 * Aliases in no particular order
515 *
516 * ⚠️ Used only *after* compilation
517 */
518 struct {
519 darray_size_t num_key_aliases;
520 struct xkb_key_alias *key_aliases;
521 };
522 };
523
524 struct xkb_key_type *types;
525 darray_size_t num_types;
526
527 darray_size_t num_sym_interprets;
528 struct xkb_sym_interpret *sym_interprets;
529
530 /**
531 * Modifiers configuration.
532 * This is *internal* to the keymap; other implementations may use different
533 * virtual modifiers indices. Ours depends on:
534 * 1. the order of the parsing of the keymap components;
535 * 2. the order of the virtual modifiers declarations;
536 */
537 struct xkb_mod_set mods;
538 /**
539 * Modifier mask of the *canonical* state, i.e. the mask with the *smallest*
540 * population count that denotes all bits used to encode the modifiers in
541 * the keyboard state. It is equal to the bitwise OR of *real* modifiers and
542 * all *virtual* modifiers mappings.
543 *
544 * [WARNING] The bits that do not correspond to *real* modifiers should
545 * *not* be interpreted as corresponding to indices of virtual modifiers of
546 * the keymap. Indeed, one may use explicit vmod mapping with an arbitrary
547 * value.
548 *
549 * E.g. if M1 is the only vmod and it is defined by:
550 *
551 * virtual_modifiers M1=0x80000000; // 1 << (32 - 1)
552 *
553 * then the 32th bit of a modifier mask input does *not* denote the 32th
554 * virtual modifier of the keymap, but merely the encoding of the mapping of
555 * M1.
556 *
557 * In the API, any input mask should be preprocessed to resolve the bits
558 * that do not match the canonical mask.
559 */
560 xkb_mod_mask_t canonical_state_mask;
561
562 /* This field has 2 uses:
563 * • During parsing: Expected layouts count after RMLVO resolution, if any;
564 * • After parsing: Number of groups in the key with the most groups. */
565 xkb_layout_index_t num_groups;
566 /* Not all groups must have names. */
567 xkb_layout_index_t num_group_names;
568 xkb_atom_t *group_names;
569
570 struct xkb_led leds[XKB_MAX_LEDS];
571 xkb_led_index_t num_leds;
572
573 char *keycodes_section_name;
574 char *symbols_section_name;
575 char *types_section_name;
576 char *compat_section_name;
577 };
578
579 #define xkb_keys_foreach(iter, keymap) \
580 /*
581 * Start at the first defined low or high keycode:
582 * - if there are some low keycodes, the index is min_key_code, because we
583 * skip the previous undefined keycodes;
584 * - else the first item is the first high keycode.
585 */ \
586 for ((iter) = (keymap)->keys + \
587 ((keymap)->num_keys_low == 0 ? 0 : (keymap)->min_key_code); \
588 (iter) < (keymap)->keys + (keymap)->num_keys; \
589 (iter)++)
590
591 #define xkb_mods_foreach(iter, mods_) \
592 for ((iter) = (mods_)->mods; \
593 (iter) < (mods_)->mods + (mods_)->num_mods; \
594 (iter)++)
595
596 #define xkb_mods_mask_foreach(mask, iter, mods_) \
597 for ((iter) = (mods_)->mods; \
598 (mask) && (iter) < (mods_)->mods + (mods_)->num_mods; \
599 (iter)++, (mask) >>= 1) \
600 if ((mask) & 0x1)
601
602 /** Enumerate all modifiers */
603 #define xkb_mods_enumerate(idx, iter, mods_) \
604 for ((idx) = 0, (iter) = (mods_)->mods; \
605 (idx) < (mods_)->num_mods; \
606 (idx)++, (iter)++)
607
608 /** Enumerate only real modifiers */
609 #define xkb_rmods_enumerate(idx, iter, mods_) \
610 for ((idx) = 0, (iter) = (mods_)->mods; \
611 (idx) < _XKB_MOD_INDEX_NUM_ENTRIES; \
612 (idx)++, (iter)++)
613
614 /** Enumerate only virtual modifiers */
615 #define xkb_vmods_enumerate(idx, iter, mods_) \
616 for ((idx) = _XKB_MOD_INDEX_NUM_ENTRIES, \
617 (iter) = &(mods_)->mods[_XKB_MOD_INDEX_NUM_ENTRIES]; \
618 (idx) < (mods_)->num_mods; \
619 (idx)++, (iter)++)
620
621 #define xkb_leds_foreach(iter, keymap) \
622 for ((iter) = (keymap)->leds; \
623 (iter) < (keymap)->leds + (keymap)->num_leds; \
624 (iter)++)
625
626 #define xkb_leds_enumerate(idx, iter, keymap) \
627 for ((idx) = 0, (iter) = (keymap)->leds; \
628 (idx) < (keymap)->num_leds; \
629 (idx)++, (iter)++)
630
631 void
632 clear_level(struct xkb_level *leveli);
633
634 static inline const struct xkb_key *
635 XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc)
636 {
637 if (kc < keymap->min_key_code || kc > keymap->max_key_code) {
638 /* Unsupported keycode */
639 return NULL;
640 } else if (kc < keymap->num_keys_low) {
641 /* Low keycodes */
642 return &keymap->keys[kc];
643 } else {
644 /* High keycodes: use binary search */
645 xkb_keycode_t lower = keymap->num_keys_low;
646 xkb_keycode_t upper = keymap->num_keys;
647 while (lower < upper) {
648 const xkb_keycode_t mid = lower + (upper - 1 - lower) / 2;
649 const struct xkb_key * const key = &keymap->keys[mid];
650 if (key->keycode < kc) {
651 lower = mid + 1;
652 } else if (key->keycode > kc) {
653 upper = mid;
654 } else {
655 return key;
656 }
657 }
658 return NULL;
659 }
660 }
661
662 static inline xkb_level_index_t
663 XkbKeyNumLevels(const struct xkb_key *key, xkb_layout_index_t layout)
664 {
665 return key->groups[layout].type->num_levels;
666 }
667
668 /*
669 * Map entries which specify unbound virtual modifiers are not considered.
670 * See: the XKB protocol, section “Determining the KeySym Associated with a Key
671 * Event”
672 *
673 * xserver does this with cached entry->active field.
674 */
675 static inline bool
676 entry_is_active(const struct xkb_key_type_entry *entry)
677 {
678 return entry->mods.mods == 0 || entry->mods.mask != 0;
679 }
680
681 struct xkb_keymap *
682 xkb_keymap_new(struct xkb_context *ctx,
683 enum xkb_keymap_format format,
684 enum xkb_keymap_compile_flags flags);
685
686 void
687 XkbEscapeMapName(char *name);
688
689 xkb_mod_index_t
690 XkbModNameToIndex(const struct xkb_mod_set *mods, xkb_atom_t name,
691 enum mod_type type);
692
693 bool
694 XkbLevelsSameSyms(const struct xkb_level *a, const struct xkb_level *b);
695
696 bool
697 action_equal(const union xkb_action *a, const union xkb_action *b);
698
699 bool
700 XkbLevelsSameActions(const struct xkb_level *a, const struct xkb_level *b);
701
702 xkb_layout_index_t
703 XkbWrapGroupIntoRange(int32_t group,
704 xkb_layout_index_t num_groups,
705 enum xkb_range_exceed_type out_of_range_group_action,
706 xkb_layout_index_t out_of_range_group_number);
707
708 XKB_EXPORT_PRIVATE xkb_mod_mask_t
709 mod_mask_get_effective(struct xkb_keymap *keymap, xkb_mod_mask_t mods);
710
711 struct xkb_level *
712 xkb_keymap_key_get_level(struct xkb_keymap *keymap, const struct xkb_key *key,
713 xkb_layout_index_t layout, xkb_level_index_t level);
714
715 xkb_action_count_t
716 xkb_keymap_key_get_actions_by_level(struct xkb_keymap *keymap,
717 const struct xkb_key *key,
718 xkb_layout_index_t layout,
719 xkb_level_index_t level,
720 const union xkb_action **actions);
721
722 struct xkb_keymap_format_ops {
723 bool (*keymap_new_from_rmlvo)(struct xkb_keymap *keymap,
724 const struct xkb_rmlvo_builder *rmlvo);
725 bool (*keymap_new_from_names)(struct xkb_keymap *keymap,
726 const struct xkb_rule_names *names);
727 bool (*keymap_new_from_string)(struct xkb_keymap *keymap,
728 const char *string, size_t length);
729 bool (*keymap_new_from_file)(struct xkb_keymap *keymap, FILE *file);
730 char *(*keymap_get_as_string)(struct xkb_keymap *keymap,
731 enum xkb_keymap_format format,
732 enum xkb_keymap_serialize_flags flags);
733 };
734
735 extern const struct xkb_keymap_format_ops text_v1_keymap_format_ops;