diff --git a/xserver/hw/kdrive/wscons/keyboard.c b/xserver/hw/kdrive/wscons/keyboard.c index eed8c4e02..487ee005f 100644 --- a/xserver/hw/kdrive/wscons/keyboard.c +++ b/xserver/hw/kdrive/wscons/keyboard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyboard.c,v 1.2 2007/05/25 19:10:43 matthieu Exp $ */ +/* $OpenBSD: keyboard.c,v 1.3 2007/05/27 05:17:06 matthieu Exp $ */ /* * Copyright (c) 2007 Matthieu Herrb * @@ -25,88 +25,118 @@ #include #include +#define DBG(x) ErrorF x + extern int WsconsConsoleFd; static int WsconsKbdType; static void -WsconsKeyboardLoad(void) +wskbdLoad(void) { + DBG(("wskbdLoad\n")); + /* Read kernel Mapping */ } +#define NUM_EVENTS 64 + static void -WsconsKeyboardRead(int fd, void *closure) +wskbdRead(int fd, void *closure) { + struct wscons_event events[NUM_EVENTS]; + int i, n, type; unsigned char b; - /* read and enqueue events */ - KdEnqueueKeyboardEvent(b & 0x7f, b & 0x80); + DBG(("wskbdRead\n")); + if ((n = read(WsconsConsoleFd, events, sizeof(events))) > 0) { + n /= sizeof(struct wscons_event); + for (i = 0; i < n; i++) { + type = events[i].type; + if (type == WSCONS_EVENT_KEY_UP || + type == WSCONS_EVENT_KEY_DOWN) { + + KdEnqueueKeyboardEvent(events[i].value, + type == WSCONS_EVENT_KEY_DOWN ? + TRUE : FALSE); + } + } /* for */ + } } static int -WsconsKeyboardEnable(int fd, void *closure) +wskbdEnable(int fd, void *closure) { int option = WSKBD_RAW; + DBG(("wskbdEnable\n")); /* Switch to X mode */ if (ioctl(fd, WSKBDIO_SETMODE, &option) == -1) { - ErrorF("WsconsKeyboardEnable: WSKBDIO_SETMODE: %d\n", errno); + ErrorF("wskbdEnable: WSKBDIO_SETMODE: %d\n", errno); return -1; } return fd; } static void -WsconsKeyboardDisable(int fd, void *closure) +wskbdDisable(int fd, void *closure) { int option = WSKBD_TRANSLATED; + DBG(("wskbdDisable\n")); /* Back to console mode */ ioctl(fd, WSKBDIO_SETMODE, &option); } static int -WsconsKeyboardInit(void) +wskbdInit(void) { + DBG(("wskbdInit\n")); if (!WsconsKbdType) WsconsKbdType = KdAllocInputType(); - KdRegisterFd(WsconsKbdType, WsconsConsoleFd, WsconsKeyboardRead, 0); - WsconsKeyboardEnable(WsconsConsoleFd, 0); + KdRegisterFd(WsconsKbdType, WsconsConsoleFd, wskbdRead, 0); + wskbdEnable(WsconsConsoleFd, 0); KdRegisterFdEnableDisable(WsconsConsoleFd, - WsconsKeyboardEnable, WsconsKeyboardDisable); + wskbdEnable, wskbdDisable); return 1; } static void -WsconsKeyboardFini(void) +wskbdFini(void) { - WsconsKeyboardDisable(WsconsConsoleFd, 0); + DBG(("wskbdFini\n")); + wskbdDisable(WsconsConsoleFd, 0); KdUnregisterFds(WsconsKbdType, FALSE); } static void -WsconsKeyboardLeds(int leds) +wskbdLeds(int leds) { - ioctl(WsconsConsoleFd, WSKBDIO_SETLEDS, &leds); + DBG(("wskbdLeds %d\n", leds)); + if (ioctl(WsconsConsoleFd, WSKBDIO_SETLEDS, &leds) == -1) + ErrorF("wskbd WSKBDIO_SETLEDS: %s\n", + strerror(errno)); } static void -WsconsKeyboardBell(int volume, int pitch, int duration) +wskbdBell(int volume, int pitch, int duration) { struct wskbd_bell_data wsb; + DBG(("wskbdBell volume %d pictch %d duration %d\n", + volume, pitch, duration)); wsb.which = WSKBD_BELL_DOALL; wsb.pitch = pitch; wsb.period = duration; wsb.volume = volume; - ioctl(WsconsConsoleFd, WSKBDIO_COMPLEXBELL, &wsb); + if (ioctl(WsconsConsoleFd, WSKBDIO_COMPLEXBELL, &wsb) == -1) + ErrorF("WsconsKeyboardBell: %s\n", strerror(errno)); } KdKeyboardFuncs WsconsKeyboardFuncs = { - WsconsKeyboardLoad, - WsconsKeyboardInit, - WsconsKeyboardLeds, - WsconsKeyboardBell, - WsconsKeyboardFini, + wskbdLoad, + wskbdInit, + wskbdLeds, + wskbdBell, + wskbdFini, 3, }; diff --git a/xserver/hw/kdrive/wscons/mouse.c b/xserver/hw/kdrive/wscons/mouse.c index 647a0aac3..750566dcc 100644 --- a/xserver/hw/kdrive/wscons/mouse.c +++ b/xserver/hw/kdrive/wscons/mouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mouse.c,v 1.3 2007/05/27 00:55:09 matthieu Exp $ */ +/* $OpenBSD: mouse.c,v 1.4 2007/05/27 05:17:06 matthieu Exp $ */ /* * Copyright (c) 2007 Matthieu Herrb * @@ -29,6 +29,8 @@ #include "scrnintstr.h" #include "kdrive.h" +#define DBG(x) ErrorF x + #define NUMEVENTS 64 static unsigned long kdbuttons[] = { @@ -38,7 +40,7 @@ static unsigned long kdbuttons[] = { }; static void -MouseRead(int mousePort, void *closure) +wsmouseRead(int mousePort, void *closure) { static struct wscons_event eventList[NUMEVENTS]; struct wscons_event *event = eventList; @@ -75,7 +77,7 @@ MouseRead(int mousePort, void *closure) dy = event->value; break; default: - ErrorF("MouseRead: bad wsmouse event type=%d\n", + ErrorF("wsmouseRead: bad wsmouse event type=%d\n", event->type); continue; } /* case */ @@ -86,31 +88,34 @@ MouseRead(int mousePort, void *closure) int MouseInputType; static Bool -MouseInit(void) +wsmouseInit(void) { char *device = "/dev/wsmouse"; int port; + DBG(("wsmouseInit\n")); + if (!MouseInputType) MouseInputType = KdAllocInputType(); port = open(device, O_RDWR | O_NONBLOCK); if (port == -1) { - ErrorF("MouseInit: couldn't open %s (%d)\n", device, errno); + ErrorF("wsmouseInit: couldn't open %s (%d)\n", device, errno); return FALSE; } - return KdRegisterFd(MouseInputType, port, MouseRead, NULL); + return KdRegisterFd(MouseInputType, port, wsmouseRead, NULL); } static void -MouseFini(void) +wsmouseFini(void) { KdMouseInfo *mi; - + + DBG(("wsmouseFini\n")); KdUnregisterFds(MouseInputType, TRUE); } KdMouseFuncs WsconsMouseFuncs = { - MouseInit, - MouseFini + wsmouseInit, + wsmouseFini };