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