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 extern unsigned int xkb_key_get_group(struct xkb_state *state,
142 extern unsigned int xkb_key_get_level(struct xkb_state *state,
146 struct xkb_any_action {
151 struct xkb_mod_action {
159 struct xkb_group_action {
165 struct xkb_iso_action {
175 struct xkb_controls_action {
181 struct xkb_device_button_action {
189 struct xkb_device_valuator_action {
200 struct xkb_pointer_default_action {
207 struct xkb_switch_screen_action {
213 struct xkb_redirect_key_action {
215 xkb_keycode_t new_key;
222 struct xkb_pointer_action {
229 struct xkb_message_action {
235 struct xkb_pointer_button_action {
243 struct xkb_any_action any;
244 struct xkb_mod_action mods;
245 struct xkb_group_action group;
246 struct xkb_iso_action iso;
247 struct xkb_controls_action ctrls;
248 struct xkb_device_button_action devbtn;
249 struct xkb_device_valuator_action devval;
250 struct xkb_pointer_default_action dflt;
251 struct xkb_switch_screen_action screen;
252 struct xkb_redirect_key_action redirect; /* XXX wholly unnecessary? */
253 struct xkb_pointer_action ptr; /* XXX delete for DeviceValuator */
254 struct xkb_pointer_button_action btn; /* XXX delete for DeviceBtn */
255 struct xkb_message_action msg; /* XXX just delete */
260 uint32_t mask; /* effective mods */
265 struct xkb_kt_map_entry {
268 struct xkb_mods mods;
271 struct xkb_key_type {
272 struct xkb_mods mods;
274 unsigned char map_count;
275 struct xkb_kt_map_entry * map;
276 struct xkb_mods * preserve;
278 const char **level_names;
281 struct xkb_sym_interpret {
286 uint32_t virtual_mod;
287 union xkb_action act;
290 struct xkb_compat_map {
291 struct xkb_sym_interpret * sym_interpret;
292 struct xkb_mods groups[XkbNumKbdGroups];
293 unsigned short num_si;
294 unsigned short size_si;
298 unsigned char kt_index[XkbNumKbdGroups];
299 unsigned char group_info;
301 unsigned short offset;
304 #define XkbNumGroups(g) ((g)&0x0f)
305 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
306 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
307 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
308 #define XkbSetGroupInfo(g,w,n) (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
309 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
311 struct xkb_client_map {
312 unsigned char size_types;
313 unsigned char num_types;
314 struct xkb_key_type * types;
319 struct xkb_sym_map * key_sym_map;
321 unsigned char *modmap;
324 struct xkb_behavior {
329 struct xkb_server_map {
330 unsigned short num_acts;
331 unsigned short size_acts;
333 #if defined(__cplusplus) || defined(c_plusplus)
334 /* explicit is a C++ reserved word */
335 unsigned char * c_explicit;
337 unsigned char * explicit;
340 union xkb_action *acts;
341 struct xkb_behavior *behaviors;
342 unsigned short *key_acts;
343 unsigned char *explicits;
344 uint32_t vmods[XkbNumVirtualMods]; /* vmod -> mod mapping */
345 uint32_t *vmodmap; /* key -> vmod mapping */
349 struct xkb_indicator_map {
351 unsigned char which_groups;
352 unsigned char groups;
353 unsigned char which_mods;
354 struct xkb_mods mods;
358 struct xkb_indicator {
359 unsigned long phys_indicators;
360 struct xkb_indicator_map maps[XkbNumIndicators];
363 struct xkb_key_name {
364 char name[XkbKeyNameLength];
367 struct xkb_key_alias {
368 char real[XkbKeyNameLength];
369 char alias[XkbKeyNameLength];
373 const char *vmods[XkbNumVirtualMods];
374 const char *indicators[XkbNumIndicators];
375 const char *groups[XkbNumKbdGroups];
376 struct xkb_key_name * keys;
377 struct xkb_key_alias * key_aliases;
379 xkb_keycode_t num_keys;
380 xkb_keycode_t num_key_aliases;
383 struct xkb_controls {
384 unsigned char num_groups;
385 unsigned char groups_wrap;
386 struct xkb_mods internal;
387 struct xkb_mods ignore_lock;
388 unsigned int enabled_ctrls;
389 unsigned short repeat_delay;
390 unsigned short repeat_interval;
391 unsigned short slow_keys_delay;
392 unsigned short debounce_delay;
393 unsigned short ax_options;
394 unsigned short ax_timeout;
395 unsigned short axt_opts_mask;
396 unsigned short axt_opts_values;
397 unsigned int axt_ctrls_mask;
398 unsigned int axt_ctrls_values;
399 unsigned char *per_key_repeat;
402 /* Common keyboard description structure */
405 unsigned int defined;
406 unsigned short flags;
407 unsigned short device_spec;
408 xkb_keycode_t min_key_code;
409 xkb_keycode_t max_key_code;
411 struct xkb_controls * ctrls;
412 struct xkb_server_map * server;
413 struct xkb_client_map * map;
414 struct xkb_indicator * indicators;
415 struct xkb_names * names;
416 struct xkb_compat_map * compat;
419 #define XkbKeyGroupInfo(d,k) ((d)->map->key_sym_map[k].group_info)
420 #define XkbKeyNumGroups(d,k) (XkbNumGroups((d)->map->key_sym_map[k].group_info))
421 #define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
422 #define XkbKeyGroupsWidth(d,k) ((d)->map->key_sym_map[k].width)
423 #define XkbKeyTypeIndex(d,k,g) ((d)->map->key_sym_map[k].kt_index[g&0x3])
424 #define XkbKeyType(d,k,g) (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
425 #define XkbKeyNumSyms(d,k) (XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k))
426 #define XkbKeySymsOffset(d,k) ((d)->map->key_sym_map[k].offset)
427 #define XkbKeySymsPtr(d,k) (&(d)->map->syms[XkbKeySymsOffset(d,k)])
428 #define XkbKeySym(d,k,n) (XkbKeySymsPtr(d,k)[n])
429 #define XkbKeySymEntry(d,k,sl,g) \
430 (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
431 #define XkbKeyHasActions(d,k) ((d)->server->key_acts[k]!=0)
432 #define XkbKeyNumActions(d,k) (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
433 #define XkbKeyActionsPtr(d,k) (&(d)->server->acts[(d)->server->key_acts[k]])
434 #define XkbKeyAction(d,k,n) \
435 (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
436 #define XkbKeyActionEntry(d,k,sl,g) \
437 (XkbKeyHasActions(d,k)?\
438 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
440 #define XkbKeycodeInRange(d,k) (((k)>=(d)->min_key_code)&&\
441 ((k)<=(d)->max_key_code))
442 #define XkbNumKeys(d) ((d)->max_key_code-(d)->min_key_code+1)
444 struct xkb_component_name {
445 unsigned short flags;
450 xkb_group_index_t base_group; /**< depressed */
451 xkb_group_index_t latched_group;
452 xkb_group_index_t locked_group;
453 xkb_group_index_t group; /**< effective */
455 xkb_mod_mask_t base_mods; /**< depressed */
456 xkb_mod_mask_t latched_mods;
457 xkb_mod_mask_t locked_mods;
458 xkb_mod_mask_t mods; /**< effective */
465 struct xkb_desc *xkb;
468 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
469 #define XkbGrabStateFromRec(s) XkbBuildCoreState((s)->grab_mods,(s)->group)
471 #define XkbNumGroups(g) ((g)&0x0f)
472 #define XkbOutOfRangeGroupInfo(g) ((g)&0xf0)
473 #define XkbOutOfRangeGroupAction(g) ((g)&0xc0)
474 #define XkbOutOfRangeGroupNumber(g) (((g)&0x30)>>4)
475 #define XkbSetNumGroups(g,n) (((g)&0xf0)|((n)&0x0f))
477 #endif /* _XKBCOMMONINT_H_ */