xkbcomp: Silence warning of return of uninitialised value
[platform/upstream/libxkbcommon.git] / include / xkbcommon / 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 /* Duplicate the modifier mask defines so libxkcommon can be used
68  * without X.h */
69 #define XKB_COMMON_SHIFT_MASK           (1<<0)
70 #define XKB_COMMON_LOCK_MASK            (1<<1)
71 #define XKB_COMMON_CONTROL_MASK         (1<<2)
72 #define XKB_COMMON_MOD1_MASK            (1<<3)
73 #define XKB_COMMON_MOD2_MASK            (1<<4)
74 #define XKB_COMMON_MOD3_MASK            (1<<5)
75 #define XKB_COMMON_MOD4_MASK            (1<<6)
76 #define XKB_COMMON_MOD5_MASK            (1<<7)
77
78
79 struct xkb_rule_names {
80     const char *  rules;
81     const char *  model;
82     const char *  layout;
83     const char *  variant;
84     const char *  options;
85 };
86
87 struct xkb_any_action {
88     uint8_t   type;
89     uint8_t   data[7];
90 };
91
92 struct xkb_mod_action {
93     uint8_t         type;
94     uint8_t         flags;
95     uint8_t         mask;
96     uint8_t         real_mods;
97     uint16_t        vmods;
98 };
99
100 struct xkb_group_action {
101     uint8_t         type;
102     uint8_t         flags;
103     int16_t         group;
104 };
105
106 struct xkb_iso_action {
107     uint8_t         type;
108     uint8_t         flags;
109     uint8_t         mask;
110     uint8_t         real_mods;
111     uint8_t         group;
112     uint8_t         affect;
113     uint16_t        vmods;
114 };
115
116 struct xkb_controls_action {
117     uint8_t         type;
118     uint8_t         flags;
119     uint32_t        ctrls;
120 };
121
122 struct xkb_device_button_action {
123     uint8_t         type;
124     uint8_t         flags;
125     uint8_t         count;
126     uint8_t         button;
127     uint8_t         device;
128 };
129
130 struct xkb_device_valuator_action {
131     uint8_t         type;
132     uint8_t         device;
133     uint8_t         v1_what;
134     uint8_t         v1_index;
135     uint8_t         v1_value;
136     uint8_t         v2_what;
137     uint8_t         v2_index;
138     uint8_t         v2_value;
139 };
140
141 struct xkb_pointer_default_action {
142     uint8_t         type;
143     uint8_t         flags;
144     uint8_t         affect;
145     uint8_t         value;
146 };
147
148 struct xkb_switch_screen_action {
149     uint8_t         type;
150     uint8_t         flags;
151     uint8_t         screen;
152 };
153
154 struct xkb_redirect_key_action {
155     uint8_t             type;
156     uint8_t             new_key;
157     uint8_t             mods_mask;
158     uint8_t             mods;
159     uint16_t            vmods_mask;
160     uint16_t            vmods;
161 };
162
163 struct xkb_pointer_action {
164     uint8_t     type;
165     uint8_t     flags;
166     uint16_t    x;
167     uint16_t    y;
168 };
169
170 struct xkb_message_action {
171     uint8_t     type;
172     uint8_t     flags;
173     uint8_t     message[6];
174 };
175
176 struct xkb_pointer_button_action {
177     uint8_t     type;
178     uint8_t     flags;
179     uint8_t     count;
180     uint8_t     button;
181 };
182
183 union xkb_action {
184     struct xkb_any_action             any;
185     struct xkb_mod_action             mods;
186     struct xkb_group_action           group;
187     struct xkb_iso_action             iso;
188     struct xkb_controls_action        ctrls;
189     struct xkb_device_button_action   devbtn;
190     struct xkb_device_valuator_action devval;
191     struct xkb_pointer_default_action dflt;
192     struct xkb_switch_screen_action   screen;
193     struct xkb_redirect_key_action    redirect; /* XXX wholly unnecessary? */
194     struct xkb_pointer_action         ptr; /* XXX delete for DeviceValuator */
195     struct xkb_pointer_button_action  btn; /* XXX delete for DeviceBtn */
196     struct xkb_message_action         msg; /* XXX just delete */
197     unsigned char                     type;
198 };
199
200 struct xkb_mods {
201         uint32_t        mask;   /* effective mods */
202         uint32_t        vmods;
203         uint8_t         real_mods;
204 };
205
206 struct xkb_kt_map_entry {
207         int            active;
208         uint16_t        level;
209         struct xkb_mods     mods;
210 };
211
212 struct xkb_key_type {
213     struct xkb_mods             mods;
214     uint16_t                num_levels;
215     unsigned char           map_count;
216     struct xkb_kt_map_entry *       map;
217     struct xkb_mods *             preserve;
218     uint32_t                  name;
219     uint32_t                 *level_names;
220 };
221
222 struct xkb_sym_interpret {
223     uint32_t          sym;
224     unsigned char   flags;
225     unsigned char   match;
226     uint8_t         mods; /* XXX real or virt? */
227     uint32_t        virtual_mod;
228     struct xkb_any_action   act;
229 };
230
231 struct xkb_compat_map {
232     struct xkb_sym_interpret *      sym_interpret;
233     struct xkb_mods              groups[XkbNumKbdGroups];
234     unsigned short           num_si;
235     unsigned short           size_si;
236 };
237
238 struct xkb_sym_map {
239         unsigned char    kt_index[XkbNumKbdGroups];
240         unsigned char    group_info;
241         unsigned char    width;
242         unsigned short   offset;
243 };
244
245 #define XkbNumGroups(g)                 ((g)&0x0f)
246 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
247 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
248 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
249 #define XkbSetGroupInfo(g,w,n)  (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
250 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
251
252 struct xkb_client_map {
253     unsigned char            size_types;
254     unsigned char            num_types;
255     struct xkb_key_type *           types;
256
257     unsigned short           size_syms;
258     unsigned short           num_syms;
259     uint32_t                *syms;
260     struct xkb_sym_map *             key_sym_map;
261
262     unsigned char           *modmap;
263 };
264
265 #define XkbCMKeyGroupInfo(m,k)  ((m)->key_sym_map[k].group_info)
266 #define XkbCMKeyNumGroups(m,k)   (XkbNumGroups((m)->key_sym_map[k].group_info))
267 #define XkbCMKeyGroupWidth(m,k,g) (XkbCMKeyType(m,k,g)->num_levels)
268 #define XkbCMKeyGroupsWidth(m,k) ((m)->key_sym_map[k].width)
269 #define XkbCMKeyTypeIndex(m,k,g) ((m)->key_sym_map[k].kt_index[g&0x3])
270 #define XkbCMKeyType(m,k,g)      (&(m)->types[XkbCMKeyTypeIndex(m,k,g)])
271 #define XkbCMKeyNumSyms(m,k) (XkbCMKeyGroupsWidth(m,k)*XkbCMKeyNumGroups(m,k))
272 #define XkbCMKeySymsOffset(m,k) ((m)->key_sym_map[k].offset)
273 #define XkbCMKeySymsPtr(m,k)    (&(m)->syms[XkbCMKeySymsOffset(m,k)])
274
275 struct xkb_behavior {
276         unsigned char   type;
277         unsigned char   data;
278 };
279
280 struct xkb_server_map {
281     unsigned short      num_acts;
282     unsigned short      size_acts;
283
284 #if defined(__cplusplus) || defined(c_plusplus)
285     /* explicit is a C++ reserved word */
286     unsigned char *     c_explicit;
287 #else
288     unsigned char *     explicit;
289 #endif
290
291     union xkb_action          *acts;
292     struct xkb_behavior         *behaviors;
293     unsigned short      *key_acts;
294     unsigned char       *explicits;
295     uint32_t            vmods[XkbNumVirtualMods];
296     uint32_t            *vmodmap;
297 };
298
299 #define XkbSMKeyActionsPtr(m,k) (&(m)->acts[(m)->key_acts[k]])
300
301 struct xkb_indicator_map {
302         unsigned char   flags;
303         unsigned char   which_groups;
304         unsigned char   groups;
305         unsigned char   which_mods;
306         struct xkb_mods mods;
307         unsigned int    ctrls;
308 };
309
310 struct xkb_indicator {
311         unsigned long           phys_indicators;
312         struct xkb_indicator_map        maps[XkbNumIndicators];
313 };
314
315 struct xkb_key_name {
316         char    name[XkbKeyNameLength];
317 };
318
319 struct xkb_key_alias {
320         char    real[XkbKeyNameLength];
321         char    alias[XkbKeyNameLength];
322 };
323
324 struct xkb_names {
325     uint32_t            keycodes;
326     uint32_t            geometry;
327     uint32_t            symbols;
328     uint32_t            types;
329     uint32_t            compat;
330     uint32_t            vmods[XkbNumVirtualMods];
331     uint32_t            indicators[XkbNumIndicators];
332     uint32_t            groups[XkbNumKbdGroups];
333     struct xkb_key_name *     keys;
334     struct xkb_key_alias *    key_aliases;
335     uint32_t           *radio_groups;
336     uint32_t            phys_symbols;
337
338     unsigned char     num_keys;
339     unsigned char     num_key_aliases;
340     unsigned short    num_rg;
341 };
342
343 struct xkb_property {
344         char    *name;
345         char    *value;
346 };
347
348 struct xkb_color {
349         unsigned int    pixel;
350         char *          spec;
351 };
352
353 struct xkb_point {
354         short   x;
355         short   y;
356 };
357
358 struct xkb_bounds {
359         short   x1,y1;
360         short   x2,y2;
361 };
362
363 struct xkb_outline {
364         unsigned short  num_points;
365         unsigned short  sz_points;
366         unsigned short  corner_radius;
367         struct xkb_point *      points;
368 };
369
370 struct xkb_shape {
371         uint32_t                 name;
372         unsigned short   num_outlines;
373         unsigned short   sz_outlines;
374         struct xkb_outline *     outlines;
375         struct xkb_outline *     approx;
376         struct xkb_outline *     primary;
377         struct xkb_bounds        bounds;
378 };
379
380 struct xkb_shape_doodad {
381         uint32_t                 name;
382         unsigned char    type;
383         unsigned char    priority;
384         short            top;
385         short            left;
386         short            angle;
387         unsigned short   color_ndx;
388         unsigned short   shape_ndx;
389 };
390 #define XkbShapeDoodadColor(g,d)        (&(g)->colors[(d)->color_ndx])
391 #define XkbShapeDoodadShape(g,d)        (&(g)->shapes[(d)->shape_ndx])
392 #define XkbSetShapeDoodadColor(g,d,c)   ((d)->color_ndx= (c)-&(g)->colors[0])
393 #define XkbSetShapeDoodadShape(g,d,s)   ((d)->shape_ndx= (s)-&(g)->shapes[0])
394
395 struct xkb_text_doodad {
396         uint32_t                 name;
397         unsigned char    type;
398         unsigned char    priority;
399         short            top;
400         short            left;
401         short            angle;
402         short            width;
403         short            height;
404         unsigned short   color_ndx;
405         char *           text;
406         char *           font;
407 };
408 #define XkbTextDoodadColor(g,d) (&(g)->colors[(d)->color_ndx])
409 #define XkbSetTextDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
410
411 struct xkb_indicator_doodad {
412         uint32_t                 name;
413         unsigned char    type;
414         unsigned char    priority;
415         short            top;
416         short            left;
417         short            angle;
418         unsigned short   shape_ndx;
419         unsigned short   on_color_ndx;
420         unsigned short   off_color_ndx;
421 };
422 #define XkbIndicatorDoodadShape(g,d)    (&(g)->shapes[(d)->shape_ndx])
423 #define XkbIndicatorDoodadOnColor(g,d)  (&(g)->colors[(d)->on_color_ndx])
424 #define XkbIndicatorDoodadOffColor(g,d) (&(g)->colors[(d)->off_color_ndx])
425 #define XkbSetIndicatorDoodadOnColor(g,d,c) \
426                                 ((d)->on_color_ndx= (c)-&(g)->colors[0])
427 #define XkbSetIndicatorDoodadOffColor(g,d,c) \
428                                 ((d)->off_color_ndx= (c)-&(g)->colors[0])
429 #define XkbSetIndicatorDoodadShape(g,d,s) \
430                                 ((d)->shape_ndx= (s)-&(g)->shapes[0])
431
432 struct xkb_logo_doodad {
433         uint32_t                 name;
434         unsigned char    type;
435         unsigned char    priority;
436         short            top;
437         short            left;
438         short            angle;
439         unsigned short   color_ndx;
440         unsigned short   shape_ndx;
441         char *           logo_name;
442 };
443 #define XkbLogoDoodadColor(g,d)         (&(g)->colors[(d)->color_ndx])
444 #define XkbLogoDoodadShape(g,d)         (&(g)->shapes[(d)->shape_ndx])
445 #define XkbSetLogoDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
446 #define XkbSetLogoDoodadShape(g,d,s)    ((d)->shape_ndx= (s)-&(g)->shapes[0])
447
448 struct xkb_any_doodad {
449         uint32_t                 name;
450         unsigned char    type;
451         unsigned char    priority;
452         short            top;
453         short            left;
454         short            angle;
455 };
456
457 union xkb_doodad {
458         struct xkb_any_doodad   any;
459         struct xkb_shape_doodad shape;
460         struct xkb_text_doodad  text;
461         struct xkb_indicator_doodad     indicator;
462         struct xkb_logo_doodad  logo;
463 };
464
465 #define XkbUnknownDoodad        0
466 #define XkbOutlineDoodad        1
467 #define XkbSolidDoodad          2
468 #define XkbTextDoodad           3
469 #define XkbIndicatorDoodad      4
470 #define XkbLogoDoodad           5
471
472 struct xkb_key {
473         struct xkb_key_name      name;
474         short            gap;
475         unsigned char    shape_ndx;
476         unsigned char    color_ndx;
477 };
478 #define XkbKeyShape(g,k)        (&(g)->shapes[(k)->shape_ndx])
479 #define XkbKeyColor(g,k)        (&(g)->colors[(k)->color_ndx])
480 #define XkbSetKeyShape(g,k,s)   ((k)->shape_ndx= (s)-&(g)->shapes[0])
481 #define XkbSetKeyColor(g,k,c)   ((k)->color_ndx= (c)-&(g)->colors[0])
482
483 struct xkb_row {
484         short           top;
485         short           left;
486         unsigned short  num_keys;
487         unsigned short  sz_keys;
488         int             vertical;
489         struct xkb_key *        keys;
490         struct xkb_bounds       bounds;
491 };
492
493 struct xkb_section {
494         uint32_t                 name;
495         unsigned char    priority;
496         short            top;
497         short            left;
498         unsigned short   width;
499         unsigned short   height;
500         short            angle;
501         unsigned short   num_rows;
502         unsigned short   num_doodads;
503         unsigned short   num_overlays;
504         unsigned short   sz_rows;
505         unsigned short   sz_doodads;
506         unsigned short   sz_overlays;
507         struct xkb_row *         rows;
508         union xkb_doodad *       doodads;
509         struct xkb_bounds        bounds;
510         struct xkb_overlay *overlays;
511 };
512
513 struct xkb_overlay_key {
514         struct xkb_key_name     over;
515         struct xkb_key_name     under;
516 };
517
518 struct xkb_overlay_row {
519         unsigned short          row_under;
520         unsigned short          num_keys;
521         unsigned short          sz_keys;
522         struct xkb_overlay_key *        keys;
523 };
524
525 struct xkb_overlay {
526         uint32_t                        name;
527         struct xkb_section *            section_under;
528         unsigned short          num_rows;
529         unsigned short          sz_rows;
530         struct xkb_overlay_row *        rows;
531         struct xkb_bounds *             bounds;
532 };
533
534 struct xkb_geometry {
535         uint32_t                 name;
536         unsigned short   width_mm;
537         unsigned short   height_mm;
538         char *           label_font;
539         struct xkb_color *       label_color;
540         struct xkb_color *       base_color;
541         unsigned short   sz_properties;
542         unsigned short   sz_colors;
543         unsigned short   sz_shapes;
544         unsigned short   sz_sections;
545         unsigned short   sz_doodads;
546         unsigned short   sz_key_aliases;
547         unsigned short   num_properties;
548         unsigned short   num_colors;
549         unsigned short   num_shapes;
550         unsigned short   num_sections;
551         unsigned short   num_doodads;
552         unsigned short   num_key_aliases;
553         struct xkb_property *    properties;
554         struct xkb_color *       colors;
555         struct xkb_shape *       shapes;
556         struct xkb_section *     sections;
557         union xkb_doodad *       doodads;
558         struct xkb_key_alias *   key_aliases;
559 };
560 #define XkbGeomColorIndex(g,c)  ((int)((c)-&(g)->colors[0]))
561
562 #define XkbGeomPropertiesMask   (1<<0)
563 #define XkbGeomColorsMask       (1<<1)
564 #define XkbGeomShapesMask       (1<<2)
565 #define XkbGeomSectionsMask     (1<<3)
566 #define XkbGeomDoodadsMask      (1<<4)
567 #define XkbGeomKeyAliasesMask   (1<<5)
568 #define XkbGeomAllMask          (0x3f)
569
570 struct xkb_geometry_sizes {
571         unsigned int    which;
572         unsigned short  num_properties;
573         unsigned short  num_colors;
574         unsigned short  num_shapes;
575         unsigned short  num_sections;
576         unsigned short  num_doodads;
577         unsigned short  num_key_aliases;
578 };
579
580 struct xkb_controls {
581         unsigned char   mk_dflt_btn;
582         unsigned char   num_groups;
583         unsigned char   groups_wrap;
584         struct xkb_mods internal;
585         struct xkb_mods ignore_lock;
586         unsigned int    enabled_ctrls;
587         unsigned short  repeat_delay;
588         unsigned short  repeat_interval;
589         unsigned short  slow_keys_delay;
590         unsigned short  debounce_delay;
591         unsigned short  mk_delay;
592         unsigned short  mk_interval;
593         unsigned short  mk_time_to_max;
594         unsigned short  mk_max_speed;
595                  short  mk_curve;
596         unsigned short  ax_options;
597         unsigned short  ax_timeout;
598         unsigned short  axt_opts_mask;
599         unsigned short  axt_opts_values;
600         unsigned int    axt_ctrls_mask;
601         unsigned int    axt_ctrls_values;
602         unsigned char   per_key_repeat[XkbPerKeyBitArraySize];
603 };
604
605 /* Common keyboard description structure */
606 struct xkb_desc {
607     unsigned int        defined;
608     unsigned short      flags;
609     unsigned short      device_spec;
610     KeyCode             min_key_code;
611     KeyCode             max_key_code;
612
613     struct xkb_controls *      ctrls;
614     struct xkb_server_map *    server;
615     struct xkb_client_map *    map;
616     struct xkb_indicator *     indicators;
617     struct xkb_names *        names;
618     struct xkb_compat_map *    compat;
619     struct xkb_geometry *     geom;
620 };
621
622 #define XkbKeyKeyTypeIndex(d,k,g)       (XkbCMKeyTypeIndex((d)->map,k,g))
623 #define XkbKeyKeyType(d,k,g)            (XkbCMKeyType((d)->map,k,g))
624 #define XkbKeyGroupWidth(d,k,g)         (XkbCMKeyGroupWidth((d)->map,k,g))
625 #define XkbKeyGroupsWidth(d,k)          (XkbCMKeyGroupsWidth((d)->map,k))
626 #define XkbKeyGroupInfo(d,k)            (XkbCMKeyGroupInfo((d)->map,(k)))
627 #define XkbKeyNumGroups(d,k)            (XkbCMKeyNumGroups((d)->map,(k)))
628 #define XkbKeyNumSyms(d,k)              (XkbCMKeyNumSyms((d)->map,(k)))
629 #define XkbKeySymsPtr(d,k)              (XkbCMKeySymsPtr((d)->map,(k)))
630 #define XkbKeySym(d,k,n)                (XkbKeySymsPtr(d,k)[n])
631 #define XkbKeySymEntry(d,k,sl,g) \
632         (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
633 #define XkbKeyAction(d,k,n) \
634         (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
635 #define XkbKeyActionEntry(d,k,sl,g) \
636         (XkbKeyHasActions(d,k)?\
637                 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
638
639 #define XkbKeyHasActions(d,k)   ((d)->server->key_acts[k]!=0)
640 #define XkbKeyNumActions(d,k)   (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
641 #define XkbKeyActionsPtr(d,k)   (XkbSMKeyActionsPtr((d)->server,k))
642 #define XkbKeycodeInRange(d,k)  (((k)>=(d)->min_key_code)&&\
643                                  ((k)<=(d)->max_key_code))
644 #define XkbNumKeys(d)           ((d)->max_key_code-(d)->min_key_code+1)
645
646 struct xkb_map_changes {
647         unsigned short           changed;
648         KeyCode                  min_key_code;
649         KeyCode                  max_key_code;
650         unsigned char            first_type;
651         unsigned char            num_types;
652         KeyCode                  first_key_sym;
653         unsigned char            num_key_syms;
654         KeyCode                  first_key_act;
655         unsigned char            num_key_acts;
656         KeyCode                  first_key_behavior;
657         unsigned char            num_key_behaviors;
658         KeyCode                  first_key_explicit;
659         unsigned char            num_key_explicit;
660         KeyCode                  first_modmap_key;
661         unsigned char            num_modmap_keys;
662         KeyCode                  first_vmodmap_key;
663         unsigned char            num_vmodmap_keys;
664         unsigned char            pad;
665         unsigned short           vmods;
666 };
667
668 struct xkb_controls_changes {
669         unsigned int             changed_ctrls;
670         unsigned int             enabled_ctrls_changes;
671         int                      num_groups_changed;
672 };
673
674 struct xkb_indicator_changes {
675         unsigned int             state_changes;
676         unsigned int             map_changes;
677 };
678
679 struct xkb_name_changes {
680         unsigned int            changed;
681         unsigned char           first_type;
682         unsigned char           num_types;
683         unsigned char           first_lvl;
684         unsigned char           num_lvls;
685         unsigned char           num_aliases;
686         unsigned char           num_rg;
687         unsigned char           first_key;
688         unsigned char           num_keys;
689         unsigned short          changed_vmods;
690         unsigned long           changed_indicators;
691         unsigned char           changed_groups;
692 };
693
694 struct xkb_compat_changes {
695         unsigned char           changed_groups;
696         unsigned short          first_si;
697         unsigned short          num_si;
698 };
699
700 struct xkb_changes {
701         unsigned short           device_spec;
702         unsigned short           state_changes;
703         struct xkb_map_changes   map;
704         struct xkb_controls_changes      ctrls;
705         struct xkb_indicator_changes     indicators;
706         struct xkb_name_changes  names;
707         struct xkb_compat_changes        compat;
708 };
709
710 struct xkb_component_names {
711         char *                   keymap;
712         char *                   keycodes;
713         char *                   types;
714         char *                   compat;
715         char *                   symbols;
716         char *                   geometry;
717 };
718
719 struct xkb_component_name {
720         unsigned short          flags;
721         char *                  name;
722 };
723
724 struct xkb_component_list {
725         int                     num_keymaps;
726         int                     num_keycodes;
727         int                     num_types;
728         int                     num_compat;
729         int                     num_symbols;
730         int                     num_geometry;
731         struct xkb_component_name *     keymaps;
732         struct xkb_component_name *     keycodes;
733         struct xkb_component_name *     types;
734         struct xkb_component_name *     compat;
735         struct xkb_component_name *     symbols;
736         struct xkb_component_name *     geometry;
737 };
738
739 struct xkb_state {
740         unsigned char   group; /* base + latched + locked */
741         /* FIXME: Why are base + latched short and not char?? */
742         unsigned short  base_group; /* physically ... down? */
743         unsigned short  latched_group;
744         unsigned char   locked_group;
745
746         unsigned char   mods; /* base + latched + locked */
747         unsigned char   base_mods; /* physically down */
748         unsigned char   latched_mods;
749         unsigned char   locked_mods;
750
751         unsigned char   compat_state; /* mods + group for core state */
752
753         /* grab mods = all depressed and latched mods, _not_ locked mods */
754         unsigned char   grab_mods; /* grab mods minus internal mods */
755         unsigned char   compat_grab_mods; /* grab mods + group for core state,
756                                              but not locked groups if
757                                              IgnoreGroupLocks set */
758
759         /* effective mods = all mods (depressed, latched, locked) */
760         unsigned char   lookup_mods; /* effective mods minus internal mods */
761         unsigned char   compat_lookup_mods; /* effective mods + group */
762
763         unsigned short  ptr_buttons; /* core pointer buttons */
764 };
765
766 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
767 #define XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
768
769 #define XkbNumGroups(g)                 ((g)&0x0f)
770 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
771 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
772 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
773 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
774
775 _XFUNCPROTOBEGIN
776
777 typedef uint32_t (*InternAtomFuncPtr)(const char *val);
778 typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
779
780 _X_EXPORT extern void
781 xkb_init_atoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
782
783 _X_EXPORT extern uint32_t
784 xkb_intern_atom(const char *name);
785
786 _X_EXPORT extern struct xkb_desc *
787 xkb_compile_keymap_from_rules(const struct xkb_rule_names *rules);
788
789 _X_EXPORT extern struct xkb_desc *
790 xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg);
791
792 _X_EXPORT extern struct xkb_desc *
793 xkb_compile_keymap_from_file(FILE *inputFile, const char *mapName);
794
795 _X_EXPORT extern struct xkb_desc *
796 xkb_compile_keymap_from_string(const char *string, const char *mapName);
797
798 _X_EXPORT extern void
799 xkb_free_keymap(struct xkb_desc *xkb);
800
801 _X_EXPORT extern struct xkb_component_list *
802 xkb_list_components(struct xkb_component_names * ptrns, int *maxMatch);
803
804 /*
805  * Canonicalises component names by prepending the relevant component from
806  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
807  * by replacing a '%' with the relevant component, e.g.:
808  *
809  * names        old           output
810  * ------------------------------------------
811  * +bar         foo           foo+bar
812  * |quux        baz           baz|quux
813  * foo+%|baz    bar           foo+bar|baz
814  *
815  * If a component in names needs to be modified, the existing value will be
816  * free()d, and a new one allocated with malloc().
817  */
818 _X_EXPORT extern void
819 xkb_canonicalise_components(struct xkb_component_names * names,
820                            const struct xkb_component_names * old);
821
822 /*
823  * Converts a keysym to a string; will return unknown Unicode codepoints
824  * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
825  *
826  * This is uint32_t rather than KeySym, as KeySym changes size between
827  * client and server (no, really).
828  */
829 _X_EXPORT extern void
830 xkb_keysym_to_string(uint32_t ks, char *buffer, size_t size);
831
832 /*
833  * See xkb_keysym_to_string comments: this function will accept any string
834  * from that function.
835  */
836 _X_EXPORT extern uint32_t
837 xkb_string_to_keysym(const char *s);
838
839 _XFUNCPROTOEND
840
841 #endif /* _XKBCOMMON_H_ */