|
|
1.1 ! root 1: /*- ! 2: * sunIo.c -- ! 3: * Functions to handle input from the keyboard and mouse. ! 4: * ! 5: * Copyright (c) 1987 by the Regents of the University of California ! 6: * ! 7: * Permission to use, copy, modify, and distribute this ! 8: * software and its documentation for any purpose and without ! 9: * fee is hereby granted, provided that the above copyright ! 10: * notice appear in all copies. The University of California ! 11: * makes no representations about the suitability of this ! 12: * software for any purpose. It is provided "as is" without ! 13: * express or implied warranty. ! 14: * ! 15: * ! 16: */ ! 17: ! 18: /************************************************************ ! 19: Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. ! 20: ! 21: All Rights Reserved ! 22: ! 23: Permission to use, copy, modify, and distribute this ! 24: software and its documentation for any purpose and without ! 25: fee is hereby granted, provided that the above copyright no- ! 26: tice appear in all copies and that both that copyright no- ! 27: tice and this permission notice appear in supporting docu- ! 28: mentation, and that the names of Sun or MIT not be used in ! 29: advertising or publicity pertaining to distribution of the ! 30: software without specific prior written permission. Sun and ! 31: M.I.T. make no representations about the suitability of this ! 32: software for any purpose. It is provided "as is" without any ! 33: express or implied warranty. ! 34: ! 35: SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, ! 36: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- ! 37: NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- ! 38: ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 39: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR ! 40: PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR ! 41: OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH ! 42: THE USE OR PERFORMANCE OF THIS SOFTWARE. ! 43: ! 44: ********************************************************/ ! 45: ! 46: #ifndef lint ! 47: static char sccsid[] = "%W %G Copyright 1987 Sun Micro"; ! 48: #endif ! 49: ! 50: #include "sun.h" ! 51: #include "opaque.h" ! 52: ! 53: Bool screenSaved = FALSE; ! 54: int lastEventTime = 0; ! 55: extern int sunSigIO; ! 56: extern void SaveScreens(); ! 57: ! 58: #ifdef SUN_WINDOWS ! 59: int windowFd = 0; ! 60: #define INPBUFSIZE 128 ! 61: #endif SUN_WINDOWS ! 62: ! 63: /*- ! 64: *----------------------------------------------------------------------- ! 65: * TimeSinceLastInputEvent -- ! 66: * Function used for screensaver purposes by the os module. ! 67: * ! 68: * Results: ! 69: * The time in milliseconds since there last was any ! 70: * input. ! 71: * ! 72: * Side Effects: ! 73: * None. ! 74: * ! 75: *----------------------------------------------------------------------- ! 76: */ ! 77: int ! 78: TimeSinceLastInputEvent() ! 79: { ! 80: struct timeval now; ! 81: ! 82: gettimeofday (&now, (struct timezone *)0); ! 83: ! 84: if (lastEventTime == 0) { ! 85: lastEventTime = TVTOMILLI(now); ! 86: } ! 87: return TVTOMILLI(now) - lastEventTime; ! 88: } ! 89: ! 90: /*- ! 91: *----------------------------------------------------------------------- ! 92: * ProcessInputEvents -- ! 93: * Retrieve all waiting input events and pass them to DIX in their ! 94: * correct chronological order. Only reads from the system pointer ! 95: * and keyboard. ! 96: * ! 97: * Results: ! 98: * None. ! 99: * ! 100: * Side Effects: ! 101: * Events are passed to the DIX layer. ! 102: * ! 103: *----------------------------------------------------------------------- ! 104: */ ! 105: void ! 106: ProcessInputEvents () ! 107: { ! 108: register Firm_event *ptrEvents, /* Current pointer event */ ! 109: *kbdEvents; /* Current keyboard event */ ! 110: register int numPtrEvents, /* Number of remaining pointer ! 111: * events */ ! 112: numKbdEvents; /* Number of remaining ! 113: * keyboard events */ ! 114: int nPE, /* Original number of pointer ! 115: * events */ ! 116: nKE; /* Original number of ! 117: * keyboard events */ ! 118: DevicePtr pPointer; ! 119: DevicePtr pKeyboard; ! 120: register PtrPrivPtr ptrPriv; ! 121: register KbPrivPtr kbdPriv; ! 122: Firm_event *lastEvent; /* Last event processed */ ! 123: enum { ! 124: NoneYet, Ptr, Kbd ! 125: } lastType = NoneYet; /* Type of last event */ ! 126: ! 127: #ifdef SUN_WINDOWS ! 128: struct inputevent sunevents[INPBUFSIZE]; ! 129: register struct inputevent *se = sunevents, *seL; ! 130: int n; ! 131: static int event_ignore = TRUE; ! 132: #endif SUN_WINDOWS ! 133: ! 134: /* ! 135: * Defensive programming - only reset sunIOPending (preventing ! 136: * further calls to ProcessInputEvents() until a future SIGIO) ! 137: * if we have actually received a SIGIO, so we know it works. ! 138: */ ! 139: if (sunSigIO) { ! 140: isItTimeToYield = 0; ! 141: } ! 142: pPointer = LookupPointerDevice(); ! 143: pKeyboard = LookupKeyboardDevice(); ! 144: ! 145: if ( sunUseSunWindows() ) { ! 146: #ifdef SUN_WINDOWS ! 147: if ((n=read(windowFd,sunevents,INPBUFSIZE*sizeof sunevents[0])) < 0 ! 148: && errno != EWOULDBLOCK) { ! 149: /* ! 150: * Error reading events; should do something. XXX ! 151: */ ! 152: return; ! 153: } ! 154: ! 155: if (autoRepeatKeyDown && autoRepeatReady && n <= 0) { ! 156: /* fake a sunwindows kbd event */ ! 157: n = sizeof(struct inputevent); ! 158: se->ie_code = AUTOREPEAT_EVENTID; ! 159: if (autoRepeatDebug) ! 160: ErrorF("ProcessInputEvents: sw auto event\n"); ! 161: } ! 162: ! 163: for (seL = sunevents + (n/(sizeof sunevents[0])); se < seL; se++) { ! 164: if (screenSaved) ! 165: SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset); ! 166: lastEventTime = TVTOMILLI(event_time(se)); ! 167: ! 168: /* ! 169: * Decide whether or not to pay attention to events. ! 170: * Ignore the events if the locator has exited X Display. ! 171: */ ! 172: switch (event_id(se)) { ! 173: case KBD_DONE: ! 174: sunChangeKbdTranslation( pKeyboard, FALSE ); ! 175: break; ! 176: case KBD_USE: ! 177: sunChangeKbdTranslation( pKeyboard, TRUE ); ! 178: break; ! 179: case LOC_WINENTER: ! 180: event_ignore = FALSE; ! 181: break; ! 182: case LOC_WINEXIT: ! 183: event_ignore = TRUE; ! 184: break; ! 185: } ! 186: ! 187: if (event_ignore) { ! 188: continue; ! 189: } ! 190: ! 191: /* ! 192: * Figure out the X device this event should be reported on. ! 193: */ ! 194: switch (event_id(se)) { ! 195: case LOC_MOVE: ! 196: case MS_LEFT: ! 197: case MS_MIDDLE: ! 198: case MS_RIGHT: ! 199: sunMouseProcessEventSunWin(pPointer,se); ! 200: break; ! 201: case LOC_WINEXIT: ! 202: case LOC_WINENTER: ! 203: case KBD_DONE: ! 204: case KBD_USE: ! 205: break; ! 206: default: ! 207: sunKbdProcessEventSunWin(pKeyboard,se); ! 208: break; ! 209: } ! 210: } ! 211: #endif SUN_WINDOWS ! 212: } ! 213: else { ! 214: ptrPriv = (PtrPrivPtr)pPointer->devicePrivate; ! 215: kbdPriv = (KbPrivPtr)pKeyboard->devicePrivate; ! 216: ! 217: /* ! 218: * Get events from both the pointer and the keyboard, storing the number ! 219: * of events gotten in nPE and nKE and keeping the start of both arrays ! 220: * in pE and kE ! 221: */ ! 222: ptrEvents = (* ptrPriv->GetEvents) (pPointer, &nPE); ! 223: kbdEvents = (* kbdPriv->GetEvents) (pKeyboard, &nKE); ! 224: ! 225: numPtrEvents = nPE; ! 226: numKbdEvents = nKE; ! 227: lastEvent = (Firm_event *)0; ! 228: ! 229: /* ! 230: * So long as one event from either device remains unprocess, we loop: ! 231: * Take the oldest remaining event and pass it to the proper module ! 232: * for processing. The DDXEvent will be sent to ProcessInput by the ! 233: * function called. ! 234: */ ! 235: while (numPtrEvents || numKbdEvents) { ! 236: if (numPtrEvents && numKbdEvents) { ! 237: if (timercmp (&kbdEvents->time, &ptrEvents->time, <)) { ! 238: if (lastType == Ptr) { ! 239: (* ptrPriv->DoneEvents) (pPointer, FALSE); ! 240: } ! 241: (* kbdPriv->ProcessEvent) (pKeyboard, kbdEvents); ! 242: numKbdEvents--; ! 243: lastEvent = kbdEvents++; ! 244: lastType = Kbd; ! 245: } else { ! 246: if (lastType == Kbd) { ! 247: (* kbdPriv->DoneEvents) (pKeyboard, FALSE); ! 248: } ! 249: (* ptrPriv->ProcessEvent) (pPointer, ptrEvents); ! 250: numPtrEvents--; ! 251: lastEvent = ptrEvents++; ! 252: lastType = Ptr; ! 253: } ! 254: } else if (numKbdEvents) { ! 255: if (lastType == Ptr) { ! 256: (* ptrPriv->DoneEvents) (pPointer, FALSE); ! 257: } ! 258: (* kbdPriv->ProcessEvent) (pKeyboard, kbdEvents); ! 259: numKbdEvents--; ! 260: lastEvent = kbdEvents++; ! 261: lastType = Kbd; ! 262: } else { ! 263: if (lastType == Kbd) { ! 264: (* kbdPriv->DoneEvents) (pKeyboard, FALSE); ! 265: } ! 266: (* ptrPriv->ProcessEvent) (pPointer, ptrEvents); ! 267: numPtrEvents--; ! 268: lastEvent = ptrEvents++; ! 269: lastType = Ptr; ! 270: } ! 271: } ! 272: ! 273: if (lastEvent) { ! 274: lastEventTime = TVTOMILLI(lastEvent->time); ! 275: if (screenSaved) { ! 276: SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset); ! 277: } ! 278: } ! 279: ! 280: (* kbdPriv->DoneEvents) (pKeyboard); ! 281: (* ptrPriv->DoneEvents) (pPointer); ! 282: ! 283: } ! 284: ! 285: sunRestoreCursor(); ! 286: ! 287: } ! 288: ! 289: ! 290: /*- ! 291: *----------------------------------------------------------------------- ! 292: * SetTimeSinceLastInputEvent -- ! 293: * Set the lastEventTime to now. ! 294: * ! 295: * Results: ! 296: * None. ! 297: * ! 298: * Side Effects: ! 299: * lastEventTime is altered. ! 300: * ! 301: *----------------------------------------------------------------------- ! 302: */ ! 303: void ! 304: SetTimeSinceLastInputEvent() ! 305: { ! 306: struct timeval now; ! 307: ! 308: gettimeofday (&now, (struct timezone *)0); ! 309: lastEventTime = TVTOMILLI(now); ! 310: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.