2007-12-23 07:28:10 -07:00
|
|
|
/* $OpenBSD: mouse.c,v 1.5 2007/12/23 14:28:10 matthieu Exp $ */
|
2007-05-25 09:33:32 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Matthieu Herrb <matthieu@openbsd.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <kdrive-config.h>
|
|
|
|
#endif
|
|
|
|
#define NEED_EVENTS
|
|
|
|
#include <errno.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
2007-05-25 13:10:43 -06:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
|
2007-05-25 09:33:32 -06:00
|
|
|
#include "inputstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "kdrive.h"
|
|
|
|
|
2007-05-26 23:17:06 -06:00
|
|
|
#define DBG(x) ErrorF x
|
|
|
|
|
2007-05-25 13:10:43 -06:00
|
|
|
#define NUMEVENTS 64
|
|
|
|
|
|
|
|
static unsigned long kdbuttons[] = {
|
|
|
|
KD_BUTTON_1,
|
|
|
|
KD_BUTTON_2,
|
|
|
|
KD_BUTTON_3
|
|
|
|
};
|
|
|
|
|
2007-05-25 09:33:32 -06:00
|
|
|
static void
|
2007-05-26 23:17:06 -06:00
|
|
|
wsmouseRead(int mousePort, void *closure)
|
2007-05-25 09:33:32 -06:00
|
|
|
{
|
2007-12-23 07:28:10 -07:00
|
|
|
KdPointerInfo *pi = closure;
|
2007-05-25 13:10:43 -06:00
|
|
|
static struct wscons_event eventList[NUMEVENTS];
|
|
|
|
struct wscons_event *event = eventList;
|
|
|
|
int n;
|
2007-05-25 09:33:32 -06:00
|
|
|
|
2007-05-25 13:10:43 -06:00
|
|
|
n = read(mousePort, &eventList,
|
|
|
|
NUMEVENTS * sizeof(struct wscons_event));
|
|
|
|
if (n <= 0)
|
|
|
|
return;
|
|
|
|
n /= sizeof(struct wscons_event);
|
|
|
|
while (n--) {
|
|
|
|
int dx = 0, dy = 0;
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
|
|
|
switch(event->type) {
|
|
|
|
case WSCONS_EVENT_MOUSE_UP:
|
|
|
|
flags &= ~kdbuttons[event->value];
|
|
|
|
break;
|
|
|
|
case WSCONS_EVENT_MOUSE_DOWN:
|
|
|
|
flags |= kdbuttons[1<<event->value];
|
|
|
|
break;
|
|
|
|
case WSCONS_EVENT_MOUSE_DELTA_X:
|
|
|
|
dx = event->value;
|
|
|
|
flags |= KD_MOUSE_DELTA;
|
|
|
|
break;
|
|
|
|
case WSCONS_EVENT_MOUSE_DELTA_Y:
|
|
|
|
dy = event->value;
|
|
|
|
flags |= KD_MOUSE_DELTA;
|
|
|
|
break;
|
|
|
|
case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
|
|
|
|
dx = event->value;
|
|
|
|
break;
|
|
|
|
case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
|
|
|
|
dy = event->value;
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-26 23:17:06 -06:00
|
|
|
ErrorF("wsmouseRead: bad wsmouse event type=%d\n",
|
2007-05-25 13:10:43 -06:00
|
|
|
event->type);
|
|
|
|
continue;
|
|
|
|
} /* case */
|
2007-12-23 07:28:10 -07:00
|
|
|
KdEnqueuePointerEvent(pi, flags, dx, dy, 0);
|
2007-05-25 13:10:43 -06:00
|
|
|
}
|
2007-05-25 09:33:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int MouseInputType;
|
|
|
|
|
2007-12-23 07:28:10 -07:00
|
|
|
static Status
|
|
|
|
wsmouseInit(KdPointerInfo *pi)
|
2007-05-25 09:33:32 -06:00
|
|
|
{
|
2007-05-25 13:10:43 -06:00
|
|
|
char *device = "/dev/wsmouse";
|
|
|
|
|
2007-05-26 23:17:06 -06:00
|
|
|
DBG(("wsmouseInit\n"));
|
|
|
|
|
2007-12-23 07:28:10 -07:00
|
|
|
if (pi->path == NULL)
|
|
|
|
pi->path = KdSaveString(device);
|
2007-05-25 09:33:32 -06:00
|
|
|
|
2007-12-23 07:28:10 -07:00
|
|
|
if (pi->name == NULL)
|
|
|
|
pi->name = KdSaveString("Wscons mouse");
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Status
|
|
|
|
wsmouseEnable(KdPointerInfo *pi)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
DBG(("wsmouseEnable\n"));
|
|
|
|
|
|
|
|
if (pi == NULL || pi->driverPrivate == NULL || pi->path == NULL)
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
|
|
fd = open(pi->path, O_RDWR | O_NONBLOCK);
|
|
|
|
if (fd < 0)
|
|
|
|
return BadMatch;
|
|
|
|
|
|
|
|
if (!KdRegisterFd(fd, wsmouseRead, pi)) {
|
|
|
|
close(fd);
|
|
|
|
return BadAlloc;
|
2007-05-25 13:10:43 -06:00
|
|
|
}
|
2007-12-23 07:28:10 -07:00
|
|
|
pi->driverPrivate = (void *)fd;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wsmouseDisable(KdPointerInfo *pi)
|
|
|
|
{
|
|
|
|
DBG(("wsmouseDisable\n"));
|
|
|
|
KdUnregisterFd(pi, (int)pi->driverPrivate, TRUE);
|
2007-05-25 09:33:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-23 07:28:10 -07:00
|
|
|
wsmouseFini(KdPointerInfo *pi)
|
2007-05-25 09:33:32 -06:00
|
|
|
{
|
2007-05-26 23:17:06 -06:00
|
|
|
DBG(("wsmouseFini\n"));
|
2007-05-25 09:33:32 -06:00
|
|
|
}
|
|
|
|
|
2007-12-23 07:28:10 -07:00
|
|
|
KdPointerDriver WsconsMouseDriver = {
|
|
|
|
"mouse",
|
2007-05-26 23:17:06 -06:00
|
|
|
wsmouseInit,
|
2007-12-23 07:28:10 -07:00
|
|
|
wsmouseEnable,
|
|
|
|
wsmouseDisable,
|
|
|
|
wsmouseFini,
|
|
|
|
NULL,
|
2007-05-25 09:33:32 -06:00
|
|
|
};
|