Remove some more useless stuff
[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 #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))
97
98 #define _XkbDupString(s)        ((s) ? strdup(s) : NULL)
99 #define _XkbStrCaseCmp          strcasecmp
100
101 /* From XKM.h */
102 #define XkmFileVersion          15
103
104 #define XkmIllegalFile          -1
105 #define XkmSemanticsFile        20
106 #define XkmLayoutFile           21
107 #define XkmKeymapFile           22
108 #define XkmGeometryFile         23
109 #define XkmRulesFile            24
110
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
119
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)
129
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)
139
140 extern unsigned int xkb_key_get_group(struct xkb_state *state,
141                                       xkb_keycode_t key);
142 extern unsigned int xkb_key_get_level(struct xkb_state *state,
143                                       xkb_keycode_t key,
144                                       unsigned int group);
145
146 struct xkb_any_action {
147     uint8_t   type;
148     uint8_t   data[7];
149 };
150
151 struct xkb_mod_action {
152     uint8_t         type;
153     uint8_t         flags;
154     uint8_t         mask;
155     uint8_t         real_mods;
156     uint16_t        vmods;
157 };
158
159 struct xkb_group_action {
160     uint8_t         type;
161     uint8_t         flags;
162     int16_t         group;
163 };
164
165 struct xkb_iso_action {
166     uint8_t         type;
167     uint8_t         flags;
168     uint8_t         mask;
169     uint8_t         real_mods;
170     uint8_t         group;
171     uint8_t         affect;
172     uint16_t        vmods;
173 };
174
175 struct xkb_controls_action {
176     uint8_t         type;
177     uint8_t         flags;
178     uint32_t        ctrls;
179 };
180
181 struct xkb_device_button_action {
182     uint8_t         type;
183     uint8_t         flags;
184     uint8_t         count;
185     uint8_t         button;
186     uint8_t         device;
187 };
188
189 struct xkb_device_valuator_action {
190     uint8_t         type;
191     uint8_t         device;
192     uint8_t         v1_what;
193     uint8_t         v1_index;
194     uint8_t         v1_value;
195     uint8_t         v2_what;
196     uint8_t         v2_index;
197     uint8_t         v2_value;
198 };
199
200 struct xkb_pointer_default_action {
201     uint8_t         type;
202     uint8_t         flags;
203     uint8_t         affect;
204     uint8_t         value;
205 };
206
207 struct xkb_switch_screen_action {
208     uint8_t         type;
209     uint8_t         flags;
210     uint8_t         screen;
211 };
212
213 struct xkb_redirect_key_action {
214     uint8_t             type;
215     xkb_keycode_t       new_key;
216     uint8_t             mods_mask;
217     uint8_t             mods;
218     uint16_t            vmods_mask;
219     uint16_t            vmods;
220 };
221
222 struct xkb_pointer_action {
223     uint8_t     type;
224     uint8_t     flags;
225     uint16_t    x;
226     uint16_t    y;
227 };
228
229 struct xkb_message_action {
230     uint8_t     type;
231     uint8_t     flags;
232     uint8_t     message[6];
233 };
234
235 struct xkb_pointer_button_action {
236     uint8_t     type;
237     uint8_t     flags;
238     uint8_t     count;
239     uint8_t     button;
240 };
241
242 union xkb_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 */
256     unsigned char                     type;
257 };
258
259 struct xkb_mods {
260         uint32_t        mask;   /* effective mods */
261         uint32_t        vmods;
262         uint8_t         real_mods;
263 };
264
265 struct xkb_kt_map_entry {
266         int            active;
267         uint16_t        level;
268         struct xkb_mods     mods;
269 };
270
271 struct xkb_key_type {
272     struct xkb_mods             mods;
273     uint16_t                num_levels;
274     unsigned char           map_count;
275     struct xkb_kt_map_entry *       map;
276     struct xkb_mods *             preserve;
277     const char              *name;
278     const char              **level_names;
279 };
280
281 struct xkb_sym_interpret {
282     xkb_keysym_t    sym;
283     unsigned char   flags;
284     unsigned char   match;
285     uint8_t         mods;
286     uint32_t        virtual_mod;
287     union xkb_action act;
288 };
289
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;
295 };
296
297 struct xkb_sym_map {
298         unsigned char    kt_index[XkbNumKbdGroups];
299         unsigned char    group_info;
300         unsigned char    width;
301         unsigned short   offset;
302 };
303
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))
310
311 struct xkb_client_map {
312     unsigned char            size_types;
313     unsigned char            num_types;
314     struct xkb_key_type *           types;
315
316     uint32_t                 size_syms;
317     uint32_t                 num_syms;
318     xkb_keysym_t             *syms;
319     struct xkb_sym_map *             key_sym_map;
320
321     unsigned char           *modmap;
322 };
323
324 struct xkb_behavior {
325         unsigned char   type;
326         unsigned char   data;
327 };
328
329 struct xkb_server_map {
330     unsigned short      num_acts;
331     unsigned short      size_acts;
332
333 #if defined(__cplusplus) || defined(c_plusplus)
334     /* explicit is a C++ reserved word */
335     unsigned char *     c_explicit;
336 #else
337     unsigned char *     explicit;
338 #endif
339
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 */
346 };
347
348
349 struct xkb_indicator_map {
350         unsigned char   flags;
351         unsigned char   which_groups;
352         unsigned char   groups;
353         unsigned char   which_mods;
354         struct xkb_mods mods;
355         unsigned int    ctrls;
356 };
357
358 struct xkb_indicator {
359         unsigned long           phys_indicators;
360         struct xkb_indicator_map        maps[XkbNumIndicators];
361 };
362
363 struct xkb_key_name {
364         char    name[XkbKeyNameLength];
365 };
366
367 struct xkb_key_alias {
368         char    real[XkbKeyNameLength];
369         char    alias[XkbKeyNameLength];
370 };
371
372 struct xkb_names {
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;
378
379     xkb_keycode_t     num_keys;
380     xkb_keycode_t     num_key_aliases;
381 };
382
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;
400 };
401
402 /* Common keyboard description structure */
403 struct xkb_desc {
404     unsigned int        refcnt;
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;
410
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;
417 };
418
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)
439
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)
443
444 struct xkb_component_name {
445         unsigned short          flags;
446         char *                  name;
447 };
448
449 struct xkb_state {
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 */
454
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 */
459
460         uint32_t        leds;
461
462         int refcnt;
463         void *filters;
464         int num_filters;
465         struct xkb_desc *xkb;
466 };
467
468 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
469 #define XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
470
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))
476
477 #endif /* _XKBCOMMONINT_H_ */