summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorsheldonh <sheldonh@FreeBSD.org>1999-12-17 10:05:36 +0000
committersheldonh <sheldonh@FreeBSD.org>1999-12-17 10:05:36 +0000
commitf4fc7fc5af87c802a08acfaff5aa9552b33f7541 (patch)
tree885b2aa3b790d028185d210924595d176fa9f8f1 /usr.sbin
parentb7a50ab0f10ee7486efaecbb36625d23c9049af0 (diff)
downloadFreeBSD-src-f4fc7fc5af87c802a08acfaff5aa9552b33f7541.zip
FreeBSD-src-f4fc7fc5af87c802a08acfaff5aa9552b33f7541.tar.gz
Back out previous commit, which broke mouse wheel support in moused.
Requested by: yokota
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/moused/moused.813
-rw-r--r--usr.sbin/moused/moused.c281
2 files changed, 43 insertions, 251 deletions
diff --git a/usr.sbin/moused/moused.8 b/usr.sbin/moused/moused.8
index a4c41e4..1f35869 100644
--- a/usr.sbin/moused/moused.8
+++ b/usr.sbin/moused/moused.8
@@ -38,7 +38,7 @@
.Nd pass mouse data to the console driver
.Sh SYNOPSIS
.Nm
-.Op Fl DPRcdfs
+.Op Fl 3DPRcdfs
.Op Fl I Ar file
.Op Fl F Ar rate
.Op Fl r Ar resolution
@@ -48,7 +48,6 @@
.Op Fl w Ar N
.Op Fl z Ar target
.Op Fl t Ar mousetype
-.Op Fl 3 Op Fl E Ar timeout
.Fl p Ar port
.Pp
.Nm
@@ -107,16 +106,6 @@ The DTR line may need to be dropped for a 3-button mouse
to operate in the
.Ar mousesystems
mode.
-.It Fl E Ar timeout
-When the third button emulation is enabled
-.Pq see above ,
-the
-.Nm
-daemon waits
-.Ar timeout
-msec at maximum before deciding if two buttons are pressed
-simultaneously.
-The default timeout is 200 msec.
.It Fl F Ar rate
Set the report rate (reports/sec) of the device if supported.
.It Fl I Ar file
diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c
index baa1781..bc522cf 100644
--- a/usr.sbin/moused/moused.c
+++ b/usr.sbin/moused/moused.c
@@ -73,7 +73,6 @@ static const char rcsid[] =
#include <unistd.h>
#define MAX_CLICKTHRESHOLD 2000 /* 2 seconds */
-#define MAX_BUTTON2TIMEOUT 2000 /* 2 seconds */
#define TRUE 1
#define FALSE 0
@@ -363,7 +362,6 @@ static struct rodentparam {
int mremsfd; /* mouse remote server file descriptor */
int mremcfd; /* mouse remote client file descriptor */
long clickthreshold; /* double click speed in msec */
- long button2timeout; /* 3 button emulation timeout */
mousehw_t hw; /* mouse device hardware information */
mousemode_t mode; /* protocol information */
} rodent = {
@@ -381,7 +379,6 @@ static struct rodentparam {
mremsfd : -1,
mremcfd : -1,
clickthreshold : 500, /* 0.5 sec */
- button2timeout : 200, /* 0.2 sec */
};
/* button status */
@@ -390,50 +387,6 @@ static struct {
struct timeval tv; /* timestamp on the last `up' event */
} buttonstate[MOUSE_MAXBUTTON];
-/* state machine for 3 button emulation */
-
-#define S0 0 /* start */
-#define S1 1 /* button 1 delayed down */
-#define S2 2 /* button 3 delayed down */
-#define S3 3 /* both buttons down -> button 2 down */
-#define S4 4 /* button 1 delayed up */
-#define S5 5 /* button 1 down */
-#define S6 6 /* button 3 down */
-#define S7 7 /* both buttons down */
-#define S8 8 /* button 3 delayed up */
-#define S9 9 /* button 1 or 3 up after S3 */
-
-#define A(b1, b3) (((b1) ? 2 : 0) | ((b3) ? 1 : 0))
-#define A_TIMEOUT 4
-
-static struct {
- int s[A_TIMEOUT + 1];
- int buttons;
- int mask;
-} states[10] = {
- /* S0 */
- { { S0, S2, S1, S3, S0 }, 0, ~(MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN) },
- /* S1 */
- { { S4, S2, S1, S3, S5 }, 0, ~MOUSE_BUTTON1DOWN },
- /* S2 */
- { { S8, S2, S1, S3, S6 }, 0, ~MOUSE_BUTTON3DOWN },
- /* S3 */
- { { S0, S9, S9, S3, S3 }, MOUSE_BUTTON2DOWN, ~0 },
- /* S4 */
- { { S0, S2, S1, S3, S0 }, MOUSE_BUTTON1DOWN, ~0 },
- /* S5 */
- { { S0, S2, S5, S7, S5 }, MOUSE_BUTTON1DOWN, ~0 },
- /* S6 */
- { { S0, S6, S1, S7, S6 }, MOUSE_BUTTON3DOWN, ~0 },
- /* S7 */
- { { S0, S6, S5, S7, S7 }, MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, ~0 },
- /* S8 */
- { { S0, S2, S1, S3, S0 }, MOUSE_BUTTON3DOWN, ~0 },
- /* S9 */
- { { S0, S9, S9, S3, S9 }, 0, ~(MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN) },
-};
-static int mouse_button_state;
-
static jmp_buf env;
/* function prototypes */
@@ -449,11 +402,8 @@ static char *r_name(int type);
static char *r_model(int model);
static void r_init(void);
static int r_protocol(u_char b, mousestatus_t *act);
-static int r_statetrans(mousestatus_t *a1, mousestatus_t *a2, int trans);
static int r_installmap(char *arg);
static void r_map(mousestatus_t *act1, mousestatus_t *act2);
-static void r_timestamp(mousestatus_t *act);
-static void r_timeout(mousestatus_t *act);
static void r_click(mousestatus_t *act);
static void setmousespeed(int old, int new, unsigned cflag);
@@ -477,22 +427,13 @@ main(int argc, char *argv[])
int c;
int i;
- while((c = getopt(argc,argv,"3C:DE:F:I:PRS:cdfhi:l:m:p:r:st:w:z:")) != -1)
+ while((c = getopt(argc,argv,"3C:DF:I:PRS:cdfhi:l:m:p:r:st:w:z:")) != -1)
switch(c) {
case '3':
rodent.flags |= Emulate3Button;
break;
- case 'E':
- rodent.button2timeout = atoi(optarg);
- if ((rodent.button2timeout < 0) ||
- (rodent.button2timeout > MAX_BUTTON2TIMEOUT)) {
- warnx("invalid argument `%s'", optarg);
- usage();
- }
- break;
-
case 'c':
rodent.flags |= ChordMiddle;
break;
@@ -751,15 +692,11 @@ static void
moused(void)
{
struct mouse_info mouse;
- mousestatus_t action0; /* original mouse action */
- mousestatus_t action; /* interrim buffer */
+ mousestatus_t action; /* original mouse action */
mousestatus_t action2; /* mapped action */
- struct timeval timeout;
fd_set fds;
u_char b;
FILE *fp;
- int flags;
- int c;
if ((rodent.cfd = open("/dev/consolectl", O_RDWR, 0)) == -1)
logerr(1, "cannot open /dev/consolectl", 0);
@@ -777,7 +714,6 @@ moused(void)
}
/* clear mouse data */
- bzero(&action0, sizeof(action0));
bzero(&action, sizeof(action));
bzero(&action2, sizeof(action2));
bzero(&buttonstate, sizeof(buttonstate));
@@ -788,68 +724,32 @@ moused(void)
extioctl = (ioctl(rodent.cfd, CONS_MOUSECTL, &mouse) == 0);
/* process mouse data */
- mouse_button_state = S0;
- timeout.tv_sec = 0;
- timeout.tv_usec = 20000; /* 20 msec */
for (;;) {
FD_ZERO(&fds);
FD_SET(rodent.mfd, &fds);
- if (rodent.mremsfd >= 0)
- FD_SET(rodent.mremsfd, &fds);
- if (rodent.mremcfd >= 0)
- FD_SET(rodent.mremcfd, &fds);
-
- c = select(FD_SETSIZE, &fds, NULL, NULL,
- (rodent.flags & Emulate3Button) ? &timeout : NULL);
- if (c < 0) { /* error */
+ if (rodent.mremsfd >= 0) FD_SET(rodent.mremsfd, &fds);
+ if (rodent.mremcfd >= 0) FD_SET(rodent.mremcfd, &fds);
+
+ if (select(FD_SETSIZE, &fds, NULL, NULL, NULL) <= 0)
logwarn("failed to read from mouse", 0);
+
+ /* MouseRemote client connect/disconnect */
+ if ((rodent.mremsfd >= 0) && FD_ISSET(rodent.mremsfd, &fds)) {
+ mremote_clientchg(TRUE);
+ continue;
+ }
+
+ if ((rodent.mremcfd >= 0) && FD_ISSET(rodent.mremcfd, &fds)) {
+ mremote_clientchg(FALSE);
continue;
- } else if (c == 0) { /* timeout */
- /* assert(rodent.flags & Emulate3Button) */
- action0.button = action0.obutton;
- action0.dx = action0.dy = action0.dz = 0;
- action0.flags = flags = 0;
- r_timeout(&action0);
- if (action0.flags) {
- debug("flags:%08x", action0.flags);
- r_statetrans(&action0, &action, A_TIMEOUT);
- debug("flags:%08x buttons:%08x obuttons:%08x", action.flags,
- action.button, action.obutton);
- } else
- continue;
- } else {
- /* MouseRemote client connect/disconnect */
- if ((rodent.mremsfd >= 0) && FD_ISSET(rodent.mremsfd, &fds)) {
- mremote_clientchg(TRUE);
- continue;
- }
- if ((rodent.mremcfd >= 0) && FD_ISSET(rodent.mremcfd, &fds)) {
- mremote_clientchg(FALSE);
- continue;
- }
- /* mouse movement */
- if (read(rodent.mfd, &b, 1) == -1) {
- if (errno == EWOULDBLOCK)
- continue;
- else
- return;
- }
- if ((flags = r_protocol(b, &action0)) == 0)
- continue;
- r_timestamp(&action0);
- r_statetrans(&action0, &action,
- A(action0.button & MOUSE_BUTTON1DOWN,
- action0.button & MOUSE_BUTTON3DOWN));
- debug("flags:%08x buttons:%08x obuttons:%08x", action.flags,
- action.button, action.obutton);
}
- action0.obutton = action0.button;
- flags &= MOUSE_POSCHANGED;
- flags |= action.obutton ^ action.button;
- action.flags = flags;
- if (flags) { /* handler detected action */
+ /* mouse event */
+ if (read(rodent.mfd, &b, 1) == -1)
+ return; /* file seems to be closed on us */
+
+ if (r_protocol(b, &action)) { /* handler detected action */
r_map(&action, &action2);
debug("activity : buttons 0x%08x dx %d dy %d dz %d",
action2.button, action2.dx, action2.dy, action2.dz);
@@ -925,9 +825,8 @@ static void
usage(void)
{
fprintf(stderr, "%s\n%s\n%s\n",
- "usage: moused [-DRcdfs] [-I file] [-F rate] [-r resolution] [-S baudrate]",
- " [-C threshold] [-m N=M] [-w N] [-z N] [-t <mousetype>]",
- " [-3 [-E timeout]] -p <port>",
+ "usage: moused [-3DRcdfs] [-I file] [-F rate] [-r resolution] [-S baudrate]",
+ " [-C threshold] [-m N=M] [-w N] [-z N] [-t <mousetype>] -p <port>",
" moused [-d] -i <info> -p <port>");
exit(1);
}
@@ -1802,37 +1701,24 @@ r_protocol(u_char rBuf, mousestatus_t *act)
act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0)
| (act->obutton ^ act->button);
- return act->flags;
-}
-
-static int
-r_statetrans(mousestatus_t *a1, mousestatus_t *a2, int trans)
-{
- int flags;
-
- a2->dx = a1->dx;
- a2->dy = a1->dy;
- a2->dz = a1->dz;
- a2->obutton = a2->button;
- a2->button = a1->button;
- a2->flags = a1->flags;
-
if (rodent.flags & Emulate3Button) {
- debug("state:%d, trans:%d -> state:%d",
- mouse_button_state, trans, states[mouse_button_state].s[trans]);
- mouse_button_state = states[mouse_button_state].s[trans];
- a2->button &=
- ~(MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN);
- a2->button &= states[mouse_button_state].mask;
- a2->button |= states[mouse_button_state].buttons;
- flags = a2->flags & MOUSE_POSCHANGED;
- flags |= a2->obutton ^ a2->button;
- if (flags & MOUSE_BUTTON2DOWN) {
- a2->flags = flags & MOUSE_BUTTON2DOWN;
- r_timestamp(a2);
+ if (((act->flags & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))
+ == (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))
+ && ((act->button & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))
+ == (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))) {
+ act->button &= ~(MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN);
+ act->button |= MOUSE_BUTTON2DOWN;
+ } else if ((act->obutton & MOUSE_BUTTON2DOWN)
+ && ((act->button & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))
+ != (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN))) {
+ act->button &= ~(MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN
+ | MOUSE_BUTTON3DOWN);
}
- a2->flags = flags;
+ act->flags &= MOUSE_POSCHANGED;
+ act->flags |= act->obutton ^ act->button;
}
+
+ return act->flags;
}
/* phisical to logical button mapping */
@@ -1947,36 +1833,26 @@ r_map(mousestatus_t *act1, mousestatus_t *act2)
}
static void
-r_timestamp(mousestatus_t *act)
+r_click(mousestatus_t *act)
{
+ struct mouse_info mouse;
struct timeval tv;
struct timeval tv1;
struct timeval tv2;
- struct timeval tv3;
struct timezone tz;
int button;
int mask;
int i;
mask = act->flags & MOUSE_BUTTONS;
-#if 0
if (mask == 0)
return;
-#endif
gettimeofday(&tv1, &tz);
-
- /* double click threshold */
tv2.tv_sec = rodent.clickthreshold/1000;
tv2.tv_usec = (rodent.clickthreshold%1000)*1000;
timersub(&tv1, &tv2, &tv);
debug("tv: %ld %ld", tv.tv_sec, tv.tv_usec);
-
- /* 3 button emulation timeout */
- tv2.tv_sec = rodent.button2timeout/1000;
- tv2.tv_usec = (rodent.button2timeout%1000)*1000;
- timersub(&tv1, &tv2, &tv3);
-
button = MOUSE_BUTTON1DOWN;
for (i = 0; (i < MOUSE_MAXBUTTON) && (mask != 0); ++i) {
if (mask & 1) {
@@ -1985,89 +1861,16 @@ r_timestamp(mousestatus_t *act)
debug(" : %ld %ld",
buttonstate[i].tv.tv_sec, buttonstate[i].tv.tv_usec);
if (timercmp(&tv, &buttonstate[i].tv, >)) {
+ buttonstate[i].tv.tv_sec = 0;
+ buttonstate[i].tv.tv_usec = 0;
buttonstate[i].count = 1;
} else {
++buttonstate[i].count;
}
- buttonstate[i].tv = tv1;
- } else {
- /* the button is up */
- buttonstate[i].tv = tv1;
- }
- } else {
- if (act->button & button) {
- /* the button has been down */
- if (timercmp(&tv3, &buttonstate[i].tv, >)) {
- buttonstate[i].count = 1;
- buttonstate[i].tv = tv1;
- act->flags |= button;
- debug("button %d timeout", i + 1);
- }
- } else {
- /* the button has been up */
- }
- }
- button <<= 1;
- mask >>= 1;
- }
-}
-
-static void
-r_timeout(mousestatus_t *act)
-{
- struct timeval tv;
- struct timeval tv1;
- struct timeval tv2;
- struct timezone tz;
- int button;
- int i;
-
- gettimeofday(&tv1, &tz);
- tv2.tv_sec = rodent.button2timeout/1000;
- tv2.tv_usec = (rodent.button2timeout%1000)*1000;
- timersub(&tv1, &tv2, &tv);
- button = MOUSE_BUTTON1DOWN;
- for (i = 0; i < MOUSE_MAXBUTTON; ++i) {
- if (act->button & button) {
- /* the button has been down */
- if (timercmp(&tv, &buttonstate[i].tv, >)) {
- buttonstate[i].count = 1;
- buttonstate[i].tv = tv1;
- act->flags |= button;
- debug("button %d (down) timeout", i + 1);
- }
- } else {
- /* the button has been up */
- if (timercmp(&tv, &buttonstate[i].tv, >)) {
- buttonstate[i].count = 0;
- buttonstate[i].tv = tv1;
- act->flags |= button;
- }
- }
- button <<= 1;
- }
-}
-
-static void
-r_click(mousestatus_t *act)
-{
- struct mouse_info mouse;
- int button;
- int mask;
- int i;
-
- mask = act->flags & MOUSE_BUTTONS;
- if (mask == 0)
- return;
-
- button = MOUSE_BUTTON1DOWN;
- for (i = 0; (i < MOUSE_MAXBUTTON) && (mask != 0); ++i) {
- if (mask & 1) {
- if (act->button & button) {
- /* the button is down */
mouse.u.event.value = buttonstate[i].count;
} else {
/* the button is up */
+ buttonstate[i].tv = tv1;
mouse.u.event.value = 0;
}
mouse.operation = MOUSE_BUTTON_EVENT;
OpenPOWER on IntegriCloud