11ab64890Smrg/************************************************************
21ab64890SmrgCopyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
31ab64890Smrg
41ab64890SmrgPermission to use, copy, modify, and distribute this
51ab64890Smrgsoftware and its documentation for any purpose and without
61ab64890Smrgfee is hereby granted, provided that the above copyright
71ab64890Smrgnotice appear in all copies and that both that copyright
81ab64890Smrgnotice and this permission notice appear in supporting
961b2299dSmrgdocumentation, and that the name of Silicon Graphics not be
1061b2299dSmrgused in advertising or publicity pertaining to distribution
111ab64890Smrgof the software without specific prior written permission.
1261b2299dSmrgSilicon Graphics makes no representation about the suitability
131ab64890Smrgof this software for any purpose. It is provided "as is"
141ab64890Smrgwithout any express or implied warranty.
151ab64890Smrg
1661b2299dSmrgSILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
1761b2299dSmrgSOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
181ab64890SmrgAND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
1961b2299dSmrgGRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
2061b2299dSmrgDAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
2161b2299dSmrgDATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
221ab64890SmrgOR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
231ab64890SmrgTHE USE OR PERFORMANCE OF THIS SOFTWARE.
241ab64890Smrg
251ab64890Smrg********************************************************/
261ab64890Smrg
271ab64890Smrg#ifndef _XKBLIBINT_H_
28818534a1Smrg#define _XKBLIBINT_H_
291ab64890Smrg
301ab64890Smrg#include <X11/Xutil.h>
311ab64890Smrg#include <X11/XKBlib.h>
32258a0ebeSmrg#include "reallocarray.h"
331ab64890Smrg
34818534a1Smrg#define XkbMapPending           (1<<0)
35818534a1Smrg#define XkbXlibNewKeyboard      (1<<1)
361ab64890Smrg
37818534a1Smrgtypedef int     (*XkbKSToMBFunc)(
38818534a1Smrg        XPointer        /* priv */,
39818534a1Smrg        KeySym          /* sym */,
40818534a1Smrg        char *          /* buf */,
41818534a1Smrg        int             /* len */,
42818534a1Smrg        int *           /* extra_rtrn */
431ab64890Smrg);
441ab64890Smrg
45818534a1Smrgtypedef KeySym  (*XkbMBToKSFunc)(
46818534a1Smrg        XPointer        /* priv */,
47818534a1Smrg        char *          /* buf */,
48818534a1Smrg        int             /* len */,
49818534a1Smrg        Status *        /* status */
501ab64890Smrg);
511ab64890Smrg
52818534a1Smrgtypedef KeySym  (*XkbToUpperFunc)(
53818534a1Smrg        KeySym          /* sym */
541ab64890Smrg);
551ab64890Smrg
561ab64890Smrgtypedef struct _XkbConverters {
57818534a1Smrg        XkbKSToMBFunc    KSToMB;
58818534a1Smrg        XPointer         KSToMBPriv;
59818534a1Smrg        XkbMBToKSFunc    MBToKS;
60818534a1Smrg        XPointer         MBToKSPriv;
61818534a1Smrg        XkbToUpperFunc   KSToUpper;
621ab64890Smrg} XkbConverters;
631ab64890Smrg
64818534a1Smrgextern  XkbInternAtomFunc       _XkbInternAtomFunc;
65818534a1Smrgextern  XkbGetAtomNameFunc      _XkbGetAtomNameFunc;
661ab64890Smrg
671ab64890Smrgtypedef struct _XkbInfoRec {
68818534a1Smrg        unsigned         flags;
69818534a1Smrg        unsigned         xlib_ctrls;
70818534a1Smrg        XExtCodes        *codes;
71818534a1Smrg        int              srv_major;
72818534a1Smrg        int              srv_minor;
73818534a1Smrg        unsigned         selected_events;
74818534a1Smrg        unsigned short   selected_nkn_details;
75818534a1Smrg        unsigned short   selected_map_details;
76818534a1Smrg        XkbDescRec      *desc;
77818534a1Smrg        XkbMapChangesRec changes;
78818534a1Smrg        Atom             composeLED;
79818534a1Smrg        XkbConverters    cvt;
80818534a1Smrg        XkbConverters    latin1cvt;
811ab64890Smrg} XkbInfoRec, *XkbInfoPtr;
821ab64890Smrg
831ab64890Smrg
84818534a1Smrg#define _XkbUnavailable(d) \
85818534a1Smrg        (((d)->flags&XlibDisplayNoXkb) || \
86818534a1Smrg         ((!(d)->xkb_info || (!(d)->xkb_info->desc)) && !_XkbLoadDpy(d)))
87818534a1Smrg
8807fb9b8fSmrg#define _XkbCheckPendingRefresh(d,xi) do { \
89818534a1Smrg    if ((xi)->flags&XkbXlibNewKeyboard) \
90818534a1Smrg        _XkbReloadDpy((d)); \
91818534a1Smrg    else if ((xi)->flags&XkbMapPending) { \
92818534a1Smrg        if (XkbGetMapChanges((d),(xi)->desc, &(xi)->changes)==Success) { \
93818534a1Smrg            LockDisplay((d)); \
94818534a1Smrg            (xi)->changes.changed= 0; \
95818534a1Smrg            UnlockDisplay((d)); \
96818534a1Smrg        } \
97818534a1Smrg    } \
9807fb9b8fSmrg} while (0)
991ab64890Smrg
100818534a1Smrg#define _XkbNeedModmap(i)    ((!(i)->desc->map)||(!(i)->desc->map->modmap))
1011ab64890Smrg
102818534a1Smrg        /*
103818534a1Smrg         * mask of the events that the "invisible" XKB support in Xlib needs
104818534a1Smrg         */
1051ab64890Smrg#define XKB_XLIB_MAP_MASK (XkbAllClientInfoMask)
1061ab64890Smrg
107818534a1Smrg        /*
108818534a1Smrg         * Handy helper macros
109818534a1Smrg         */
1101ab64890Smrg
1111ab64890Smrgtypedef struct _XkbReadBuffer {
112818534a1Smrg        int      error;
113818534a1Smrg        int      size;
114818534a1Smrg        char    *start;
115818534a1Smrg        char    *data;
116818534a1Smrg} XkbReadBufferRec, *XkbReadBufferPtr;
117818534a1Smrg
118818534a1Smrg#define _XkbAlloc(s)            Xmalloc((s))
119818534a1Smrg#define _XkbCalloc(n,s)         Xcalloc((n),(s))
120818534a1Smrg#define _XkbRealloc(o,s)        Xrealloc((o),(s))
121818534a1Smrg#define _XkbTypedAlloc(t)       ((t *)Xmalloc(sizeof(t)))
122818534a1Smrg#define _XkbTypedCalloc(n,t)    ((t *)Xcalloc((n),sizeof(t)))
123818534a1Smrg#define _XkbFree(p)             Xfree(p)
1241ab64890Smrg
125258a0ebeSmrg/* Resizes array to hold new_num elements, zeroing newly added entries.
126258a0ebeSmrg   Destroys old array on failure. */
127258a0ebeSmrg#define _XkbResizeArray(array, old_num, new_num, type)                       \
128258a0ebeSmrg    do {                                                                     \
129258a0ebeSmrg        if (array == NULL) {                                                 \
130258a0ebeSmrg            array = _XkbTypedCalloc(new_num, type);                          \
131258a0ebeSmrg        } else {                                                             \
132258a0ebeSmrg            type *prev_array = array;                                        \
133258a0ebeSmrg            array = Xreallocarray(array, new_num, sizeof(type));             \
134258a0ebeSmrg            if (_X_UNLIKELY((array) == NULL)) {                              \
135258a0ebeSmrg                _XkbFree(prev_array);                                        \
136258a0ebeSmrg            } else if ((new_num) > (old_num)) {                              \
137258a0ebeSmrg                bzero(&array[old_num],                                       \
138258a0ebeSmrg                      ((new_num) - (old_num)) * sizeof(type));               \
139258a0ebeSmrg            }                                                                \
140258a0ebeSmrg        }                                                                    \
141258a0ebeSmrg    } while(0)
142258a0ebeSmrg
1431ab64890Smrg_XFUNCPROTOBEGIN
1441ab64890Smrg
145818534a1Smrgextern  void _XkbReloadDpy(
146818534a1Smrg    Display *           /* dpy */
1471ab64890Smrg);
1481ab64890Smrg
1491ab64890Smrgextern KeySym _XKeycodeToKeysym(
150818534a1Smrg    Display *           /* display */,
1511ab64890Smrg#if NeedWidePrototypes
152818534a1Smrg    unsigned int        /* keycode */,
1531ab64890Smrg#else
154818534a1Smrg    KeyCode             /* keycode */,
1551ab64890Smrg#endif
156818534a1Smrg    int                 /* index */
1571ab64890Smrg);
1581ab64890Smrg
1591ab64890Smrgextern KeyCode _XKeysymToKeycode(
160818534a1Smrg    Display *           /* display */,
161818534a1Smrg    KeySym              /* keysym */
1621ab64890Smrg);
1631ab64890Smrg
1641ab64890Smrgextern KeySym _XLookupKeysym(
165818534a1Smrg    XKeyEvent *         /* key_event */,
166818534a1Smrg    int                 /* index */
1671ab64890Smrg);
1681ab64890Smrg
1691ab64890Smrgextern int _XRefreshKeyboardMapping(
170818534a1Smrg    XMappingEvent *     /* event_map */
1711ab64890Smrg);
1721ab64890Smrg
173818534a1Smrgextern unsigned _XKeysymToModifiers(
174818534a1Smrg    Display *           /* dpy */,
175818534a1Smrg    KeySym              /* ks */
1761ab64890Smrg);
1771ab64890Smrg
17861b2299dSmrgextern int _XTranslateKey(
179818534a1Smrg    register Display *  /* dpy */,
180818534a1Smrg    KeyCode             /* keycode */,
1811ab64890Smrg    register unsigned int /* modifiers */,
182818534a1Smrg    unsigned int *      /* modifiers_return */,
183818534a1Smrg    KeySym *            /* keysym_return */
1841ab64890Smrg);
1851ab64890Smrg
186818534a1Smrgextern int      _XTranslateKeySym(
187818534a1Smrg    Display *           /* dpy */,
188818534a1Smrg    register KeySym     /* symbol */,
189818534a1Smrg    unsigned int        /* modifiers */,
190818534a1Smrg    char *              /* buffer */,
191818534a1Smrg    int                 /* nbytes */
1921ab64890Smrg);
1931ab64890Smrg
194818534a1Smrgextern  int _XLookupString(
195818534a1Smrg    register XKeyEvent *        /* event */,
196818534a1Smrg    char *                      /* buffer */,
197818534a1Smrg    int                         /* nbytes */,
198818534a1Smrg    KeySym *                    /* keysym */,
199818534a1Smrg    XComposeStatus *            /* status */
2001ab64890Smrg);
2011ab64890Smrg
2021ab64890Smrgextern void _XkbNoteCoreMapChanges(
203818534a1Smrg    XkbMapChangesRec *          /* old */,
204818534a1Smrg    XMappingEvent *             /* new */,
205818534a1Smrg    unsigned int                /* wanted */
2061ab64890Smrg);
2071ab64890Smrg
208818534a1Smrgextern  int _XkbInitReadBuffer(
209818534a1Smrg    Display *           /* dpy */,
210818534a1Smrg    XkbReadBufferPtr    /* buf */,
211818534a1Smrg    int                 /* size */
2121ab64890Smrg);
2131ab64890Smrg
2141ab64890Smrgextern int _XkbSkipReadBufferData(
215818534a1Smrg    XkbReadBufferPtr    /* from */,
216818534a1Smrg    int                 /* size */
2171ab64890Smrg);
2181ab64890Smrg
2191ab64890Smrgextern int _XkbCopyFromReadBuffer(
220818534a1Smrg    XkbReadBufferPtr    /* from */,
221818534a1Smrg    char *              /* to */,
222818534a1Smrg    int                 /* size */
2231ab64890Smrg);
2241ab64890Smrg
2251ab64890Smrg
226eb411b4bSmrg#ifdef LONG64
227818534a1Smrgextern  int _XkbReadCopyData32(
228818534a1Smrg    int *               /* from */,
229818534a1Smrg    long *              /* to */,
230818534a1Smrg    int                 /* num_words */
2311ab64890Smrg);
2321ab64890Smrg
233818534a1Smrgextern  int _XkbWriteCopyData32(
234818534a1Smrg    unsigned long *     /* from */,
235818534a1Smrg    CARD32 *            /* to */,
236818534a1Smrg    int                 /* num_words */
2371ab64890Smrg);
2381ab64890Smrg
2391ab64890Smrgextern int _XkbReadBufferCopy32(
240818534a1Smrg    XkbReadBufferPtr    /* from */,
241818534a1Smrg    long *              /* to */,
242818534a1Smrg    int                 /* size */
2431ab64890Smrg);
2441ab64890Smrg#else
245818534a1Smrg#define _XkbReadCopyData32(f,t,s)    memcpy((char *)(t), (char *)(f), (s)*4)
246818534a1Smrg#define _XkbWriteCopyData32(f,t,s)   memcpy((char *)(t), (char *)(f), (s)*4)
247818534a1Smrg#define _XkbReadBufferCopy32(f,t,s) _XkbCopyFromReadBuffer(f, (char *)t, (s)*4)
2481ab64890Smrg#endif
2491ab64890Smrg
2501ab64890Smrg#ifndef NO_DEC_BINARY_COMPATIBILITY
2511ab64890Smrg#define XKB_FORCE_INT_KEYSYM 1
2521ab64890Smrg#endif
2531ab64890Smrg
2541ab64890Smrg#ifdef XKB_FORCE_INT_KEYSYM
2551ab64890Smrgextern int _XkbReadCopyKeySyms(
256818534a1Smrg    int *               /* from */,
257818534a1Smrg    KeySym *            /* to */,
258818534a1Smrg    int                 /* num_words */
2591ab64890Smrg);
2601ab64890Smrg
261818534a1Smrgextern  int _XkbWriteCopyKeySyms(
262818534a1Smrg    KeySym *            /* from */,
263818534a1Smrg    CARD32 *            /* to */,
264818534a1Smrg    int                 /* num_words */
2651ab64890Smrg);
2661ab64890Smrg
2671ab64890Smrgextern int _XkbReadBufferCopyKeySyms(
268818534a1Smrg    XkbReadBufferPtr    /* from */,
2691ab64890Smrg#ifndef NO_DEC_BUG_FIX
270818534a1Smrg    KeySym *            /* to */,
2711ab64890Smrg#else
272818534a1Smrg    long *              /* to */,
2731ab64890Smrg#endif
274818534a1Smrg    int                 /* size */
2751ab64890Smrg);
2761ab64890Smrg#else
277818534a1Smrg#define _XkbReadCopyKeySyms(f,t,n)              _XkbReadCopyData32(f,t,n)
278818534a1Smrg#define _XkbWriteCopyKeySyms(f,t,n)             _XkbWriteCopyData32(f,t,n)
279818534a1Smrg#define _XkbReadBufferCopyKeySyms(f,t,s)        _XkbReadBufferCopy32(f,t,s)
2801ab64890Smrg#endif
2811ab64890Smrg
2821ab64890Smrgextern char *_XkbPeekAtReadBuffer(
283818534a1Smrg    XkbReadBufferPtr    /* from */,
284818534a1Smrg    int                 /*  size */
2851ab64890Smrg);
2861ab64890Smrg
2871ab64890Smrgextern char *_XkbGetReadBufferPtr(
288818534a1Smrg    XkbReadBufferPtr    /* from */,
289818534a1Smrg    int                 /* size */
2901ab64890Smrg);
291818534a1Smrg#define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t)))
2921ab64890Smrg
2931ab64890Smrgextern int _XkbFreeReadBuffer(
294818534a1Smrg    XkbReadBufferPtr    /* buf */
2951ab64890Smrg);
2961ab64890Smrg
2971ab64890Smrgextern Bool
2981ab64890Smrg_XkbGetReadBufferCountedString(
299818534a1Smrg    XkbReadBufferPtr    /* buf */,
300818534a1Smrg    char **             /* rtrn */
3011ab64890Smrg);
3021ab64890Smrg
303818534a1Smrgextern char *_XkbGetCharset(
3041ab64890Smrg    void
3051ab64890Smrg);
3061ab64890Smrg
307818534a1Smrgextern int       _XkbGetConverters(
3081ab64890Smrg    const char *       /* encoding_name */,
3091ab64890Smrg    XkbConverters *    /* cvt_rtrn */
3101ab64890Smrg);
3111ab64890Smrg
312818534a1Smrg#ifdef  NEED_MAP_READERS
3131ab64890Smrg
314818534a1Smrgextern  Status  _XkbReadGetMapReply(
315818534a1Smrg    Display *           /* dpy */,
316818534a1Smrg    xkbGetMapReply *    /* rep */,
317818534a1Smrg    XkbDescRec *        /* xkb */,
318818534a1Smrg    int *               /* nread_rtrn */
3191ab64890Smrg);
3201ab64890Smrg
321818534a1Smrgextern  Status  _XkbReadGetCompatMapReply(
322818534a1Smrg    Display *                   /* dpy */,
323818534a1Smrg    xkbGetCompatMapReply *      /* rep */,
324818534a1Smrg    XkbDescPtr                  /* xkb */,
325818534a1Smrg    int *                       /* nread_rtrn */
3261ab64890Smrg);
3271ab64890Smrg
328818534a1Smrgextern  Status  _XkbReadGetIndicatorMapReply(
329818534a1Smrg    Display *                   /* dpy */,
330818534a1Smrg    xkbGetIndicatorMapReply *   /* rep */,
331818534a1Smrg    XkbDescPtr                  /* xkb */,
332818534a1Smrg    int *                       /* nread_rtrn */
3331ab64890Smrg);
3341ab64890Smrg
335818534a1Smrgextern  Status  _XkbReadGetNamesReply(
336818534a1Smrg    Display *                   /* dpy */,
337818534a1Smrg    xkbGetNamesReply *          /* rep */,
338818534a1Smrg    XkbDescPtr                  /* xkb */,
339818534a1Smrg    int *                       /* nread_rtrn */
3401ab64890Smrg);
3411ab64890Smrg
342818534a1Smrgextern  Status  _XkbReadGetGeometryReply(
343818534a1Smrg    Display *                   /* dpy */,
344818534a1Smrg    xkbGetGeometryReply *       /* rep */,
345818534a1Smrg    XkbDescPtr                  /* xkb */,
346818534a1Smrg    int *                       /* nread_rtrn */
3471ab64890Smrg);
3481ab64890Smrg
3491ab64890Smrg#endif
3501ab64890Smrg
3511ab64890Smrg_XFUNCPROTOEND
3521ab64890Smrg
3531ab64890Smrg#endif /* _XKBLIBINT_H_ */
354