From 5f310d7f8b566b1e331286752d349f87ef43a811 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 29 Sep 2001 04:16:39 +0000 Subject: kdrive: restructure APM/VT switch support to reset keyboard state and flush buffer on APM resume --- hw/kdrive/linux/Imakefile | 6 ++--- hw/kdrive/linux/keyboard.c | 46 +++++++++++++++++++++++++--------- hw/kdrive/src/kdrive.c | 62 ++++++++++++++++------------------------------ hw/kdrive/src/kinput.c | 30 +++++++++++++++++++++- 4 files changed, 88 insertions(+), 56 deletions(-) diff --git a/hw/kdrive/linux/Imakefile b/hw/kdrive/linux/Imakefile index 2bc47c1e3..51ff075d8 100644 --- a/hw/kdrive/linux/Imakefile +++ b/hw/kdrive/linux/Imakefile @@ -1,5 +1,5 @@ XCOMM $XConsortium: Imakefile /main/10 1996/12/02 10:20:33 lehors $ -XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/linux/Imakefile,v 1.5 2001/03/30 02:15:20 keithp Exp $ +XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/linux/Imakefile,v 1.6 2001/08/09 20:45:15 dawes Exp $ KDRIVE=.. #include "../Kdrive.tmpl" @@ -8,9 +8,9 @@ TSSRCS = ts.c TSOBJS = ts.o #endif -SRCS = keyboard.c linux.c ps2.c ms.c bus.c agp.c $(TSSRCS) +SRCS = keyboard.c linux.c ps2.c ms.c bus.c agp.c $(TSSRCS) -OBJS = keyboard.o linux.o ps2.o ms.o bus.o agp.o $(TSOBJS) +OBJS = keyboard.o linux.o ps2.o ms.o bus.o agp.o $(TSOBJS) INCLUDES = -I. $(KDINCS) diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c index 51e3c4e34..12486adc5 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.6 2001/03/30 02:15:20 keithp Exp $ + * $XFree86: xc/programs/Xserver/hw/kdrive/linux/keyboard.c,v 1.7 2001/06/29 14:00:41 keithp Exp $ * * Copyright © 1999 Keith Packard * @@ -397,18 +397,17 @@ static int LinuxKbdTrans; static struct termios LinuxTermios; static int LinuxKbdType; -int -LinuxKeyboardInit (void) +void +LinuxKeyboardEnable (int fd, void *closure) { struct termios nTty; + unsigned char buf[256]; + int n; - if (!LinuxKbdType) - LinuxKbdType = KdAllocInputType (); - - ioctl (LinuxConsoleFd, KDGKBMODE, &LinuxKbdTrans); - tcgetattr (LinuxConsoleFd, &LinuxTermios); + ioctl (fd, KDGKBMODE, &LinuxKbdTrans); + tcgetattr (fd, &LinuxTermios); - ioctl(LinuxConsoleFd, KDSKBMODE, K_MEDIUMRAW); + ioctl(fd, KDSKBMODE, K_MEDIUMRAW); nTty = LinuxTermios; nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); nTty.c_oflag = 0; @@ -418,16 +417,39 @@ LinuxKeyboardInit (void) nTty.c_cc[VMIN]=1; cfsetispeed(&nTty, 9600); cfsetospeed(&nTty, 9600); - tcsetattr(LinuxConsoleFd, TCSANOW, &nTty); + tcsetattr(fd, TCSANOW, &nTty); + /* + * Flush any pending keystrokes + */ + while ((n = read (fd, buf, sizeof (buf))) > 0) + ; +} + +void +LinuxKeyboardDisable (int fd, void *closure) +{ + ioctl(LinuxConsoleFd, KDSKBMODE, LinuxKbdTrans); + tcsetattr(LinuxConsoleFd, TCSANOW, &LinuxTermios); +} + +int +LinuxKeyboardInit (void) +{ + if (!LinuxKbdType) + LinuxKbdType = KdAllocInputType (); + + LinuxKeyboardEnable (LinuxConsoleFd, 0); KdRegisterFd (LinuxKbdType, LinuxConsoleFd, LinuxKeyboardRead, 0); + KdRegisterFdEnableDisable (LinuxConsoleFd, + LinuxKeyboardEnable, + LinuxKeyboardDisable); return 1; } void LinuxKeyboardFini (void) { - ioctl(LinuxConsoleFd, KDSKBMODE, LinuxKbdTrans); - tcsetattr(LinuxConsoleFd, TCSANOW, &LinuxTermios); + LinuxKeyboardDisable (LinuxConsoleFd, 0); KdUnregisterFds (LinuxKbdType, FALSE); } diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index 0693367d4..3e1aa84ff 100644 --- a/hw/kdrive/src/kdrive.c +++ b/hw/kdrive/src/kdrive.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/kdrive.c,v 1.18 2001/07/20 19:35:29 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kdrive.c,v 1.19 2001/07/24 21:26:17 keithp Exp $ */ #include "kdrive.h" #ifdef PSEUDO8 @@ -211,28 +211,6 @@ KdDisableScreen (ScreenPtr pScreen) (*pScreenPriv->card->cfuncs->disable) (pScreen); } -void -KdDisableScreens (void) -{ - KdCardInfo *card; - KdScreenInfo *screen; - - if (kdEnabled) - { - kdEnabled = FALSE; - for (card = kdCardInfo; card; card = card->next) - { - for (screen = card->screenList; screen; screen = screen->next) - if (screen->mynum == card->selected && screen->pScreen) - KdDisableScreen (screen->pScreen); - if (card->driver) - (*card->cfuncs->restore) (card); - } - (*kdOsFuncs->Disable) (); - KdDisableInput (); - } -} - void KdSuspend (void) { @@ -254,21 +232,13 @@ KdSuspend (void) } void -KdResume (void) +KdDisableScreens (void) { - KdCardInfo *card; - KdScreenInfo *screen; - + KdSuspend (); if (kdEnabled) { - for (card = kdCardInfo; card; card = card->next) - { - (*card->cfuncs->preserve) (card); - for (screen = card->screenList; screen; screen = screen->next) - if (screen->mynum == card->selected && screen->pScreen) - KdEnableScreen (screen->pScreen); - } - KdEnableInput (); + (*kdOsFuncs->Disable) (); + kdEnabled = FALSE; } } @@ -295,15 +265,13 @@ KdEnableScreen (ScreenPtr pScreen) } void -KdEnableScreens (void) +KdResume (void) { KdCardInfo *card; KdScreenInfo *screen; - if (!kdEnabled) + if (kdEnabled) { - kdEnabled = TRUE; - (*kdOsFuncs->Enable) (); for (card = kdCardInfo; card; card = card->next) { (*card->cfuncs->preserve) (card); @@ -312,9 +280,24 @@ KdEnableScreens (void) KdEnableScreen (screen->pScreen); } KdEnableInput (); + KdReleaseAllKeys (); } } +void +KdEnableScreens (void) +{ + KdCardInfo *card; + KdScreenInfo *screen; + + if (!kdEnabled) + { + kdEnabled = TRUE; + (*kdOsFuncs->Enable) (); + } + KdResume (); +} + void KdProcessSwitch (void) { @@ -322,7 +305,6 @@ KdProcessSwitch (void) KdDisableScreens (); else { - KdReleaseAllKeys (); KdEnableScreens (); } } diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index 1d96173a4..d683e39fc 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.19 2001/07/20 19:35:29 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/kdrive/kinput.c,v 1.20 2001/08/09 09:06:08 keithp Exp $ */ #include "kdrive.h" #include "inputstr.h" @@ -81,6 +81,8 @@ typedef struct _kdInputFd { int type; int fd; void (*read) (int fd, void *closure); + void (*enable) (int fd, void *closure); + void (*disable) (int fd, void *closure); void *closure; } KdInputFd; @@ -203,6 +205,8 @@ KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *clos kdInputFds[kdNumInputFds].type = type; kdInputFds[kdNumInputFds].fd = fd; kdInputFds[kdNumInputFds].read = read; + kdInputFds[kdNumInputFds].enable = 0; + kdInputFds[kdNumInputFds].disable = 0; kdInputFds[kdNumInputFds].closure = closure; ++kdNumInputFds; if (kdInputEnabled) @@ -210,6 +214,22 @@ KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *clos return TRUE; } +void +KdRegisterFdEnableDisable (int fd, + void (*enable) (int fd, void *closure), + void (*disable) (int fd, void *closure)) +{ + int i; + + for (i = 0; i < kdNumInputFds; i++) + if (kdInputFds[i].fd == fd) + { + kdInputFds[i].enable = enable; + kdInputFds[i].disable = disable; + break; + } +} + void KdUnregisterFds (int type, Bool do_close) { @@ -238,7 +258,11 @@ KdDisableInput (void) int i; for (i = 0; i < kdNumInputFds; i++) + { KdRemoveFd (kdInputFds[i].fd); + if (kdInputFds[i].disable) + (*kdInputFds[i].disable) (kdInputFds[i].fd, kdInputFds[i].closure); + } kdInputEnabled = FALSE; } @@ -250,7 +274,11 @@ KdEnableInput (void) kdInputEnabled = TRUE; for (i = 0; i < kdNumInputFds; i++) + { KdAddFd (kdInputFds[i].fd); + if (kdInputFds[i].enable) + (*kdInputFds[i].enable) (kdInputFds[i].fd, kdInputFds[i].closure); + } /* reset screen saver */ xE.u.keyButtonPointer.time = GetTimeInMillis (); -- cgit v1.2.3