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

1.1       root        1: #define NEED_EVENTS
                      2: #include    "sun.h"
                      3: #include <sys/ioctl.h>
                      4: 
                      5: extern int     lastEventTime;
                      6: static void    sunMouseCtrl();
                      7: static int     sunMouseGetMotionEvents();
                      8: 
                      9: static PtrPrivRec sysMousePriv = {
                     10:     0,                         /* Current X coordinate of pointer */
                     11:     0,                         /* Current Y coordinate */
                     12:     NULL,                      /* Screen pointer is on */
                     13: };
                     14: int sunMousefd = -1;
                     15: 
                     16: int
                     17: sunMouseProc (pMouse, what)
                     18:     DevicePtr    pMouse;       /* Mouse to play with */
                     19:     int                  what;         /* What to do with it */
                     20: {
                     21:     register int  fd;
                     22:     int                  format;
                     23:     static int   oformat;
                     24:     BYTE         map[4];
                     25:     struct ttydevb tspeed;
                     26: 
                     27:     switch (what) {
                     28:        case DEVICE_INIT:
                     29:                if (pMouse != LookupPointerDevice()) {
                     30:                        ErrorF ("Cannot open non-system mouse");        
                     31:                        return (!Success);
                     32:                }
                     33: 
                     34:                if (sunMousefd >= 0) {
                     35:                    fd = sunMousefd;
                     36:                } else {
                     37:                    fd = open ("/dev/mouse", 0);
                     38:                    if (fd < 0) {
                     39:                        Error ("Opening /dev/mouse");
                     40:                        return (!Success);
                     41:                    }
                     42:                    sunMousefd = fd;
                     43:                    ioctl(sunMousefd, TIOCGDEV, &tspeed);
                     44:                    tspeed.ispeed = tspeed.ospeed = B1200;
                     45:                    ioctl(sunMousefd, TIOCSDEV, &tspeed);
                     46:                }
                     47: 
                     48:            sysMousePriv.pScreen = &screenInfo.screen[0];
                     49:            sysMousePriv.x = sysMousePriv.pScreen->width / 2;
                     50:            sysMousePriv.y = sysMousePriv.pScreen->height / 2;
                     51: 
                     52:            pMouse->devicePrivate = (pointer) &sysMousePriv;
                     53:            pMouse->on = FALSE;
                     54:            map[1] = 1;
                     55:            map[2] = 2;
                     56:            map[3] = 3;
                     57:            InitPointerDeviceStruct(
                     58:                pMouse, map, 3, sunMouseGetMotionEvents, sunMouseCtrl);
                     59:            break;
                     60: 
                     61:        case DEVICE_ON:
                     62:                AddEnabledDevice (sunMousefd);
                     63:                pMouse->on = TRUE;
                     64:                break;
                     65: 
                     66:        case DEVICE_CLOSE:
                     67:            break;
                     68: 
                     69:        case DEVICE_OFF:
                     70:                pMouse->on = FALSE;
                     71:                RemoveEnabledDevice (sunMousefd);
                     72:                break;
                     73:        }
                     74:     return (Success);
                     75: }
                     76:            
                     77: static void
                     78: sunMouseCtrl (pMouse)
                     79:     DevicePtr    pMouse;
                     80: {
                     81: }
                     82: 
                     83: static int
                     84: sunMouseGetMotionEvents (buff, start, stop)
                     85:     CARD32 start, stop;
                     86:     xTimecoord *buff;
                     87: {
                     88:     return 0;
                     89: }
                     90: 
                     91: static short
                     92: MouseAccelerate (pMouse, delta)
                     93:     DevicePtr    pMouse;
                     94:     int                  delta;
                     95: {
                     96:     register int  sgn = sign(delta);
                     97:     register PtrCtrl *pCtrl;
                     98: 
                     99:     delta = abs(delta);
                    100:     pCtrl = &((DeviceIntPtr) pMouse)->u.ptr.ctrl;
                    101: 
                    102:     if (delta > pCtrl->threshold) {
                    103:        return ((short) (sgn * (pCtrl->threshold +
                    104:                                ((delta - pCtrl->threshold) * pCtrl->num) /
                    105:                                pCtrl->den)));
                    106:     } else {
                    107:        return ((short) (sgn * delta));
                    108:     }
                    109: }
                    110: 
                    111: void
                    112: sunMouseEvent(pMouse)
                    113: DevicePtr pMouse;
                    114: {
                    115:        register i;
                    116:        static char rbuf[512];
                    117:        static mstate, buttons, changebuttons;
                    118:        static deltax, deltay;
                    119:        int mousemoved = 0;
                    120:        char *tail;
                    121:        register char c, *cp;
                    122: 
                    123:        if ((i = read (sunMousefd, rbuf, sizeof(rbuf))) < 0)
                    124:                FatalError ("Could not read from mouse");
                    125: 
                    126:        tail = &rbuf[i];
                    127:        for (cp = rbuf; cp != tail; mstate++) {
                    128:                c = *cp++;
                    129:        
                    130:                /*
                    131:                 * State Machine - corresponds to the 5 bytes of the
                    132:                 * Microport mouse.
                    133:                 */
                    134:                switch(mstate) {
                    135:                case 0:
                    136:                        if ((c & 0xf0) == 0x80) {
                    137:                                i = ~c & 0x7;
                    138:                                changebuttons = buttons ^ i;
                    139:                                buttons = i;
                    140:                        } else
                    141:                                mstate--;
                    142:                        break;
                    143:                case 1:
                    144:                        deltax = c;
                    145:                        break;
                    146:                case 2:
                    147:                        deltay = c;
                    148:                        break;
                    149:                case 3:
                    150:                        deltax += c;
                    151:                        break;
                    152:                case 4:
                    153:                        deltay += c;
                    154:                        /* The mouse moved */
                    155:                        if (deltax || deltay) {
                    156:                            if (deltax)
                    157:                                sysMousePriv.x += MouseAccelerate (pMouse, deltax);
                    158:                            if (deltay)
                    159:                                sysMousePriv.y -= MouseAccelerate (pMouse, deltay);
                    160:                            if (sunConstrainXY (&sysMousePriv.x, &sysMousePriv.y))
                    161:                                mousemoved++;
                    162:                        }
                    163:                        /* Buttons changed states */
                    164:                        if (changebuttons) {
                    165:                            if (mousemoved) {
                    166:                                sunmkX(pMouse, MotionNotify, 0);
                    167:                                mousemoved = 0;
                    168:                            }
                    169:                            for (i = 0; i < 3; i++) {
                    170:                                if (changebuttons & (1 << i)) {
                    171:                                 int type;
                    172:                                 if (buttons & (1 << i))
                    173:                                   type = ButtonPress;
                    174:                                 else
                    175:                                   type = ButtonRelease;
                    176:                                 sunmkX(pMouse, type, 3 - i);
                    177:                                }
                    178:                            }
                    179:                        }
                    180:                        mstate = -1;
                    181:                        break;
                    182:                }
                    183:        }
                    184:        if (mousemoved)
                    185:                sunmkX(pMouse, MotionNotify, 0);
                    186: }
                    187: 
                    188: /*
                    189:  * Send a mouse of keyboard X event to dix
                    190:  */
                    191: sunmkX(pDev, type, detail)
                    192: DevicePtr pDev;
                    193: {
                    194:        xEvent xE;
                    195: 
                    196:        if (type == MotionNotify)
                    197:                sunMoveCursor (sysMousePriv.pScreen,
                    198:                                sysMousePriv.x, sysMousePriv.y);
                    199:        xE.u.u.type = type;
                    200:        xE.u.u.detail = detail;
                    201:        xE.u.keyButtonPointer.rootX = sysMousePriv.x;
                    202:        xE.u.keyButtonPointer.rootY = sysMousePriv.y;
                    203:        xE.u.keyButtonPointer.time = ++lastEventTime;
                    204:        (*pDev->processInputProc) (&xE, pDev);
                    205: }

unix.superglobalmegacorp.com

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