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>
79 #ifndef _XKBCOMMONINT_H_
80 #define _XKBCOMMONINT_H_
85 #include "xkbcommon/xkbcommon.h"
92 #define _XkbTypedAlloc(t) ((t *)malloc(sizeof(t)))
93 #define _XkbTypedCalloc(n,t) ((t *)calloc((n),sizeof(t)))
94 #define _XkbTypedRealloc(o,n,t) \
95 ((o)?(t *)realloc((o),(n)*sizeof(t)):_XkbTypedCalloc(n,t))
96 #define _XkbClearElems(a,f,l,t) memset(&(a)[f], 0, ((l) - (f) + 1) * sizeof(t))
98 #define _XkbDupString(s) ((s) ? strdup(s) : NULL)
99 #define _XkbStrCaseCmp strcasecmp
102 #define XkmFileVersion 15
104 #define XkmIllegalFile -1
105 #define XkmSemanticsFile 20
106 #define XkmLayoutFile 21
107 #define XkmKeymapFile 22
108 #define XkmGeometryFile 23
109 #define XkmRulesFile 24
111 #define XkmTypesIndex 0
112 #define XkmCompatMapIndex 1
113 #define XkmSymbolsIndex 2
114 #define XkmIndicatorsIndex 3
115 #define XkmKeyNamesIndex 4
116 #define XkmGeometryIndex 5
117 #define XkmVirtualModsIndex 6
118 #define XkmLastIndex XkmVirtualModsIndex
120 #define XkmTypesMask (1<<0)
121 #define XkmCompatMapMask (1<<1)
122 #define XkmSymbolsMask (1<<2)
123 #define XkmIndicatorsMask (1<<3)
124 #define XkmKeyNamesMask (1<<4)
125 #define XkmGeometryMask (1<<5)
126 #define XkmVirtualModsMask (1<<6)
127 #define XkmLegalIndexMask (0x7f)
128 #define XkmAllIndicesMask (0x7f)
130 #define XkmSemanticsRequired (XkmCompatMapMask)
131 #define XkmSemanticsOptional (XkmTypesMask|XkmVirtualModsMask|XkmIndicatorsMask|XkmGeometryMask)
132 #define XkmSemanticsLegal (XkmSemanticsRequired|XkmSemanticsOptional)
133 #define XkmLayoutRequired (XkmKeyNamesMask|XkmSymbolsMask|XkmTypesMask)
134 #define XkmLayoutOptional (XkmVirtualModsMask|XkmGeometryMask)
135 #define XkmLayoutLegal (XkmLayoutRequired|XkmLayoutOptional)
136 #define XkmKeymapRequired (XkmSemanticsRequired|XkmLayoutRequired)
137 #define XkmKeymapOptional ((XkmSemanticsOptional|XkmLayoutOptional)&(~XkmKeymapRequired))
138 #define XkmKeymapLegal (XkmKeymapRequired|XkmKeymapOptional)
140 #define XkmLegalSection(m) (((m)&(~XkmKeymapLegal))==0)
141 #define XkmSingleSection(m) (XkmLegalSection(m)&&(((m)&(~(m)+1))==(m)))
143 extern unsigned int xkb_key_get_group(struct xkb_state *state,
145 extern unsigned int xkb_key_get_level(struct xkb_state *state,
149 struct xkb_any_action {
154 struct xkb_mod_action {
162 struct xkb_group_action {
168 struct xkb_iso_action {
178 struct xkb_controls_action {
184 struct xkb_device_button_action {
192 struct xkb_device_valuator_action {
203 struct xkb_pointer_default_action {
210 struct xkb_switch_screen_action {
216 struct xkb_redirect_key_action {
218 xkb_keycode_t new_key;
225 struct xkb_pointer_action {
232 struct xkb_message_action {
238 struct xkb_pointer_button_action {
246 struct xkb_any_action any;
247 struct xkb_mod_action mods;
248 struct xkb_group_action group;
249 struct xkb_iso_action iso;
250 struct xkb_controls_action ctrls;
251 struct xkb_device_button_action devbtn;
252 struct xkb_device_valuator_action devval;
253 struct xkb_pointer_default_action dflt;
254 struct xkb_switch_screen_action screen;
255 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
256 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
257 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
258 struct xkb_message_action msg; /* XXX just delete */
263 uint32_t mask; /* effective mods */
268 struct xkb_kt_map_entry {
271 struct xkb_mods mods;
274 struct xkb_key_type {
275 struct xkb_mods mods;
277 unsigned char map_count;
278 struct xkb_kt_map_entry * map;
279 struct xkb_mods * preserve;
281 const char **level_names;
284 struct xkb_sym_interpret {
289 uint32_t virtual_mod;
290 union xkb_action act;
293 struct xkb_compat_map {
294 struct xkb_sym_interpret * sym_interpret;
295 struct xkb_mods groups[XkbNumKbdGroups];
296 unsigned short num_si;
297 unsigned short size_si;
301 unsigned char kt_index[XkbNumKbdGroups];
302 unsigned char group_info;
304 unsigned short offset;
307 #define XkbNumGroups(g) ((g)&0x0f)
308 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
309 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
310 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
311 #define XkbSetGroupInfo(g,w,n) (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
312 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
314 struct xkb_client_map {
315 unsigned char size_types;
316 unsigned char num_types;
317 struct xkb_key_type * types;
322 struct xkb_sym_map * key_sym_map;
324 unsigned char *modmap;
327 struct xkb_behavior {
332 struct xkb_server_map {
333 unsigned short num_acts;
334 unsigned short size_acts;
336 #if defined(__cplusplus) || defined(c_plusplus)
337 /* explicit is a C++ reserved word */
338 unsigned char * c_explicit;
340 unsigned char * explicit;
343 union xkb_action *acts;
344 struct xkb_behavior *behaviors;
345 unsigned short *key_acts;
346 unsigned char *explicits;
347 uint32_t vmods[XkbNumVirtualMods]; /* vmod -> mod mapping */
348 uint32_t *vmodmap; /* key -> vmod mapping */
352 struct xkb_indicator_map {
354 unsigned char which_groups;
355 unsigned char groups;
356 unsigned char which_mods;
357 struct xkb_mods mods;
361 struct xkb_indicator {
362 unsigned long phys_indicators;
363 struct xkb_indicator_map maps[XkbNumIndicators];
366 struct xkb_key_name {
367 char name[XkbKeyNameLength];
370 struct xkb_key_alias {
371 char real[XkbKeyNameLength];
372 char alias[XkbKeyNameLength];
376 const char *vmods[XkbNumVirtualMods];
377 const char *indicators[XkbNumIndicators];
378 const char *groups[XkbNumKbdGroups];
379 struct xkb_key_name * keys;
380 struct xkb_key_alias * key_aliases;
382 xkb_keycode_t num_keys;
383 xkb_keycode_t num_key_aliases;
386 struct xkb_controls {
387 unsigned char num_groups;
388 unsigned char groups_wrap;
389 struct xkb_mods internal;
390 struct xkb_mods ignore_lock;
391 unsigned int enabled_ctrls;
392 unsigned short repeat_delay;
393 unsigned short repeat_interval;
394 unsigned short slow_keys_delay;
395 unsigned short debounce_delay;
396 unsigned short ax_options;
397 unsigned short ax_timeout;
398 unsigned short axt_opts_mask;
399 unsigned short axt_opts_values;
400 unsigned int axt_ctrls_mask;
401 unsigned int axt_ctrls_values;
402 unsigned char *per_key_repeat;
405 /* Common keyboard description structure */
408 unsigned int defined;
409 unsigned short flags;
410 unsigned short device_spec;
411 xkb_keycode_t min_key_code;
412 xkb_keycode_t max_key_code;
414 struct xkb_controls * ctrls;
415 struct xkb_server_map * server;
416 struct xkb_client_map * map;
417 struct xkb_indicator * indicators;
418 struct xkb_names * names;
419 struct xkb_compat_map * compat;
422 #define XkbKeyGroupInfo(d,k) ((d)->map->key_sym_map[k].group_info)
423 #define XkbKeyNumGroups(d,k) (XkbNumGroups((d)->map->key_sym_map[k].group_info))
424 #define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
425 #define XkbKeyGroupsWidth(d,k) ((d)->map->key_sym_map[k].width)
426 #define XkbKeyTypeIndex(d,k,g) ((d)->map->key_sym_map[k].kt_index[g&0x3])
427 #define XkbKeyType(d,k,g) (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
428 #define XkbKeyNumSyms(d,k) (XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k))
429 #define XkbKeySymsOffset(d,k) ((d)->map->key_sym_map[k].offset)
430 #define XkbKeySymsPtr(d,k) (&(d)->map->syms[XkbKeySymsOffset(d,k)])
431 #define XkbKeySym(d,k,n) (XkbKeySymsPtr(d,k)[n])
432 #define XkbKeySymEntry(d,k,sl,g) \
433 (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
434 #define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0)
435 #define XkbKeyNumActions(d,k) (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
436 #define XkbKeyActionsPtr(d,k) (&(d)->server->acts[(d)->server->key_acts[k]])
437 #define XkbKeyAction(d,k,n) \
438 (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
439 #define XkbKeyActionEntry(d,k,sl,g) \
440 (XkbKeyHasActions(d,k)?\
441 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
443 #define XkbKeycodeInRange(d,k) (((k)>=(d)->min_key_code)&&\
444 ((k)<=(d)->max_key_code))
445 #define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
447 struct xkb_component_name {
448 unsigned short flags;
453 xkb_group_index_t base_group; /**< depressed */
454 xkb_group_index_t latched_group;
455 xkb_group_index_t locked_group;
456 xkb_group_index_t group; /**< effective */
458 xkb_mod_mask_t base_mods; /**< depressed */
459 xkb_mod_mask_t latched_mods;
460 xkb_mod_mask_t locked_mods;
461 xkb_mod_mask_t mods; /**< effective */
468 struct xkb_desc *xkb;
471 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
472 #define XkbGrabStateFromRec(s) XkbBuildCoreState((s)->grab_mods,(s)->group)
474 #define XkbNumGroups(g) ((g)&0x0f)
475 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
476 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
477 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
478 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
480 #endif /* _XKBCOMMONINT_H_ */