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