Annotation of researchv9/X11/src/X.V11R1/server/ddx/v9sun/sunKbd.c, revision 1.1.1.1

1.1       root        1: #define NEED_EVENTS
                      2: #include "sun.h"
                      3: #include <stdio.h>
                      4: #include <sys/ioctl.h>
                      5: #include "Xproto.h"
                      6: #include "keysym.h"
                      7: 
                      8: extern CARD8 *sunModMap[];
                      9: extern KeySymsRec sunKeySyms[];
                     10: 
                     11: static void      sunBell();
                     12: static void      sunKbdCtrl();
                     13: 
                     14: int sunKbdfd = -1;
                     15: static struct sgttyb   sttymodes;
                     16: static struct ttydevb  devmodes;
                     17: static struct tchars   tcharmodes;
                     18: #define        MAXNLINED       10
                     19: static int sunnld, linedstack[MAXNLINED];
                     20: 
                     21: static void
                     22: sunsavemodes()
                     23: {
                     24:        char filename[256], *p;
                     25:        char *getenv();
                     26:        int fd;
                     27: 
                     28:        if((p=getenv("HOME")) == 0)
                     29:                return;
                     30:        strcpy(filename, p);
                     31:        strcat(filename, "/.sttymodes");
                     32:        if ((fd = creat(filename, 0644)) < 0)
                     33:                return;
                     34:        ioctl(sunKbdfd, TIOCGETP, &sttymodes);
                     35:        ioctl(sunKbdfd, TIOCGDEV, &devmodes);
                     36:        ioctl(sunKbdfd, TIOCGETC, &tcharmodes);
                     37:        write(fd, &sttymodes, sizeof(struct sgttyb));
                     38:        write(fd, &devmodes, sizeof(struct ttydevb));
                     39:        write(fd, &tcharmodes, sizeof(struct tchars));
                     40:        close(fd);
                     41:        sunnld = 0;
                     42:        while ((linedstack[sunnld] = ioctl(sunKbdfd, FIOLOOKLD, 0)) >= 0) {
                     43:                ioctl(sunKbdfd, FIOPOPLD, 0);
                     44:                sunnld++;
                     45:        }
                     46: }
                     47: 
                     48: static void
                     49: sunresetmodes()
                     50: {
                     51:         for (sunnld--; sunnld >= 0; sunnld--)
                     52:                ioctl(sunKbdfd, FIOPUSHLD, &linedstack[sunnld]);
                     53:        ioctl(sunKbdfd, TIOCSETP, &sttymodes);
                     54:        ioctl(sunKbdfd, TIOCSDEV, &devmodes);
                     55:        ioctl(sunKbdfd, TIOCSETC, &tcharmodes);
                     56: }
                     57: 
                     58: int
                     59: sunKbdProc (pKeyboard, what)
                     60:     DevicePtr    pKeyboard;    /* Keyboard to manipulate */
                     61:     int                  what;         /* What to do to it */
                     62: {
                     63:     register int  kbdFd;
                     64: 
                     65:        switch (what) {
                     66:        case DEVICE_INIT:
                     67:                if (pKeyboard != LookupKeyboardDevice()) {
                     68:                        ErrorF ("Cannot open non-system keyboard");
                     69:                        return (!Success);
                     70:                }
                     71:                if (sunKbdfd >= 0)
                     72:                        kbdFd = sunKbdfd;
                     73:                else {
                     74:                        kbdFd = open ("/dev/console", 2);
                     75:                        if (kbdFd < 0) {
                     76:                                Error ("Opening /dev/console");
                     77:                                return (!Success);
                     78:                        }
                     79:                        sunKbdfd = kbdFd;
                     80:                        sunsavemodes();
                     81:                }
                     82:            
                     83:                pKeyboard->on = FALSE;
                     84:                InitKeyboardDeviceStruct(
                     85:                        pKeyboard, sunKeySyms, sunModMap[0], sunBell, sunKbdCtrl);
                     86:                break;
                     87: 
                     88:        case DEVICE_ON:
                     89:                AddEnabledDevice(sunKbdfd);
                     90:                pKeyboard->on = TRUE;
                     91:                break;
                     92: 
                     93:        case DEVICE_CLOSE:
                     94:        case DEVICE_OFF:
                     95:                sunresetmodes();
                     96:                RemoveEnabledDevice(sunKbdfd);
                     97:                pKeyboard->on = FALSE;
                     98:                break;
                     99:     }
                    100:     return (Success);
                    101: }
                    102: 
                    103: static void
                    104: sunBell (loudness, pKeyboard)
                    105:     int                  loudness;         /* Percentage of full volume */
                    106:     DevicePtr    pKeyboard;        /* Keyboard to ring */
                    107: {
                    108: #define        KBD_CMD_BELL    0x02            /* Turn on the bell */
                    109: #define        KBD_CMD_NOBELL  0x03            /* Turn off the bell */
                    110:        static char c[2] = { KBD_CMD_BELL, KBD_CMD_NOBELL};
                    111: 
                    112:        if (loudness)
                    113:                write(sunKbdfd, c, 2);
                    114: }
                    115: 
                    116: void
                    117: sunKbdEvent(pKeyboard)
                    118: DevicePtr pKeyboard;
                    119: {
                    120:        register char c, *cp;
                    121:        register i;
                    122:        char *tail;
                    123:        static char rbuf[512];
                    124: 
                    125:        if ((i = read (sunKbdfd, rbuf, sizeof(rbuf))) < 0)
                    126:                FatalError ("Could not read from keyboard");
                    127: 
                    128:        tail = &rbuf[i];
                    129:        for (cp = rbuf; cp != tail; ) {
                    130:                c = *cp++;
                    131:                /*
                    132:                 * Eat the idle key messages
                    133:                 */
                    134:                if (c == 0x7f)
                    135:                        continue;
                    136:                if (c & 0x80)
                    137:                        sunmkX(pKeyboard, KeyRelease, c & 0x7F);
                    138:                else
                    139:                        sunmkX(pKeyboard, KeyPress, c & 0x7F);
                    140:        }
                    141: 
                    142: }
                    143: 
                    144: static void
                    145: sunKbdCtrl (pKeyboard, ctrl)
                    146:     DevicePtr  pKeyboard;          /* Keyboard to alter */
                    147:     KeybdCtrl  *ctrl;
                    148: {
                    149:     char c;
                    150: 
                    151: #define        KBD_CMD_CLICK   0x0A            /* Turn on the click annunciator */
                    152: #define        KBD_CMD_NOCLICK 0x0B            /* Turn off the click annunciator */
                    153:     if (ctrl->click == 0) {   /* turn click off */
                    154:        c = KBD_CMD_NOCLICK;
                    155:        write(sunKbdfd, &c, 1);
                    156:     } else {
                    157:        c = KBD_CMD_CLICK;
                    158:        write(sunKbdfd, &c, 1);
                    159:     }
                    160: }
                    161: 
                    162: Bool
                    163: LegalModifier(key)
                    164: {
                    165:     return (TRUE);
                    166: }

unix.superglobalmegacorp.com

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