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