2 Copyright 1985, 1987, 1990, 1998 The Open Group
3 Copyright 2008 Dan Nicholson
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:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
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.
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.
28 /************************************************************
29 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
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.
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.
52 ********************************************************/
60 #include <X11/Xfuncproto.h>
62 #include <X11/extensions/XKBstrcommon.h>
63 #include <X11/extensions/XKBrulescommon.h>
65 /* Action structures used in the server */
67 #define XkbcAnyActionDataSize 18
68 typedef struct _XkbcAnyAction {
70 unsigned char pad[XkbcAnyActionDataSize];
73 typedef struct _XkbcModAction {
81 typedef struct _XkbcGroupAction {
87 typedef struct _XkbcISOAction {
97 typedef struct _XkbcCtrlsAction {
103 typedef struct _XkbcDeviceBtnAction {
109 } XkbcDeviceBtnAction;
111 typedef struct _XkbcDeviceValuatorAction {
120 } XkbcDeviceValuatorAction;
122 typedef struct _XkbcPtrDfltAction {
129 typedef struct _XkbcSwitchScreenAction {
133 } XkbcSwitchScreenAction;
135 typedef union _XkbcAction {
138 XkbcGroupAction group;
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 */
152 typedef struct _XkbcMods {
153 uint32_t mask; /* effective mods */
156 } XkbcModsRec, *XkbcModsPtr;
158 typedef struct _XkbcKTMapEntry {
162 } XkbcKTMapEntryRec, *XkbcKTMapEntryPtr;
164 typedef struct _XkbcKeyType {
167 unsigned char map_count;
168 XkbcKTMapEntryPtr map;
169 XkbcModsPtr preserve;
171 uint32_t *level_names;
172 } XkbcKeyTypeRec, *XkbcKeyTypePtr;
174 typedef struct _XkbcSymInterpretRec {
178 uint8_t mods; /* XXX real or virt? */
179 uint32_t virtual_mod;
181 } XkbcSymInterpretRec, *XkbcSymInterpretPtr;
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;
190 typedef struct _XkbcClientMapRec {
191 unsigned char size_types;
192 unsigned char num_types;
193 XkbcKeyTypePtr types;
195 unsigned short size_syms;
196 unsigned short num_syms;
198 XkbSymMapPtr key_sym_map;
200 unsigned char *modmap;
201 } XkbcClientMapRec, *XkbcClientMapPtr;
203 typedef struct _XkbcServerMapRec {
204 unsigned short num_acts;
205 unsigned short size_acts;
207 #if defined(__cplusplus) || defined(c_plusplus)
208 /* explicit is a C++ reserved word */
209 unsigned char * c_explicit;
211 unsigned char * explicit;
215 XkbBehavior *behaviors;
216 unsigned short *key_acts;
217 unsigned char *explicits;
218 uint32_t vmods[XkbNumVirtualMods];
220 } XkbcServerMapRec, *XkbcServerMapPtr;
222 typedef struct _XkbcNamesRec {
228 uint32_t vmods[XkbNumVirtualMods];
229 uint32_t indicators[XkbNumIndicators];
230 uint32_t groups[XkbNumKbdGroups];
232 XkbKeyAliasPtr key_aliases;
233 uint32_t *radio_groups;
234 uint32_t phys_symbols;
236 unsigned char num_keys;
237 unsigned char num_key_aliases;
238 unsigned short num_rg;
239 } XkbcNamesRec, *XkbcNamesPtr;
241 typedef struct _XkbcProperty {
244 } XkbcPropertyRec, *XkbcPropertyPtr;
246 typedef struct _XkbcColor {
249 } XkbcColorRec, *XkbcColorPtr;
251 typedef struct _XkbcPoint {
254 } XkbcPointRec, *XkbcPointPtr;
256 typedef struct _XkbcBounds {
259 } XkbcBoundsRec, *XkbcBoundsPtr;
260 #define XkbBoundsWidth(b) (((b)->x2)-((b)->x1))
261 #define XkbBoundsHeight(b) (((b)->y2)-((b)->y1))
263 typedef struct _XkbcOutline {
264 unsigned short num_points;
265 unsigned short sz_points;
266 unsigned short corner_radius;
268 } XkbcOutlineRec, *XkbcOutlinePtr;
270 typedef struct _XkbcShape {
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]))
281 typedef struct _XkbcShapeDoodad {
284 unsigned char priority;
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])
296 typedef struct _XkbcTextDoodad {
299 unsigned char priority;
305 unsigned short color_ndx;
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])
312 typedef struct _XkbcIndicatorDoodad {
315 unsigned char priority;
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])
333 typedef struct _XkbcLogoDoodad {
336 unsigned char priority;
340 unsigned short color_ndx;
341 unsigned short shape_ndx;
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])
349 typedef struct _XkbcAnyDoodad {
352 unsigned char priority;
356 } XkbcAnyDoodadRec, *XkbcAnyDoodadPtr;
358 typedef union _XkbcDoodad {
359 XkbcAnyDoodadRec any;
360 XkbcShapeDoodadRec shape;
361 XkbcTextDoodadRec text;
362 XkbcIndicatorDoodadRec indicator;
363 XkbcLogoDoodadRec logo;
364 } XkbcDoodadRec, *XkbcDoodadPtr;
366 #define XkbUnknownDoodad 0
367 #define XkbOutlineDoodad 1
368 #define XkbSolidDoodad 2
369 #define XkbTextDoodad 3
370 #define XkbIndicatorDoodad 4
371 #define XkbLogoDoodad 5
373 typedef struct _XkbcKey {
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])
384 typedef struct _XkbRow {
387 unsigned short num_keys;
388 unsigned short sz_keys;
391 XkbcBoundsRec bounds;
392 } XkbcRowRec, *XkbcRowPtr;
394 typedef struct _XkbcSection {
396 unsigned char priority;
399 unsigned short width;
400 unsigned short height;
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;
409 XkbcDoodadPtr doodads;
410 XkbcBoundsRec bounds;
411 struct _XkbOverlay *overlays;
412 } XkbcSectionRec, *XkbcSectionPtr;
414 typedef struct _XkbcOverlayKey {
417 } XkbcOverlayKeyRec, *XkbcOverlayKeyPtr;
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;
426 typedef struct _XkbOverlay {
428 XkbcSectionPtr section_under;
429 unsigned short num_rows;
430 unsigned short sz_rows;
431 XkbcOverlayRowPtr rows;
432 XkbcBoundsPtr bounds;
433 } XkbcOverlayRec, *XkbcOverlayPtr;
435 typedef struct _XkbcGeometry {
437 unsigned short width_mm;
438 unsigned short height_mm;
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;
457 XkbcSectionPtr sections;
458 XkbcDoodadPtr doodads;
459 XkbKeyAliasPtr key_aliases;
460 } XkbcGeometryRec, *XkbcGeometryPtr;
461 #define XkbGeomColorIndex(g,c) ((int)((c)-&(g)->colors[0]))
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)
471 typedef struct _XkbcGeometrySizes {
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;
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;
489 XkbControlsPtr ctrls;
490 XkbcServerMapPtr server;
491 XkbcClientMapPtr map;
492 XkbIndicatorPtr indicators;
494 XkbcCompatMapPtr compat;
495 XkbcGeometryPtr geom;
496 } XkbcDescRec, *XkbcDescPtr;
500 typedef uint32_t (*InternAtomFuncPtr)(const char *val);
501 typedef const char *(*GetAtomValueFuncPtr)(uint32_t atom);
504 XkbcInitAtoms(InternAtomFuncPtr intern, GetAtomValueFuncPtr get_atom_value);
507 XkbcCompileKeymapFromRules(const XkbRMLVOSet *rmlvo);
510 XkbcCompileKeymapFromComponents(const XkbComponentNamesPtr ktcsg);
513 XkbcCompileKeymapFromFile(FILE *inputFile, const char *mapName);
515 extern XkbComponentListPtr
516 XkbcListComponents(XkbComponentNamesPtr ptrns, int *maxMatch);
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.:
524 * ------------------------------------------
527 * foo+%|baz bar foo+bar|baz
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().
533 XkbcCanonicaliseComponents(XkbComponentNamesPtr names,
534 const XkbComponentNamesPtr old);
537 * Converts a keysym to a string; will return unknown Unicode codepoints
538 * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
540 * The string returned may become invalidated after the next call to
541 * XkbcKeysymToString: if you need to preserve it, then you must
544 * This is uint32_t rather than KeySym, as KeySym changes size between
545 * client and server (no, really).
548 XkbcKeysymToString(uint32_t ks);
551 * See XkbcKeysymToString comments: this function will accept any string
552 * from that function.
555 XkbcStringToKeysym(const char *s);
559 #endif /* _XKBCOMMON_H_ */