Misc KNF and cleanup for readability.
This commit is contained in:
parent
33bbb384fc
commit
dca853ba03
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ms.c,v 1.26 2014/07/25 08:10:32 dholland Exp $ */
|
||||
/* $NetBSD: ms.c,v 1.27 2022/06/26 06:02:28 tsutsui Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Leo Weppelman.
|
||||
|
@ -52,7 +52,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.26 2014/07/25 08:10:32 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2022/06/26 06:02:28 tsutsui Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
|
@ -79,9 +79,9 @@ __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.26 2014/07/25 08:10:32 dholland Exp $");
|
|||
#define NMOUSE 1
|
||||
#endif
|
||||
|
||||
typedef void (*FPV)(void *);
|
||||
typedef void (*FPV)(void *);
|
||||
|
||||
static struct ms_softc ms_softc[NMOUSE];
|
||||
static struct ms_softc ms_softc[NMOUSE];
|
||||
|
||||
dev_type_open(msopen);
|
||||
dev_type_close(msclose);
|
||||
|
@ -105,45 +105,47 @@ const struct cdevsw ms_cdevsw = {
|
|||
.d_flag = 0
|
||||
};
|
||||
|
||||
static void ms_3b_delay(struct ms_softc *);
|
||||
static void ms_3b_delay(struct ms_softc *);
|
||||
|
||||
int
|
||||
mouseattach(int cnt)
|
||||
{
|
||||
|
||||
printf("1 mouse configured\n");
|
||||
ms_softc[0].ms_emul3b = 1;
|
||||
callout_init(&ms_softc[0].ms_delay_ch, 0);
|
||||
return(NMOUSE);
|
||||
|
||||
return NMOUSE;
|
||||
}
|
||||
|
||||
static void
|
||||
ms_3b_delay(struct ms_softc *ms)
|
||||
{
|
||||
REL_MOUSE rel_ms;
|
||||
REL_MOUSE rel_ms;
|
||||
|
||||
rel_ms.id = TIMEOUT_ID;
|
||||
rel_ms.dx = rel_ms.dy = 0;
|
||||
mouse_soft(&rel_ms, sizeof(rel_ms), KBD_TIMEO_PKG);
|
||||
}
|
||||
/*
|
||||
/*
|
||||
* Note that we are called from the keyboard software interrupt!
|
||||
*/
|
||||
void
|
||||
mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
||||
{
|
||||
struct ms_softc *ms = &ms_softc[0];
|
||||
struct firm_event *fe, *fe2;
|
||||
REL_MOUSE fake_mouse;
|
||||
int get, put;
|
||||
int sps;
|
||||
u_char mbut, bmask;
|
||||
int flush_buttons;
|
||||
struct ms_softc *ms = &ms_softc[0];
|
||||
struct firm_event *fe, *fe2;
|
||||
REL_MOUSE fake_mouse;
|
||||
int get, put;
|
||||
int s;
|
||||
uint8_t mbut, bmask;
|
||||
int flush_buttons;
|
||||
|
||||
if (ms->ms_events.ev_io == NULL)
|
||||
return;
|
||||
|
||||
switch (type) {
|
||||
case KBD_JOY1_PKG:
|
||||
case KBD_JOY1_PKG:
|
||||
/*
|
||||
* Ignore if in emulation mode
|
||||
*/
|
||||
|
@ -158,11 +160,12 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
* Flush all button changes.
|
||||
*/
|
||||
flush_buttons = 1;
|
||||
fake_mouse.id = (rel_ms->dx & 1 ? 4 : 0) | (ms->ms_buttons & 3);
|
||||
fake_mouse.id = ((rel_ms->dx & 0x01) != 0 ? 0x04 : 0x00) |
|
||||
(ms->ms_buttons & 0x03);
|
||||
fake_mouse.dx = fake_mouse.dy = 0;
|
||||
rel_ms = &fake_mouse;
|
||||
break;
|
||||
case KBD_TIMEO_PKG:
|
||||
case KBD_TIMEO_PKG:
|
||||
/*
|
||||
* Timeout package. No button changes and no movement.
|
||||
* Flush all button changes.
|
||||
|
@ -172,31 +175,31 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
fake_mouse.dx = fake_mouse.dy = 0;
|
||||
rel_ms = &fake_mouse;
|
||||
break;
|
||||
case KBD_RMS_PKG:
|
||||
case KBD_RMS_PKG:
|
||||
/*
|
||||
* Normal mouse package. Always copy the middle button
|
||||
* status. The emulation code decides if button changes
|
||||
* must be flushed.
|
||||
*/
|
||||
rel_ms->id = (ms->ms_buttons & 4) | (rel_ms->id & 3);
|
||||
flush_buttons = (ms->ms_emul3b) ? 0 : 1;
|
||||
rel_ms->id = (ms->ms_buttons & 0x04) | (rel_ms->id & 0x03);
|
||||
flush_buttons = ms->ms_emul3b ? 0 : 1;
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
sps = splev();
|
||||
s = splev();
|
||||
get = ms->ms_events.ev_get;
|
||||
put = ms->ms_events.ev_put;
|
||||
fe = &ms->ms_events.ev_q[put];
|
||||
|
||||
if ((type != KBD_TIMEO_PKG) && ms->ms_emul3b && ms->ms_bq_idx)
|
||||
if ((type != KBD_TIMEO_PKG) && ms->ms_emul3b && ms->ms_bq_idx != 0)
|
||||
callout_stop(&ms->ms_delay_ch);
|
||||
|
||||
/*
|
||||
* Button states are encoded in the lower 3 bits of 'id'
|
||||
*/
|
||||
if (!(mbut = (rel_ms->id ^ ms->ms_buttons)) && (put != get)) {
|
||||
if ((mbut = (rel_ms->id ^ ms->ms_buttons)) == 0 && (put != get)) {
|
||||
/*
|
||||
* Compact dx/dy messages. Always generate an event when
|
||||
* a button is pressed or the event queue is empty.
|
||||
|
@ -213,7 +216,7 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
* Output location events _before_ button events ie. make sure
|
||||
* the button is pressed at the correct location.
|
||||
*/
|
||||
if (rel_ms->dx) {
|
||||
if (rel_ms->dx != 0) {
|
||||
if ((++put) % EV_QSIZE == get) {
|
||||
put--;
|
||||
goto out;
|
||||
|
@ -224,10 +227,11 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
if (put >= EV_QSIZE) {
|
||||
put = 0;
|
||||
fe = &ms->ms_events.ev_q[0];
|
||||
} else {
|
||||
fe++;
|
||||
}
|
||||
else fe++;
|
||||
}
|
||||
if (rel_ms->dy) {
|
||||
if (rel_ms->dy != 0) {
|
||||
if ((++put) % EV_QSIZE == get) {
|
||||
put--;
|
||||
goto out;
|
||||
|
@ -238,20 +242,23 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
if (put >= EV_QSIZE) {
|
||||
put = 0;
|
||||
fe = &ms->ms_events.ev_q[0];
|
||||
} else {
|
||||
fe++;
|
||||
}
|
||||
else fe++;
|
||||
}
|
||||
if (mbut && (type != KBD_TIMEO_PKG)) {
|
||||
for (bmask = 1; bmask < 0x08; bmask <<= 1) {
|
||||
if (!(mbut & bmask))
|
||||
if (mbut != 0 && (type != KBD_TIMEO_PKG)) {
|
||||
for (bmask = 0x01; bmask < 0x08; bmask <<= 1) {
|
||||
if ((mbut & bmask) == 0)
|
||||
continue;
|
||||
fe2 = &ms->ms_bq[ms->ms_bq_idx++];
|
||||
if (bmask == 1)
|
||||
if (bmask == 0x01)
|
||||
fe2->id = MS_RIGHT;
|
||||
else if (bmask == 2)
|
||||
else if (bmask == 0x02)
|
||||
fe2->id = MS_LEFT;
|
||||
else fe2->id = MS_MIDDLE;
|
||||
fe2->value = rel_ms->id & bmask ? VKEY_DOWN : VKEY_UP;
|
||||
else
|
||||
fe2->id = MS_MIDDLE;
|
||||
fe2->value =
|
||||
(rel_ms->id & bmask) != 0 ? VKEY_DOWN : VKEY_UP;
|
||||
firm_gettime(fe2);
|
||||
}
|
||||
}
|
||||
|
@ -259,19 +266,19 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
/*
|
||||
* Handle 3rd button emulation.
|
||||
*/
|
||||
if (ms->ms_emul3b && ms->ms_bq_idx && (type != KBD_TIMEO_PKG)) {
|
||||
if (ms->ms_emul3b && ms->ms_bq_idx != 0 && (type != KBD_TIMEO_PKG)) {
|
||||
/*
|
||||
* If the middle button is pressed, any change to
|
||||
* one of the other buttons releases all.
|
||||
*/
|
||||
if ((ms->ms_buttons & 4) && (mbut & 3)) {
|
||||
if ((ms->ms_buttons & 0x04) != 0 && (mbut & 0x03) != 0) {
|
||||
ms->ms_bq[0].id = MS_MIDDLE;
|
||||
ms->ms_bq_idx = 1;
|
||||
rel_ms->id = 0;
|
||||
flush_buttons = 1;
|
||||
goto out;
|
||||
}
|
||||
if (ms->ms_bq_idx == 2) {
|
||||
if (ms->ms_bq_idx == 2) {
|
||||
if (ms->ms_bq[0].value == ms->ms_bq[1].value) {
|
||||
/* Must be 2 button presses! */
|
||||
ms->ms_bq[0].id = MS_MIDDLE;
|
||||
|
@ -286,9 +293,9 @@ mouse_soft(REL_MOUSE *rel_ms, int size, int type)
|
|||
}
|
||||
flush_buttons = 1;
|
||||
}
|
||||
out:
|
||||
out:
|
||||
if (flush_buttons) {
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ms->ms_bq_idx; i++) {
|
||||
if ((++put) % EV_QSIZE == get) {
|
||||
|
@ -300,32 +307,33 @@ out:
|
|||
if (put >= EV_QSIZE) {
|
||||
put = 0;
|
||||
fe = &ms->ms_events.ev_q[0];
|
||||
} else {
|
||||
fe++;
|
||||
}
|
||||
else fe++;
|
||||
}
|
||||
ms->ms_bq_idx = 0;
|
||||
}
|
||||
ms->ms_events.ev_put = put;
|
||||
ms->ms_buttons = rel_ms->id;
|
||||
splx(sps);
|
||||
splx(s);
|
||||
EV_WAKEUP(&ms->ms_events);
|
||||
}
|
||||
|
||||
int
|
||||
msopen(dev_t dev, int flags, int mode, struct lwp *l)
|
||||
{
|
||||
u_char report_ms_joy[] = { 0x14, 0x08 };
|
||||
struct ms_softc *ms;
|
||||
int unit;
|
||||
uint8_t report_ms_joy[] = { 0x14, 0x08 };
|
||||
struct ms_softc *ms;
|
||||
int unit;
|
||||
|
||||
unit = minor(dev);
|
||||
ms = &ms_softc[unit];
|
||||
|
||||
if (unit >= NMOUSE)
|
||||
return(EXDEV);
|
||||
return EXDEV;
|
||||
|
||||
if (ms->ms_events.ev_io)
|
||||
return(EBUSY);
|
||||
return EBUSY;
|
||||
|
||||
ms->ms_events.ev_io = l->l_proc;
|
||||
ms->ms_dx = ms->ms_dy = 0;
|
||||
|
@ -338,17 +346,17 @@ msopen(dev_t dev, int flags, int mode, struct lwp *l)
|
|||
* Enable mouse reporting.
|
||||
*/
|
||||
kbd_write(report_ms_joy, sizeof(report_ms_joy));
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
msclose(dev_t dev, int flags, int mode, struct lwp *l)
|
||||
{
|
||||
u_char disable_ms_joy[] = { 0x12, 0x1a };
|
||||
int unit;
|
||||
struct ms_softc *ms;
|
||||
uint8_t disable_ms_joy[] = { 0x12, 0x1a };
|
||||
int unit;
|
||||
struct ms_softc *ms;
|
||||
|
||||
unit = minor (dev);
|
||||
unit = minor(dev);
|
||||
ms = &ms_softc[unit];
|
||||
|
||||
/*
|
||||
|
@ -357,7 +365,7 @@ msclose(dev_t dev, int flags, int mode, struct lwp *l)
|
|||
kbd_write(disable_ms_joy, sizeof(disable_ms_joy));
|
||||
ev_fini(&ms->ms_events);
|
||||
ms->ms_events.ev_io = NULL;
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -366,48 +374,48 @@ msread(dev_t dev, struct uio *uio, int flags)
|
|||
struct ms_softc *ms;
|
||||
|
||||
ms = &ms_softc[minor(dev)];
|
||||
return(ev_read(&ms->ms_events, uio, flags));
|
||||
return ev_read(&ms->ms_events, uio, flags);
|
||||
}
|
||||
|
||||
int
|
||||
msioctl(dev_t dev, u_long cmd, register void * data, int flag, struct lwp *l)
|
||||
{
|
||||
struct ms_softc *ms;
|
||||
int unit;
|
||||
int unit;
|
||||
|
||||
unit = minor(dev);
|
||||
ms = &ms_softc[unit];
|
||||
|
||||
switch (cmd) {
|
||||
case MIOCS3B_EMUL:
|
||||
case MIOCS3B_EMUL:
|
||||
ms->ms_emul3b = (*(int *)data != 0) ? 1 : 0;
|
||||
return (0);
|
||||
case MIOCG3B_EMUL:
|
||||
return 0;
|
||||
case MIOCG3B_EMUL:
|
||||
*(int *)data = ms->ms_emul3b;
|
||||
return (0);
|
||||
return 0;
|
||||
case FIONBIO: /* we will remove this someday (soon???) */
|
||||
return(0);
|
||||
return 0;
|
||||
case FIOASYNC:
|
||||
ms->ms_events.ev_async = *(int *)data != 0;
|
||||
return(0);
|
||||
return 0;
|
||||
case FIOSETOWN:
|
||||
if (-*(int *)data != ms->ms_events.ev_io->p_pgid
|
||||
&& *(int *)data != ms->ms_events.ev_io->p_pid)
|
||||
return(EPERM);
|
||||
return(0);
|
||||
if (-*(int *)data != ms->ms_events.ev_io->p_pgid &&
|
||||
*(int *)data != ms->ms_events.ev_io->p_pid)
|
||||
return EPERM;
|
||||
return 0;
|
||||
case TIOCSPGRP:
|
||||
if (*(int *)data != ms->ms_events.ev_io->p_pgid)
|
||||
return(EPERM);
|
||||
return(0);
|
||||
return EPERM;
|
||||
return 0;
|
||||
case VUIDGFORMAT: /* we only do firm_events */
|
||||
*(int *)data = VUID_FIRM_EVENT;
|
||||
return(0);
|
||||
return 0;
|
||||
case VUIDSFORMAT:
|
||||
if (*(int *)data != VUID_FIRM_EVENT)
|
||||
return(EINVAL);
|
||||
return(0);
|
||||
return EINVAL;
|
||||
return 0;
|
||||
}
|
||||
return(ENOTTY);
|
||||
return ENOTTY;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -416,7 +424,7 @@ mspoll(dev_t dev, int events, struct lwp *l)
|
|||
struct ms_softc *ms;
|
||||
|
||||
ms = &ms_softc[minor(dev)];
|
||||
return(ev_poll(&ms->ms_events, events, l));
|
||||
return ev_poll(&ms->ms_events, events, l);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -425,6 +433,6 @@ mskqfilter(dev_t dev, struct knote *kn)
|
|||
struct ms_softc *ms;
|
||||
|
||||
ms = &ms_softc[minor(dev)];
|
||||
return (ev_kqfilter(&ms->ms_events, kn));
|
||||
return ev_kqfilter(&ms->ms_events, kn);
|
||||
}
|
||||
#endif /* NMOUSE > 0 */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msvar.h,v 1.4 2009/10/20 19:10:10 snj Exp $ */
|
||||
/* $NetBSD: msvar.h,v 1.5 2022/06/26 06:02:28 tsutsui Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Leo Weppelman
|
||||
|
@ -32,17 +32,17 @@
|
|||
* define the REL_MOUSE package, as this is the only one used.
|
||||
*/
|
||||
typedef struct {
|
||||
u_char id;
|
||||
char dx;
|
||||
char dy;
|
||||
uint8_t id;
|
||||
int8_t dx;
|
||||
int8_t dy;
|
||||
} REL_MOUSE;
|
||||
|
||||
#define IS_REL_MOUSE(id) (((u_int)(id) & 0xF8) == 0xF8)
|
||||
#define TIMEOUT_ID (0xFC)
|
||||
|
||||
struct ms_softc {
|
||||
u_char ms_buttons; /* button states */
|
||||
u_char ms_emul3b; /* emulate 3rd button */
|
||||
uint8_t ms_buttons; /* button states */
|
||||
uint8_t ms_emul3b; /* emulate 3rd button */
|
||||
struct evvar ms_events; /* event queue state */
|
||||
int ms_dx; /* accumulated dx */
|
||||
int ms_dy; /* accumulated dy */
|
||||
|
|
Loading…
Reference in New Issue