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