ab67e6e4de836c5d6399f5099c43b935099759c4
[platform/upstream/libxkbcommon.git] / include / X11 / extensions / XKBcommon.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 #ifndef _XKBCOMMON_H_
56 #define _XKBCOMMON_H_
57
58 #include <stdint.h>
59 #include <stdio.h>
60 #include <X11/Xfuncproto.h>
61 #include <X11/extensions/XKB.h>
62
63 #ifndef X_PROTOCOL
64 typedef unsigned char KeyCode;
65 #endif
66
67 #ifndef _XTYPEDEF_BOOL
68 typedef int Bool;
69 #endif
70
71 /* From filecommon */
72
73 #define XkbXKMFile  0
74 #define XkbCFile    1
75 #define XkbXKBFile  2
76 #define XkbMessage  3
77
78 #define XkbMapDefined   (1 << 0)
79 #define XkbStateDefined (1 << 1)
80
81 /***====================================================================***/
82
83 #define _XkbSuccess                 0
84 #define _XkbErrMissingNames         1
85 #define _XkbErrMissingTypes         2
86 #define _XkbErrMissingReqTypes      3
87 #define _XkbErrMissingSymbols       4
88 #define _XkbErrMissingVMods         5
89 #define _XkbErrMissingIndicators    6
90 #define _XkbErrMissingCompatMap     7
91 #define _XkbErrMissingSymInterps    8
92 #define _XkbErrMissingGeometry      9
93 #define _XkbErrIllegalDoodad        10
94 #define _XkbErrIllegalTOCType       11
95 #define _XkbErrIllegalContents      12
96 #define _XkbErrEmptyFile            13
97 #define _XkbErrFileNotFound         14
98 #define _XkbErrFileCannotOpen       15
99 #define _XkbErrBadValue             16
100 #define _XkbErrBadMatch             17
101 #define _XkbErrBadTypeName          18
102 #define _XkbErrBadTypeWidth         19
103 #define _XkbErrBadFileType          20
104 #define _XkbErrBadFileVersion       21
105 #define _XkbErrBadFileFormat        22
106 #define _XkbErrBadAlloc             23
107 #define _XkbErrBadLength            24
108 #define _XkbErrXReqFailure          25
109 #define _XkbErrBadImplementation    26
110
111 /* From rulescommon */
112
113 #define _XkbKSLower (1 << 0)
114 #define _XkbKSUpper (1 << 1)
115
116 #define XkbKSIsKeypad(k) (((k) >= XK_KP_Space) && ((k) <= XK_KP_Equal))
117 #define XkbKSIsDeadKey(k) \
118     (((k) >= XK_dead_grave) && ((k) <= XK_dead_semivoiced_sound))
119
120
121
122 typedef struct _XkbRMLVOSet {
123     char *  rules;
124     char *  model;
125     char *  layout;
126     char *  variant;
127     char *  options;
128 } XkbRMLVOSet;
129
130 typedef struct _XkbRF_VarDefs {
131     char *          model;
132     char *          layout;
133     char *          variant;
134     char *          options;
135     unsigned short  sz_extra;
136     unsigned short  num_extra;
137     char *          extra_names;
138     char **         extra_values;
139 } XkbRF_VarDefsRec,*XkbRF_VarDefsPtr;
140
141 typedef struct _XkbRF_VarDesc {
142     char *  name;
143     char *  desc;
144 } XkbRF_VarDescRec, *XkbRF_VarDescPtr;
145
146 typedef struct _XkbRF_DescribeVars {
147     int                 sz_desc;
148     int                 num_desc;
149     XkbRF_VarDescPtr    desc;
150 } XkbRF_DescribeVarsRec,*XkbRF_DescribeVarsPtr;
151
152 typedef struct _XkbRF_Rule {
153     int         number;
154     int         layout_num;
155     int         variant_num;
156     char *      model;
157     char *      layout;
158     char *      variant;
159     char *      option;
160     /* yields */
161     char *      keycodes;
162     char *      symbols;
163     char *      types;
164     char *      compat;
165     char *      geometry;
166     char *      keymap;
167     unsigned    flags;
168 } XkbRF_RuleRec,*XkbRF_RulePtr;
169
170 typedef struct _XkbRF_Group {
171     int     number;
172     char *  name;
173     char *  words;
174 } XkbRF_GroupRec, *XkbRF_GroupPtr;
175
176 #define XkbRF_PendingMatch  (1L<<1)
177 #define XkbRF_Option        (1L<<2)
178 #define XkbRF_Append        (1L<<3)
179 #define XkbRF_Normal        (1L<<4)
180 #define XkbRF_Invalid       (1L<<5)
181
182 typedef struct _XkbRF_Rules {
183     XkbRF_DescribeVarsRec   models;
184     XkbRF_DescribeVarsRec   layouts;
185     XkbRF_DescribeVarsRec   variants;
186     XkbRF_DescribeVarsRec   options;
187     unsigned short          sz_extra;
188     unsigned short          num_extra;
189     char **                 extra_names;
190     XkbRF_DescribeVarsPtr   extra;
191
192     unsigned short          sz_rules;
193     unsigned short          num_rules;
194     XkbRF_RulePtr           rules;
195     unsigned short          sz_groups;
196     unsigned short          num_groups;
197     XkbRF_GroupPtr          groups;
198 } XkbRF_RulesRec, *XkbRF_RulesPtr;
199
200 #define _XKB_RF_NAMES_PROP_ATOM     "_XKB_RULES_NAMES"
201 #define _XKB_RF_NAMES_PROP_MAXLEN   1024
202
203
204
205 /* Action structures used in the server */
206
207 #define XkbcAnyActionDataSize 18
208 struct xkb_any_action {
209     unsigned char   type;
210     unsigned char   pad[XkbcAnyActionDataSize];
211 };
212
213 struct xkb_mod_action {
214     unsigned char   type;
215     uint8_t         flags;
216     uint8_t         real_mods;
217     uint32_t        mask;
218     uint32_t        vmods;
219 };
220
221 struct xkb_group_action {
222     unsigned char   type;
223     unsigned char   flags;
224     int16_t         group;
225 };
226
227 struct xkb_iso_action {
228     unsigned char   type;
229     uint8_t         flags;
230     int16_t         group;
231     uint32_t        mask;
232     uint32_t        vmods;
233     uint8_t         real_mods;
234  
235    uint8_t         affect;
236 };
237
238 struct xkb_controls_action {
239     unsigned char   type;
240     uint8_t         flags;
241     uint32_t        ctrls;
242 };
243
244 struct xkb_device_button_action {
245     unsigned char   type;
246     uint8_t         flags;
247     uint16_t        device;
248     uint16_t        button;
249     uint8_t         count;
250 };
251
252 struct xkb_device_valuator_action {
253     unsigned char   type;
254     uint8_t         v1_what;
255     uint16_t        device;
256     uint16_t        v1_index;
257     int16_t         v1_value;
258     uint16_t        v2_index;
259     int16_t         v2_value;
260     uint8_t         v2_what;
261 };
262
263 struct xkb_pointer_default_action {
264     unsigned char   type;
265     uint8_t         flags;
266     uint8_t         affect;
267     uint8_t         value;
268 };
269
270 struct xkb_switch_screen_action {
271     unsigned char   type;
272     uint8_t         flags;
273     uint8_t         screen;
274 };
275
276 struct xkb_redirect_key_action {
277         unsigned char   type;
278         unsigned char   new_key;
279         unsigned char   mods_mask;
280         unsigned char   mods;
281         unsigned char   vmods_mask0;
282         unsigned char   vmods_mask1;
283         unsigned char   vmods0;
284         unsigned char   vmods1;
285 };
286 #define XkbSARedirectVMods(a)           ((((unsigned int)(a)->vmods1)<<8)|\
287                                         ((unsigned int)(a)->vmods0))
288 #define XkbSARedirectSetVMods(a,m)      (((a)->vmods_mask1=(((m)>>8)&0xff)),\
289                                          ((a)->vmods_mask0=((m)&0xff)))
290 #define XkbSARedirectVModsMask(a)       ((((unsigned int)(a)->vmods_mask1)<<8)|\
291                                         ((unsigned int)(a)->vmods_mask0))
292 #define XkbSARedirectSetVModsMask(a,m)  (((a)->vmods_mask1=(((m)>>8)&0xff)),\
293                                          ((a)->vmods_mask0=((m)&0xff)))
294
295
296 struct xkb_pointer_action {
297         unsigned char   type;
298         unsigned char   flags;
299         unsigned char   high_XXX;
300         unsigned char   low_XXX;
301         unsigned char   high_YYY;
302         unsigned char   low_YYY;
303 };
304 #define XkbIntTo2Chars(i,h,l)   (((h)=((i>>8)&0xff)),((l)=((i)&0xff)))
305 #define XkbPtrActionX(a)      (Xkb2CharsToInt((a)->high_XXX,(a)->low_XXX))
306 #define XkbPtrActionY(a)      (Xkb2CharsToInt((a)->high_YYY,(a)->low_YYY))
307 #define XkbSetPtrActionX(a,x) (XkbIntTo2Chars(x,(a)->high_XXX,(a)->low_XXX))
308 #define XkbSetPtrActionY(a,y) (XkbIntTo2Chars(y,(a)->high_YYY,(a)->low_YYY))
309
310 struct xkb_message_action {
311         unsigned char   type;
312         unsigned char   flags;
313         unsigned char   message[6];
314 };
315
316 struct xkb_pointer_button_action {
317         unsigned char   type;
318         unsigned char   flags;
319         unsigned char   count;
320         unsigned char   button;
321 };
322
323 union xkb_action {
324     struct xkb_any_action             any;
325     struct xkb_mod_action             mods;
326     struct xkb_group_action           group;
327     struct xkb_iso_action             iso;
328     struct xkb_controls_action        ctrls;
329     struct xkb_device_button_action   devbtn;
330     struct xkb_device_valuator_action devval;
331     struct xkb_pointer_default_action dflt;
332     struct xkb_switch_screen_action   screen;
333     struct xkb_redirect_key_action    redirect; /* XXX wholly unnecessary? */
334     struct xkb_pointer_action         ptr; /* XXX delete for DeviceValuator */
335     struct xkb_pointer_button_action  btn; /* XXX delete for DeviceBtn */
336     struct xkb_message_action         msg; /* XXX just delete */
337     unsigned char                     type;
338 };
339
340 struct xkb_mods {
341         uint32_t        mask;   /* effective mods */
342         uint32_t        vmods;
343         uint8_t         real_mods;
344 };
345
346 struct xkb_kt_map_entry {
347         Bool            active;
348         uint16_t        level;
349         struct xkb_mods     mods;
350 };
351
352 struct xkb_key_type {
353     struct xkb_mods             mods;
354     uint16_t                num_levels;
355     unsigned char           map_count;
356     struct xkb_kt_map_entry *       map;
357     struct xkb_mods *             preserve;
358     uint32_t                  name;
359     uint32_t                 *level_names;
360 };
361
362 struct xkb_sym_interpret {
363     uint32_t          sym;
364     unsigned char   flags;
365     unsigned char   match;
366     uint8_t         mods; /* XXX real or virt? */
367     uint32_t        virtual_mod;
368     struct xkb_any_action   act;
369 };
370
371 struct xkb_compat_map {
372     struct xkb_sym_interpret *      sym_interpret;
373     struct xkb_mods              groups[XkbNumKbdGroups];
374     unsigned short           num_si;
375     unsigned short           size_si;
376 };
377
378 struct xkb_sym_map {
379         unsigned char    kt_index[XkbNumKbdGroups];
380         unsigned char    group_info;
381         unsigned char    width;
382         unsigned short   offset;
383 };
384
385 #define XkbNumGroups(g)                 ((g)&0x0f)
386 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
387 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
388 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
389 #define XkbSetGroupInfo(g,w,n)  (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
390 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
391
392 struct xkb_client_map {
393     unsigned char            size_types;
394     unsigned char            num_types;
395     struct xkb_key_type *           types;
396
397     unsigned short           size_syms;
398     unsigned short           num_syms;
399     uint32_t                *syms;
400     struct xkb_sym_map *             key_sym_map;
401
402     unsigned char           *modmap;
403 };
404
405 #define XkbCMKeyGroupInfo(m,k)  ((m)->key_sym_map[k].group_info)
406 #define XkbCMKeyNumGroups(m,k)   (XkbNumGroups((m)->key_sym_map[k].group_info))
407 #define XkbCMKeyGroupWidth(m,k,g) (XkbCMKeyType(m,k,g)->num_levels)
408 #define XkbCMKeyGroupsWidth(m,k) ((m)->key_sym_map[k].width)
409 #define XkbCMKeyTypeIndex(m,k,g) ((m)->key_sym_map[k].kt_index[g&0x3])
410 #define XkbCMKeyType(m,k,g)      (&(m)->types[XkbCMKeyTypeIndex(m,k,g)])
411 #define XkbCMKeyNumSyms(m,k) (XkbCMKeyGroupsWidth(m,k)*XkbCMKeyNumGroups(m,k))
412 #define XkbCMKeySymsOffset(m,k) ((m)->key_sym_map[k].offset)
413 #define XkbCMKeySymsPtr(m,k)    (&(m)->syms[XkbCMKeySymsOffset(m,k)])
414
415 struct xkb_behavior {
416         unsigned char   type;
417         unsigned char   data;
418 };
419
420 struct xkb_server_map {
421     unsigned short      num_acts;
422     unsigned short      size_acts;
423
424 #if defined(__cplusplus) || defined(c_plusplus)
425     /* explicit is a C++ reserved word */
426     unsigned char *     c_explicit;
427 #else
428     unsigned char *     explicit;
429 #endif
430
431     union xkb_action          *acts;
432     struct xkb_behavior         *behaviors;
433     unsigned short      *key_acts;
434     unsigned char       *explicits;
435     uint32_t            vmods[XkbNumVirtualMods];
436     uint32_t            *vmodmap;
437 };
438
439 #define XkbSMKeyActionsPtr(m,k) (&(m)->acts[(m)->key_acts[k]])
440
441 struct xkb_indicator_map {
442         unsigned char   flags;
443         unsigned char   which_groups;
444         unsigned char   groups;
445         unsigned char   which_mods;
446         struct xkb_mods mods;
447         unsigned int    ctrls;
448 };
449
450 struct xkb_indicator {
451         unsigned long           phys_indicators;
452         struct xkb_indicator_map        maps[XkbNumIndicators];
453 };
454
455 struct xkb_key_name {
456         char    name[XkbKeyNameLength];
457 };
458
459 struct xkb_key_alias {
460         char    real[XkbKeyNameLength];
461         char    alias[XkbKeyNameLength];
462 };
463
464 struct xkb_names {
465     uint32_t            keycodes;
466     uint32_t            geometry;
467     uint32_t            symbols;
468     uint32_t            types;
469     uint32_t            compat;
470     uint32_t            vmods[XkbNumVirtualMods];
471     uint32_t            indicators[XkbNumIndicators];
472     uint32_t            groups[XkbNumKbdGroups];
473     struct xkb_key_name *     keys;
474     struct xkb_key_alias *    key_aliases;
475     uint32_t           *radio_groups;
476     uint32_t            phys_symbols;
477
478     unsigned char     num_keys;
479     unsigned char     num_key_aliases;
480     unsigned short    num_rg;
481 };
482
483 struct xkb_property {
484         char    *name;
485         char    *value;
486 };
487
488 struct xkb_color {
489         unsigned int    pixel;
490         char *          spec;
491 };
492
493 struct xkb_point {
494         short   x;
495         short   y;
496 };
497
498 struct xkb_bounds {
499         short   x1,y1;
500         short   x2,y2;
501 };
502 #define XkbBoundsWidth(b)       (((b)->x2)-((b)->x1))
503 #define XkbBoundsHeight(b)      (((b)->y2)-((b)->y1))
504
505 struct xkb_outline {
506         unsigned short  num_points;
507         unsigned short  sz_points;
508         unsigned short  corner_radius;
509         struct xkb_point *      points;
510 };
511
512 struct xkb_shape {
513         uint32_t                 name;
514         unsigned short   num_outlines;
515         unsigned short   sz_outlines;
516         struct xkb_outline *     outlines;
517         struct xkb_outline *     approx;
518         struct xkb_outline *     primary;
519         struct xkb_bounds        bounds;
520 };
521 #define XkbOutlineIndex(s,o)    ((int)((o)-&(s)->outlines[0]))
522
523 struct xkb_shape_doodad {
524         uint32_t                 name;
525         unsigned char    type;
526         unsigned char    priority;
527         short            top;
528         short            left;
529         short            angle;
530         unsigned short   color_ndx;
531         unsigned short   shape_ndx;
532 };
533 #define XkbShapeDoodadColor(g,d)        (&(g)->colors[(d)->color_ndx])
534 #define XkbShapeDoodadShape(g,d)        (&(g)->shapes[(d)->shape_ndx])
535 #define XkbSetShapeDoodadColor(g,d,c)   ((d)->color_ndx= (c)-&(g)->colors[0])
536 #define XkbSetShapeDoodadShape(g,d,s)   ((d)->shape_ndx= (s)-&(g)->shapes[0])
537
538 struct xkb_text_doodad {
539         uint32_t                 name;
540         unsigned char    type;
541         unsigned char    priority;
542         short            top;
543         short            left;
544         short            angle;
545         short            width;
546         short            height;
547         unsigned short   color_ndx;
548         char *           text;
549         char *           font;
550 };
551 #define XkbTextDoodadColor(g,d) (&(g)->colors[(d)->color_ndx])
552 #define XkbSetTextDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
553
554 struct xkb_indicator_doodad {
555         uint32_t                 name;
556         unsigned char    type;
557         unsigned char    priority;
558         short            top;
559         short            left;
560         short            angle;
561         unsigned short   shape_ndx;
562         unsigned short   on_color_ndx;
563         unsigned short   off_color_ndx;
564 };
565 #define XkbIndicatorDoodadShape(g,d)    (&(g)->shapes[(d)->shape_ndx])
566 #define XkbIndicatorDoodadOnColor(g,d)  (&(g)->colors[(d)->on_color_ndx])
567 #define XkbIndicatorDoodadOffColor(g,d) (&(g)->colors[(d)->off_color_ndx])
568 #define XkbSetIndicatorDoodadOnColor(g,d,c) \
569                                 ((d)->on_color_ndx= (c)-&(g)->colors[0])
570 #define XkbSetIndicatorDoodadOffColor(g,d,c) \
571                                 ((d)->off_color_ndx= (c)-&(g)->colors[0])
572 #define XkbSetIndicatorDoodadShape(g,d,s) \
573                                 ((d)->shape_ndx= (s)-&(g)->shapes[0])
574
575 struct xkb_logo_doodad {
576         uint32_t                 name;
577         unsigned char    type;
578         unsigned char    priority;
579         short            top;
580         short            left;
581         short            angle;
582         unsigned short   color_ndx;
583         unsigned short   shape_ndx;
584         char *           logo_name;
585 };
586 #define XkbLogoDoodadColor(g,d)         (&(g)->colors[(d)->color_ndx])
587 #define XkbLogoDoodadShape(g,d)         (&(g)->shapes[(d)->shape_ndx])
588 #define XkbSetLogoDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
589 #define XkbSetLogoDoodadShape(g,d,s)    ((d)->shape_ndx= (s)-&(g)->shapes[0])
590
591 struct xkb_any_doodad {
592         uint32_t                 name;
593         unsigned char    type;
594         unsigned char    priority;
595         short            top;
596         short            left;
597         short            angle;
598 };
599
600 union xkb_doodad {
601         struct xkb_any_doodad   any;
602         struct xkb_shape_doodad shape;
603         struct xkb_text_doodad  text;
604         struct xkb_indicator_doodad     indicator;
605         struct xkb_logo_doodad  logo;
606 };
607
608 #define XkbUnknownDoodad        0
609 #define XkbOutlineDoodad        1
610 #define XkbSolidDoodad          2
611 #define XkbTextDoodad           3
612 #define XkbIndicatorDoodad      4
613 #define XkbLogoDoodad           5
614
615 struct xkb_key {
616         struct xkb_key_name      name;
617         short            gap;
618         unsigned char    shape_ndx;
619         unsigned char    color_ndx;
620 };
621 #define XkbKeyShape(g,k)        (&(g)->shapes[(k)->shape_ndx])
622 #define XkbKeyColor(g,k)        (&(g)->colors[(k)->color_ndx])
623 #define XkbSetKeyShape(g,k,s)   ((k)->shape_ndx= (s)-&(g)->shapes[0])
624 #define XkbSetKeyColor(g,k,c)   ((k)->color_ndx= (c)-&(g)->colors[0])
625
626 struct xkb_row {
627         short           top;
628         short           left;
629         unsigned short  num_keys;
630         unsigned short  sz_keys;
631         int             vertical;
632         struct xkb_key *        keys;
633         struct xkb_bounds       bounds;
634 };
635
636 struct xkb_section {
637         uint32_t                 name;
638         unsigned char    priority;
639         short            top;
640         short            left;
641         unsigned short   width;
642         unsigned short   height;
643         short            angle;
644         unsigned short   num_rows;
645         unsigned short   num_doodads;
646         unsigned short   num_overlays;
647         unsigned short   sz_rows;
648         unsigned short   sz_doodads;
649         unsigned short   sz_overlays;
650         struct xkb_row *         rows;
651         union xkb_doodad *       doodads;
652         struct xkb_bounds        bounds;
653         struct xkb_overlay *overlays;
654 };
655
656 struct xkb_overlay_key {
657         struct xkb_key_name     over;
658         struct xkb_key_name     under;
659 };
660
661 struct xkb_overlay_row {
662         unsigned short          row_under;
663         unsigned short          num_keys;
664         unsigned short          sz_keys;
665         struct xkb_overlay_key *        keys;
666 };
667
668 struct xkb_overlay {
669         uint32_t                        name;
670         struct xkb_section *            section_under;
671         unsigned short          num_rows;
672         unsigned short          sz_rows;
673         struct xkb_overlay_row *        rows;
674         struct xkb_bounds *             bounds;
675 };
676
677 struct xkb_geometry {
678         uint32_t                 name;
679         unsigned short   width_mm;
680         unsigned short   height_mm;
681         char *           label_font;
682         struct xkb_color *       label_color;
683         struct xkb_color *       base_color;
684         unsigned short   sz_properties;
685         unsigned short   sz_colors;
686         unsigned short   sz_shapes;
687         unsigned short   sz_sections;
688         unsigned short   sz_doodads;
689         unsigned short   sz_key_aliases;
690         unsigned short   num_properties;
691         unsigned short   num_colors;
692         unsigned short   num_shapes;
693         unsigned short   num_sections;
694         unsigned short   num_doodads;
695         unsigned short   num_key_aliases;
696         struct xkb_property *    properties;
697         struct xkb_color *       colors;
698         struct xkb_shape *       shapes;
699         struct xkb_section *     sections;
700         union xkb_doodad *       doodads;
701         struct xkb_key_alias *   key_aliases;
702 };
703 #define XkbGeomColorIndex(g,c)  ((int)((c)-&(g)->colors[0]))
704
705 #define XkbGeomPropertiesMask   (1<<0)
706 #define XkbGeomColorsMask       (1<<1)
707 #define XkbGeomShapesMask       (1<<2)
708 #define XkbGeomSectionsMask     (1<<3)
709 #define XkbGeomDoodadsMask      (1<<4)
710 #define XkbGeomKeyAliasesMask   (1<<5)
711 #define XkbGeomAllMask          (0x3f)
712
713 struct xkb_geometry_sizes {
714         unsigned int    which;
715         unsigned short  num_properties;
716         unsigned short  num_colors;
717         unsigned short  num_shapes;
718         unsigned short  num_sections;
719         unsigned short  num_doodads;
720         unsigned short  num_key_aliases;
721 };
722
723 struct xkb_controls {
724         unsigned char   mk_dflt_btn;
725         unsigned char   num_groups;
726         unsigned char   groups_wrap;
727         struct xkb_mods internal;
728         struct xkb_mods ignore_lock;
729         unsigned int    enabled_ctrls;
730         unsigned short  repeat_delay;
731         unsigned short  repeat_interval;
732         unsigned short  slow_keys_delay;
733         unsigned short  debounce_delay;
734         unsigned short  mk_delay;
735         unsigned short  mk_interval;
736         unsigned short  mk_time_to_max;
737         unsigned short  mk_max_speed;
738                  short  mk_curve;
739         unsigned short  ax_options;
740         unsigned short  ax_timeout;
741         unsigned short  axt_opts_mask;
742         unsigned short  axt_opts_values;
743         unsigned int    axt_ctrls_mask;
744         unsigned int    axt_ctrls_values;
745         unsigned char   per_key_repeat[XkbPerKeyBitArraySize];
746 };
747
748 /* Common keyboard description structure */
749 struct xkb_desc {
750     unsigned int        defined;
751     unsigned short      flags;
752     unsigned short      device_spec;
753     KeyCode             min_key_code;
754     KeyCode             max_key_code;
755
756     struct xkb_controls *      ctrls;
757     struct xkb_server_map *    server;
758     struct xkb_client_map *    map;
759     struct xkb_indicator *     indicators;
760     struct xkb_names *        names;
761     struct xkb_compat_map *    compat;
762     struct xkb_geometry *     geom;
763 };
764
765 #define XkbKeyKeyTypeIndex(d,k,g)       (XkbCMKeyTypeIndex((d)->map,k,g))
766 #define XkbKeyKeyType(d,k,g)            (XkbCMKeyType((d)->map,k,g))
767 #define XkbKeyGroupWidth(d,k,g)         (XkbCMKeyGroupWidth((d)->map,k,g))
768 #define XkbKeyGroupsWidth(d,k)          (XkbCMKeyGroupsWidth((d)->map,k))
769 #define XkbKeyGroupInfo(d,k)            (XkbCMKeyGroupInfo((d)->map,(k)))
770 #define XkbKeyNumGroups(d,k)            (XkbCMKeyNumGroups((d)->map,(k)))
771 #define XkbKeyNumSyms(d,k)              (XkbCMKeyNumSyms((d)->map,(k)))
772 #define XkbKeySymsPtr(d,k)              (XkbCMKeySymsPtr((d)->map,(k)))
773 #define XkbKeySym(d,k,n)                (XkbKeySymsPtr(d,k)[n])
774 #define XkbKeySymEntry(d,k,sl,g) \
775         (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
776 #define XkbKeyAction(d,k,n) \
777         (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
778 #define XkbKeyActionEntry(d,k,sl,g) \
779         (XkbKeyHasActions(d,k)?\
780                 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
781
782 #define XkbKeyHasActions(d,k)   ((d)->server->key_acts[k]!=0)
783 #define XkbKeyNumActions(d,k)   (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
784 #define XkbKeyActionsPtr(d,k)   (XkbSMKeyActionsPtr((d)->server,k))
785 #define XkbKeycodeInRange(d,k)  (((k)>=(d)->min_key_code)&&\
786                                  ((k)<=(d)->max_key_code))
787 #define XkbNumKeys(d)           ((d)->max_key_code-(d)->min_key_code+1)
788
789 struct xkb_map_changes {
790         unsigned short           changed;
791         KeyCode                  min_key_code;
792         KeyCode                  max_key_code;
793         unsigned char            first_type;
794         unsigned char            num_types;
795         KeyCode                  first_key_sym;
796         unsigned char            num_key_syms;
797         KeyCode                  first_key_act;
798         unsigned char            num_key_acts;
799         KeyCode                  first_key_behavior;
800         unsigned char            num_key_behaviors;
801         KeyCode                  first_key_explicit;
802         unsigned char            num_key_explicit;
803         KeyCode                  first_modmap_key;
804         unsigned char            num_modmap_keys;
805         KeyCode                  first_vmodmap_key;
806         unsigned char            num_vmodmap_keys;
807         unsigned char            pad;
808         unsigned short           vmods;
809 };
810
811 struct xkb_controls_changes {
812         unsigned int             changed_ctrls;
813         unsigned int             enabled_ctrls_changes;
814         Bool                     num_groups_changed;
815 };
816
817 struct xkb_indicator_changes {
818         unsigned int             state_changes;
819         unsigned int             map_changes;
820 };
821
822 struct xkb_name_changes {
823         unsigned int            changed;
824         unsigned char           first_type;
825         unsigned char           num_types;
826         unsigned char           first_lvl;
827         unsigned char           num_lvls;
828         unsigned char           num_aliases;
829         unsigned char           num_rg;
830         unsigned char           first_key;
831         unsigned char           num_keys;
832         unsigned short          changed_vmods;
833         unsigned long           changed_indicators;
834         unsigned char           changed_groups;
835 };
836
837 struct xkb_compat_changes {
838         unsigned char           changed_groups;
839         unsigned short          first_si;
840         unsigned short          num_si;
841 };
842
843 struct xkb_changes {
844         unsigned short           device_spec;
845         unsigned short           state_changes;
846         struct xkb_map_changes   map;
847         struct xkb_controls_changes      ctrls;
848         struct xkb_indicator_changes     indicators;
849         struct xkb_name_changes  names;
850         struct xkb_compat_changes        compat;
851 };
852
853 struct xkb_component_names {
854         char *                   keymap;
855         char *                   keycodes;
856         char *                   types;
857         char *                   compat;
858         char *                   symbols;
859         char *                   geometry;
860 };
861
862 struct xkb_component_name {
863         unsigned short          flags;
864         char *                  name;
865 };
866
867 struct xkb_component_list {
868         int                     num_keymaps;
869         int                     num_keycodes;
870         int                     num_types;
871         int                     num_compat;
872         int                     num_symbols;
873         int                     num_geometry;
874         struct xkb_component_name *     keymaps;
875         struct xkb_component_name *     keycodes;
876         struct xkb_component_name *     types;
877         struct xkb_component_name *     compat;
878         struct xkb_component_name *     symbols;
879         struct xkb_component_name *     geometry;
880 };
881
882 _XFUNCPROTOBEGIN
883
884 typedef uint32_t (*InternAtomFuncPtr)(const char *val);
885 typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
886
887 extern void
888 XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
889
890 extern struct xkb_desc *
891 XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
892
893 extern struct xkb_desc *
894 XkbcCompileKeymapFromComponents(const struct xkb_component_names * ktcsg);
895
896 extern struct xkb_desc *
897 XkbcCompileKeymapFromFile(FILE *inputFile, const char *mapName);
898
899 extern struct xkb_component_list *
900 XkbcListComponents(struct xkb_component_names * ptrns, int *maxMatch);
901
902 /*
903  * Canonicalises component names by prepending the relevant component from
904  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
905  * by replacing a '%' with the relevant component, e.g.:
906  *
907  * names        old           output
908  * ------------------------------------------
909  * +bar         foo           foo+bar
910  * |quux        baz           baz|quux
911  * foo+%|baz    bar           foo+bar|baz
912  *
913  * If a component in names needs to be modified, the existing value will be
914  * free()d, and a new one allocated with malloc().
915  */
916 extern void
917 XkbcCanonicaliseComponents(struct xkb_component_names * names,
918                            const struct xkb_component_names * old);
919
920 /*
921  * Converts a keysym to a string; will return unknown Unicode codepoints
922  * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
923  *
924  * The string returned may become invalidated after the next call to
925  * XkbcKeysymToString: if you need to preserve it, then you must
926  * duplicate it.
927  *
928  * This is uint32_t rather than KeySym, as KeySym changes size between
929  * client and server (no, really).
930  */
931 extern char *
932 XkbcKeysymToString(uint32_t ks);
933
934 /*
935  * See XkbcKeysymToString comments: this function will accept any string
936  * from that function.
937  */
938 extern uint32_t
939 XkbcStringToKeysym(const char *s);
940
941 _XFUNCPROTOEND
942
943 #endif /* _XKBCOMMON_H_ */