diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c index 9e4bce0c8..0237e5279 100644 --- a/hw/kdrive/linux/bus.c +++ b/hw/kdrive/linux/bus.c @@ -33,7 +33,7 @@ /* /dev/adbmouse is a busmouse */ void -BusRead (int adbPort) +BusRead (int adbPort, void *closure) { unsigned char buf[3]; unsigned char *b; @@ -64,29 +64,36 @@ char *BusNames[] = { #define NUM_BUS_NAMES (sizeof (BusNames) / sizeof (BusNames[0])) +int BusInputType; + int BusInit (void) { int i; int busPort; + int n = 0; + if (!BusInputType) + BusInputType = KdAllocInputType (); + for (i = 0; i < NUM_BUS_NAMES; i++) { busPort = open (BusNames[i], 0); - if (busPort >= 0) - return busPort; + { + KdRegisterFd (BusInputType, busPort, BusRead, 0); + n++; + } } + return n; } void -BusFini (int busPort) +BusFini (void) { - if (busPort >= 0) - close (busPort); + KdUnregisterFds (BusInputType, TRUE); } KdMouseFuncs BusMouseFuncs = { BusInit, - BusRead, BusFini }; diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c index 0ba7a0e92..51e3c4e34 100644 --- a/hw/kdrive/linux/keyboard.c +++ b/hw/kdrive/linux/keyboard.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/programs/Xserver/hw/kdrive/linux/keyboard.c,v 1.5 2000/12/08 23:04:57 keithp Exp $ + * $XFree86: xc/programs/Xserver/hw/kdrive/linux/keyboard.c,v 1.6 2001/03/30 02:15:20 keithp Exp $ * * Copyright © 1999 Keith Packard * @@ -376,14 +376,35 @@ LinuxKeyboardLoad (void) readKernelMapping (); } +void +LinuxKeyboardRead (int fd, void *closure) +{ + unsigned char buf[256], *b; + int n; + + while ((n = read (fd, buf, sizeof (buf))) > 0) + { + b = buf; + while (n--) + { + KdEnqueueKeyboardEvent (b[0] & 0x7f, b[0] & 0x80); + b++; + } + } +} + static int LinuxKbdTrans; static struct termios LinuxTermios; +static int LinuxKbdType; int LinuxKeyboardInit (void) { struct termios nTty; + if (!LinuxKbdType) + LinuxKbdType = KdAllocInputType (); + ioctl (LinuxConsoleFd, KDGKBMODE, &LinuxKbdTrans); tcgetattr (LinuxConsoleFd, &LinuxTermios); @@ -398,31 +419,16 @@ LinuxKeyboardInit (void) cfsetispeed(&nTty, 9600); cfsetospeed(&nTty, 9600); tcsetattr(LinuxConsoleFd, TCSANOW, &nTty); - return LinuxConsoleFd; + KdRegisterFd (LinuxKbdType, LinuxConsoleFd, LinuxKeyboardRead, 0); + return 1; } void -LinuxKeyboardFini (int fd) +LinuxKeyboardFini (void) { ioctl(LinuxConsoleFd, KDSKBMODE, LinuxKbdTrans); tcsetattr(LinuxConsoleFd, TCSANOW, &LinuxTermios); -} - -void -LinuxKeyboardRead (int fd) -{ - unsigned char buf[256], *b; - int n; - - while ((n = read (fd, buf, sizeof (buf))) > 0) - { - b = buf; - while (n--) - { - KdEnqueueKeyboardEvent (b[0] & 0x7f, b[0] & 0x80); - b++; - } - } + KdUnregisterFds (LinuxKbdType, FALSE); } void @@ -447,7 +453,6 @@ LinuxKeyboardBell (int volume, int pitch, int duration) KdKeyboardFuncs LinuxKeyboardFuncs = { LinuxKeyboardLoad, LinuxKeyboardInit, - LinuxKeyboardRead, LinuxKeyboardLeds, LinuxKeyboardBell, LinuxKeyboardFini, diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c index ba9f481c2..f1ccfd77c 100644 --- a/hw/kdrive/linux/ps2.c +++ b/hw/kdrive/linux/ps2.c @@ -1,5 +1,5 @@ /* - * $XFree86$ + * $XFree86: xc/programs/Xserver/hw/kdrive/linux/ps2.c,v 1.4 2001/04/01 14:00:04 tsi Exp $ * * Copyright © 1999 Keith Packard * @@ -60,15 +60,34 @@ Ps2ReadBytes (int fd, char *buf, int len, int min) return tot; } +char *Ps2Names[] = { + "/dev/psaux", + "/dev/mouse", + "/dev/input/mice", +}; + +#define NUM_PS2_NAMES (sizeof (Ps2Names) / sizeof (Ps2Names[0])) + void -Ps2Read (int ps2Port) +Ps2Read (int ps2Port, void *closure) { unsigned char buf[3 * 200]; unsigned char *b; int n; int dx, dy; unsigned long flags; + int id = (int) closure; + unsigned long left_button = KD_BUTTON_1; + unsigned long right_button = KD_BUTTON_3; +#undef SWAP_USB +#ifdef SWAP_USB + if (id == 2) + { + left_button = KD_BUTTON_3; + right_button = KD_BUTTON_1; + } +#endif while ((n = Ps2ReadBytes (ps2Port, buf, sizeof (buf), 3)) > 0) { b = buf; @@ -78,10 +97,10 @@ Ps2Read (int ps2Port) if (b[0] & 4) flags |= KD_BUTTON_2; if (b[0] & 2) - flags |= KD_BUTTON_3; + flags |= right_button; if (b[0] & 1) - flags |= KD_BUTTON_1; - + flags |= left_button; + dx = b[1]; if (b[0] & 0x10) dx -= 256; @@ -96,37 +115,37 @@ Ps2Read (int ps2Port) } } -char *Ps2Names[] = { - "/dev/psaux", - "/dev/mouse", -}; - -#define NUM_PS2_NAMES (sizeof (Ps2Names) / sizeof (Ps2Names[0])) +int Ps2InputType; int Ps2Init (void) { int i; int ps2Port; + int n; + if (!Ps2InputType) + Ps2InputType = KdAllocInputType (); + n = 0; for (i = 0; i < NUM_PS2_NAMES; i++) { ps2Port = open (Ps2Names[i], 0); if (ps2Port >= 0) - return ps2Port; + { + if (KdRegisterFd (Ps2InputType, ps2Port, Ps2Read, (void *) i)) + n++; + } } - return -1; + return n; } void -Ps2Fini (int ps2Port) +Ps2Fini (void) { - if (ps2Port >= 0) - close (ps2Port); + KdUnregisterFds (Ps2InputType, TRUE); } KdMouseFuncs Ps2MouseFuncs = { Ps2Init, - Ps2Read, Ps2Fini }; diff --git a/hw/kdrive/linux/ts.c b/hw/kdrive/linux/ts.c index e130dc557..2481bb2df 100644 --- a/hw/kdrive/linux/ts.c +++ b/hw/kdrive/linux/ts.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/programs/Xserver/hw/kdrive/linux/ts.c,v 1.2 2000/09/26 15:57:04 tsi Exp $ + * $XFree86: xc/programs/Xserver/hw/kdrive/linux/ts.c,v 1.3 2001/05/23 08:56:08 alanh Exp $ * * Derived from ps2.c by Jim Gettys * @@ -97,31 +97,36 @@ char *TsNames[] = { #define NUM_TS_NAMES (sizeof (TsNames) / sizeof (TsNames[0])) +int TsInputType; + int TsInit (void) { int i; int TsPort; + if (!TsInputType) + TsInputType = KdAllocInputType (); for (i = 0; i < NUM_TS_NAMES; i++) { TsPort = open (TsNames[i], 0); if (TsPort >= 0) - return TsPort; + { + if (KdRegisterFd (TsInputType, TsPort, TsRead)) + return 1; + } } perror("Touch screen not found.\n"); exit (1); } void -TsFini (int tsPort) +TsFini (void) { - if (tsPort >= 0) - close (tsPort); + KdUnregisterFds (TsInputType, TRUE); } KdTsFuncs TsFuncs = { TsInit, - TsRead, TsFini }; diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index 0070daf6a..a332d180a 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -21,7 +21,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.h,v 1.14 2001/05/29 04:54:10 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.h,v 1.15 2001/06/04 09:45:41 keithp Exp $ */ #include #include "X.h" @@ -168,25 +168,15 @@ typedef struct { typedef struct _KdMouseFuncs { int (*Init) (void); - void (*Read) (int); - void (*Fini) (int); + void (*Fini) (void); } KdMouseFuncs; -#ifdef TOUCHSCREEN -typedef struct _KdTsFuncs { - int (*Init) (void); - void (*Read) (int); - void (*Fini) (int); -} KdTsFuncs; -#endif - typedef struct _KdKeyboardFuncs { void (*Load) (void); int (*Init) (void); - void (*Read) (int); void (*Leds) (int); void (*Bell) (int, int, int); - void (*Fini) (int); + void (*Fini) (void); int LockLed; } KdKeyboardFuncs; @@ -542,6 +532,15 @@ KdScreenInfoDispose (KdScreenInfo *si); void KdInitInput(KdMouseFuncs *, KdKeyboardFuncs *); +int +KdAllocInputType (void); + +Bool +KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *closure); + +void +KdUnregisterFds (int type, Bool do_close); + #ifdef TOUCHSCREEN void KdInitTouchScreen(KdTsFuncs *pTsFuncs); diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index bbedd5338..5059eb02a 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -21,7 +21,7 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/hw/kdrive/kinput.c,v 1.15 2001/05/25 07:44:29 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kinput.c,v 1.16 2001/05/25 18:40:59 dawes Exp $ */ #include "kdrive.h" #include "inputstr.h" @@ -37,8 +37,6 @@ static DeviceIntPtr pKdKeyboard, pKdPointer; static KdMouseFuncs *kdMouseFuncs; static KdKeyboardFuncs *kdKeyboardFuncs; -static int kdMouseFd = -1; -static int kdKeyboardFd = -1; static unsigned long kdEmulationTimeout; static Bool kdTimeoutPending; static int kdBellPitch; @@ -54,7 +52,6 @@ static KdMouseMatrix kdMouseMatrix = { #ifdef TOUCHSCREEN static KdTsFuncs *kdTsFuncs; -static int kdTsFd = -1; #endif int kdMinScanCode; @@ -78,17 +75,26 @@ CARD8 kdKeyState[KD_KEY_COUNT/8]; #define IsKeyDown(key) ((kdKeyState[(key) >> 3] >> ((key) & 7)) & 1) +#define KD_MAX_INPUT_FDS 8 + +typedef struct _kdInputFd { + int type; + int fd; + void (*read) (int fd, void *closure); + void *closure; +} KdInputFd; + +KdInputFd kdInputFds[KD_MAX_INPUT_FDS]; +int kdNumInputFds; +int kdInputTypeSequence; + void KdSigio (int sig) { -#ifdef TOUCHSCREEN - if (kdTsFd >= 0) - (*kdTsFuncs->Read) (kdTsFd); -#endif - if (kdMouseFd >= 0) - (*kdMouseFuncs->Read) (kdMouseFd); - if (kdKeyboardFd >= 0) - (*kdKeyboardFuncs->Read) (kdKeyboardFd); + int i; + + for (i = 0; i < kdNumInputFds; i++) + (*kdInputFds[i].read) (kdInputFds[i].fd, kdInputFds[i].closure); } void @@ -183,17 +189,56 @@ KdRemoveFd (int fd) } } +int +KdAllocInputType (void) +{ + return ++kdInputTypeSequence; +} + +Bool +KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *closure) +{ + if (kdNumInputFds == KD_MAX_INPUT_FDS) + return FALSE; + kdInputFds[kdNumInputFds].type = type; + kdInputFds[kdNumInputFds].fd = fd; + kdInputFds[kdNumInputFds].read = read; + kdInputFds[kdNumInputFds].closure = closure; + ++kdNumInputFds; + if (kdInputEnabled) + KdAddFd (fd); + return TRUE; +} + +void +KdUnregisterFds (int type, Bool do_close) +{ + int i; + + for (i = 0; i < kdNumInputFds;) + { + if (kdInputFds[i].type == type) + { + if (kdInputEnabled) + KdRemoveFd (kdInputFds[i].fd); + if (do_close) + close (kdInputFds[i].fd); + --kdNumInputFds; + for (; i < kdNumInputFds; i++) + kdInputFds[i] = kdInputFds[i+1]; + } + else + i++; + } +} + void KdDisableInput (void) { -#ifdef TOUCHSCREEN - if (kdTsFd >= 0) - KdRemoveFd (kdTsFd); -#endif - if (kdMouseFd >= 0) - KdRemoveFd (kdMouseFd); - if (kdKeyboardFd >= 0) - KdRemoveFd (kdKeyboardFd); + int i; + + for (i = 0; i < kdNumInputFds; i++) + KdRemoveFd (kdInputFds[i].fd); kdInputEnabled = FALSE; } @@ -201,16 +246,12 @@ void KdEnableInput (void) { xEvent xE; + int i; kdInputEnabled = TRUE; -#ifdef TOUCHSCREEN - if (kdTsFd >= 0) - KdAddFd (kdTsFd); -#endif - if (kdMouseFd >= 0) - KdAddFd (kdMouseFd); - if (kdKeyboardFd >= 0) - KdAddFd (kdKeyboardFd); + for (i = 0; i < kdNumInputFds; i++) + KdAddFd (kdInputFds[i].fd); + /* reset screen saver */ xE.u.keyButtonPointer.time = GetTimeInMillis (); NoticeEventTime (&xE); @@ -241,18 +282,10 @@ KdMouseProc(DeviceIntPtr pDevice, int onoff) pDev->on = TRUE; pKdPointer = pDevice; if (kdMouseFuncs) - { - kdMouseFd = (*kdMouseFuncs->Init) (); - if (kdMouseFd >= 0 && kdInputEnabled) - KdAddFd (kdMouseFd); - } + (*kdMouseFuncs->Init) (); #ifdef TOUCHSCREEN if (kdTsFuncs) - { - kdTsFd = (*kdTsFuncs->Init) (); - if (kdTsFd >= 0 && kdInputEnabled) - KdAddFd (kdTsFd); - } + (*kdTsFuncs->Init) (); #endif break; case DEVICE_OFF: @@ -261,21 +294,11 @@ KdMouseProc(DeviceIntPtr pDevice, int onoff) { pDev->on = FALSE; pKdPointer = 0; - if (kdMouseFd >= 0) - { - if (kdInputEnabled) - KdRemoveFd (kdMouseFd); - (*kdMouseFuncs->Fini) (kdMouseFd); - kdMouseFd = -1; - } + if (kdMouseFuncs) + (*kdMouseFuncs->Fini) (); #ifdef TOUCHSCREEN - if (kdTsFd >= 0) - { - if (kdInputEnabled) - KdRemoveFd (kdTsFd); - (*kdTsFuncs->Fini) (kdTsFd); - kdTsFd = -1; - } + if (kdTsFuncs >= 0) + (*kdTsFuncs->Fini) (); #endif } break; @@ -354,11 +377,7 @@ KdKeybdProc(DeviceIntPtr pDevice, int onoff) pDev->on = TRUE; pKdKeyboard = pDevice; if (kdKeyboardFuncs) - { - kdKeyboardFd = (*kdKeyboardFuncs->Init) (); - if (kdKeyboardFd >= 0 && kdInputEnabled) - KdAddFd (kdKeyboardFd); - } + (*kdKeyboardFuncs->Init) (); break; case DEVICE_OFF: case DEVICE_CLOSE: @@ -366,13 +385,8 @@ KdKeybdProc(DeviceIntPtr pDevice, int onoff) if (pDev->on) { pDev->on = FALSE; - if (kdKeyboardFd >= 0) - { - if (kdInputEnabled) - KdRemoveFd (kdKeyboardFd); - (*kdKeyboardFuncs->Fini) (kdKeyboardFd); - kdKeyboardFd = -1; - } + if (kdKeyboardFuncs) + (*kdKeyboardFuncs->Fini) (); } break; } @@ -1354,29 +1368,17 @@ KdWakeupHandler (int screen, { int result = (int) lresult; fd_set *pReadmask = (fd_set *) readmask; + int i; if (kdInputEnabled && result > 0) { - if (kdMouseFd >= 0 && FD_ISSET (kdMouseFd, pReadmask)) - { - KdBlockSigio (); - (*kdMouseFuncs->Read) (kdMouseFd); - KdUnblockSigio (); - } -#ifdef TOUCHSCREEN - if (kdTsFd >= 0 && FD_ISSET (kdTsFd, pReadmask)) - { - KdBlockSigio (); - (*kdTsFuncs->Read) (kdTsFd); - KdUnblockSigio (); - } -#endif - if (kdKeyboardFd >= 0 && FD_ISSET (kdKeyboardFd, pReadmask)) - { - KdBlockSigio (); - (*kdKeyboardFuncs->Read) (kdKeyboardFd); - KdUnblockSigio (); - } + for (i = 0; i < kdNumInputFds; i++) + if (FD_ISSET (kdInputFds[i].fd, pReadmask)) + { + KdBlockSigio (); + (*kdInputFds[i].read) (kdInputFds[i].fd, kdInputFds[i].closure); + KdUnblockSigio (); + } } if (kdTimeoutPending) {