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