Annotation of researchv9/X11/src/X.V11R1/lib/X/XModMap.c, revision 1.1

1.1     ! root        1: #include "copyright.h"
        !             2: 
        !             3: /* $Header: XModMap.c,v 11.3 87/09/13 00:32:22 toddb Exp $ */
        !             4: /* Copyright    Massachusetts Institute of Technology    1986  */
        !             5: 
        !             6: #define NEED_REPLIES
        !             7: #include "Xlibint.h"
        !             8: 
        !             9: XModifierKeymap *
        !            10: XGetModifierMapping(dpy)
        !            11:      register Display *dpy;
        !            12: {       
        !            13:     xGetModifierMappingReply rep;
        !            14:     register xReq *req;
        !            15:     unsigned int nbytes;
        !            16:     XModifierKeymap *res;
        !            17: 
        !            18:     LockDisplay(dpy);
        !            19:     GetEmptyReq(GetModifierMapping, req);
        !            20:     (void) _XReply (dpy, (xReply *)&rep, 0, xFalse);
        !            21: 
        !            22:     nbytes = (long)rep.length << 2;
        !            23:     res = (XModifierKeymap *) Xmalloc(sizeof (XModifierKeymap));
        !            24:     res->modifiermap = (KeyCode *) Xmalloc (nbytes);
        !            25:     _XReadPad(dpy, res->modifiermap, nbytes);
        !            26:     res->max_keypermod = rep.numKeyPerModifier;
        !            27: 
        !            28:     UnlockDisplay(dpy);
        !            29:     SyncHandle();
        !            30:     return (res);
        !            31: }
        !            32: 
        !            33: /*
        !            34:  *     Returns:
        !            35:  *     0       Success
        !            36:  *     1       Busy - one or more old or new modifiers are down
        !            37:  *     2       Failed - one or more new modifiers unacceptable
        !            38:  */
        !            39: int
        !            40: XSetModifierMapping(dpy, modifier_map)
        !            41:     register Display *dpy;
        !            42:     register XModifierKeymap *modifier_map;
        !            43: {
        !            44:     register xSetModifierMappingReq *req;
        !            45:     xSetModifierMappingReply rep;
        !            46:     int         mapSize = modifier_map->max_keypermod << 3;    /* 8 modifiers */
        !            47: 
        !            48:     LockDisplay(dpy);
        !            49:     GetReqExtra(SetModifierMapping, mapSize, req);
        !            50: 
        !            51:     req->numKeyPerModifier = modifier_map->max_keypermod;
        !            52: 
        !            53:     bcopy(modifier_map->modifiermap, (char *)&req[1], mapSize);
        !            54: 
        !            55:     (void) _XReply(dpy, (xReply *) & rep,
        !            56:        (sizeof(xSetModifierMappingReply) - sizeof(xReply)) >> 2, xTrue);
        !            57:     UnlockDisplay(dpy);
        !            58:     SyncHandle();
        !            59:     return (rep.success);
        !            60: }
        !            61: 
        !            62: XModifierKeymap *
        !            63: XNewModifiermap(keyspermodifier)
        !            64:     int keyspermodifier;
        !            65: {
        !            66:     XModifierKeymap *res = (XModifierKeymap *) Xmalloc((sizeof (XModifierKeymap)));
        !            67: 
        !            68:     res->max_keypermod = keyspermodifier;
        !            69:     res->modifiermap = (keyspermodifier > 0 ?
        !            70:                        (KeyCode *) Xmalloc(8 * keyspermodifier)
        !            71:                        : (KeyCode *) NULL);
        !            72:     return (res);
        !            73: }
        !            74: 
        !            75: void
        !            76: XFreeModifiermap(map)
        !            77:     XModifierKeymap *map;
        !            78: {
        !            79:     if (map) {
        !            80:        if (map->modifiermap)
        !            81:            Xfree((char *) map->modifiermap);
        !            82:        Xfree((char *) map);
        !            83:     }
        !            84: }
        !            85: 
        !            86: XModifierKeymap *
        !            87: XInsertModifiermapEntry(map, keysym, modifier)
        !            88:     XModifierKeymap *map;
        !            89:     KeyCode keysym;
        !            90:     int modifier;
        !            91: {
        !            92:     XModifierKeymap *newmap;
        !            93:     int i,
        !            94:        row = modifier * map->max_keypermod,
        !            95:        newrow,
        !            96:        lastrow;
        !            97: 
        !            98:     for (i=0; i<map->max_keypermod; i++) {
        !            99:         if (map->modifiermap[ row+i ] == keysym)
        !           100:            return(map); /* already in the map */
        !           101:         if (map->modifiermap[ row+i ] == 0) {
        !           102:             map->modifiermap[ row+i ] = keysym;
        !           103:            return(map); /* we added it without stretching the map */
        !           104:        }
        !           105:     }   
        !           106: 
        !           107:     /* stretch the map */
        !           108:     newmap = XNewModifiermap(map->max_keypermod+1);
        !           109:     newrow = row = 0;
        !           110:     lastrow = map->max_keypermod * 8;
        !           111:     while (row < lastrow) {
        !           112:        for (i=0; i<map->max_keypermod; i++)
        !           113:            newmap->modifiermap[ newrow+i ] = map->modifiermap[ row+i ];
        !           114:        newmap->modifiermap[ newrow+i ] = 0;
        !           115:        row += map->max_keypermod;
        !           116:        newrow += newmap->max_keypermod;
        !           117:     }
        !           118:     XFreeModifiermap(map);
        !           119:     newrow = newmap->max_keypermod * modifier + newmap->max_keypermod - 1;
        !           120:     newmap->modifiermap[ newrow ] = keysym;
        !           121:     return(newmap);
        !           122: }
        !           123: 
        !           124: XModifierKeymap *
        !           125: XDeleteModifiermapEntry(map, keysym, modifier)
        !           126:     XModifierKeymap *map;
        !           127:     KeyCode keysym;
        !           128:     int modifier;
        !           129: {
        !           130:     int i,
        !           131:        row = modifier * map->max_keypermod;
        !           132: 
        !           133:     for (i=0; i<map->max_keypermod; i++) {
        !           134:         if (map->modifiermap[ row+i ] == keysym)
        !           135:             map->modifiermap[ row+i ] = 0;
        !           136:     }
        !           137:     /* should we shrink the map?? */
        !           138:     return (map);
        !           139: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.