5d63ce9f313295365da7c4d135817bbb17cf0064
[platform/upstream/libxkbcommon.git] / src / XKBcommonint.h
1 /*
2 Copyright 1985, 1987, 1990, 1998  The Open Group
3 Copyright 2008  Dan Nicholson
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
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.
26 */
27
28 /************************************************************
29 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
30
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.
42
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.
51
52 ********************************************************/
53
54 /*
55  * Copyright © 2012 Intel Corporation
56  *
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:
63  *
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
66  * Software.
67  *
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.
75  *
76  * Author: Daniel Stone <daniel@fooishbar.org>
77  */
78
79 #ifndef _XKBCOMMONINT_H_
80 #define _XKBCOMMONINT_H_
81
82 #include <stdlib.h>
83 #include <string.h>
84
85 #include "xkbcommon/xkbcommon.h"
86
87 #ifndef True
88 #define True  1
89 #define False 0
90 #endif
91
92 typedef int Bool;
93
94 /* From XKM.h */
95 #define XkmFileVersion          15
96
97 #define XkmIllegalFile          -1
98 #define XkmSemanticsFile        20
99 #define XkmLayoutFile           21
100 #define XkmKeymapFile           22
101 #define XkmGeometryFile         23
102 #define XkmRulesFile            24
103
104 #define XkmTypesIndex           0
105 #define XkmCompatMapIndex       1
106 #define XkmSymbolsIndex         2
107 #define XkmIndicatorsIndex      3
108 #define XkmKeyNamesIndex        4
109 #define XkmGeometryIndex        5
110 #define XkmVirtualModsIndex     6
111 #define XkmLastIndex            XkmVirtualModsIndex
112
113 #define XkmTypesMask            (1<<0)
114 #define XkmCompatMapMask        (1<<1)
115 #define XkmSymbolsMask          (1<<2)
116 #define XkmIndicatorsMask       (1<<3)
117 #define XkmKeyNamesMask         (1<<4)
118 #define XkmGeometryMask         (1<<5)
119 #define XkmVirtualModsMask      (1<<6)
120 #define XkmLegalIndexMask       (0x7f)
121 #define XkmAllIndicesMask       (0x7f)
122
123 #define XkmSemanticsRequired    (XkmCompatMapMask)
124 #define XkmSemanticsOptional    (XkmTypesMask|XkmVirtualModsMask|XkmIndicatorsMask|XkmGeometryMask)
125 #define XkmSemanticsLegal       (XkmSemanticsRequired|XkmSemanticsOptional)
126 #define XkmLayoutRequired       (XkmKeyNamesMask|XkmSymbolsMask|XkmTypesMask)
127 #define XkmLayoutOptional       (XkmVirtualModsMask|XkmGeometryMask)
128 #define XkmLayoutLegal          (XkmLayoutRequired|XkmLayoutOptional)
129 #define XkmKeymapRequired       (XkmSemanticsRequired|XkmLayoutRequired)
130 #define XkmKeymapOptional       ((XkmSemanticsOptional|XkmLayoutOptional)&(~XkmKeymapRequired))
131 #define XkmKeymapLegal          (XkmKeymapRequired|XkmKeymapOptional)
132
133 extern unsigned int xkb_key_get_group(struct xkb_state *state,
134                                       xkb_keycode_t key);
135 extern unsigned int xkb_key_get_level(struct xkb_state *state,
136                                       xkb_keycode_t key,
137                                       unsigned int group);
138
139 struct xkb_any_action {
140     uint8_t   type;
141     uint8_t   data[7];
142 };
143
144 struct xkb_mod_action {
145     uint8_t         type;
146     uint8_t         flags;
147     uint8_t         mask;
148     uint8_t         real_mods;
149     uint16_t        vmods;
150 };
151
152 struct xkb_group_action {
153     uint8_t         type;
154     uint8_t         flags;
155     int16_t         group;
156 };
157
158 struct xkb_iso_action {
159     uint8_t         type;
160     uint8_t         flags;
161     uint8_t         mask;
162     uint8_t         real_mods;
163     uint8_t         group;
164     uint8_t         affect;
165     uint16_t        vmods;
166 };
167
168 struct xkb_controls_action {
169     uint8_t         type;
170     uint8_t         flags;
171     uint32_t        ctrls;
172 };
173
174 struct xkb_device_button_action {
175     uint8_t         type;
176     uint8_t         flags;
177     uint8_t         count;
178     uint8_t         button;
179     uint8_t         device;
180 };
181
182 struct xkb_device_valuator_action {
183     uint8_t         type;
184     uint8_t         device;
185     uint8_t         v1_what;
186     uint8_t         v1_index;
187     uint8_t         v1_value;
188     uint8_t         v2_what;
189     uint8_t         v2_index;
190     uint8_t         v2_value;
191 };
192
193 struct xkb_pointer_default_action {
194     uint8_t         type;
195     uint8_t         flags;
196     uint8_t         affect;
197     uint8_t         value;
198 };
199
200 struct xkb_switch_screen_action {
201     uint8_t         type;
202     uint8_t         flags;
203     uint8_t         screen;
204 };
205
206 struct xkb_redirect_key_action {
207     uint8_t             type;
208     xkb_keycode_t       new_key;
209     uint8_t             mods_mask;
210     uint8_t             mods;
211     uint16_t            vmods_mask;
212     uint16_t            vmods;
213 };
214
215 struct xkb_pointer_action {
216     uint8_t     type;
217     uint8_t     flags;
218     uint16_t    x;
219     uint16_t    y;
220 };
221
222 struct xkb_message_action {
223     uint8_t     type;
224     uint8_t     flags;
225     uint8_t     message[6];
226 };
227
228 struct xkb_pointer_button_action {
229     uint8_t     type;
230     uint8_t     flags;
231     uint8_t     count;
232     uint8_t     button;
233 };
234
235 union xkb_action {
236     struct xkb_any_action             any;
237     struct xkb_mod_action             mods;
238     struct xkb_group_action           group;
239     struct xkb_iso_action             iso;
240     struct xkb_controls_action        ctrls;
241     struct xkb_device_button_action   devbtn;
242     struct xkb_device_valuator_action devval;
243     struct xkb_pointer_default_action dflt;
244     struct xkb_switch_screen_action   screen;
245     struct xkb_redirect_key_action    redirect; /* XXX wholly unnecessary? */
246     struct xkb_pointer_action         ptr; /* XXX delete for DeviceValuator */
247     struct xkb_pointer_button_action  btn; /* XXX delete for DeviceBtn */
248     struct xkb_message_action         msg; /* XXX just delete */
249     unsigned char                     type;
250 };
251
252 struct xkb_mods {
253         uint32_t        mask;   /* effective mods */
254         uint32_t        vmods;
255         uint8_t         real_mods;
256 };
257
258 struct xkb_kt_map_entry {
259         int            active;
260         uint16_t        level;
261         struct xkb_mods     mods;
262 };
263
264 struct xkb_key_type {
265     struct xkb_mods             mods;
266     uint16_t                num_levels;
267     unsigned char           map_count;
268     struct xkb_kt_map_entry *       map;
269     struct xkb_mods *             preserve;
270     const char              *name;
271     const char              **level_names;
272 };
273
274 struct xkb_sym_interpret {
275     xkb_keysym_t    sym;
276     unsigned char   flags;
277     unsigned char   match;
278     uint8_t         mods;
279     uint32_t        virtual_mod;
280     union xkb_action act;
281 };
282
283 struct xkb_compat_map {
284     struct xkb_sym_interpret *      sym_interpret;
285     struct xkb_mods              groups[XkbNumKbdGroups];
286     unsigned short           num_si;
287     unsigned short           size_si;
288 };
289
290 struct xkb_sym_map {
291         unsigned char    kt_index[XkbNumKbdGroups];
292         unsigned char    group_info;
293         unsigned char    width;
294         int              *sym_index; /* per level/group index into 'syms' */
295         unsigned int     *num_syms; /* per level/group */
296         xkb_keysym_t     *syms;
297         unsigned int     size_syms; /* size of 'syms' */
298 };
299
300 #define XkbNumGroups(g)                 ((g)&0x0f)
301 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
302 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
303 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
304 #define XkbSetGroupInfo(g,w,n)  (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
305 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
306
307 struct xkb_client_map {
308     unsigned char            size_types;
309     unsigned char            num_types;
310     struct xkb_key_type *           types;
311     struct xkb_sym_map *             key_sym_map;
312     unsigned char           *modmap;
313 };
314
315 struct xkb_behavior {
316         unsigned char   type;
317         unsigned char   data;
318 };
319
320 struct xkb_server_map {
321     unsigned short      num_acts;
322     unsigned short      size_acts;
323
324 #if defined(__cplusplus) || defined(c_plusplus)
325     /* explicit is a C++ reserved word */
326     unsigned char *     c_explicit;
327 #else
328     unsigned char *     explicit;
329 #endif
330
331     union xkb_action          *acts;
332     struct xkb_behavior         *behaviors;
333     unsigned short      *key_acts;
334     unsigned char       *explicits;
335     uint32_t            vmods[XkbNumVirtualMods]; /* vmod -> mod mapping */
336     uint32_t            *vmodmap; /* key -> vmod mapping */
337 };
338
339
340 struct xkb_indicator_map {
341         unsigned char   flags;
342         unsigned char   which_groups;
343         unsigned char   groups;
344         unsigned char   which_mods;
345         struct xkb_mods mods;
346         unsigned int    ctrls;
347 };
348
349 struct xkb_indicator {
350         unsigned long           phys_indicators;
351         struct xkb_indicator_map        maps[XkbNumIndicators];
352 };
353
354 struct xkb_key_name {
355         char    name[XkbKeyNameLength];
356 };
357
358 struct xkb_key_alias {
359         char    real[XkbKeyNameLength];
360         char    alias[XkbKeyNameLength];
361 };
362
363 struct xkb_names {
364     const char            *vmods[XkbNumVirtualMods];
365     const char            *indicators[XkbNumIndicators];
366     const char            *groups[XkbNumKbdGroups];
367     struct xkb_key_name *     keys;
368     struct xkb_key_alias *    key_aliases;
369
370     xkb_keycode_t     num_keys;
371     xkb_keycode_t     num_key_aliases;
372 };
373
374 struct xkb_controls {
375         unsigned char   num_groups;
376         unsigned char   groups_wrap;
377         struct xkb_mods internal;
378         struct xkb_mods ignore_lock;
379         unsigned int    enabled_ctrls;
380         unsigned short  repeat_delay;
381         unsigned short  repeat_interval;
382         unsigned short  slow_keys_delay;
383         unsigned short  debounce_delay;
384         unsigned short  ax_options;
385         unsigned short  ax_timeout;
386         unsigned short  axt_opts_mask;
387         unsigned short  axt_opts_values;
388         unsigned int    axt_ctrls_mask;
389         unsigned int    axt_ctrls_values;
390         unsigned char   *per_key_repeat;
391 };
392
393 /* Common keyboard description structure */
394 struct xkb_keymap {
395     struct xkb_context  *context;
396
397     unsigned int        refcnt;
398     unsigned int        defined;
399     unsigned short      flags;
400     xkb_keycode_t       min_key_code;
401     xkb_keycode_t       max_key_code;
402
403     struct xkb_controls *      ctrls;
404     struct xkb_server_map *    server;
405     struct xkb_client_map *    map;
406     struct xkb_indicator *     indicators;
407     struct xkb_names *        names;
408     struct xkb_compat_map *    compat;
409 };
410
411 #define XkbKeyGroupInfo(d,k)    ((d)->map->key_sym_map[k].group_info)
412 #define XkbKeyNumGroups(d,k)    (XkbNumGroups((d)->map->key_sym_map[k].group_info))
413 #define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
414 #define XkbKeyGroupsWidth(d,k)  ((d)->map->key_sym_map[k].width)
415 #define XkbKeyTypeIndex(d,k,g)  ((d)->map->key_sym_map[k].kt_index[g&0x3])
416 #define XkbKeyType(d,k,g)       (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
417 #define XkbKeyNumSyms(d,k,g,sl) \
418         ((d)->map->key_sym_map[k].num_syms[(g*XkbKeyGroupsWidth(d,k))+sl])
419 #define XkbKeySym(d,k,n)        (&(d)->map->key_sym_map[k].syms[n])
420 #define XkbKeySymOffset(d,k,g,sl) \
421         ((d)->map->key_sym_map[k].sym_index[(g*XkbKeyGroupsWidth(d,k))+sl])
422 #define XkbKeySymEntry(d,k,g,sl) \
423         (XkbKeySym(d,k,XkbKeySymOffset(d,k,g,sl)))
424 #define XkbKeyHasActions(d,k)   ((d)->server->key_acts[k]!=0)
425 #define XkbKeyNumActions(d,k)   \
426         (XkbKeyHasActions(d,k)?(XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k)):1)
427 #define XkbKeyActionsPtr(d,k)   (&(d)->server->acts[(d)->server->key_acts[k]])
428 #define XkbKeyAction(d,k,n) \
429         (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
430 #define XkbKeyActionEntry(d,k,sl,g) \
431         (XkbKeyHasActions(d,k)?\
432                 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
433
434 #define XkbKeycodeInRange(d,k)  (((k)>=(d)->min_key_code)&&\
435                                  ((k)<=(d)->max_key_code))
436 #define XkbNumKeys(d)           ((d)->max_key_code-(d)->min_key_code+1)
437
438 struct xkb_component_name {
439         unsigned short          flags;
440         char *                  name;
441 };
442
443 struct xkb_state {
444         xkb_group_index_t base_group; /**< depressed */
445         xkb_group_index_t latched_group;
446         xkb_group_index_t locked_group;
447         xkb_group_index_t group; /**< effective */
448
449         xkb_mod_mask_t base_mods; /**< depressed */
450         xkb_mod_mask_t latched_mods;
451         xkb_mod_mask_t locked_mods;
452         xkb_mod_mask_t mods; /**< effective */
453
454         uint32_t        leds;
455
456         int refcnt;
457         void *filters;
458         int num_filters;
459         struct xkb_keymap *xkb;
460 };
461
462 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
463 #define XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
464
465 #define XkbNumGroups(g)                 ((g)&0x0f)
466 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
467 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
468 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
469 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
470
471 #endif /* _XKBCOMMONINT_H_ */