home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1999 March / PCShareware-3-99.iso / IMPLE / DJGPP.RAR / DJGPP2 / XLIB-SR0.ZIP / SRC / XLIBEMU / MODMAP.C < prev    next >
C/C++ Source or Header  |  1994-01-26  |  2KB  |  84 lines

  1. /* $Id: modmap.c 1.3 1994/01/26 19:23:03 ulrich Exp $ */
  2. /*
  3.  * modmap.c 
  4.  *
  5.  * X library functions for keyboard modifier mappings.
  6.  */
  7. #include "Xlibemu.h"
  8. #include <X11/keysym.h>
  9.  
  10. /* see also getpntma.c */
  11. static KeyCode _DefaultModifierMapping[16] = {
  12.   50 /* Shift_L */,    62 /* Shift_R */,    /* Shift */
  13.   66 /* Caps_Lock */,    77 /* Num_Lock */,    /* Lock */
  14.   37 /* Control_L */,    109 /* Control_R */,    /* Control */
  15.   64 /* Alt_R */,    113 /* Mode_Switch */,    /* Mod1 */
  16.   0,    0,    /* Mod2 */
  17.   0,    0,    /* Mod3 */
  18.   0,    0,    /* Mod4 */
  19.   0,    0,    /* Mod5 */
  20.   };
  21.  
  22. XModifierKeymap *
  23. XGetModifierMapping(dpy)
  24.      register Display *dpy;
  25. {       
  26.     unsigned long nbytes;
  27.     XModifierKeymap *res;
  28.  
  29.     nbytes = sizeof(_DefaultModifierMapping);
  30.     res = (XModifierKeymap *) Xmalloc(sizeof (XModifierKeymap));
  31.     if (res) res->modifiermap = (KeyCode *) Xmalloc ((unsigned) nbytes);
  32.     if ((! res) || (! res->modifiermap)) {
  33.       if (res) Xfree((char *) res);
  34.       res = (XModifierKeymap *) NULL;
  35.     } else {
  36.       memcpy (res->modifiermap, _DefaultModifierMapping, nbytes);
  37.       res->max_keypermod = 2;
  38.     }
  39.     return (res);
  40. }
  41.  
  42. /*
  43.  *    Returns:
  44.  *    0    Success
  45.  *    1    Busy - one or more old or new modifiers are down
  46.  *    2    Failed - one or more new modifiers unacceptable
  47.  */
  48. int
  49. XSetModifierMapping(dpy, modifier_map)
  50.     register Display *dpy;
  51.     register XModifierKeymap *modifier_map;
  52. {
  53.   return (2);
  54. }
  55.  
  56. XModifierKeymap *
  57. XNewModifiermap(keyspermodifier)
  58.     int keyspermodifier;
  59. {
  60.     XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap)));
  61.     if (res) {
  62.     res->max_keypermod = keyspermodifier;
  63.     res->modifiermap = (keyspermodifier > 0 ?
  64.                 (KeyCode *) Xmalloc((unsigned) (8 * keyspermodifier))
  65.                 : (KeyCode *) NULL);
  66.     if (keyspermodifier && (res->modifiermap == NULL)) {
  67.         Xfree((char *) res);
  68.         return (XModifierKeymap *) NULL;
  69.     }
  70.     }
  71.     return (res);
  72. }
  73.  
  74.  
  75. XFreeModifiermap(map)
  76.     XModifierKeymap *map;
  77. {
  78.     if (map) {
  79.     if (map->modifiermap)
  80.         Xfree((char *) map->modifiermap);
  81.     Xfree((char *) map);
  82.     }
  83. }
  84.