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