- rename some functions for consistancy
- fill more code
This commit is contained in:
parent
871e6b9af8
commit
255c61fb6a
@ -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 <matthieu@openbsd.org>
|
* Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org>
|
||||||
*
|
*
|
||||||
@ -25,88 +25,118 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dev/wscons/wsconsio.h>
|
#include <dev/wscons/wsconsio.h>
|
||||||
|
|
||||||
|
#define DBG(x) ErrorF x
|
||||||
|
|
||||||
extern int WsconsConsoleFd;
|
extern int WsconsConsoleFd;
|
||||||
static int WsconsKbdType;
|
static int WsconsKbdType;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
WsconsKeyboardLoad(void)
|
wskbdLoad(void)
|
||||||
{
|
{
|
||||||
|
DBG(("wskbdLoad\n"));
|
||||||
|
|
||||||
/* Read kernel Mapping */
|
/* Read kernel Mapping */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NUM_EVENTS 64
|
||||||
|
|
||||||
static void
|
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;
|
unsigned char b;
|
||||||
|
|
||||||
/* read and enqueue events */
|
DBG(("wskbdRead\n"));
|
||||||
KdEnqueueKeyboardEvent(b & 0x7f, b & 0x80);
|
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
|
static int
|
||||||
WsconsKeyboardEnable(int fd, void *closure)
|
wskbdEnable(int fd, void *closure)
|
||||||
{
|
{
|
||||||
int option = WSKBD_RAW;
|
int option = WSKBD_RAW;
|
||||||
|
|
||||||
|
DBG(("wskbdEnable\n"));
|
||||||
/* Switch to X mode */
|
/* Switch to X mode */
|
||||||
if (ioctl(fd, WSKBDIO_SETMODE, &option) == -1) {
|
if (ioctl(fd, WSKBDIO_SETMODE, &option) == -1) {
|
||||||
ErrorF("WsconsKeyboardEnable: WSKBDIO_SETMODE: %d\n", errno);
|
ErrorF("wskbdEnable: WSKBDIO_SETMODE: %d\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
WsconsKeyboardDisable(int fd, void *closure)
|
wskbdDisable(int fd, void *closure)
|
||||||
{
|
{
|
||||||
int option = WSKBD_TRANSLATED;
|
int option = WSKBD_TRANSLATED;
|
||||||
|
|
||||||
|
DBG(("wskbdDisable\n"));
|
||||||
/* Back to console mode */
|
/* Back to console mode */
|
||||||
ioctl(fd, WSKBDIO_SETMODE, &option);
|
ioctl(fd, WSKBDIO_SETMODE, &option);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
WsconsKeyboardInit(void)
|
wskbdInit(void)
|
||||||
{
|
{
|
||||||
|
DBG(("wskbdInit\n"));
|
||||||
if (!WsconsKbdType)
|
if (!WsconsKbdType)
|
||||||
WsconsKbdType = KdAllocInputType();
|
WsconsKbdType = KdAllocInputType();
|
||||||
KdRegisterFd(WsconsKbdType, WsconsConsoleFd, WsconsKeyboardRead, 0);
|
KdRegisterFd(WsconsKbdType, WsconsConsoleFd, wskbdRead, 0);
|
||||||
WsconsKeyboardEnable(WsconsConsoleFd, 0);
|
wskbdEnable(WsconsConsoleFd, 0);
|
||||||
KdRegisterFdEnableDisable(WsconsConsoleFd,
|
KdRegisterFdEnableDisable(WsconsConsoleFd,
|
||||||
WsconsKeyboardEnable, WsconsKeyboardDisable);
|
wskbdEnable, wskbdDisable);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
WsconsKeyboardFini(void)
|
wskbdFini(void)
|
||||||
{
|
{
|
||||||
WsconsKeyboardDisable(WsconsConsoleFd, 0);
|
DBG(("wskbdFini\n"));
|
||||||
|
wskbdDisable(WsconsConsoleFd, 0);
|
||||||
KdUnregisterFds(WsconsKbdType, FALSE);
|
KdUnregisterFds(WsconsKbdType, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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
|
static void
|
||||||
WsconsKeyboardBell(int volume, int pitch, int duration)
|
wskbdBell(int volume, int pitch, int duration)
|
||||||
{
|
{
|
||||||
struct wskbd_bell_data wsb;
|
struct wskbd_bell_data wsb;
|
||||||
|
|
||||||
|
DBG(("wskbdBell volume %d pictch %d duration %d\n",
|
||||||
|
volume, pitch, duration));
|
||||||
wsb.which = WSKBD_BELL_DOALL;
|
wsb.which = WSKBD_BELL_DOALL;
|
||||||
wsb.pitch = pitch;
|
wsb.pitch = pitch;
|
||||||
wsb.period = duration;
|
wsb.period = duration;
|
||||||
wsb.volume = volume;
|
wsb.volume = volume;
|
||||||
ioctl(WsconsConsoleFd, WSKBDIO_COMPLEXBELL, &wsb);
|
if (ioctl(WsconsConsoleFd, WSKBDIO_COMPLEXBELL, &wsb) == -1)
|
||||||
|
ErrorF("WsconsKeyboardBell: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
KdKeyboardFuncs WsconsKeyboardFuncs = {
|
KdKeyboardFuncs WsconsKeyboardFuncs = {
|
||||||
WsconsKeyboardLoad,
|
wskbdLoad,
|
||||||
WsconsKeyboardInit,
|
wskbdInit,
|
||||||
WsconsKeyboardLeds,
|
wskbdLeds,
|
||||||
WsconsKeyboardBell,
|
wskbdBell,
|
||||||
WsconsKeyboardFini,
|
wskbdFini,
|
||||||
3,
|
3,
|
||||||
};
|
};
|
||||||
|
@ -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 <matthieu@openbsd.org>
|
* Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org>
|
||||||
*
|
*
|
||||||
@ -29,6 +29,8 @@
|
|||||||
#include "scrnintstr.h"
|
#include "scrnintstr.h"
|
||||||
#include "kdrive.h"
|
#include "kdrive.h"
|
||||||
|
|
||||||
|
#define DBG(x) ErrorF x
|
||||||
|
|
||||||
#define NUMEVENTS 64
|
#define NUMEVENTS 64
|
||||||
|
|
||||||
static unsigned long kdbuttons[] = {
|
static unsigned long kdbuttons[] = {
|
||||||
@ -38,7 +40,7 @@ static unsigned long kdbuttons[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
MouseRead(int mousePort, void *closure)
|
wsmouseRead(int mousePort, void *closure)
|
||||||
{
|
{
|
||||||
static struct wscons_event eventList[NUMEVENTS];
|
static struct wscons_event eventList[NUMEVENTS];
|
||||||
struct wscons_event *event = eventList;
|
struct wscons_event *event = eventList;
|
||||||
@ -75,7 +77,7 @@ MouseRead(int mousePort, void *closure)
|
|||||||
dy = event->value;
|
dy = event->value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ErrorF("MouseRead: bad wsmouse event type=%d\n",
|
ErrorF("wsmouseRead: bad wsmouse event type=%d\n",
|
||||||
event->type);
|
event->type);
|
||||||
continue;
|
continue;
|
||||||
} /* case */
|
} /* case */
|
||||||
@ -86,31 +88,34 @@ MouseRead(int mousePort, void *closure)
|
|||||||
int MouseInputType;
|
int MouseInputType;
|
||||||
|
|
||||||
static Bool
|
static Bool
|
||||||
MouseInit(void)
|
wsmouseInit(void)
|
||||||
{
|
{
|
||||||
char *device = "/dev/wsmouse";
|
char *device = "/dev/wsmouse";
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
|
DBG(("wsmouseInit\n"));
|
||||||
|
|
||||||
if (!MouseInputType)
|
if (!MouseInputType)
|
||||||
MouseInputType = KdAllocInputType();
|
MouseInputType = KdAllocInputType();
|
||||||
|
|
||||||
port = open(device, O_RDWR | O_NONBLOCK);
|
port = open(device, O_RDWR | O_NONBLOCK);
|
||||||
if (port == -1) {
|
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 FALSE;
|
||||||
}
|
}
|
||||||
return KdRegisterFd(MouseInputType, port, MouseRead, NULL);
|
return KdRegisterFd(MouseInputType, port, wsmouseRead, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
MouseFini(void)
|
wsmouseFini(void)
|
||||||
{
|
{
|
||||||
KdMouseInfo *mi;
|
KdMouseInfo *mi;
|
||||||
|
|
||||||
|
DBG(("wsmouseFini\n"));
|
||||||
KdUnregisterFds(MouseInputType, TRUE);
|
KdUnregisterFds(MouseInputType, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
KdMouseFuncs WsconsMouseFuncs = {
|
KdMouseFuncs WsconsMouseFuncs = {
|
||||||
MouseInit,
|
wsmouseInit,
|
||||||
MouseFini
|
wsmouseFini
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user