|
|
1.1 ! root 1: /* ! 2: * $Source: /u1/X/libis/RCS/events.c,v $ ! 3: * $Header: events.c,v 1.1 86/11/17 14:33:56 swick Rel $ ! 4: */ ! 5: ! 6: #ifndef lint ! 7: static char *rcsid_events_c = "$Header: events.c,v 1.1 86/11/17 14:33:56 swick Rel $"; ! 8: #endif lint ! 9: ! 10: #include "is-copyright.h" ! 11: ! 12: /* events.c ! 13: * ! 14: * ProcessInput stub ! 15: * InputHandler Read IS input; convert to X event ! 16: * ! 17: * Copyright (c) 1986, Integrated Solutions, Inc. ! 18: */ ! 19: ! 20: #include "Xis.h" ! 21: #include <fcntl.h> ! 22: #include "lk201.h" ! 23: #include <sys/time.h> ! 24: ! 25: #define IBUFSIZE 512 ! 26: #define KEY_MASKS (ControlMask|MetaMask|ShiftMask|ShiftLockMask) ! 27: ! 28: /* ! 29: * taken from ../X/input.c ! 30: */ ! 31: #define ShiftKeyCode 0256 ! 32: #define ControlKeyCode 0257 ! 33: #define LockKeyCode 0260 ! 34: #define MetaKeyCode 0261 ! 35: ! 36: #define VSE_LEFT_BUTTON 0 ! 37: #define VSE_MIDDLE_BUTTON 1 ! 38: #define VSE_RIGHT_BUTTON 2 ! 39: ! 40: extern DEVICE *CurrentDevice; ! 41: extern int indev; ! 42: extern vsCursor last_mouse; ! 43: ! 44: int mouse_acceleration = 1; ! 45: int mouse_threshold; ! 46: int invalid_mouse; ! 47: ! 48: /* ! 49: * ProcessInput ! 50: */ ! 51: /*ARGSUSED*/ ! 52: ProcessInput(ev) ! 53: register vsEvent *ev; ! 54: { ! 55: /*NOTREACHED*/ ! 56: } ! 57: ! 58: /* ! 59: * InputHandler ! 60: * ! 61: * It is assumed that read always returns complete sequences. ! 62: * Uses PF[1-4] to toggle ShiftKey, LockKey, ControlKey, and MetaKey. ! 63: */ ! 64: int InputHandler() ! 65: { ! 66: unsigned char inbuf[IBUFSIZE]; ! 67: register unsigned char *p = inbuf; ! 68: register int nread; ! 69: ! 70: #ifdef DEBUG ! 71: fflush(stdout); ! 72: #endif ! 73: ! 74: fcntl(indev, F_SETFL, FNDELAY); ! 75: if ((nread = read(indev, (char *)inbuf, IBUFSIZE)) <= 0) { ! 76: /* no input now */ ! 77: fcntl(indev, F_SETFL, 0); ! 78: if (invalid_mouse) ! 79: --invalid_mouse; ! 80: return; ! 81: } ! 82: ! 83: while (p < &inbuf[nread]) { ! 84: static unsigned mask = 0; ! 85: vsEvent event; ! 86: ! 87: if (*p == VT_MOUSE) { ! 88: /* a mouse input */ ! 89: int warp = 0; ! 90: ! 91: event.vse_device = VSE_MOUSE; ! 92: p++; ! 93: ! 94: /* which button */ ! 95: switch (*p & (VT_MOUSE_LEFT|VT_MOUSE_MIDDLE|VT_MOUSE_RIGHT)) { ! 96: case VT_MOUSE_LEFT: ! 97: event.vse_key = VSE_LEFT_BUTTON; ! 98: break; ! 99: case VT_MOUSE_MIDDLE: ! 100: event.vse_key = VSE_MIDDLE_BUTTON; ! 101: break; ! 102: case VT_MOUSE_RIGHT: ! 103: event.vse_key = VSE_RIGHT_BUTTON; ! 104: break; ! 105: } ! 106: ! 107: /* which direction */ ! 108: switch (*p++ & (VT_MOUSE_DOWN|VT_MOUSE_UP|VT_MOUSE_NOBUTTON)) { ! 109: case VT_MOUSE_DOWN: ! 110: event.vse_type = VSE_BUTTON; ! 111: event.vse_direction = VSE_KBTDOWN; ! 112: break; ! 113: case VT_MOUSE_UP: ! 114: event.vse_type = VSE_BUTTON; ! 115: event.vse_direction = VSE_KBTUP; ! 116: break; ! 117: case VT_MOUSE_NOBUTTON: ! 118: event.vse_type = VSE_MMOTION; ! 119: event.vse_direction = VSE_KBTRAW; ! 120: break; ! 121: } ! 122: ! 123: p++; /* window */ ! 124: p++; /* pane */ ! 125: ! 126: event.vse_x = *p++ << 8; event.vse_x |= *p++; /* x location */ ! 127: event.vse_y = *p++ << 8; event.vse_y |= *p++; /* y location */ ! 128: ! 129: if (invalid_mouse && (event.vse_type == VSE_MMOTION)) { ! 130: /* throw away buffered mouse motion events after warp */ ! 131: continue; ! 132: } ! 133: ! 134: /* adjust for mouse acceleration if necessary */ ! 135: if ((mouse_acceleration > 1) && (event.vse_type == VSE_MMOTION)) { ! 136: /* accelerated mouse */ ! 137: register int delta; ! 138: delta = event.vse_x - last_mouse.x; ! 139: if ((delta < -mouse_threshold) || (delta > mouse_threshold)) { ! 140: /* accelerate mouse in x direction */ ! 141: register short new_x; ! 142: warp = 1; /* will have to warp the mouse */ ! 143: new_x = last_mouse.x + ! 144: ((delta<0?-1:1)*mouse_threshold)*(1-mouse_acceleration) ! 145: + (mouse_acceleration*delta); ! 146: /* keep warped mouse on the screen */ ! 147: if (new_x >= ScreenPixmap.width) ! 148: event.vse_x = ScreenPixmap.width - 1; ! 149: else if (new_x < 0) ! 150: event.vse_x = 0; ! 151: else ! 152: event.vse_x = (unsigned short) new_x; ! 153: } ! 154: delta = event.vse_y - last_mouse.y; ! 155: if ((delta < -mouse_threshold) || (delta > mouse_threshold)) { ! 156: /* accelerate mouse in y direction */ ! 157: register short new_y; ! 158: warp = 1; /* will have to warp the mouse */ ! 159: new_y = last_mouse.y + ! 160: ((delta<0?-1:1)*mouse_threshold)*(1-mouse_acceleration) ! 161: + (mouse_acceleration*delta); ! 162: /* keep warped mouse on the screen */ ! 163: if (new_y >= ScreenPixmap.height) ! 164: event.vse_y = ScreenPixmap.height - 1; ! 165: else if (new_y < 0) ! 166: event.vse_y = 0; ! 167: else ! 168: event.vse_y = (unsigned short) new_y; ! 169: } ! 170: } ! 171: ! 172: if (invalid_mouse && (event.vse_type != VSE_MMOTION)) { ! 173: /* don't throw away buffered mouse button events after warp */ ! 174: /* but set them to warp location */ ! 175: event.vse_x = last_mouse.x; ! 176: event.vse_y = last_mouse.y; ! 177: } ! 178: ! 179: if (warp) ! 180: SetCursorPosition((vsCursor *) &event); ! 181: else ! 182: UpdateCursorPosition((vsCursor *) &event); ! 183: ! 184: if (event.vse_type == VSE_MMOTION) { ! 185: register vsBox *b = CurrentDevice->mbox; ! 186: register vsCursor *m = CurrentDevice->mouse; ! 187: /* Has it left the box? */ ! 188: if (m->y >= b->bottom || m->y < b->top || ! 189: m->x >= b->right || m->x < b->left) { ! 190: b->bottom = 0; ! 191: Deal_with_movement(); ! 192: } ! 193: } else { ! 194: /* a mouse button press or release */ ! 195: struct timeval t; ! 196: struct timezone tz; ! 197: /* this is the best we can do for now */ ! 198: gettimeofday(&t, &tz); ! 199: event.vse_time = t.tv_sec*100 + t.tv_usec/10000; ! 200: Deal_with_input(&event); ! 201: } ! 202: } else { ! 203: /* keyboard input */ ! 204: struct timeval t; ! 205: struct timezone tz; ! 206: /* this is the best we can do for now */ ! 207: gettimeofday(&t, &tz); ! 208: event.vse_time = t.tv_sec*100 + t.tv_usec/10000; ! 209: event.vse_type = VSE_BUTTON; ! 210: event.vse_device = VSE_DKB; ! 211: /* check for PF[1-4] (ESC O [PQRS]); assumes that if a */ ! 212: /* complete PF escape sequence is in the buffer, it was */ ! 213: /* produced by a PF key */ ! 214: if ((&inbuf[nread] - p >= 3) && ! 215: (*p == '\033') && (*(p+1) == 'O') && ! 216: (*(p+2) >= 'P') && (*(p+2) <= 'S')) { ! 217: /* one of Shift, Lock, Control, Meta (PF[1-4]) was pressed */ ! 218: switch (*(p+2)) { /* toggle the appropriate key */ ! 219: case 'P': /* PF1 -- ShiftKey */ ! 220: mask ^= ShiftMask; ! 221: event.vse_key = ShiftKeyCode; ! 222: event.vse_direction = ! 223: (mask & ShiftMask) ? VSE_KBTDOWN : VSE_KBTUP; ! 224: break; ! 225: case 'Q': /* PF2 -- LockKey */ ! 226: mask ^= ShiftLockMask; ! 227: event.vse_key = LockKeyCode; ! 228: event.vse_direction = ! 229: (mask & ShiftLockMask) ? VSE_KBTDOWN : VSE_KBTUP; ! 230: break; ! 231: case 'R': /* PF3 -- ControlKey */ ! 232: mask ^= ControlMask; ! 233: event.vse_key = ControlKeyCode; ! 234: event.vse_direction = ! 235: (mask & ControlMask) ? VSE_KBTDOWN : VSE_KBTUP; ! 236: break; ! 237: case 'S': /* PF4 -- MetaKey */ ! 238: mask ^= MetaMask; ! 239: event.vse_key = MetaKeyCode; ! 240: event.vse_direction = ! 241: (mask & MetaMask) ? VSE_KBTDOWN : VSE_KBTUP; ! 242: break; ! 243: } ! 244: p += 3; ! 245: Deal_with_input(&event); ! 246: } else { ! 247: /* "normal" key */ ! 248: register unsigned short key = LK201[*p++]; ! 249: static vsEvent upkey = {0,0,0,VSE_BUTTON,0,VSE_KBTUP,VSE_DKB}; ! 250: static vsEvent dnkey = {0,0,0,VSE_BUTTON,0,VSE_KBTDOWN,VSE_DKB}; ! 251: upkey.vse_time = dnkey.vse_time = event.vse_time; ! 252: ! 253: /* send UP for any Shift, Lock, Control, or Meta keys down */ ! 254: /* but not if this is a Shift or Control key */ ! 255: if ((mask & ShiftMask) && !(key & ShiftMask)) { ! 256: upkey.vse_key = ShiftKeyCode; ! 257: Deal_with_input(&upkey); ! 258: } ! 259: if (mask & ShiftLockMask) { ! 260: upkey.vse_key = LockKeyCode; ! 261: Deal_with_input(&upkey); ! 262: } ! 263: if ((mask & ControlMask) && !(key & ControlMask)) { ! 264: upkey.vse_key = ControlKeyCode; ! 265: Deal_with_input(&upkey); ! 266: } ! 267: if (mask & MetaMask) { ! 268: upkey.vse_key = MetaKeyCode; ! 269: Deal_with_input(&upkey); ! 270: } ! 271: ! 272: /* set up keyboard event */ ! 273: event.vse_key = key & 0377; ! 274: event.vse_direction = VSE_KBTRAW; ! 275: ! 276: switch (key & KEY_MASKS) { ! 277: case ShiftMask: ! 278: /* send Shift down if not down already */ ! 279: if (!(mask & ShiftMask)) { ! 280: dnkey.vse_key = ShiftKeyCode; ! 281: Deal_with_input(&dnkey); ! 282: } ! 283: /* send the key */ ! 284: Deal_with_input(&event); ! 285: /* send Shift up */ ! 286: upkey.vse_key = ShiftKeyCode; ! 287: Deal_with_input(&upkey); ! 288: break; ! 289: case ControlMask: ! 290: /* send Control down if not down already */ ! 291: if (!(mask & ControlMask)) { ! 292: dnkey.vse_key = ControlKeyCode; ! 293: Deal_with_input(&dnkey); ! 294: } ! 295: /* send the key */ ! 296: Deal_with_input(&event); ! 297: /* send Control up */ ! 298: upkey.vse_key = ControlKeyCode; ! 299: Deal_with_input(&upkey); ! 300: break; ! 301: case ShiftLockMask: ! 302: case MetaMask: ! 303: default: ! 304: /* send the key */ ! 305: Deal_with_input(&event); ! 306: break; ! 307: } ! 308: ! 309: mask = 0; /* nothing should be down now */ ! 310: } ! 311: } ! 312: fflush(stdout); ! 313: } ! 314: if (invalid_mouse) ! 315: --invalid_mouse; ! 316: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.