sunIo.c revision b9325ec5
1/* $Xorg: sunIo.c,v 1.4 2001/03/07 17:34:19 pookie Exp $ */ 2/*- 3 * sunIo.c -- 4 * Functions to handle input from the keyboard and mouse. 5 * 6 * Copyright 1987 by the Regents of the University of California 7 * 8 * Permission to use, copy, modify, and distribute this 9 * software and its documentation for any purpose and without 10 * fee is hereby granted, provided that the above copyright 11 * notice appear in all copies. The University of California 12 * makes no representations about the suitability of this 13 * software for any purpose. It is provided "as is" without 14 * express or implied warranty. 15 * 16 * 17 */ 18/* $XFree86: xc/programs/Xserver/hw/sun/sunIo.c,v 3.10 2003/11/17 22:20:36 dawes Exp $ */ 19 20/************************************************************ 21Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 22 23 All Rights Reserved 24 25Permission to use, copy, modify, and distribute this 26software and its documentation for any purpose and without 27fee is hereby granted, provided that the above copyright no- 28tice appear in all copies and that both that copyright no- 29tice and this permission notice appear in supporting docu- 30mentation, and that the names of Sun or The Open Group 31not be used in advertising or publicity pertaining to 32distribution of the software without specific prior 33written permission. Sun and The Open Group make no 34representations about the suitability of this software for 35any purpose. It is provided "as is" without any express or 36implied warranty. 37 38SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 39INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 40NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 41ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 42ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 43PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 44OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 45THE USE OR PERFORMANCE OF THIS SOFTWARE. 46 47********************************************************/ 48 49#define NEED_EVENTS 50#include "sun.h" 51#include "mi.h" 52#include "os.h" 53 54/*- 55 *----------------------------------------------------------------------- 56 * ProcessInputEvents -- 57 * Retrieve all waiting input events and pass them to DIX in their 58 * correct chronological order. Only reads from the system pointer 59 * and keyboard. 60 * 61 * Results: 62 * None. 63 * 64 * Side Effects: 65 * Events are passed to the DIX layer. 66 * 67 *----------------------------------------------------------------------- 68 */ 69void 70ProcessInputEvents(void) 71{ 72 mieqProcessInputEvents (); 73} 74 75/* 76 *----------------------------------------------------------------------- 77 * sunEnqueueEvents 78 * When a SIGIO is received, read device hard events and 79 * enqueue them using the mi event queue 80 */ 81 82void 83sunEnqueueEvents(void) 84{ 85 Firm_event *ptrEvents, /* Current pointer event */ 86 *kbdEvents; /* Current keyboard event */ 87 int numPtrEvents, /* Number of remaining pointer events */ 88 numKbdEvents; /* Number of remaining keyboard events */ 89 int nPE, /* Original number of pointer events */ 90 nKE; /* Original number of keyboard events */ 91 Bool PtrAgain, /* need to (re)read */ 92 KbdAgain; /* need to (re)read */ 93 DeviceIntPtr pPointer; 94 DeviceIntPtr pKeyboard; 95 sunKbdPrivPtr kbdPriv; 96 sunPtrPrivPtr ptrPriv; 97 98 pPointer = sunPointerDevice; 99 pKeyboard = sunKeyboardDevice; 100 ptrPriv = (sunPtrPrivPtr) pPointer->public.devicePrivate; 101 kbdPriv = (sunKbdPrivPtr) pKeyboard->public.devicePrivate; 102 if (!pPointer->public.on || !pKeyboard->public.on) 103 return; 104 105 numPtrEvents = 0; 106 ptrEvents = NULL; 107 PtrAgain = TRUE; 108 numKbdEvents = 0; 109 kbdEvents = NULL; 110 KbdAgain = TRUE; 111 112 /* 113 * So long as one event from either device remains unprocess, we loop: 114 * Take the oldest remaining event and pass it to the proper module 115 * for processing. The DDXEvent will be sent to ProcessInput by the 116 * function called. 117 */ 118 while (1) { 119 /* 120 * Get events from both the pointer and the keyboard, storing the number 121 * of events gotten in nPE and nKE and keeping the start of both arrays 122 * in pE and kE 123 */ 124 if ((numPtrEvents == 0) && PtrAgain) { 125 ptrEvents = sunMouseGetEvents (ptrPriv->fd, pPointer->public.on, 126 &nPE, &PtrAgain); 127 numPtrEvents = nPE; 128 } 129 if ((numKbdEvents == 0) && KbdAgain) { 130 kbdEvents = sunKbdGetEvents (kbdPriv->fd, pKeyboard->public.on, 131 &nKE, &KbdAgain); 132 numKbdEvents = nKE; 133 } 134 if ((numPtrEvents == 0) && (numKbdEvents == 0)) 135 break; 136 if (numPtrEvents && numKbdEvents) { 137 if (timercmp (&kbdEvents->time, &ptrEvents->time, <)) { 138 sunKbdEnqueueEvent (pKeyboard, kbdEvents); 139 numKbdEvents--; 140 kbdEvents++; 141 } else { 142 sunMouseEnqueueEvent (pPointer, ptrEvents); 143 numPtrEvents--; 144 ptrEvents++; 145 } 146 } else if (numKbdEvents) { 147 sunKbdEnqueueEvent (pKeyboard, kbdEvents); 148 numKbdEvents--; 149 kbdEvents++; 150 } else { 151 sunMouseEnqueueEvent (pPointer, ptrEvents); 152 numPtrEvents--; 153 ptrEvents++; 154 } 155 } 156} 157 158/* 159 * DDX - specific abort routine. Called by AbortServer(). 160 */ 161void 162AbortDDX(void) 163{ 164 int i; 165 ScreenPtr pScreen; 166 DevicePtr devPtr; 167 168#ifdef SVR4 169 (void) OsSignal (SIGPOLL, SIG_IGN); 170#else 171 (void) OsSignal (SIGIO, SIG_IGN); 172#endif 173 devPtr = (DevicePtr)sunKeyboardDevice; 174 if (devPtr) 175 (void) sunChangeKbdTranslation (((sunKbdPrivPtr)(devPtr->devicePrivate))->fd, FALSE); 176#if defined(SVR4) || defined(CSRG_BASED) 177 sunNonBlockConsoleOff (); 178#else 179 sunNonBlockConsoleOff (NULL); 180#endif 181 for (i = 0; i < screenInfo.numScreens; i++) 182 { 183 pScreen = screenInfo.screens[i]; 184 (*pScreen->SaveScreen) (pScreen, SCREEN_SAVER_OFF); 185#if 0 /* XXX GX is disabled for now */ 186 sunDisableCursor (pScreen); 187#endif 188 } 189} 190 191/* Called by GiveUp(). */ 192void 193ddxGiveUp(void) 194{ 195 AbortDDX (); 196} 197 198int 199ddxProcessArgument(int argc, char *argv[], int i) 200{ 201 202 if (strcmp (argv[i], "-swapLkeys") == 0) { /* -swapLkeys */ 203 sunSwapLkeys = TRUE; 204 return 1; 205 } 206 if (strcmp (argv[i], "-debug") == 0) { /* -debug */ 207 return 1; 208 } 209 if (strcmp (argv[i], "-dev") == 0) { /* -dev /dev/mumble */ 210 if (++i >= argc) UseMsg (); 211 return 2; 212 } 213 if (strcmp (argv[i], "-mono") == 0) { /* -mono */ 214 return 1; 215 } 216 if (strcmp (argv[i], "-zaphod") == 0) { /* -zaphod */ 217 sunActiveZaphod = FALSE; 218 return 1; 219 } 220 if (strcmp (argv[i], "-flipPixels") == 0) { /* -flipPixels */ 221 sunFlipPixels = TRUE; 222 return 1; 223 } 224 if (strcmp (argv[i], "-fbinfo") == 0) { /* -fbinfo */ 225 sunFbInfo = TRUE; 226 return 1; 227 } 228 if (strcmp (argv[i], "-kbd") == 0) { /* -kbd */ 229 if (++i >= argc) UseMsg(); 230 return 2; 231 } 232 if (strcmp (argv[i], "-protect") == 0) { /* -protect */ 233 if (++i >= argc) UseMsg(); 234 return 2; 235 } 236 if (strcmp (argv[i], "-cg4frob") == 0) { 237 sunCG4Frob = TRUE; 238 return 1; 239 } 240 if (strcmp (argv[i], "-noGX") == 0) { 241 sunNoGX = TRUE; 242 return 1; 243 } 244 return 0; 245} 246 247void 248ddxUseMsg(void) 249{ 250 ErrorF("-swapLkeys swap keysyms on L1..L10\n"); 251 ErrorF("-debug disable non-blocking console mode\n"); 252 ErrorF("-dev fn[:fn][:fn] name of device[s] to open\n"); 253 ErrorF("-mono force monochrome-only screen\n"); 254 ErrorF("-zaphod disable active Zaphod mode\n"); 255 ErrorF("-fbinfo tell more about the found frame buffer(s)\n"); 256#ifdef UNDOCUMENTED 257 ErrorF("-cg4frob don't use the mono plane of the cgfour\n"); 258 ErrorF("-noGX treat the GX as a dumb frame buffer\n"); 259#endif 260} 261