XKBlibint.h revision 07fb9b8f
1/************************************************************
2Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
3
4Permission to use, copy, modify, and distribute this
5software and its documentation for any purpose and without
6fee is hereby granted, provided that the above copyright
7notice appear in all copies and that both that copyright
8notice and this permission notice appear in supporting
9documentation, and that the name of Silicon Graphics not be
10used in advertising or publicity pertaining to distribution
11of the software without specific prior written permission.
12Silicon Graphics makes no representation about the suitability
13of this software for any purpose. It is provided "as is"
14without any express or implied warranty.
15
16SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25********************************************************/
26
27#ifndef _XKBLIBINT_H_
28#define _XKBLIBINT_H_
29
30#include <X11/Xutil.h>
31#include <X11/XKBlib.h>
32#include "reallocarray.h"
33
34#define XkbMapPending           (1<<0)
35#define XkbXlibNewKeyboard      (1<<1)
36
37typedef int     (*XkbKSToMBFunc)(
38        XPointer        /* priv */,
39        KeySym          /* sym */,
40        char *          /* buf */,
41        int             /* len */,
42        int *           /* extra_rtrn */
43);
44
45typedef KeySym  (*XkbMBToKSFunc)(
46        XPointer        /* priv */,
47        char *          /* buf */,
48        int             /* len */,
49        Status *        /* status */
50);
51
52typedef KeySym  (*XkbToUpperFunc)(
53        KeySym          /* sym */
54);
55
56typedef struct _XkbConverters {
57        XkbKSToMBFunc    KSToMB;
58        XPointer         KSToMBPriv;
59        XkbMBToKSFunc    MBToKS;
60        XPointer         MBToKSPriv;
61        XkbToUpperFunc   KSToUpper;
62} XkbConverters;
63
64extern  XkbInternAtomFunc       _XkbInternAtomFunc;
65extern  XkbGetAtomNameFunc      _XkbGetAtomNameFunc;
66
67typedef struct _XkbInfoRec {
68        unsigned         flags;
69        unsigned         xlib_ctrls;
70        XExtCodes        *codes;
71        int              srv_major;
72        int              srv_minor;
73        unsigned         selected_events;
74        unsigned short   selected_nkn_details;
75        unsigned short   selected_map_details;
76        XkbDescRec      *desc;
77        XkbMapChangesRec changes;
78        Atom             composeLED;
79        XkbConverters    cvt;
80        XkbConverters    latin1cvt;
81} XkbInfoRec, *XkbInfoPtr;
82
83
84#define _XkbUnavailable(d) \
85        (((d)->flags&XlibDisplayNoXkb) || \
86         ((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d)))
87
88#define _XkbCheckPendingRefresh(d,xi) do { \
89    if ((xi)->flags&XkbXlibNewKeyboard) \
90        _XkbReloadDpy((d)); \
91    else if ((xi)->flags&XkbMapPending) { \
92        if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) { \
93            LockDisplay((d)); \
94            (xi)->changes.changed= 0; \
95            UnlockDisplay((d)); \
96        } \
97    } \
98} while (0)
99
100#define _XkbNeedModmap(i)    ((!(i)->desc->map)||(!(i)->desc->map->modmap))
101
102        /*
103         * mask of the events that the "invisible" XKB support in Xlib needs
104         */
105#define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask)
106
107        /*
108         * Handy helper macros
109         */
110
111typedef struct _XkbReadBuffer {
112        int      error;
113        int      size;
114        char    *start;
115        char    *data;
116} XkbReadBufferRec, *XkbReadBufferPtr;
117
118#define _XkbAlloc(s)            Xmalloc((s))
119#define _XkbCalloc(n,s)         Xcalloc((n),(s))
120#define _XkbRealloc(o,s)        Xrealloc((o),(s))
121#define _XkbTypedAlloc(t)       ((t *)Xmalloc(sizeof(t)))
122#define _XkbTypedCalloc(n,t)    ((t *)Xcalloc((n),sizeof(t)))
123#define _XkbFree(p)             Xfree(p)
124
125/* Resizes array to hold new_num elements, zeroing newly added entries.
126   Destroys old array on failure. */
127#define _XkbResizeArray(array, old_num, new_num, type)                       \
128    do {                                                                     \
129        if (array == NULL) {                                                 \
130            array = _XkbTypedCalloc(new_num, type);                          \
131        } else {                                                             \
132            type *prev_array = array;                                        \
133            array = Xreallocarray(array, new_num, sizeof(type));             \
134            if (_X_UNLIKELY((array) == NULL)) {                              \
135                _XkbFree(prev_array);                                        \
136            } else if ((new_num) > (old_num)) {                              \
137                bzero(&array[old_num],                                       \
138                      ((new_num) - (old_num)) * sizeof(type));               \
139            }                                                                \
140        }                                                                    \
141    } while(0)
142
143_XFUNCPROTOBEGIN
144
145extern  void _XkbReloadDpy(
146    Display *           /* dpy */
147);
148
149extern KeySym _XKeycodeToKeysym(
150    Display *           /* display */,
151#if NeedWidePrototypes
152    unsigned int        /* keycode */,
153#else
154    KeyCode             /* keycode */,
155#endif
156    int                 /* index */
157);
158
159extern KeyCode _XKeysymToKeycode(
160    Display *           /* display */,
161    KeySym              /* keysym */
162);
163
164extern KeySym _XLookupKeysym(
165    XKeyEvent *         /* key_event */,
166    int                 /* index */
167);
168
169extern int _XRefreshKeyboardMapping(
170    XMappingEvent *     /* event_map */
171);
172
173extern unsigned _XKeysymToModifiers(
174    Display *           /* dpy */,
175    KeySym              /* ks */
176);
177
178extern int _XTranslateKey(
179    register Display *  /* dpy */,
180    KeyCode             /* keycode */,
181    register unsigned int /* modifiers */,
182    unsigned int *      /* modifiers_return */,
183    KeySym *            /* keysym_return */
184);
185
186extern int      _XTranslateKeySym(
187    Display *           /* dpy */,
188    register KeySym     /* symbol */,
189    unsigned int        /* modifiers */,
190    char *              /* buffer */,
191    int                 /* nbytes */
192);
193
194extern  int _XLookupString(
195    register XKeyEvent *        /* event */,
196    char *                      /* buffer */,
197    int                         /* nbytes */,
198    KeySym *                    /* keysym */,
199    XComposeStatus *            /* status */
200);
201
202extern void _XkbNoteCoreMapChanges(
203    XkbMapChangesRec *          /* old */,
204    XMappingEvent *             /* new */,
205    unsigned int                /* wanted */
206);
207
208extern  int _XkbInitReadBuffer(
209    Display *           /* dpy */,
210    XkbReadBufferPtr    /* buf */,
211    int                 /* size */
212);
213
214extern int _XkbSkipReadBufferData(
215    XkbReadBufferPtr    /* from */,
216    int                 /* size */
217);
218
219extern int _XkbCopyFromReadBuffer(
220    XkbReadBufferPtr    /* from */,
221    char *              /* to */,
222    int                 /* size */
223);
224
225
226#ifdef LONG64
227extern  int _XkbReadCopyData32(
228    int *               /* from */,
229    long *              /* to */,
230    int                 /* num_words */
231);
232
233extern  int _XkbWriteCopyData32(
234    unsigned long *     /* from */,
235    CARD32 *            /* to */,
236    int                 /* num_words */
237);
238
239extern int _XkbReadBufferCopy32(
240    XkbReadBufferPtr    /* from */,
241    long *              /* to */,
242    int                 /* size */
243);
244#else
245#define _XkbReadCopyData32(f,t,s)    memcpy((char *)(t), (char *)(f), (s)*4)
246#define _XkbWriteCopyData32(f,t,s)   memcpy((char *)(t), (char *)(f), (s)*4)
247#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f, (char *)t, (s)*4)
248#endif
249
250#ifndef NO_DEC_BINARY_COMPATIBILITY
251#define XKB_FORCE_INT_KEYSYM 1
252#endif
253
254#ifdef XKB_FORCE_INT_KEYSYM
255extern int _XkbReadCopyKeySyms(
256    int *               /* from */,
257    KeySym *            /* to */,
258    int                 /* num_words */
259);
260
261extern  int _XkbWriteCopyKeySyms(
262    KeySym *            /* from */,
263    CARD32 *            /* to */,
264    int                 /* num_words */
265);
266
267extern int _XkbReadBufferCopyKeySyms(
268    XkbReadBufferPtr    /* from */,
269#ifndef NO_DEC_BUG_FIX
270    KeySym *            /* to */,
271#else
272    long *              /* to */,
273#endif
274    int                 /* size */
275);
276#else
277#define _XkbReadCopyKeySyms(f,t,n)              _XkbReadCopyData32(f,t,n)
278#define _XkbWriteCopyKeySyms(f,t,n)             _XkbWriteCopyData32(f,t,n)
279#define _XkbReadBufferCopyKeySyms(f,t,s)        _XkbReadBufferCopy32(f,t,s)
280#endif
281
282extern char *_XkbPeekAtReadBuffer(
283    XkbReadBufferPtr    /* from */,
284    int                 /*  size */
285);
286
287extern char *_XkbGetReadBufferPtr(
288    XkbReadBufferPtr    /* from */,
289    int                 /* size */
290);
291#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t)))
292
293extern int _XkbFreeReadBuffer(
294    XkbReadBufferPtr    /* buf */
295);
296
297extern Bool
298_XkbGetReadBufferCountedString(
299    XkbReadBufferPtr    /* buf */,
300    char **             /* rtrn */
301);
302
303extern char *_XkbGetCharset(
304    void
305);
306
307extern int       _XkbGetConverters(
308    const char *       /* encoding_name */,
309    XkbConverters *    /* cvt_rtrn */
310);
311
312#ifdef  NEED_MAP_READERS
313
314extern  Status  _XkbReadGetMapReply(
315    Display *           /* dpy */,
316    xkbGetMapReply *    /* rep */,
317    XkbDescRec *        /* xkb */,
318    int *               /* nread_rtrn */
319);
320
321extern  Status  _XkbReadGetCompatMapReply(
322    Display *                   /* dpy */,
323    xkbGetCompatMapReply *      /* rep */,
324    XkbDescPtr                  /* xkb */,
325    int *                       /* nread_rtrn */
326);
327
328extern  Status  _XkbReadGetIndicatorMapReply(
329    Display *                   /* dpy */,
330    xkbGetIndicatorMapReply *   /* rep */,
331    XkbDescPtr                  /* xkb */,
332    int *                       /* nread_rtrn */
333);
334
335extern  Status  _XkbReadGetNamesReply(
336    Display *                   /* dpy */,
337    xkbGetNamesReply *          /* rep */,
338    XkbDescPtr                  /* xkb */,
339    int *                       /* nread_rtrn */
340);
341
342extern  Status  _XkbReadGetGeometryReply(
343    Display *                   /* dpy */,
344    xkbGetGeometryReply *       /* rep */,
345    XkbDescPtr                  /* xkb */,
346    int *                       /* nread_rtrn */
347);
348
349#endif
350
351_XFUNCPROTOEND
352
353#endif /* _XKBLIBINT_H_ */
354