1: #ifndef lint
   2: static char *rcsid_events_c = "$Header: events.c,v 10.2 86/02/01 16:20:48 tony Rel $";
   3: #endif	lint
   4: #ifdef  sun
   5: /*
   6:  * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided
   7:  * for unrestricted use provided that this legend is included on all tape
   8:  * media and as a part of the software program in whole or part.  Users
   9:  * may copy or modify these drivers without charge, but are not authorized
  10:  * to license or distribute them to anyone else except as part of a product or
  11:  * program developed by the user.
  12:  *
  13:  * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
  14:  * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A
  15:  * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE
  16:  * PRACTICE.
  17:  *
  18:  * The Sun X Drivers are provided with no support and without any obligation
  19:  * on the part of Sun Microsystems, Inc. to assist in their use, correction,
  20:  * modification or enhancement.
  21:  *
  22:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  23:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X
  24:  * DRIVERS OR ANY PART THEREOF.
  25:  *
  26:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  27:  * or profits or other special, indirect and consequential damages, even if
  28:  * Sun has been advised of the possibility of such damages.
  29:  *
  30:  * Sun Microsystems, Inc.
  31:  * 2550 Garcia Avenue
  32:  * Mountain View, California  94043
  33:  */
  34: 
  35: #ifndef lint
  36: static char sccsid[] = "@(#)events.c 2.1 86/01/28 Copyright 1986 Sun Micro";
  37: #endif
  38: 
  39: /*-
  40:  * Copyright (c) 1986 by Sun Microsystems,  Inc.
  41:  */
  42: 
  43: /*
  44:  *	ToDo:
  45:  *		Up events
  46:  *		Shiftlock support
  47:  */
  48: 
  49: #include    <stdio.h>
  50: #include    <sys/types.h>
  51: #include    <sys/time.h>
  52: #include    <sys/errno.h>
  53: #include    "../X/X.h"
  54: #include    "../X/vsinput.h"
  55: #include    "../X/Xdev.h"
  56: #include    <sundev/kbd.h>
  57: #include    <sunwindow/win_input.h>
  58: 
  59: #ifndef event_is_ascii
  60: #define event_is_ascii(e) (e->ie_code >= ASCII_FIRST && e->ie_code <= ASCII_LAST)
  61: #endif
  62: #ifndef event_is_meta
  63: #define event_is_meta(e) (e->ie_code >= META_FIRST && e->ie_code <= META_LAST)
  64: #endif
  65: /* Should be qevent.h */
  66: #define VSE_LEFT_BUTTON 0
  67: #define VSE_MIDDLE_BUTTON   1
  68: #define VSE_RIGHT_BUTTON    2
  69: 
  70: extern int errno;
  71: unsigned state_mask = 0;
  72: extern int vsdev;
  73: extern DEVICE *CurrentDevice;
  74: 
  75: /*ARGSUSED*/
  76: ProcessInput(ev)
  77:     register vsEvent *ev;
  78: {
  79:     /*NOTREACHED*/
  80: }
  81: 
  82: #include "lk201.h"
  83: 
  84: static int
  85: SunToXKeyCode(s)
  86: int s;
  87: {
  88:     register int ret = LK201[s&0177];
  89:     char *c = "^.";
  90:     char *f = ".";
  91: 
  92:     c[1] = (s&0177)|0100;
  93:     f[0] = (s&0177);
  94: 
  95:     return(ret);
  96: }
  97: 
  98: /*
  99:  * Convert from a Sun event to an X event
 100:  */
 101: static int
 102: ConvertEvent(se, xe)
 103: struct inputevent *se;
 104: vsEvent *xe;
 105: {
 106:     /* Map the coordinates */
 107:     xe->vse_x = se->ie_locx;
 108:     xe->vse_y = se->ie_locy;
 109:     /* Map the time stamps */
 110:     xe->vse_time = (se->ie_time.tv_usec/10000 + se->ie_time.tv_sec);
 111:     /* Set direction */
 112:     xe->vse_direction = (win_inputposevent(se) ? VSE_KBTDOWN : VSE_KBTUP);
 113:     /* Sort out the event codes */
 114:     if (event_is_ascii(se)) {
 115:     /* ASCII keystroke */
 116:     int key = SunToXKeyCode(se->ie_code);
 117:     xe->vse_key = (key & 0377);
 118:     xe->vse_device = VSE_DKB;
 119:     xe->vse_type = VSE_BUTTON;
 120:     state_mask = (state_mask & ~(ControlMask|MetaMask|ShiftMask|ShiftLockMask))
 121:         | (key & (ControlMask|MetaMask|ShiftMask|ShiftLockMask));
 122:     } else if (event_is_meta(se)) {
 123:     /* META keystroke - map to ASCII for now */
 124:     int key = SunToXKeyCode(se->ie_code - META_FIRST + ASCII_FIRST) | MetaMask;
 125:     xe->vse_key = (key & 0377);
 126:     xe->vse_device = VSE_DKB;
 127:     xe->vse_type = VSE_BUTTON;
 128:     state_mask = (state_mask & ~(ControlMask|MetaMask|ShiftMask|ShiftLockMask))
 129:         | (key & (ControlMask|MetaMask|ShiftMask|ShiftLockMask));
 130:     } else switch (se->ie_code) {
 131:     case LOC_MOVE:
 132:         xe->vse_device = VSE_MOUSE;     /* XXX - should query shift state here but ... */
 133:         xe->vse_type = VSE_MMOTION;
 134:         break;
 135:     case MS_LEFT:
 136:         xe->vse_key = VSE_LEFT_BUTTON;  /* XXX - should query shift state here */
 137:         xe->vse_device = VSE_MOUSE;
 138:         xe->vse_type = VSE_BUTTON;
 139:         if (xe->vse_direction == VSE_KBTUP)
 140:         state_mask &= ~LeftMask;
 141:         else
 142:             state_mask |= LeftMask;
 143:         goto ShiftKeys;
 144:     case MS_MIDDLE:
 145:         xe->vse_device = VSE_MOUSE;
 146:         xe->vse_type = VSE_BUTTON;
 147:         xe->vse_key = VSE_MIDDLE_BUTTON;
 148:         if (xe->vse_direction == VSE_KBTUP)
 149:         state_mask &= ~MiddleMask;
 150:         else
 151:             state_mask |= MiddleMask;
 152:         goto ShiftKeys;
 153:     case MS_RIGHT:
 154:         xe->vse_key = VSE_RIGHT_BUTTON;
 155:         xe->vse_device = VSE_MOUSE;
 156:         xe->vse_type = VSE_BUTTON;
 157:         if (xe->vse_direction == VSE_KBTUP)
 158:         state_mask &= ~RightMask;
 159:         else
 160:             state_mask |= RightMask;
 161: ShiftKeys:
 162:         if (se->ie_shiftmask & CAPSMASK)
 163:         state_mask |= ShiftLockMask;
 164:         else
 165:             state_mask &= ~ShiftMask;
 166:         if (se->ie_shiftmask & SHIFTMASK)
 167:         state_mask |= ShiftMask;
 168:         else
 169:             state_mask &= ~ShiftMask;
 170:         if (se->ie_shiftmask & CTRLMASK)
 171:         state_mask |= ControlMask;
 172:         else
 173:         state_mask &= ~ControlMask;
 174: #ifdef  META_SHIFT_MASK
 175:         if (se->ie_shiftmask & META_SHIFT_MASK)
 176:         state_mask |= MetaMask;
 177:         else
 178:         state_mask &= ~MetaMask;
 179: #endif
 180:         break;
 181:     default:
 182:         /* Ignore it */
 183:         break;
 184:     }
 185:     return (state_mask);
 186: }
 187: 
 188: #define INPBUFSIZE  128
 189: 
 190: /*
 191:  * Read pending input events
 192:  */
 193: InputReader()
 194: {
 195:     struct inputevent sunevents[INPBUFSIZE];
 196:     int         n, m;
 197:     static int last_mask = 0;
 198: 
 199:     if ((n = read(vsdev, sunevents, INPBUFSIZE * sizeof sunevents[0])) < 0
 200:     && errno != EWOULDBLOCK) {
 201:     /*
 202: 	 * Error reading events
 203: 	 */
 204:     /* XXX_DO_SOMETHING(); */
 205:     return;
 206:     }
 207:     for (n /= sizeof sunevents[0], m = 0; m < n; m++) {
 208:     vsEvent Xevent, Sevent;
 209:     int mask;
 210: 
 211:     mask = ConvertEvent(&(sunevents[m]), &Xevent);
 212:     SetCursorPosition((vsCursor *) &Xevent);    /* XXX - tacky */
 213: 
 214:     if (mask != last_mask) {
 215:         last_mask ^= mask;
 216:         Sevent.vse_device = VSE_DKB;
 217:         Sevent.vse_x = Xevent.vse_x;
 218:         Sevent.vse_y = Xevent.vse_y;
 219:         Sevent.vse_time = Xevent.vse_time;
 220:         Sevent.vse_device = VSE_DKB;
 221:         if (last_mask & ShiftMask) {
 222:         if (mask & ShiftMask)
 223:             Sevent.vse_direction = VSE_KBTDOWN;
 224:         else
 225:             Sevent.vse_direction = VSE_KBTUP;
 226:         Sevent.vse_key = 0256;
 227:         Deal_with_input(&Sevent);
 228:         }
 229:         if (last_mask & ControlMask) {
 230:         if (mask & ControlMask)
 231:             Sevent.vse_direction = VSE_KBTDOWN;
 232:         else
 233:             Sevent.vse_direction = VSE_KBTUP;
 234:         Sevent.vse_key = 0257;
 235:         Deal_with_input(&Sevent);
 236:         }
 237:         if (last_mask & ShiftLockMask) {
 238:         if (mask & ShiftLockMask)
 239:             Sevent.vse_direction = VSE_KBTDOWN;
 240:         else
 241:             Sevent.vse_direction = VSE_KBTUP;
 242:         Sevent.vse_key = 0260;
 243:         Deal_with_input(&Sevent);
 244:         }
 245:         if (last_mask & MetaMask) {
 246:         if (mask & MetaMask)
 247:             Sevent.vse_direction = VSE_KBTDOWN;
 248:         else
 249:             Sevent.vse_direction = VSE_KBTUP;
 250:         Sevent.vse_key = 0261;
 251:         Deal_with_input(&Sevent);
 252:         }
 253:         last_mask = mask;
 254:     }
 255:     if (Xevent.vse_type == VSE_MMOTION) {
 256:         register vsBox *b = CurrentDevice->mbox;
 257:         register vsCursor *m = CurrentDevice->mouse;
 258:         /*
 259: 	     * Has it left the box?
 260: 	     */
 261:         if (m->y >= b->bottom || m->y < b->top ||
 262:         m->x >= b->right || m->x < b->left) {
 263:             b->bottom = 0;
 264:             Deal_with_movement();
 265:         }
 266:     } else
 267:         Deal_with_input(&Xevent);
 268:     }
 269: }
 270: #endif	sun

Defined functions

ConvertEvent defined in line 101; used 1 times
InputReader defined in line 193; used 2 times
ProcessInput defined in line 76; never used
SunToXKeyCode defined in line 84; used 2 times

Defined variables

rcsid_events_c defined in line 2; never used
sccsid defined in line 36; never used
state_mask defined in line 71; used 19 times

Defined macros

INPBUFSIZE defined in line 188; used 2 times
VSE_LEFT_BUTTON defined in line 66; used 1 times
VSE_MIDDLE_BUTTON defined in line 67; used 1 times
VSE_RIGHT_BUTTON defined in line 68; used 1 times
event_is_ascii defined in line 60; used 2 times
event_is_meta defined in line 63; used 2 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 918
Valid CSS Valid XHTML 1.0 Strict