2 * Copyright 1985, 1987, 1990, 1998 The Open Group
3 * Copyright 2008 Dan Nicholson
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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.
28 /************************************************************
29 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
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.
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.
52 ********************************************************/
55 * Copyright © 2012 Intel Corporation
57 * Permission is hereby granted, free of charge, to any person obtaining a
58 * copy of this software and associated documentation files (the "Software"),
59 * to deal in the Software without restriction, including without limitation
60 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
61 * and/or sell copies of the Software, and to permit persons to whom the
62 * Software is furnished to do so, subject to the following conditions:
64 * The above copyright notice and this permission notice (including the next
65 * paragraph) shall be included in all copies or substantial portions of the
68 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
71 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
73 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
74 * DEALINGS IN THE SOFTWARE.
76 * Author: Daniel Stone <daniel@fooishbar.org>
85 #include <X11/extensions/XKB.h>
88 #include "xkbcommon/xkbcommon.h"
93 /* The top level file which includes the other component files. */
94 FILE_TYPE_KEYMAP = (1 << 0),
96 /* Component files. */
97 FILE_TYPE_TYPES = (1 << 1),
98 FILE_TYPE_COMPAT = (1 << 2),
99 FILE_TYPE_SYMBOLS = (1 << 3),
100 FILE_TYPE_KEYCODES = (1 << 4),
101 FILE_TYPE_GEOMETRY = (1 << 5),
103 /* This one doesn't mix with the others, but useful here as well. */
104 FILE_TYPE_RULES = (1 << 6),
107 /* Files needed for a complete keymap. */
108 #define REQUIRED_FILE_TYPES (FILE_TYPE_TYPES | FILE_TYPE_COMPAT | \
109 FILE_TYPE_SYMBOLS | FILE_TYPE_KEYCODES)
110 #define LEGAL_FILE_TYPES REQUIRED_FILE_TYPES
113 * Legacy names for the components of an XKB keymap, also known as KcCGST.
115 struct xkb_component_names {
122 struct xkb_any_action {
127 struct xkb_mod_action {
135 struct xkb_group_action {
141 struct xkb_iso_action {
151 struct xkb_controls_action {
157 struct xkb_device_button_action {
165 struct xkb_device_valuator_action {
176 struct xkb_pointer_default_action {
183 struct xkb_switch_screen_action {
189 struct xkb_redirect_key_action {
191 xkb_keycode_t new_key;
198 struct xkb_pointer_action {
205 struct xkb_message_action {
211 struct xkb_pointer_button_action {
219 struct xkb_any_action any;
220 struct xkb_mod_action mods;
221 struct xkb_group_action group;
222 struct xkb_iso_action iso;
223 struct xkb_controls_action ctrls;
224 struct xkb_device_button_action devbtn;
225 struct xkb_device_valuator_action devval;
226 struct xkb_pointer_default_action dflt;
227 struct xkb_switch_screen_action screen;
228 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
229 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
230 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
231 struct xkb_message_action msg; /* XXX just delete */
236 uint32_t mask; /* effective mods */
241 struct xkb_kt_map_entry {
243 struct xkb_mods mods;
246 struct xkb_key_type {
247 struct xkb_mods mods;
249 darray(struct xkb_kt_map_entry) map;
250 struct xkb_mods * preserve;
255 struct xkb_sym_interpret {
260 uint32_t virtual_mod;
261 union xkb_action act;
265 unsigned char kt_index[XkbNumKbdGroups];
266 unsigned char group_info;
268 int *sym_index; /* per level/group index into 'syms' */
269 unsigned int *num_syms; /* per level/group */
270 darray(xkb_keysym_t) syms;
273 struct xkb_behavior {
278 struct xkb_indicator_map {
280 unsigned char which_groups;
281 unsigned char groups;
282 unsigned char which_mods;
283 struct xkb_mods mods;
287 struct xkb_key_name {
288 char name[XkbKeyNameLength];
291 struct xkb_key_alias {
292 char real[XkbKeyNameLength];
293 char alias[XkbKeyNameLength];
296 struct xkb_controls {
297 /* unsigned char groups_wrap; */
298 /* struct xkb_mods internal; */
299 /* struct xkb_mods ignore_lock; */
300 unsigned int enabled_ctrls;
301 /* unsigned short repeat_delay; */
302 /* unsigned short repeat_interval; */
303 /* unsigned short slow_keys_delay; */
304 /* unsigned short debounce_delay; */
305 /* unsigned short ax_options; */
306 /* unsigned short ax_timeout; */
307 /* unsigned short axt_opts_mask; */
308 /* unsigned short axt_opts_values; */
309 /* unsigned int axt_ctrls_mask; */
310 /* unsigned int axt_ctrls_values; */
311 unsigned char *per_key_repeat;
314 /* Common keyboard description structure */
316 struct xkb_context *ctx;
319 unsigned short flags;
320 xkb_keycode_t min_key_code;
321 xkb_keycode_t max_key_code;
323 struct xkb_controls * ctrls;
325 /* key -> key name mapping */
326 darray(struct xkb_key_name) key_names;
327 /* aliases in no particular order */
328 darray(struct xkb_key_alias) key_aliases;
330 /* key -> explicit flags mapping */
331 unsigned char *explicit;
333 darray(struct xkb_key_type) types;
335 /* key -> symbols mapping */
336 darray(struct xkb_sym_map) key_sym_map;
338 darray(struct xkb_sym_interpret) sym_interpret;
340 /* key -> mod mapping */
341 unsigned char *modmap;
342 /* key -> vmod mapping */
344 /* vmod -> mod mapping */
345 uint32_t vmods[XkbNumVirtualMods];
346 char *vmod_names[XkbNumVirtualMods];
348 struct xkb_mods groups[XkbNumKbdGroups];
349 char *group_names[XkbNumKbdGroups];
351 /* key -> actions mapping: acts[key_acts[keycode]] */
352 darray(union xkb_action) acts;
353 darray(size_t) key_acts;
355 /* key -> behavior mapping */
356 struct xkb_behavior *behaviors;
358 struct xkb_indicator_map indicators[XkbNumIndicators];
359 char *indicator_names[XkbNumIndicators];
361 char *keycodes_section_name;
362 char *symbols_section_name;
363 char *types_section_name;
364 char *compat_section_name;
367 #define XkbNumGroups(g) ((g) & 0x0f)
368 #define XkbOutOfRangeGroupInfo(g) ((g) & 0xf0)
369 #define XkbOutOfRangeGroupAction(g) ((g) & 0xc0)
370 #define XkbOutOfRangeGroupNumber(g) (((g) & 0x30) >> 4)
371 #define XkbSetGroupInfo(g, w, \
373 0xc0) | (((n) & 3) << 4) | ((g) & 0x0f))
374 #define XkbSetNumGroups(g, n) (((g) & 0xf0) | ((n) & 0x0f))
376 #define XkbKeyGroupInfo(d, k) \
377 (darray_item((d)->key_sym_map, k).group_info)
378 #define XkbKeyNumGroups(d, k) \
379 (XkbNumGroups(darray_item((d)->key_sym_map, k).group_info))
380 #define XkbKeyGroupWidth(d, k, g) \
381 (XkbKeyType(d, k, g)->num_levels)
382 #define XkbKeyGroupsWidth(d, k) \
383 (darray_item((d)->key_sym_map, k).width)
384 #define XkbKeyTypeIndex(d, k, g) \
385 (darray_item((d)->key_sym_map, k).kt_index[g & 0x3])
386 #define XkbKeyType(d, k, g) \
387 (&darray_item((d)->types, XkbKeyTypeIndex(d, k, g)))
388 #define XkbKeyNumSyms(d, k, g, sl) \
389 (darray_item((d)->map->key_sym_map, \
390 k).num_syms[(g * XkbKeyGroupsWidth(d, k)) + sl])
391 #define XkbKeySym(d, k, n) \
392 (&darray_item(darray_item((d)->key_sym_map, k).syms, n))
393 #define XkbKeySymOffset(d, k, g, sl) \
394 (darray_item((d)->map->key_sym_map, \
395 k).sym_index[(g * XkbKeyGroupsWidth(d, k)) + sl])
396 #define XkbKeySymEntry(d, k, g, sl) \
397 (XkbKeySym(d, k, XkbKeySymOffset(d, k, g, sl)))
398 #define XkbKeyHasActions(d, k) \
399 (darray_item((d)->key_acts, k) != 0)
400 #define XkbKeyNumActions(d, k) \
401 (XkbKeyHasActions(d, k) ? \
402 (XkbKeyGroupsWidth(d, k) * XkbKeyNumGroups(d, k)) : \
404 #define XkbKeyActionsPtr(d, k) \
405 (darray_mem((d)->acts, darray_item((d)->key_acts, k)))
406 #define XkbKeyAction(d, k, n) \
407 (XkbKeyHasActions(d, k) ? &XkbKeyActionsPtr(d, k)[n] : NULL)
408 #define XkbKeyActionEntry(d, k, sl, g) \
409 (XkbKeyHasActions(d, k) ? \
410 XkbKeyAction(d, k, ((XkbKeyGroupsWidth(d, k) * (g)) + (sl))) : \
413 #define XkbKeycodeInRange(d, k) \
414 (((k) >= (d)->min_key_code) && ((k) <= (d)->max_key_code))
416 typedef uint32_t xkb_atom_t;
418 #define XKB_ATOM_NONE 0
421 xkb_atom_intern(struct xkb_context *ctx, const char *string);
424 xkb_atom_strdup(struct xkb_context *ctx, xkb_atom_t atom);
427 xkb_atom_text(struct xkb_context *ctx, xkb_atom_t atom);
430 xkb_key_get_group(struct xkb_state *state, xkb_keycode_t key);
433 xkb_key_get_level(struct xkb_state *state, xkb_keycode_t key,
437 xkb_key_get_syms_by_level(struct xkb_keymap *keymap, xkb_keycode_t key,
438 unsigned int group, unsigned int level,
439 const xkb_keysym_t **syms_out);
442 * Deprecated entrypoint for legacy users who need to be able to compile
443 * XKB keymaps by KcCGST (Keycodes + Compat + Geometry + Symbols + Types)
446 * You should not use this unless you are the X server. This entrypoint
447 * may well disappear in future releases. Please, please, don't use it.
449 * Geometry will be ignored since xkbcommon does not support it in any way.
452 xkb_map_new_from_kccgst(struct xkb_context *ctx,
453 const struct xkb_component_names *kccgst,
454 enum xkb_map_compile_flags flags);
457 xkb_context_take_file_id(struct xkb_context *ctx);
460 xkb_keysym_is_lower(xkb_keysym_t keysym);
463 xkb_keysym_is_upper(xkb_keysym_t keysym);
466 xkb_keysym_is_keypad(xkb_keysym_t keysym);
468 #endif /* XKB_PRIV_H */