2000-01-15 15:25:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer as
|
|
|
|
* the first lines of this file unmodified.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-08-24 18:17:24 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-01-15 15:25:43 +00:00
|
|
|
#include "opt_syscons.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/kernel.h>
|
2000-10-08 21:34:00 +00:00
|
|
|
#include <sys/consio.h>
|
2000-10-09 08:08:36 +00:00
|
|
|
#include <sys/mouse.h>
|
2000-01-15 15:25:43 +00:00
|
|
|
|
|
|
|
#include <dev/syscons/syscons.h>
|
|
|
|
|
|
|
|
#ifndef SC_NO_SYSMOUSE
|
|
|
|
|
|
|
|
#define SC_MOUSE 128 /* minor number */
|
|
|
|
|
|
|
|
static d_open_t smopen;
|
|
|
|
static d_close_t smclose;
|
|
|
|
static d_ioctl_t smioctl;
|
|
|
|
|
|
|
|
static struct cdevsw sm_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = smopen,
|
|
|
|
.d_close = smclose,
|
|
|
|
.d_ioctl = smioctl,
|
|
|
|
.d_name = "sysmouse",
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_flags = D_TTY | D_NEEDGIANT,
|
2000-01-15 15:25:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
static struct tty *sysmouse_tty;
|
|
|
|
static int mouse_level; /* sysmouse protocol level */
|
|
|
|
static mousestatus_t mouse_status;
|
|
|
|
|
|
|
|
static void smstart(struct tty *tp);
|
|
|
|
static int smparam(struct tty *tp, struct termios *t);
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
smopen(struct cdev *dev, int flag, int mode, struct thread *td)
|
2000-01-15 15:25:43 +00:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
|
2005-02-27 21:16:26 +00:00
|
|
|
DPRINTF(5, ("smopen: dev:%s, vty:%d\n",
|
|
|
|
devtoname(dev), SC_VTY(dev)));
|
2000-01-15 15:25:43 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (SC_VTY(dev) != SC_MOUSE)
|
|
|
|
return ENXIO;
|
|
|
|
#endif
|
|
|
|
|
2004-10-14 08:58:28 +00:00
|
|
|
tp = dev->si_tty;
|
2000-01-15 15:25:43 +00:00
|
|
|
if (!(tp->t_state & TS_ISOPEN)) {
|
2004-10-18 21:51:27 +00:00
|
|
|
ttyinitmode(tp, 0, 0);
|
2000-01-15 15:25:43 +00:00
|
|
|
smparam(tp, &tp->t_termios);
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_modem(tp, 1);
|
2002-04-01 21:31:13 +00:00
|
|
|
} else if (tp->t_state & TS_XCLUDE && suser(td)) {
|
2000-01-15 15:25:43 +00:00
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
2004-06-04 16:02:56 +00:00
|
|
|
return ttyld_open(tp, dev);
|
2000-01-15 15:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
smclose(struct cdev *dev, int flag, int mode, struct thread *td)
|
2000-01-15 15:25:43 +00:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
tp = dev->si_tty;
|
|
|
|
s = spltty();
|
|
|
|
mouse_level = 0;
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_close(tp, flag);
|
2004-07-15 20:47:41 +00:00
|
|
|
tty_close(tp);
|
2000-01-15 15:25:43 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
smstart(struct tty *tp)
|
|
|
|
{
|
|
|
|
struct clist *rbp;
|
|
|
|
u_char buf[PCBURST];
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
rbp = &tp->t_outq;
|
|
|
|
while (rbp->c_cc)
|
|
|
|
q_to_b(rbp, buf, PCBURST);
|
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
ttwwakeup(tp);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
smparam(struct tty *tp, struct termios *t)
|
|
|
|
{
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = t->c_cflag;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
smioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2000-01-15 15:25:43 +00:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
mousehw_t *hw;
|
|
|
|
mousemode_t *mode;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
tp = dev->si_tty;
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case MOUSE_GETHWINFO: /* get device information */
|
|
|
|
hw = (mousehw_t *)data;
|
|
|
|
hw->buttons = 10; /* XXX unknown */
|
|
|
|
hw->iftype = MOUSE_IF_SYSMOUSE;
|
|
|
|
hw->type = MOUSE_MOUSE;
|
|
|
|
hw->model = MOUSE_MODEL_GENERIC;
|
|
|
|
hw->hwid = 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MOUSE_GETMODE: /* get protocol/mode */
|
|
|
|
mode = (mousemode_t *)data;
|
|
|
|
mode->level = mouse_level;
|
|
|
|
switch (mode->level) {
|
|
|
|
case 0: /* emulate MouseSystems protocol */
|
|
|
|
mode->protocol = MOUSE_PROTO_MSC;
|
|
|
|
mode->rate = -1; /* unknown */
|
|
|
|
mode->resolution = -1; /* unknown */
|
|
|
|
mode->accelfactor = 0; /* disabled */
|
|
|
|
mode->packetsize = MOUSE_MSC_PACKETSIZE;
|
|
|
|
mode->syncmask[0] = MOUSE_MSC_SYNCMASK;
|
|
|
|
mode->syncmask[1] = MOUSE_MSC_SYNC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* sysmouse protocol */
|
|
|
|
mode->protocol = MOUSE_PROTO_SYSMOUSE;
|
|
|
|
mode->rate = -1;
|
|
|
|
mode->resolution = -1;
|
|
|
|
mode->accelfactor = 0;
|
|
|
|
mode->packetsize = MOUSE_SYS_PACKETSIZE;
|
|
|
|
mode->syncmask[0] = MOUSE_SYS_SYNCMASK;
|
|
|
|
mode->syncmask[1] = MOUSE_SYS_SYNC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MOUSE_SETMODE: /* set protocol/mode */
|
|
|
|
mode = (mousemode_t *)data;
|
2000-08-27 12:36:28 +00:00
|
|
|
if (mode->level == -1)
|
|
|
|
; /* don't change the current setting */
|
|
|
|
else if ((mode->level < 0) || (mode->level > 1))
|
2000-01-15 15:25:43 +00:00
|
|
|
return EINVAL;
|
2000-08-27 12:36:28 +00:00
|
|
|
else
|
|
|
|
mouse_level = mode->level;
|
2000-01-15 15:25:43 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MOUSE_GETLEVEL: /* get operation level */
|
|
|
|
*(int *)data = mouse_level;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MOUSE_SETLEVEL: /* set operation level */
|
|
|
|
if ((*(int *)data < 0) || (*(int *)data > 1))
|
|
|
|
return EINVAL;
|
|
|
|
mouse_level = *(int *)data;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MOUSE_GETSTATUS: /* get accumulated mouse events */
|
|
|
|
s = spltty();
|
|
|
|
*(mousestatus_t *)data = mouse_status;
|
|
|
|
mouse_status.flags = 0;
|
|
|
|
mouse_status.obutton = mouse_status.button;
|
|
|
|
mouse_status.dx = 0;
|
|
|
|
mouse_status.dy = 0;
|
|
|
|
mouse_status.dz = 0;
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
|
2005-12-04 02:12:43 +00:00
|
|
|
#ifdef notyet
|
2000-01-15 15:25:43 +00:00
|
|
|
case MOUSE_GETVARS: /* get internal mouse variables */
|
|
|
|
case MOUSE_SETVARS: /* set internal mouse variables */
|
|
|
|
return ENODEV;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case MOUSE_READSTATE: /* read status from the device */
|
|
|
|
case MOUSE_READDATA: /* read data from the device */
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
|
2004-06-01 13:49:28 +00:00
|
|
|
return(ttyioctl(dev, cmd, data, flag, td));
|
2000-01-15 15:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sm_attach_mouse(void *unused)
|
|
|
|
{
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev;
|
2004-10-14 08:58:28 +00:00
|
|
|
struct tty *tp;
|
2000-01-15 15:25:43 +00:00
|
|
|
|
|
|
|
dev = make_dev(&sm_cdevsw, SC_MOUSE, UID_ROOT, GID_WHEEL, 0600,
|
|
|
|
"sysmouse");
|
2004-10-14 08:58:28 +00:00
|
|
|
dev->si_tty = tp = ttyalloc();
|
|
|
|
tp->t_oproc = smstart;
|
|
|
|
tp->t_param = smparam;
|
|
|
|
tp->t_stop = nottystop;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
|
|
|
|
sysmouse_tty = tp;
|
2000-01-15 15:25:43 +00:00
|
|
|
/* sysmouse doesn't have scr_stat */
|
|
|
|
}
|
|
|
|
|
2004-02-21 19:42:58 +00:00
|
|
|
SYSINIT(sysmouse, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sm_attach_mouse, NULL)
|
2000-01-15 15:25:43 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
sysmouse_event(mouse_info_t *info)
|
|
|
|
{
|
|
|
|
/* MOUSE_BUTTON?DOWN -> MOUSE_MSC_BUTTON?UP */
|
|
|
|
static int butmap[8] = {
|
|
|
|
MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
|
|
|
|
MOUSE_MSC_BUTTON2UP | MOUSE_MSC_BUTTON3UP,
|
|
|
|
MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON3UP,
|
|
|
|
MOUSE_MSC_BUTTON3UP,
|
|
|
|
MOUSE_MSC_BUTTON1UP | MOUSE_MSC_BUTTON2UP,
|
|
|
|
MOUSE_MSC_BUTTON2UP,
|
|
|
|
MOUSE_MSC_BUTTON1UP,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
u_char buf[8];
|
|
|
|
int x, y, z;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (info->operation) {
|
|
|
|
case MOUSE_ACTION:
|
|
|
|
mouse_status.button = info->u.data.buttons;
|
|
|
|
/* FALL THROUGH */
|
|
|
|
case MOUSE_MOTION_EVENT:
|
|
|
|
x = info->u.data.x;
|
|
|
|
y = info->u.data.y;
|
|
|
|
z = info->u.data.z;
|
|
|
|
break;
|
|
|
|
case MOUSE_BUTTON_EVENT:
|
|
|
|
x = y = z = 0;
|
|
|
|
if (info->u.event.value > 0)
|
|
|
|
mouse_status.button |= info->u.event.id;
|
|
|
|
else
|
|
|
|
mouse_status.button &= ~info->u.event.id;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mouse_status.dx += x;
|
|
|
|
mouse_status.dy += y;
|
|
|
|
mouse_status.dz += z;
|
|
|
|
mouse_status.flags |= ((x || y || z) ? MOUSE_POSCHANGED : 0)
|
|
|
|
| (mouse_status.obutton ^ mouse_status.button);
|
|
|
|
if (mouse_status.flags == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((sysmouse_tty == NULL) || !(sysmouse_tty->t_state & TS_ISOPEN))
|
|
|
|
return mouse_status.flags;
|
|
|
|
|
|
|
|
/* the first five bytes are compatible with MouseSystems' */
|
|
|
|
buf[0] = MOUSE_MSC_SYNC
|
|
|
|
| butmap[mouse_status.button & MOUSE_STDBUTTONS];
|
|
|
|
x = imax(imin(x, 255), -256);
|
|
|
|
buf[1] = x >> 1;
|
|
|
|
buf[3] = x - buf[1];
|
|
|
|
y = -imax(imin(y, 255), -256);
|
|
|
|
buf[2] = y >> 1;
|
|
|
|
buf[4] = y - buf[2];
|
|
|
|
for (i = 0; i < MOUSE_MSC_PACKETSIZE; ++i)
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_rint(sysmouse_tty, buf[i]);
|
2000-01-15 15:25:43 +00:00
|
|
|
if (mouse_level >= 1) {
|
|
|
|
/* extended part */
|
|
|
|
z = imax(imin(z, 127), -128);
|
|
|
|
buf[5] = (z >> 1) & 0x7f;
|
|
|
|
buf[6] = (z - (z >> 1)) & 0x7f;
|
|
|
|
/* buttons 4-10 */
|
|
|
|
buf[7] = (~mouse_status.button >> 3) & 0x7f;
|
|
|
|
for (i = MOUSE_MSC_PACKETSIZE; i < MOUSE_SYS_PACKETSIZE; ++i)
|
2004-06-04 20:04:52 +00:00
|
|
|
ttyld_rint(sysmouse_tty, buf[i]);
|
2000-01-15 15:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mouse_status.flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !SC_NO_SYSMOUSE */
|