Copy in XkbCompatMapRec and XkbSymInterpretRec
[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 #ifndef _XKBCOMMON_H_
29 #define _XKBCOMMON_H_
30
31 #include <stdint.h>
32 #include <stdio.h>
33 #include <X11/Xfuncproto.h>
34 #include <X11/extensions/XKBstrcommon.h>
35 #include <X11/extensions/XKBrulescommon.h>
36
37 #define KeySym CARD32
38 #define Atom CARD32
39
40 /* Action structures used in the server */
41
42 #define XkbcAnyActionDataSize 18
43 typedef struct _XkbcAnyAction {
44     unsigned char   type;
45     unsigned char   pad[XkbcAnyActionDataSize];
46 } XkbcAnyAction;
47
48 typedef struct _XkbcModAction {
49     unsigned char   type;
50     uint8_t         flags;
51     uint32_t        mask;
52     uint32_t        real_mods;
53     uint32_t        vmods;
54 } XkbcModAction;
55
56 typedef struct _XkbcGroupAction {
57     unsigned char   type;
58     unsigned char   flags;
59     int16_t         group;
60 } XkbcGroupAction;
61
62 typedef struct _XkbcISOAction {
63     unsigned char   type;
64     uint8_t         flags;
65     int16_t         group;
66     uint32_t        mask;
67     uint32_t        vmods;
68     uint32_t        real_mods;
69     uint8_t         affect;
70 } XkbcISOAction;
71
72 typedef struct _XkbcCtrlsAction {
73     unsigned char   type;
74     unsigned char   flags;
75     uint32_t        ctrls;
76 } XkbcCtrlsAction;
77
78 typedef struct _XkbcDeviceBtnAction {
79     unsigned char   type;
80     unsigned char   flags;
81     uint16_t        device;
82     uint16_t        button;
83     uint8_t         count;
84 } XkbcDeviceBtnAction;
85
86 typedef struct _XkbcDeviceValuatorAction {
87     unsigned char   type;
88     uint8_t         v1_what;
89     uint16_t        device;
90     uint16_t        v1_index;
91     int16_t         v1_value;
92     uint16_t        v2_index;
93     int16_t         v2_value;
94     uint8_t         v2_what;
95 } XkbcDeviceValuatorAction;
96
97 typedef struct _XkbcPtrDfltAction {
98     unsigned char   type;
99     uint8_t         flags;
100     uint8_t         affect;
101     uint8_t         value;
102 } XkbcPtrDfltAction;
103
104 typedef struct _XkbcSwitchScreenAction {
105     unsigned char   type;
106     uint8_t         flags;
107     uint8_t         screen;
108 } XkbcSwitchScreenAction;
109
110 typedef union _XkbcAction {
111     XkbcAnyAction            any;
112     XkbcModAction            mods;
113     XkbcGroupAction          group;
114     XkbcISOAction            iso;
115     XkbcCtrlsAction          ctrls;
116     XkbcDeviceBtnAction      devbtn;
117     XkbcDeviceValuatorAction devval;
118     XkbcPtrDfltAction        dflt;
119     XkbcSwitchScreenAction   screen;
120     XkbRedirectKeyAction     redirect; /* XXX wholly unnecessary? */
121     XkbPtrAction             ptr; /* XXX delete for DeviceValuator */
122     XkbPtrBtnAction          btn; /* XXX delete for DeviceBtn */
123     XkbMessageAction         msg; /* XXX just delete */
124     unsigned char           type;
125 } XkbcAction;
126
127 typedef struct _XkbcSymInterpretRec {
128     CARD32          sym;
129     unsigned char   flags;
130     unsigned char   match;
131     unsigned char   mods;
132     unsigned char   virtual_mod;
133     XkbcAnyAction    act;
134 } XkbcSymInterpretRec,*XkbcSymInterpretPtr;
135
136 typedef struct _XkbcCompatMapRec {
137     XkbcSymInterpretPtr      sym_interpret;
138     XkbModsRec               groups[XkbNumKbdGroups];
139     unsigned short           num_si;
140     unsigned short           size_si;
141 } XkbcCompatMapRec, *XkbcCompatMapPtr;
142
143 typedef struct _XkbcClientMapRec {
144     unsigned char            size_types;
145     unsigned char            num_types;
146     XkbKeyTypePtr            types;
147
148     unsigned short           size_syms;
149     unsigned short           num_syms;
150     uint32_t                *syms;
151     XkbSymMapPtr             key_sym_map;
152
153     unsigned char           *modmap;
154 } XkbcClientMapRec, *XkbcClientMapPtr;
155
156 typedef struct _XkbcServerMapRec {
157     unsigned short      num_acts;
158     unsigned short      size_acts;
159
160 #if defined(__cplusplus) || defined(c_plusplus)
161     /* explicit is a C++ reserved word */
162     unsigned char *     c_explicit;
163 #else
164     unsigned char *     explicit;
165 #endif
166
167     XkbcAction          *acts;
168     XkbBehavior         *behaviors;
169     unsigned short      *key_acts;
170     unsigned char       *explicits;
171     uint32_t            vmods[XkbNumVirtualMods];
172     uint32_t            *vmodmap;
173 } XkbcServerMapRec, *XkbcServerMapPtr;
174
175 /* Common keyboard description structure */
176 typedef struct _XkbcDesc {
177     unsigned int        defined;
178     unsigned short      flags;
179     unsigned short      device_spec;
180     KeyCode             min_key_code;
181     KeyCode             max_key_code;
182
183     XkbControlsPtr      ctrls;
184     XkbcServerMapPtr    server;
185     XkbcClientMapPtr    map;
186     XkbIndicatorPtr     indicators;
187     XkbNamesPtr         names;
188     XkbcCompatMapPtr    compat;
189     XkbGeometryPtr      geom;
190 } XkbcDescRec, *XkbcDescPtr;
191
192 _XFUNCPROTOBEGIN
193
194 extern void
195 XkbcInitAtoms(void);
196
197 extern XkbcDescPtr
198 XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
199
200 extern XkbcDescPtr
201 XkbcCompileKeymapFromComponents(const XkbComponentNamesPtr ktcsg);
202
203 extern XkbcDescPtr
204 XkbcCompileKeymapFromFile(FILE *inputFile, const char *mapName);
205
206 extern XkbComponentListPtr
207 XkbcListComponents(XkbComponentNamesPtr ptrns, int *maxMatch);
208
209 /*
210  * Canonicalises component names by prepending the relevant component from
211  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
212  * by replacing a '%' with the relevant component, e.g.:
213  *
214  * names        old           output
215  * ------------------------------------------
216  * +bar         foo           foo+bar
217  * |quux        baz           baz|quux
218  * foo+%|baz    bar           foo+bar|baz
219  *
220  * If a component in names needs to be modified, the existing value will be
221  * free()d, and a new one allocated with malloc().
222  */
223 extern void
224 XkbcCanonicaliseComponents(XkbComponentNamesPtr names,
225                            const XkbComponentNamesPtr old);
226
227 /*
228  * Converts a keysym to a string; will return unknown Unicode codepoints
229  * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
230  *
231  * The string returned may become invalidated after the next call to
232  * XkbcKeysymToString: if you need to preserve it, then you must
233  * duplicate it.
234  *
235  * This is CARD32 rather than KeySym, as KeySym changes size between
236  * client and server (no, really).
237  */
238 extern char *
239 XkbcKeysymToString(CARD32 ks);
240
241 /*
242  * See XkbcKeysymToString comments: this function will accept any string
243  * from that function.
244  */
245 extern CARD32
246 XkbcStringToKeysym(const char *s);
247
248 _XFUNCPROTOEND
249
250 #undef KeySym
251 #undef Atom
252
253 #endif /* _XKBCOMMON_H_ */