Home | History | Annotate | Line # | Download | only in xkb
      1 /************************************************************
      2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
      3 
      4 Permission to use, copy, modify, and distribute this
      5 software and its documentation for any purpose and without
      6 fee is hereby granted, provided that the above copyright
      7 notice appear in all copies and that both that copyright
      8 notice and this permission notice appear in supporting
      9 documentation, and that the name of Silicon Graphics not be
     10 used in advertising or publicity pertaining to distribution
     11 of the software without specific prior written permission.
     12 Silicon Graphics makes no representation about the suitability
     13 of this software for any purpose. It is provided "as is"
     14 without any express or implied warranty.
     15 
     16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
     17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
     18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
     19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
     20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
     21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
     22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
     23 THE 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 
     37 typedef int     (*XkbKSToMBFunc)(
     38         XPointer        /* priv */,
     39         KeySym          /* sym */,
     40         char *          /* buf */,
     41         int             /* len */,
     42         int *           /* extra_rtrn */
     43 );
     44 
     45 typedef KeySym  (*XkbMBToKSFunc)(
     46         XPointer        /* priv */,
     47         char *          /* buf */,
     48         int             /* len */,
     49         Status *        /* status */
     50 );
     51 
     52 typedef KeySym  (*XkbToUpperFunc)(
     53         KeySym          /* sym */
     54 );
     55 
     56 typedef struct _XkbConverters {
     57         XkbKSToMBFunc    KSToMB;
     58         XPointer         KSToMBPriv;
     59         XkbMBToKSFunc    MBToKS;
     60         XPointer         MBToKSPriv;
     61         XkbToUpperFunc   KSToUpper;
     62 } XkbConverters;
     63 
     64 extern  XkbInternAtomFunc       _XkbInternAtomFunc;
     65 extern  XkbGetAtomNameFunc      _XkbGetAtomNameFunc;
     66 
     67 typedef 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 
    111 typedef 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 
    145 extern  void _XkbReloadDpy(
    146     Display *           /* dpy */
    147 );
    148 
    149 extern KeySym _XKeycodeToKeysym(
    150     Display *           /* display */,
    151 #if NeedWidePrototypes
    152     unsigned int        /* keycode */,
    153 #else
    154     KeyCode             /* keycode */,
    155 #endif
    156     int                 /* index */
    157 );
    158 
    159 extern KeyCode _XKeysymToKeycode(
    160     Display *           /* display */,
    161     KeySym              /* keysym */
    162 );
    163 
    164 extern KeySym _XLookupKeysym(
    165     XKeyEvent *         /* key_event */,
    166     int                 /* index */
    167 );
    168 
    169 extern int _XRefreshKeyboardMapping(
    170     XMappingEvent *     /* event_map */
    171 );
    172 
    173 extern unsigned _XKeysymToModifiers(
    174     Display *           /* dpy */,
    175     KeySym              /* ks */
    176 );
    177 
    178 extern 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 
    186 extern int      _XTranslateKeySym(
    187     Display *           /* dpy */,
    188     register KeySym     /* symbol */,
    189     unsigned int        /* modifiers */,
    190     char *              /* buffer */,
    191     int                 /* nbytes */
    192 );
    193 
    194 extern  int _XLookupString(
    195     register XKeyEvent *        /* event */,
    196     char *                      /* buffer */,
    197     int                         /* nbytes */,
    198     KeySym *                    /* keysym */,
    199     XComposeStatus *            /* status */
    200 );
    201 
    202 extern void _XkbNoteCoreMapChanges(
    203     XkbMapChangesRec *          /* old */,
    204     XMappingEvent *             /* new */,
    205     unsigned int                /* wanted */
    206 );
    207 
    208 extern  int _XkbInitReadBuffer(
    209     Display *           /* dpy */,
    210     XkbReadBufferPtr    /* buf */,
    211     int                 /* size */
    212 );
    213 
    214 extern int _XkbSkipReadBufferData(
    215     XkbReadBufferPtr    /* from */,
    216     int                 /* size */
    217 );
    218 
    219 extern int _XkbCopyFromReadBuffer(
    220     XkbReadBufferPtr    /* from */,
    221     char *              /* to */,
    222     int                 /* size */
    223 );
    224 
    225 
    226 #ifdef LONG64
    227 extern  int _XkbReadCopyData32(
    228     int *               /* from */,
    229     long *              /* to */,
    230     int                 /* num_words */
    231 );
    232 
    233 extern  int _XkbWriteCopyData32(
    234     unsigned long *     /* from */,
    235     CARD32 *            /* to */,
    236     int                 /* num_words */
    237 );
    238 
    239 extern 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
    255 extern int _XkbReadCopyKeySyms(
    256     int *               /* from */,
    257     KeySym *            /* to */,
    258     int                 /* num_words */
    259 );
    260 
    261 extern  int _XkbWriteCopyKeySyms(
    262     KeySym *            /* from */,
    263     CARD32 *            /* to */,
    264     int                 /* num_words */
    265 );
    266 
    267 extern 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 
    282 extern char *_XkbPeekAtReadBuffer(
    283     XkbReadBufferPtr    /* from */,
    284     int                 /*  size */
    285 );
    286 
    287 extern char *_XkbGetReadBufferPtr(
    288     XkbReadBufferPtr    /* from */,
    289     int                 /* size */
    290 );
    291 #define _XkbGetTypedRdBufPtr(b,n,t) ((t *)_XkbGetReadBufferPtr(b,(n)*SIZEOF(t)))
    292 
    293 extern int _XkbFreeReadBuffer(
    294     XkbReadBufferPtr    /* buf */
    295 );
    296 
    297 extern Bool
    298 _XkbGetReadBufferCountedString(
    299     XkbReadBufferPtr    /* buf */,
    300     char **             /* rtrn */
    301 );
    302 
    303 extern char *_XkbGetCharset(
    304     void
    305 );
    306 
    307 extern int       _XkbGetConverters(
    308     const char *       /* encoding_name */,
    309     XkbConverters *    /* cvt_rtrn */
    310 );
    311 
    312 #ifdef  NEED_MAP_READERS
    313 
    314 extern  Status  _XkbReadGetMapReply(
    315     Display *           /* dpy */,
    316     xkbGetMapReply *    /* rep */,
    317     XkbDescRec *        /* xkb */,
    318     int *               /* nread_rtrn */
    319 );
    320 
    321 extern  Status  _XkbReadGetCompatMapReply(
    322     Display *                   /* dpy */,
    323     xkbGetCompatMapReply *      /* rep */,
    324     XkbDescPtr                  /* xkb */,
    325     int *                       /* nread_rtrn */
    326 );
    327 
    328 extern  Status  _XkbReadGetIndicatorMapReply(
    329     Display *                   /* dpy */,
    330     xkbGetIndicatorMapReply *   /* rep */,
    331     XkbDescPtr                  /* xkb */,
    332     int *                       /* nread_rtrn */
    333 );
    334 
    335 extern  Status  _XkbReadGetNamesReply(
    336     Display *                   /* dpy */,
    337     xkbGetNamesReply *          /* rep */,
    338     XkbDescPtr                  /* xkb */,
    339     int *                       /* nread_rtrn */
    340 );
    341 
    342 extern  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