Remove useless stuff from utils
[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 #define XkmLegalSection(m)      (((m)&(~XkmKeymapLegal))==0)
141 #define XkmSingleSection(m)     (XkmLegalSection(m)&&(((m)&(~(m)+1))==(m)))
142
143 extern unsigned int xkb_key_get_group(struct xkb_state *state,
144                                       xkb_keycode_t key);
145 extern unsigned int xkb_key_get_level(struct xkb_state *state,
146                                       xkb_keycode_t key,
147                                       unsigned int group);
148
149 struct xkb_any_action {
150     uint8_t   type;
151     uint8_t   data[7];
152 };
153
154 struct xkb_mod_action {
155     uint8_t         type;
156     uint8_t         flags;
157     uint8_t         mask;
158     uint8_t         real_mods;
159     uint16_t        vmods;
160 };
161
162 struct xkb_group_action {
163     uint8_t         type;
164     uint8_t         flags;
165     int16_t         group;
166 };
167
168 struct xkb_iso_action {
169     uint8_t         type;
170     uint8_t         flags;
171     uint8_t         mask;
172     uint8_t         real_mods;
173     uint8_t         group;
174     uint8_t         affect;
175     uint16_t        vmods;
176 };
177
178 struct xkb_controls_action {
179     uint8_t         type;
180     uint8_t         flags;
181     uint32_t        ctrls;
182 };
183
184 struct xkb_device_button_action {
185     uint8_t         type;
186     uint8_t         flags;
187     uint8_t         count;
188     uint8_t         button;
189     uint8_t         device;
190 };
191
192 struct xkb_device_valuator_action {
193     uint8_t         type;
194     uint8_t         device;
195     uint8_t         v1_what;
196     uint8_t         v1_index;
197     uint8_t         v1_value;
198     uint8_t         v2_what;
199     uint8_t         v2_index;
200     uint8_t         v2_value;
201 };
202
203 struct xkb_pointer_default_action {
204     uint8_t         type;
205     uint8_t         flags;
206     uint8_t         affect;
207     uint8_t         value;
208 };
209
210 struct xkb_switch_screen_action {
211     uint8_t         type;
212     uint8_t         flags;
213     uint8_t         screen;
214 };
215
216 struct xkb_redirect_key_action {
217     uint8_t             type;
218     xkb_keycode_t       new_key;
219     uint8_t             mods_mask;
220     uint8_t             mods;
221     uint16_t            vmods_mask;
222     uint16_t            vmods;
223 };
224
225 struct xkb_pointer_action {
226     uint8_t     type;
227     uint8_t     flags;
228     uint16_t    x;
229     uint16_t    y;
230 };
231
232 struct xkb_message_action {
233     uint8_t     type;
234     uint8_t     flags;
235     uint8_t     message[6];
236 };
237
238 struct xkb_pointer_button_action {
239     uint8_t     type;
240     uint8_t     flags;
241     uint8_t     count;
242     uint8_t     button;
243 };
244
245 union xkb_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 */
259     unsigned char                     type;
260 };
261
262 struct xkb_mods {
263         uint32_t        mask;   /* effective mods */
264         uint32_t        vmods;
265         uint8_t         real_mods;
266 };
267
268 struct xkb_kt_map_entry {
269         int            active;
270         uint16_t        level;
271         struct xkb_mods     mods;
272 };
273
274 struct xkb_key_type {
275     struct xkb_mods             mods;
276     uint16_t                num_levels;
277     unsigned char           map_count;
278     struct xkb_kt_map_entry *       map;
279     struct xkb_mods *             preserve;
280     const char              *name;
281     const char              **level_names;
282 };
283
284 struct xkb_sym_interpret {
285     xkb_keysym_t    sym;
286     unsigned char   flags;
287     unsigned char   match;
288     uint8_t         mods;
289     uint32_t        virtual_mod;
290     union xkb_action act;
291 };
292
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;
298 };
299
300 struct xkb_sym_map {
301         unsigned char    kt_index[XkbNumKbdGroups];
302         unsigned char    group_info;
303         unsigned char    width;
304         unsigned short   offset;
305 };
306
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))
313
314 struct xkb_client_map {
315     unsigned char            size_types;
316     unsigned char            num_types;
317     struct xkb_key_type *           types;
318
319     uint32_t                 size_syms;
320     uint32_t                 num_syms;
321     xkb_keysym_t             *syms;
322     struct xkb_sym_map *             key_sym_map;
323
324     unsigned char           *modmap;
325 };
326
327 struct xkb_behavior {
328         unsigned char   type;
329         unsigned char   data;
330 };
331
332 struct xkb_server_map {
333     unsigned short      num_acts;
334     unsigned short      size_acts;
335
336 #if defined(__cplusplus) || defined(c_plusplus)
337     /* explicit is a C++ reserved word */
338     unsigned char *     c_explicit;
339 #else
340     unsigned char *     explicit;
341 #endif
342
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 */
349 };
350
351
352 struct xkb_indicator_map {
353         unsigned char   flags;
354         unsigned char   which_groups;
355         unsigned char   groups;
356         unsigned char   which_mods;
357         struct xkb_mods mods;
358         unsigned int    ctrls;
359 };
360
361 struct xkb_indicator {
362         unsigned long           phys_indicators;
363         struct xkb_indicator_map        maps[XkbNumIndicators];
364 };
365
366 struct xkb_key_name {
367         char    name[XkbKeyNameLength];
368 };
369
370 struct xkb_key_alias {
371         char    real[XkbKeyNameLength];
372         char    alias[XkbKeyNameLength];
373 };
374
375 struct xkb_names {
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;
381
382     xkb_keycode_t     num_keys;
383     xkb_keycode_t     num_key_aliases;
384 };
385
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;
403 };
404
405 /* Common keyboard description structure */
406 struct xkb_desc {
407     unsigned int        refcnt;
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;
413
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;
420 };
421
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)
442
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)
446
447 struct xkb_component_name {
448         unsigned short          flags;
449         char *                  name;
450 };
451
452 struct xkb_state {
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 */
457
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 */
462
463         uint32_t        leds;
464
465         int refcnt;
466         void *filters;
467         int num_filters;
468         struct xkb_desc *xkb;
469 };
470
471 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
472 #define XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
473
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))
479
480 #endif /* _XKBCOMMONINT_H_ */