Rename Xkbc*Action to struct xkb_*_action
[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/Xmd.h>
62 #include <X11/extensions/XKBstrcommon.h>
63 #include <X11/extensions/XKBrulescommon.h>
64
65 /* Action structures used in the server */
66
67 #define XkbcAnyActionDataSize 18
68 struct xkb_any_action {
69     unsigned char   type;
70     unsigned char   pad[XkbcAnyActionDataSize];
71 };
72
73 struct xkb_mod_action {
74     unsigned char   type;
75     uint8_t         flags;
76     uint8_t         real_mods;
77     uint32_t        mask;
78     uint32_t        vmods;
79 };
80
81 struct xkb_group_action {
82     unsigned char   type;
83     unsigned char   flags;
84     int16_t         group;
85 };
86
87 struct xkb_iso_action {
88     unsigned char   type;
89     uint8_t         flags;
90     int16_t         group;
91     uint32_t        mask;
92     uint32_t        vmods;
93     uint8_t         real_mods;
94  
95    uint8_t         affect;
96 };
97
98 struct xkb_controls_action {
99     unsigned char   type;
100     uint8_t         flags;
101     uint32_t        ctrls;
102 };
103
104 struct xkb_device_button_action {
105     unsigned char   type;
106     uint8_t         flags;
107     uint16_t        device;
108     uint16_t        button;
109     uint8_t         count;
110 };
111
112 struct xkb_device_valuator_action {
113     unsigned char   type;
114     uint8_t         v1_what;
115     uint16_t        device;
116     uint16_t        v1_index;
117     int16_t         v1_value;
118     uint16_t        v2_index;
119     int16_t         v2_value;
120     uint8_t         v2_what;
121 };
122
123 struct xkb_pointer_default_action {
124     unsigned char   type;
125     uint8_t         flags;
126     uint8_t         affect;
127     uint8_t         value;
128 };
129
130 struct xkb_switch_screen_action {
131     unsigned char   type;
132     uint8_t         flags;
133     uint8_t         screen;
134 };
135
136 union xkb_action {
137     struct xkb_any_action            any;
138     struct xkb_mod_action            mods;
139     struct xkb_group_action          group;
140     struct xkb_iso_action            iso;
141     struct xkb_controls_action          ctrls;
142     struct xkb_device_button_action      devbtn;
143     struct xkb_device_valuator_action devval;
144     struct xkb_pointer_default_action        dflt;
145     struct xkb_switch_screen_action   screen;
146     XkbRedirectKeyAction     redirect; /* XXX wholly unnecessary? */
147     XkbPtrAction             ptr; /* XXX delete for DeviceValuator */
148     XkbPtrBtnAction          btn; /* XXX delete for DeviceBtn */
149     XkbMessageAction         msg; /* XXX just delete */
150     unsigned char            type;
151 };
152
153 typedef struct _XkbcMods {
154         uint32_t        mask;   /* effective mods */
155         uint32_t        vmods;
156         uint8_t         real_mods;
157 } XkbcModsRec, *XkbcModsPtr;
158
159 typedef struct _XkbcKTMapEntry {
160         Bool            active;
161         uint16_t        level;
162         XkbcModsRec     mods;
163 } XkbcKTMapEntryRec, *XkbcKTMapEntryPtr;
164
165 typedef struct _XkbcKeyType {
166     XkbcModsRec             mods;
167     uint16_t                num_levels;
168     unsigned char           map_count;
169     XkbcKTMapEntryPtr       map;
170     XkbcModsPtr             preserve;
171     uint32_t                  name;
172     uint32_t                 *level_names;
173 } XkbcKeyTypeRec, *XkbcKeyTypePtr;
174
175 typedef struct _XkbcSymInterpretRec {
176     uint32_t          sym;
177     unsigned char   flags;
178     unsigned char   match;
179     uint8_t         mods; /* XXX real or virt? */
180     uint32_t        virtual_mod;
181     struct xkb_any_action   act;
182 } XkbcSymInterpretRec, *XkbcSymInterpretPtr;
183
184 typedef struct _XkbcCompatMapRec {
185     XkbcSymInterpretPtr      sym_interpret;
186     XkbcModsRec              groups[XkbNumKbdGroups];
187     unsigned short           num_si;
188     unsigned short           size_si;
189 } XkbcCompatMapRec, *XkbcCompatMapPtr;
190
191 typedef struct _XkbcClientMapRec {
192     unsigned char            size_types;
193     unsigned char            num_types;
194     XkbcKeyTypePtr           types;
195
196     unsigned short           size_syms;
197     unsigned short           num_syms;
198     uint32_t                *syms;
199     XkbSymMapPtr             key_sym_map;
200
201     unsigned char           *modmap;
202 } XkbcClientMapRec, *XkbcClientMapPtr;
203
204 typedef struct _XkbcServerMapRec {
205     unsigned short      num_acts;
206     unsigned short      size_acts;
207
208 #if defined(__cplusplus) || defined(c_plusplus)
209     /* explicit is a C++ reserved word */
210     unsigned char *     c_explicit;
211 #else
212     unsigned char *     explicit;
213 #endif
214
215     union xkb_action          *acts;
216     XkbBehavior         *behaviors;
217     unsigned short      *key_acts;
218     unsigned char       *explicits;
219     uint32_t            vmods[XkbNumVirtualMods];
220     uint32_t            *vmodmap;
221 } XkbcServerMapRec, *XkbcServerMapPtr;
222
223 typedef struct _XkbcNamesRec {
224     uint32_t            keycodes;
225     uint32_t            geometry;
226     uint32_t            symbols;
227     uint32_t            types;
228     uint32_t            compat;
229     uint32_t            vmods[XkbNumVirtualMods];
230     uint32_t            indicators[XkbNumIndicators];
231     uint32_t            groups[XkbNumKbdGroups];
232     XkbKeyNamePtr     keys;
233     XkbKeyAliasPtr    key_aliases;
234     uint32_t           *radio_groups;
235     uint32_t            phys_symbols;
236
237     unsigned char     num_keys;
238     unsigned char     num_key_aliases;
239     unsigned short    num_rg;
240 } XkbcNamesRec, *XkbcNamesPtr;
241
242 typedef struct _XkbcProperty {
243         char    *name;
244         char    *value;
245 } XkbcPropertyRec, *XkbcPropertyPtr;
246
247 typedef struct _XkbcColor {
248         unsigned int    pixel;
249         char *          spec;
250 } XkbcColorRec, *XkbcColorPtr;
251
252 typedef struct _XkbcPoint {
253         short   x;
254         short   y;
255 } XkbcPointRec, *XkbcPointPtr;
256
257 typedef struct  _XkbcBounds {
258         short   x1,y1;
259         short   x2,y2;
260 } XkbcBoundsRec, *XkbcBoundsPtr;
261 #define XkbBoundsWidth(b)       (((b)->x2)-((b)->x1))
262 #define XkbBoundsHeight(b)      (((b)->y2)-((b)->y1))
263
264 typedef struct _XkbcOutline {
265         unsigned short  num_points;
266         unsigned short  sz_points;
267         unsigned short  corner_radius;
268         XkbcPointPtr    points;
269 } XkbcOutlineRec, *XkbcOutlinePtr;
270
271 typedef struct _XkbcShape {
272         uint32_t                 name;
273         unsigned short   num_outlines;
274         unsigned short   sz_outlines;
275         XkbcOutlinePtr   outlines;
276         XkbcOutlinePtr   approx;
277         XkbcOutlinePtr   primary;
278         XkbcBoundsRec    bounds;
279 } XkbcShapeRec, *XkbcShapePtr;
280 #define XkbOutlineIndex(s,o)    ((int)((o)-&(s)->outlines[0]))
281
282 typedef struct _XkbcShapeDoodad {
283         uint32_t                 name;
284         unsigned char    type;
285         unsigned char    priority;
286         short            top;
287         short            left;
288         short            angle;
289         unsigned short   color_ndx;
290         unsigned short   shape_ndx;
291 } XkbcShapeDoodadRec, *XkbcShapeDoodadPtr;
292 #define XkbShapeDoodadColor(g,d)        (&(g)->colors[(d)->color_ndx])
293 #define XkbShapeDoodadShape(g,d)        (&(g)->shapes[(d)->shape_ndx])
294 #define XkbSetShapeDoodadColor(g,d,c)   ((d)->color_ndx= (c)-&(g)->colors[0])
295 #define XkbSetShapeDoodadShape(g,d,s)   ((d)->shape_ndx= (s)-&(g)->shapes[0])
296
297 typedef struct _XkbcTextDoodad {
298         uint32_t                 name;
299         unsigned char    type;
300         unsigned char    priority;
301         short            top;
302         short            left;
303         short            angle;
304         short            width;
305         short            height;
306         unsigned short   color_ndx;
307         char *           text;
308         char *           font;
309 } XkbcTextDoodadRec, *XkbcTextDoodadPtr;
310 #define XkbTextDoodadColor(g,d) (&(g)->colors[(d)->color_ndx])
311 #define XkbSetTextDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
312
313 typedef struct _XkbcIndicatorDoodad {
314         uint32_t                 name;
315         unsigned char    type;
316         unsigned char    priority;
317         short            top;
318         short            left;
319         short            angle;
320         unsigned short   shape_ndx;
321         unsigned short   on_color_ndx;
322         unsigned short   off_color_ndx;
323 } XkbcIndicatorDoodadRec, *XkbcIndicatorDoodadPtr;
324 #define XkbIndicatorDoodadShape(g,d)    (&(g)->shapes[(d)->shape_ndx])
325 #define XkbIndicatorDoodadOnColor(g,d)  (&(g)->colors[(d)->on_color_ndx])
326 #define XkbIndicatorDoodadOffColor(g,d) (&(g)->colors[(d)->off_color_ndx])
327 #define XkbSetIndicatorDoodadOnColor(g,d,c) \
328                                 ((d)->on_color_ndx= (c)-&(g)->colors[0])
329 #define XkbSetIndicatorDoodadOffColor(g,d,c) \
330                                 ((d)->off_color_ndx= (c)-&(g)->colors[0])
331 #define XkbSetIndicatorDoodadShape(g,d,s) \
332                                 ((d)->shape_ndx= (s)-&(g)->shapes[0])
333
334 typedef struct _XkbcLogoDoodad {
335         uint32_t                 name;
336         unsigned char    type;
337         unsigned char    priority;
338         short            top;
339         short            left;
340         short            angle;
341         unsigned short   color_ndx;
342         unsigned short   shape_ndx;
343         char *           logo_name;
344 } XkbcLogoDoodadRec, *XkbcLogoDoodadPtr;
345 #define XkbLogoDoodadColor(g,d)         (&(g)->colors[(d)->color_ndx])
346 #define XkbLogoDoodadShape(g,d)         (&(g)->shapes[(d)->shape_ndx])
347 #define XkbSetLogoDoodadColor(g,d,c)    ((d)->color_ndx= (c)-&(g)->colors[0])
348 #define XkbSetLogoDoodadShape(g,d,s)    ((d)->shape_ndx= (s)-&(g)->shapes[0])
349
350 typedef struct _XkbcAnyDoodad {
351         uint32_t                 name;
352         unsigned char    type;
353         unsigned char    priority;
354         short            top;
355         short            left;
356         short            angle;
357 } XkbcAnyDoodadRec, *XkbcAnyDoodadPtr;
358
359 typedef union _XkbcDoodad {
360         XkbcAnyDoodadRec        any;
361         XkbcShapeDoodadRec      shape;
362         XkbcTextDoodadRec       text;
363         XkbcIndicatorDoodadRec  indicator;
364         XkbcLogoDoodadRec       logo;
365 } XkbcDoodadRec, *XkbcDoodadPtr;
366
367 #define XkbUnknownDoodad        0
368 #define XkbOutlineDoodad        1
369 #define XkbSolidDoodad          2
370 #define XkbTextDoodad           3
371 #define XkbIndicatorDoodad      4
372 #define XkbLogoDoodad           5
373
374 typedef struct _XkbcKey {
375         XkbKeyNameRec    name;
376         short            gap;
377         unsigned char    shape_ndx;
378         unsigned char    color_ndx;
379 } XkbcKeyRec, *XkbcKeyPtr;
380 #define XkbKeyShape(g,k)        (&(g)->shapes[(k)->shape_ndx])
381 #define XkbKeyColor(g,k)        (&(g)->colors[(k)->color_ndx])
382 #define XkbSetKeyShape(g,k,s)   ((k)->shape_ndx= (s)-&(g)->shapes[0])
383 #define XkbSetKeyColor(g,k,c)   ((k)->color_ndx= (c)-&(g)->colors[0])
384
385 typedef struct _XkbRow {
386         short           top;
387         short           left;
388         unsigned short  num_keys;
389         unsigned short  sz_keys;
390         int             vertical;
391         XkbcKeyPtr      keys;
392         XkbcBoundsRec   bounds;
393 } XkbcRowRec, *XkbcRowPtr;
394
395 typedef struct _XkbcSection {
396         uint32_t                 name;
397         unsigned char    priority;
398         short            top;
399         short            left;
400         unsigned short   width;
401         unsigned short   height;
402         short            angle;
403         unsigned short   num_rows;
404         unsigned short   num_doodads;
405         unsigned short   num_overlays;
406         unsigned short   sz_rows;
407         unsigned short   sz_doodads;
408         unsigned short   sz_overlays;
409         XkbcRowPtr       rows;
410         XkbcDoodadPtr    doodads;
411         XkbcBoundsRec    bounds;
412         struct _XkbOverlay *overlays;
413 } XkbcSectionRec, *XkbcSectionPtr;
414
415 typedef struct _XkbcOverlayKey {
416         XkbKeyNameRec   over;
417         XkbKeyNameRec   under;
418 } XkbcOverlayKeyRec, *XkbcOverlayKeyPtr;
419
420 typedef struct _XkbOverlayRow {
421         unsigned short          row_under;
422         unsigned short          num_keys;
423         unsigned short          sz_keys;
424         XkbcOverlayKeyPtr       keys;
425 } XkbcOverlayRowRec, *XkbcOverlayRowPtr;
426
427 typedef struct _XkbOverlay {
428         uint32_t                        name;
429         XkbcSectionPtr          section_under;
430         unsigned short          num_rows;
431         unsigned short          sz_rows;
432         XkbcOverlayRowPtr       rows;
433         XkbcBoundsPtr           bounds;
434 } XkbcOverlayRec, *XkbcOverlayPtr;
435
436 typedef struct _XkbcGeometry {
437         uint32_t                 name;
438         unsigned short   width_mm;
439         unsigned short   height_mm;
440         char *           label_font;
441         XkbcColorPtr     label_color;
442         XkbcColorPtr     base_color;
443         unsigned short   sz_properties;
444         unsigned short   sz_colors;
445         unsigned short   sz_shapes;
446         unsigned short   sz_sections;
447         unsigned short   sz_doodads;
448         unsigned short   sz_key_aliases;
449         unsigned short   num_properties;
450         unsigned short   num_colors;
451         unsigned short   num_shapes;
452         unsigned short   num_sections;
453         unsigned short   num_doodads;
454         unsigned short   num_key_aliases;
455         XkbcPropertyPtr  properties;
456         XkbcColorPtr     colors;
457         XkbcShapePtr     shapes;
458         XkbcSectionPtr   sections;
459         XkbcDoodadPtr    doodads;
460         XkbKeyAliasPtr   key_aliases;
461 } XkbcGeometryRec, *XkbcGeometryPtr;
462 #define XkbGeomColorIndex(g,c)  ((int)((c)-&(g)->colors[0]))
463
464 #define XkbGeomPropertiesMask   (1<<0)
465 #define XkbGeomColorsMask       (1<<1)
466 #define XkbGeomShapesMask       (1<<2)
467 #define XkbGeomSectionsMask     (1<<3)
468 #define XkbGeomDoodadsMask      (1<<4)
469 #define XkbGeomKeyAliasesMask   (1<<5)
470 #define XkbGeomAllMask          (0x3f)
471
472 typedef struct _XkbcGeometrySizes {
473         unsigned int    which;
474         unsigned short  num_properties;
475         unsigned short  num_colors;
476         unsigned short  num_shapes;
477         unsigned short  num_sections;
478         unsigned short  num_doodads;
479         unsigned short  num_key_aliases;
480 } XkbcGeometrySizesRec, *XkbcGeometrySizesPtr;
481
482 /* Common keyboard description structure */
483 typedef struct _XkbcDesc {
484     unsigned int        defined;
485     unsigned short      flags;
486     unsigned short      device_spec;
487     KeyCode             min_key_code;
488     KeyCode             max_key_code;
489
490     XkbControlsPtr      ctrls;
491     XkbcServerMapPtr    server;
492     XkbcClientMapPtr    map;
493     XkbIndicatorPtr     indicators;
494     XkbcNamesPtr        names;
495     XkbcCompatMapPtr    compat;
496     XkbcGeometryPtr     geom;
497 } XkbcDescRec, *XkbcDescPtr;
498
499 _XFUNCPROTOBEGIN
500
501 typedef uint32_t (*InternAtomFuncPtr)(const char *val);
502 typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
503
504 extern void
505 XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
506
507 extern XkbcDescPtr
508 XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
509
510 extern XkbcDescPtr
511 XkbcCompileKeymapFromComponents(const XkbComponentNamesPtr ktcsg);
512
513 extern XkbcDescPtr
514 XkbcCompileKeymapFromFile(FILE *inputFile, const char *mapName);
515
516 extern XkbComponentListPtr
517 XkbcListComponents(XkbComponentNamesPtr ptrns, int *maxMatch);
518
519 /*
520  * Canonicalises component names by prepending the relevant component from
521  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
522  * by replacing a '%' with the relevant component, e.g.:
523  *
524  * names        old           output
525  * ------------------------------------------
526  * +bar         foo           foo+bar
527  * |quux        baz           baz|quux
528  * foo+%|baz    bar           foo+bar|baz
529  *
530  * If a component in names needs to be modified, the existing value will be
531  * free()d, and a new one allocated with malloc().
532  */
533 extern void
534 XkbcCanonicaliseComponents(XkbComponentNamesPtr names,
535                            const XkbComponentNamesPtr old);
536
537 /*
538  * Converts a keysym to a string; will return unknown Unicode codepoints
539  * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
540  *
541  * The string returned may become invalidated after the next call to
542  * XkbcKeysymToString: if you need to preserve it, then you must
543  * duplicate it.
544  *
545  * This is uint32_t rather than KeySym, as KeySym changes size between
546  * client and server (no, really).
547  */
548 extern char *
549 XkbcKeysymToString(uint32_t ks);
550
551 /*
552  * See XkbcKeysymToString comments: this function will accept any string
553  * from that function.
554  */
555 extern uint32_t
556 XkbcStringToKeysym(const char *s);
557
558 _XFUNCPROTOEND
559
560 #endif /* _XKBCOMMON_H_ */