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