From ceb43781049aece44b26891691decbbdb9fafdfa Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 8 Feb 2008 10:17:40 +0000 Subject: [PATCH] Add 'virtual scrolling' support to moused(8). When holding down the middle mouse button, motions are interpreted as scrolling. Besides that, the code contains some whitespace and mdoc cleanup. Obtained-from: FreeBSD --- usr.sbin/moused/moused.8 | 68 ++- usr.sbin/moused/moused.c | 1184 ++++++++++++++++++++++++++-------------------- 2 files changed, 725 insertions(+), 527 deletions(-) diff --git a/usr.sbin/moused/moused.8 b/usr.sbin/moused/moused.8 index 8fb88b42e7..c44e9456ea 100644 --- a/usr.sbin/moused/moused.8 +++ b/usr.sbin/moused/moused.8 @@ -28,10 +28,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/moused/moused.8,v 1.27.2.11 2003/04/28 08:34:04 brueffer Exp $ -.\" $DragonFly: src/usr.sbin/moused/moused.8,v 1.8 2007/11/23 20:08:35 swildner Exp $ +.\" $FreeBSD: src/usr.sbin/moused/moused.8,v 1.47 2004/10/11 07:57:08 philip Exp $ +.\" $DragonFly: src/usr.sbin/moused/moused.8,v 1.9 2008/02/08 10:17:40 matthias Exp $ .\" -.Dd April 1, 2000 +.Dd February 8, 2008 .Dt MOUSED 8 .Os .Sh NAME @@ -44,12 +44,14 @@ .Op Fl F Ar rate .Op Fl r Ar resolution .Op Fl S Ar baudrate +.Op Fl V Op Fl U Ar distance .Op Fl a Ar X Ns Op , Ns Ar Y .Op Fl C Ar threshold .Op Fl m Ar N=M .Op Fl w Ar N .Op Fl z Ar target .Op Fl t Ar mousetype +.Op Fl l Ar level .Op Fl 3 Op Fl E Ar timeout .Fl p Ar port .Pp @@ -156,6 +158,14 @@ mode. .It Fl S Ar baudrate Select the baudrate for the serial port (1200 to 9600). Not all serial mice support this option. +.It Fl V +Enable +.Dq Virtual Scrolling . +With this option set, holding the middle mouse +button down will cause motion to be interpreted as scrolling. Use the +.Fl U +option to set the distance the mouse must move before the scrolling mode is +activated. .It Fl a Ar X Ns Op , Ns Ar Y Accelerate or decelerate the mouse input. This is a linear acceleration only. @@ -172,7 +182,8 @@ Enable debugging messages. Do not become a daemon and instead run as a foreground process. Useful for testing and debugging. .It Fl i Ar info -Print specified information and quit. Available pieces of +Print specified information and quit. +Available pieces of information are: .Pp .Bl -tag -compact -width modelxxx @@ -194,11 +205,13 @@ if the driver supports the .Ar sysmouse data format standard. .It Ar model -Mouse model. The +Mouse model. +The .Nm utility may not always be able to identify the model. .It Ar all -All of the above items. Print port, interface, type and model in this order +All of the above items. +Print port, interface, type and model in this order in one line. .El .Pp @@ -206,6 +219,15 @@ If the .Nm utility cannot determine the requested information, it prints ``unknown'' or ``generic''. +.It Fl l Ar level +Specifies at which level +.Nm +should operate the mouse driver. +Refer to +.Em Operation Levels +in +.Xr psm 4 +for more information on this. .It Fl m Ar N=M Assign the physical button .Ar M @@ -260,7 +282,8 @@ always choose .Ar auto or .Ar ps/2 , -regardless of the brand and model of the mouse. Likewise, if your +regardless of the brand and model of the mouse. +Likewise, if your mouse is attached to the bus mouse port, choose .Ar auto or @@ -277,26 +300,32 @@ listed below. For the serial mouse: .Bl -tag -compact -width mousesystemsxxx .It Ar microsoft -Microsoft serial mouse protocol. Most 2-button serial mice use this protocol. +Microsoft serial mouse protocol. +Most 2-button serial mice use this protocol. .It Ar intellimouse -Microsoft IntelliMouse protocol. Genius NetMouse, +Microsoft IntelliMouse protocol. +Genius NetMouse, .Tn ASCII Mie Mouse, Logitech MouseMan+ and FirstMouse+ use this protocol too. Other mice with a roller/wheel may be compatible with this protocol. .It Ar mousesystems -MouseSystems 5-byte protocol. 3-button mice may use this protocol. +MouseSystems 5-byte protocol. +3-button mice may use this protocol. .It Ar mmseries MM Series mouse protocol. .It Ar logitech -Logitech mouse protocol. Note that this is for old Logitech models. +Logitech mouse protocol. +Note that this is for old Logitech models. .Ar mouseman or .Ar intellimouse should be specified for newer models. .It Ar mouseman -Logitech MouseMan and TrackMan protocol. Some 3-button mice may be compatible -with this protocol. Note that MouseMan+ and FirstMouse+ use +Logitech MouseMan and TrackMan protocol. +Some 3-button mice may be compatible +with this protocol. +Note that MouseMan+ and FirstMouse+ use .Ar intellimouse protocol rather than this one. .It Ar glidepoint @@ -407,7 +436,8 @@ The bus and InPort mice have either a D-Sub male 9-pin connector or a round DIN 9-pin connector. The PS/2 mouse is equipped with a small, round DIN 6-pin connector. Some mice come with adapters with which the connector can -be converted to another. If you are to use such an adapter, +be converted to another. +If you are to use such an adapter, remember the connector at the very end of the mouse/adapter pair is what matters. The USB mouse has a flat rectangular connector. @@ -419,7 +449,8 @@ the bus and InPort mice always use and the PS/2 mouse is always at .Pa /dev/psm0 . There may be more than one serial port to which the serial -mouse can be attached. Many people often assign the first, built-in +mouse can be attached. +Many people often assign the first, built-in serial port .Pa /dev/cuaa0 to the mouse. @@ -441,7 +472,8 @@ Run the .Nm utility with the .Fl i -option and see what it says. If the command can identify +option and see what it says. +If the command can identify the protocol type, no further investigation is necessary on your part. You may start the daemon without explicitly specifying a protocol type (see @@ -613,8 +645,8 @@ This will effectively swap the left and right buttons. .Pp .Dl moused -p /dev/mouse -t intellimouse -z 4 .Pp -Report negative Z axis (roller) movement as the button 4 pressed -and positive Z axis movement as the button 5 pressed. +Report negative Z axis movement (i.e., mouse wheel) as the button 4 pressed +and positive Z axis movement (i.e., mouse wheel) as the button 5 pressed. .Sh CAVEATS Many pad devices behave as if the first (left) button were pressed if the user `taps' the surface of the pad. diff --git a/usr.sbin/moused/moused.c b/usr.sbin/moused/moused.c index 95b4cda964..e7c3a785b6 100644 --- a/usr.sbin/moused/moused.c +++ b/usr.sbin/moused/moused.c @@ -35,47 +35,51 @@ ** MOUSED.C ** ** Mouse daemon : listens to a serial port, the bus mouse interface, or - ** the PS/2 mouse port for mouse data stream, interprets data and passes + ** the PS/2 mouse port for mouse data stream, interprets data and passes ** ioctls off to the console driver. ** ** The mouse interface functions are derived closely from the mouse ** handler in the XFree86 X server. Many thanks to the XFree86 people ** for their great work! - ** + ** **/ /* - * $FreeBSD: src/usr.sbin/moused/moused.c,v 1.37.2.11 2002/04/15 00:52:08 will Exp $ - * $DragonFly: src/usr.sbin/moused/moused.c,v 1.5 2005/12/05 02:40:27 swildner Exp $ + * $FreeBSD: src/usr.sbin/moused/moused.c,v 1.69 2005/01/06 08:38:29 philip Exp $ + * $DragonFly: src/usr.sbin/moused/moused.c,v 1.6 2008/02/08 10:17:40 matthias Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include +#include +#include +#include #include #include -#include #include -#include -#include -#include -#include #include - -#include -#include - -#include -#include -#include -#include +#include #include #define MAX_CLICKTHRESHOLD 2000 /* 2 seconds */ #define MAX_BUTTON2TIMEOUT 2000 /* 2 seconds */ #define DFLT_CLICKTHRESHOLD 500 /* 0.5 second */ #define DFLT_BUTTON2TIMEOUT 100 /* 0.1 second */ +#define DFLT_SCROLLTHRESHOLD 3 /* 3 pixels */ /* Abort 3-button emulation delay after this many movement events. */ #define BUTTON2_MAXMOVE 3 @@ -97,46 +101,35 @@ #define ClearDTR 0x0004 #define ClearRTS 0x0008 #define NoPnP 0x0010 - +#define VirtualScroll 0x0020 + #define ID_NONE 0 #define ID_PORT 1 #define ID_IF 2 -#define ID_TYPE 4 +#define ID_TYPE 4 #define ID_MODEL 8 #define ID_ALL (ID_PORT | ID_IF | ID_TYPE | ID_MODEL) -#define debug(fmt,args...) \ - if (debug&&nodaemon) warnx(fmt, ##args) +#define debug(fmt, args...) do { \ + if (debug && nodaemon) \ + warnx(fmt, ##args); \ +} while (0) -#define logerr(e, fmt, args...) { \ - if (background) { \ - syslog(LOG_DAEMON | LOG_ERR, fmt ": %m", ##args); \ - exit(e); \ - } else \ - err(e, fmt, ##args); \ -} +#define logerr(e, fmt, args...) do { \ + log_or_warn(LOG_DAEMON | LOG_ERR, errno, fmt, ##args); \ + exit(e); \ +} while (0) -#define logerrx(e, fmt, args...) { \ - if (background) { \ - syslog(LOG_DAEMON | LOG_ERR, fmt, ##args); \ - exit(e); \ - } else \ - errx(e, fmt, ##args); \ -} +#define logerrx(e, fmt, args...) do { \ + log_or_warn(LOG_DAEMON | LOG_ERR, 0, fmt, ##args); \ + exit(e); \ +} while (0) -#define logwarn(fmt, args...) { \ - if (background) \ - syslog(LOG_DAEMON | LOG_WARNING, fmt ": %m", ##args); \ - else \ - warn(fmt, ##args); \ -} +#define logwarn(fmt, args...) \ + log_or_warn(LOG_DAEMON | LOG_WARNING, errno, fmt, ##args) -#define logwarnx(fmt, args...) { \ - if (background) \ - syslog(LOG_DAEMON | LOG_WARNING, fmt, ##args); \ - else \ - warnx(fmt, ##args); \ -} +#define logwarnx(fmt, args...) \ + log_or_warn(LOG_DAEMON | LOG_WARNING, 0, fmt, ##args) /* structures */ @@ -171,6 +164,13 @@ int identify = ID_NONE; int extioctl = FALSE; char *pidfile = "/var/run/moused.pid"; +#define SCROLL_NOTSCROLLING 0 +#define SCROLL_PREPARE 1 +#define SCROLL_SCROLLING 2 + +static int scroll_state; +static int scroll_movement; + /* local variables */ /* interface (the table must be ordered by MOUSE_IF_XXX in mouse.h) */ @@ -224,7 +224,7 @@ static symtab_t rmodels[] = { { "4D Mouse", MOUSE_MODEL_4D }, { "4D+ Mouse", MOUSE_MODEL_4DPLUS }, { "generic", MOUSE_MODEL_GENERIC }, - { NULL, MOUSE_MODEL_UNKNOWN }, + { NULL, MOUSE_MODEL_UNKNOWN }, }; /* PnP EISA/product IDs */ @@ -246,7 +246,7 @@ static symtab_t pnpprod[] = { /* Genius Kidspad, Easypad and other tablets */ { "KYE0005", MOUSE_PROTO_KIDSPAD, MOUSE_MODEL_KIDSPAD }, /* Genius EZScroll */ - { "KYEEZ00", MOUSE_PROTO_MS, MOUSE_MODEL_EASYSCROLL }, + { "KYEEZ00", MOUSE_PROTO_MS, MOUSE_MODEL_EASYSCROLL }, /* Logitech Cordless MouseMan Wheel */ { "LGI8033", MOUSE_PROTO_INTELLI, MOUSE_MODEL_MOUSEMANPLUS }, /* Logitech MouseMan (new 4 button model) */ @@ -267,60 +267,60 @@ static symtab_t pnpprod[] = { /* MS bus */ { "PNP0F00", MOUSE_PROTO_BUS, MOUSE_MODEL_GENERIC }, /* MS serial */ - { "PNP0F01", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F01", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, /* MS InPort */ - { "PNP0F02", MOUSE_PROTO_INPORT, MOUSE_MODEL_GENERIC }, + { "PNP0F02", MOUSE_PROTO_INPORT, MOUSE_MODEL_GENERIC }, /* MS PS/2 */ - { "PNP0F03", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, + { "PNP0F03", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, /* * EzScroll returns PNP0F04 in the compatible device field; but it * doesn't look compatible... XXX */ - /* MouseSystems */ - { "PNP0F04", MOUSE_PROTO_MSC, MOUSE_MODEL_GENERIC }, - /* MouseSystems */ - { "PNP0F05", MOUSE_PROTO_MSC, MOUSE_MODEL_GENERIC }, + /* MouseSystems */ + { "PNP0F04", MOUSE_PROTO_MSC, MOUSE_MODEL_GENERIC }, + /* MouseSystems */ + { "PNP0F05", MOUSE_PROTO_MSC, MOUSE_MODEL_GENERIC }, #if notyet - /* Genius Mouse */ - { "PNP0F06", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, - /* Genius Mouse */ - { "PNP0F07", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + /* Genius Mouse */ + { "PNP0F06", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, + /* Genius Mouse */ + { "PNP0F07", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, #endif /* Logitech serial */ { "PNP0F08", MOUSE_PROTO_LOGIMOUSEMAN, MOUSE_MODEL_GENERIC }, /* MS BallPoint serial */ - { "PNP0F09", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F09", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, /* MS PnP serial */ - { "PNP0F0A", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F0A", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, /* MS PnP BallPoint serial */ - { "PNP0F0B", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F0B", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, /* MS serial comatible */ - { "PNP0F0C", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F0C", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, /* MS InPort comatible */ - { "PNP0F0D", MOUSE_PROTO_INPORT, MOUSE_MODEL_GENERIC }, + { "PNP0F0D", MOUSE_PROTO_INPORT, MOUSE_MODEL_GENERIC }, /* MS PS/2 comatible */ - { "PNP0F0E", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, + { "PNP0F0E", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, /* MS BallPoint comatible */ - { "PNP0F0F", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, + { "PNP0F0F", MOUSE_PROTO_MS, MOUSE_MODEL_GENERIC }, #if notyet /* TI QuickPort */ - { "PNP0F10", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F10", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, #endif /* MS bus comatible */ - { "PNP0F11", MOUSE_PROTO_BUS, MOUSE_MODEL_GENERIC }, + { "PNP0F11", MOUSE_PROTO_BUS, MOUSE_MODEL_GENERIC }, /* Logitech PS/2 */ { "PNP0F12", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, /* PS/2 */ { "PNP0F13", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, #if notyet /* MS Kids Mouse */ - { "PNP0F14", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F14", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, #endif - /* Logitech bus */ + /* Logitech bus */ { "PNP0F15", MOUSE_PROTO_BUS, MOUSE_MODEL_GENERIC }, #if notyet /* Logitech SWIFT */ - { "PNP0F16", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F16", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, #endif /* Logitech serial compat */ { "PNP0F17", MOUSE_PROTO_LOGIMOUSEMAN, MOUSE_MODEL_GENERIC }, @@ -330,15 +330,15 @@ static symtab_t pnpprod[] = { { "PNP0F19", MOUSE_PROTO_PS2, MOUSE_MODEL_GENERIC }, #if notyet /* Logitech SWIFT compatible */ - { "PNP0F1A", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F1A", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, /* HP Omnibook */ - { "PNP0F1B", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F1B", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, /* Compaq LTE TrackBall PS/2 */ - { "PNP0F1C", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F1C", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, /* Compaq LTE TrackBall serial */ - { "PNP0F1D", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F1D", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, /* MS Kidts Trackball */ - { "PNP0F1E", MOUSE_PROTO_???, MOUSE_MODEL_GENERIC }, + { "PNP0F1E", MOUSE_PROTO_XXX, MOUSE_MODEL_GENERIC }, #endif /* Interlink VersaPad */ { "LNK0001", MOUSE_PROTO_VERSAPAD, MOUSE_MODEL_VERSAPAD }, @@ -349,25 +349,25 @@ static symtab_t pnpprod[] = { /* the table must be ordered by MOUSE_PROTO_XXX in mouse.h */ static unsigned short rodentcflags[] = { - (CS7 | CREAD | CLOCAL | HUPCL ), /* MicroSoft */ - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* MouseSystems */ - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* Logitech */ - (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL ), /* MMSeries */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* MouseMan */ + (CS7 | CREAD | CLOCAL | HUPCL), /* MicroSoft */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* MouseSystems */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* Logitech */ + (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL), /* MMSeries */ + (CS7 | CREAD | CLOCAL | HUPCL), /* MouseMan */ 0, /* Bus */ 0, /* InPort */ 0, /* PS/2 */ - (CS8 | CREAD | CLOCAL | HUPCL ), /* MM HitTablet */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* GlidePoint */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* IntelliMouse */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* Thinking Mouse */ - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* sysmouse */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* X10 MouseRemote */ - (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL ), /* kidspad etc. */ - (CS8 | CREAD | CLOCAL | HUPCL ), /* VersaPad */ + (CS8 | CREAD | CLOCAL | HUPCL), /* MM HitTablet */ + (CS7 | CREAD | CLOCAL | HUPCL), /* GlidePoint */ + (CS7 | CREAD | CLOCAL | HUPCL), /* IntelliMouse */ + (CS7 | CREAD | CLOCAL | HUPCL), /* Thinking Mouse */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* sysmouse */ + (CS7 | CREAD | CLOCAL | HUPCL), /* X10 MouseRemote */ + (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL), /* kidspad etc. */ + (CS8 | CREAD | CLOCAL | HUPCL), /* VersaPad */ 0, /* JogDial */ #if notyet - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* Mariqua */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* Mariqua */ #endif }; @@ -391,24 +391,26 @@ static struct rodentparam { mousemode_t mode; /* protocol information */ float accelx; /* Acceleration in the X axis */ float accely; /* Acceleration in the Y axis */ -} rodent = { - flags : 0, - portname : NULL, - rtype : MOUSE_PROTO_UNKNOWN, - level : -1, - baudrate : 1200, - rate : 0, - resolution : MOUSE_RES_UNKNOWN, - zmap: { 0, 0, 0, 0 }, - wmode: 0, - mfd : -1, - cfd : -1, - mremsfd : -1, - mremcfd : -1, - clickthreshold : DFLT_CLICKTHRESHOLD, - button2timeout : DFLT_BUTTON2TIMEOUT, - accelx : 1.0, - accely : 1.0, + int scrollthreshold; /* Movement distance before virtual scrolling */ +} rodent = { + .flags = 0, + .portname = NULL, + .rtype = MOUSE_PROTO_UNKNOWN, + .level = -1, + .baudrate = 1200, + .rate = 0, + .resolution = MOUSE_RES_UNKNOWN, + .zmap = { 0, 0, 0, 0 }, + .wmode = 0, + .mfd = -1, + .cfd = -1, + .mremsfd = -1, + .mremcfd = -1, + .clickthreshold = DFLT_CLICKTHRESHOLD, + .button2timeout = DFLT_BUTTON2TIMEOUT, + .accelx = 1.0, + .accely = 1.0, + .scrollthreshold = DFLT_SCROLLTHRESHOLD, }; /* button status */ @@ -476,6 +478,8 @@ static void moused(void); static void hup(int sig); static void cleanup(int sig); static void usage(void); +static void log_or_warn(int log_pri, int errnum, const char *fmt, ...) + __printflike(3, 4); static int r_identify(void); static char *r_if(int type); @@ -503,19 +507,22 @@ static char *gettokenname(symtab_t *tab, int val); static void mremote_serversetup(); static void mremote_clientchg(int add); -static int kidspad(u_char rxc, mousestatus_t *act); +static int kidspad(u_char rxc, mousestatus_t *act); + +static int usbmodule(void); int -main(int argc, char **argv) +main(int argc, char *argv[]) { int c; int i; int j; + int retry; for (i = 0; i < MOUSE_MAXBUTTON; ++i) mstate[i] = &bstate[i]; - while((c = getopt(argc,argv,"3C:DE:F:I:PRS:a:cdfhi:l:m:p:r:st:w:z:")) != -1) + while ((c = getopt(argc, argv, "3C:DE:F:I:PRS:VU:a:cdfhi:l:m:p:r:st:w:z:")) != -1) switch(c) { case '3': @@ -524,10 +531,10 @@ main(int argc, char **argv) case 'E': rodent.button2timeout = atoi(optarg); - if ((rodent.button2timeout < 0) || - (rodent.button2timeout > MAX_BUTTON2TIMEOUT)) { - warnx("invalid argument `%s'", optarg); - usage(); + if ((rodent.button2timeout < 0) || + (rodent.button2timeout > MAX_BUTTON2TIMEOUT)) { + warnx("invalid argument `%s'", optarg); + usage(); } break; @@ -537,12 +544,12 @@ main(int argc, char **argv) warnx("invalid acceleration argument '%s'", optarg); usage(); } - + if (i == 1) rodent.accely = rodent.accelx; - + break; - + case 'c': rodent.flags |= ChordMiddle; break; @@ -557,18 +564,18 @@ main(int argc, char **argv) case 'i': if (strcmp(optarg, "all") == 0) - identify = ID_ALL; + identify = ID_ALL; else if (strcmp(optarg, "port") == 0) - identify = ID_PORT; + identify = ID_PORT; else if (strcmp(optarg, "if") == 0) - identify = ID_IF; + identify = ID_IF; else if (strcmp(optarg, "type") == 0) - identify = ID_TYPE; + identify = ID_TYPE; else if (strcmp(optarg, "model") == 0) - identify = ID_MODEL; + identify = ID_MODEL; else { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } nodaemon = TRUE; break; @@ -576,15 +583,15 @@ main(int argc, char **argv) case 'l': rodent.level = atoi(optarg); if ((rodent.level < 0) || (rodent.level > 4)) { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } break; case 'm': if (!r_installmap(optarg)) { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } break; @@ -594,21 +601,21 @@ main(int argc, char **argv) case 'r': if (strcmp(optarg, "high") == 0) - rodent.resolution = MOUSE_RES_HIGH; + rodent.resolution = MOUSE_RES_HIGH; else if (strcmp(optarg, "medium-high") == 0) - rodent.resolution = MOUSE_RES_HIGH; + rodent.resolution = MOUSE_RES_HIGH; else if (strcmp(optarg, "medium-low") == 0) - rodent.resolution = MOUSE_RES_MEDIUMLOW; + rodent.resolution = MOUSE_RES_MEDIUMLOW; else if (strcmp(optarg, "low") == 0) - rodent.resolution = MOUSE_RES_LOW; + rodent.resolution = MOUSE_RES_LOW; else if (strcmp(optarg, "default") == 0) - rodent.resolution = MOUSE_RES_DEFAULT; + rodent.resolution = MOUSE_RES_DEFAULT; else { - rodent.resolution = atoi(optarg); - if (rodent.resolution <= 0) { - warnx("invalid argument `%s'", optarg); - usage(); - } + rodent.resolution = atoi(optarg); + if (rodent.resolution <= 0) { + warnx("invalid argument `%s'", optarg); + usage(); + } } break; @@ -630,15 +637,15 @@ main(int argc, char **argv) rodent.zmap[0] = MOUSE_XAXIS; else if (strcmp(optarg, "y") == 0) rodent.zmap[0] = MOUSE_YAXIS; - else { + else { i = atoi(optarg); - /* - * Use button i for negative Z axis movement and + /* + * Use button i for negative Z axis movement and * button (i + 1) for positive Z axis movement. */ if ((i <= 0) || (i > MOUSE_MAXBUTTON - 1)) { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } rodent.zmap[0] = i; rodent.zmap[1] = i + 1; @@ -661,10 +668,10 @@ main(int argc, char **argv) case 'C': rodent.clickthreshold = atoi(optarg); - if ((rodent.clickthreshold < 0) || - (rodent.clickthreshold > MAX_CLICKTHRESHOLD)) { - warnx("invalid argument `%s'", optarg); - usage(); + if ((rodent.clickthreshold < 0) || + (rodent.clickthreshold > MAX_CLICKTHRESHOLD)) { + warnx("invalid argument `%s'", optarg); + usage(); } break; @@ -675,8 +682,8 @@ main(int argc, char **argv) case 'F': rodent.rate = atoi(optarg); if (rodent.rate <= 0) { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } break; @@ -695,8 +702,8 @@ main(int argc, char **argv) case 'S': rodent.baudrate = atoi(optarg); if (rodent.baudrate <= 0) { - warnx("invalid argument `%s'", optarg); - usage(); + warnx("invalid argument `%s'", optarg); + usage(); } debug("rodent baudrate %d", rodent.baudrate); break; @@ -720,6 +727,17 @@ main(int argc, char **argv) warnx("no such mouse type `%s'", optarg); usage(); + case 'V': + rodent.flags |= VirtualScroll; + break; + case 'U': + rodent.scrollthreshold = atoi(optarg); + if (rodent.scrollthreshold < 0) { + warnx("invalid argument `%s'", optarg); + usage(); + } + break; + case 'h': case '?': default: @@ -741,9 +759,9 @@ main(int argc, char **argv) switch(rodent.rtype) { case MOUSE_PROTO_INPORT: - /* INPORT and BUS are the same... */ + /* INPORT and BUS are the same... */ rodent.rtype = MOUSE_PROTO_BUS; - /* FALL THROUGH */ + /* FALLTHROUGH */ case MOUSE_PROTO_BUS: if (!rodent.portname) rodent.portname = "/dev/mse0"; @@ -761,27 +779,39 @@ main(int argc, char **argv) usage(); } + retry = 1; + if (strncmp(rodent.portname, "/dev/ums", 8) == 0) { + if (usbmodule() != 0) + retry = 5; + } + for (;;) { if (setjmp(env) == 0) { signal(SIGHUP, hup); signal(SIGINT , cleanup); signal(SIGQUIT, cleanup); signal(SIGTERM, cleanup); - if ((rodent.mfd = open(rodent.portname, O_RDWR | O_NONBLOCK, 0)) - == -1) - logerr(1, "unable to open %s", rodent.portname); - if (r_identify() == MOUSE_PROTO_UNKNOWN) { - logwarnx("cannot determine mouse type on %s", rodent.portname); - close(rodent.mfd); - rodent.mfd = -1; - } + for (i = 0; i < retry; ++i) { + if (i > 0) + sleep(2); + rodent.mfd = open(rodent.portname, O_RDWR | O_NONBLOCK); + if (rodent.mfd != -1 || errno != ENOENT) + break; + } + if (rodent.mfd == -1) + logerr(1, "unable to open %s", rodent.portname); + if (r_identify() == MOUSE_PROTO_UNKNOWN) { + logwarnx("cannot determine mouse type on %s", rodent.portname); + close(rodent.mfd); + rodent.mfd = -1; + } /* print some information */ - if (identify != ID_NONE) { + if (identify != ID_NONE) { if (identify == ID_ALL) - printf("%s %s %s %s\n", - rodent.portname, r_if(rodent.hw.iftype), - r_name(rodent.rtype), r_model(rodent.hw.model)); + printf("%s %s %s %s\n", + rodent.portname, r_if(rodent.hw.iftype), + r_name(rodent.rtype), r_model(rodent.hw.model)); else if (identify & ID_PORT) printf("%s\n", rodent.portname); else if (identify & ID_IF) @@ -792,23 +822,23 @@ main(int argc, char **argv) printf("%s\n", r_model(rodent.hw.model)); exit(0); } else { - debug("port: %s interface: %s type: %s model: %s", + debug("port: %s interface: %s type: %s model: %s", rodent.portname, r_if(rodent.hw.iftype), r_name(rodent.rtype), r_model(rodent.hw.model)); } if (rodent.mfd == -1) { - /* - * We cannot continue because of error. Exit if the - * program has not become a daemon. Otherwise, block - * until the the user corrects the problem and issues SIGHUP. - */ - if (!background) + /* + * We cannot continue because of error. Exit if the + * program has not become a daemon. Otherwise, block + * until the the user corrects the problem and issues SIGHUP. + */ + if (!background) exit(1); - sigpause(0); + sigpause(0); } - r_init(); /* call init function */ + r_init(); /* call init function */ moused(); } @@ -823,6 +853,43 @@ main(int argc, char **argv) exit(0); } +static int +usbmodule(void) +{ + struct kld_file_stat fstat; + struct module_stat mstat; + int fileid, modid; + int loaded; + + for (loaded = 0, fileid = kldnext(0); !loaded && fileid > 0; + fileid = kldnext(fileid)) { + fstat.version = sizeof(fstat); + if (kldstat(fileid, &fstat) < 0) + continue; + if (strncmp(fstat.name, "uhub/ums", 8) == 0) { + loaded = 1; + break; + } + for (modid = kldfirstmod(fileid); modid > 0; + modid = modfnext(modid)) { + mstat.version = sizeof(mstat); + if (modstat(modid, &mstat) < 0) + continue; + if (strncmp(mstat.name, "uhub/ums", 8) == 0) { + loaded = 1; + break; + } + } + } + if (!loaded) { + if (kldload("ums") != -1) + return 1; + if (errno != EEXIST) + logerr(1, "unable to load USB mouse driver"); + } + return 0; +} + static void moused(void) { @@ -839,11 +906,11 @@ moused(void) int i; if ((rodent.cfd = open("/dev/consolectl", O_RDWR, 0)) == -1) - logerr(1, "cannot open /dev/consolectl", 0); + logerr(1, "cannot open /dev/consolectl"); - if (!nodaemon && !background) + if (!nodaemon && !background) { if (daemon(0, 0)) { - logerr(1, "failed to become a daemon", 0); + logerr(1, "failed to become a daemon"); } else { background = TRUE; fp = fopen(pidfile, "w"); @@ -852,6 +919,7 @@ moused(void) fclose(fp); } } + } /* clear mouse data */ bzero(&action0, sizeof(action0)); @@ -889,7 +957,7 @@ moused(void) c = select(FD_SETSIZE, &fds, NULL, NULL, (rodent.flags & Emulate3Button) ? &timeout : NULL); if (c < 0) { /* error */ - logwarn("failed to read from mouse", 0); + logwarn("failed to read from mouse"); continue; } else if (c == 0) { /* timeout */ /* assert(rodent.flags & Emulate3Button) */ @@ -923,10 +991,54 @@ moused(void) } if ((flags = r_protocol(b, &action0)) == 0) continue; + + if (rodent.flags & VirtualScroll) { + /* Allow middle button drags to scroll up and down */ + if (action0.button == MOUSE_BUTTON2DOWN) { + if (scroll_state == SCROLL_NOTSCROLLING) { + scroll_state = SCROLL_PREPARE; + debug("PREPARING TO SCROLL"); + } + debug("[BUTTON2] flags:%08x buttons:%08x obuttons:%08x", + action.flags, action.button, action.obutton); + } else { + debug("[NOTBUTTON2] flags:%08x buttons:%08x obuttons:%08x", + action.flags, action.button, action.obutton); + + /* This isn't a middle button down... move along... */ + if (scroll_state == SCROLL_SCROLLING) { + /* + * We were scrolling, someone let go of button 2. + * Now turn autoscroll off. + */ + scroll_state = SCROLL_NOTSCROLLING; + debug("DONE WITH SCROLLING / %d", scroll_state); + } else if (scroll_state == SCROLL_PREPARE) { + mousestatus_t newaction = action0; + + /* We were preparing to scroll, but we never moved... */ + r_timestamp(&action0); + r_statetrans(&action0, &newaction, + A(newaction.button & MOUSE_BUTTON1DOWN, + action0.button & MOUSE_BUTTON3DOWN)); + + /* Send middle down */ + newaction.button = MOUSE_BUTTON2DOWN; + r_click(&newaction); + + /* Send middle up */ + r_timestamp(&newaction); + newaction.obutton = newaction.button; + newaction.button = action0.button; + r_click(&newaction); + } + } + } + r_timestamp(&action0); - r_statetrans(&action0, &action, - A(action0.button & MOUSE_BUTTON1DOWN, - action0.button & MOUSE_BUTTON3DOWN)); + 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); } @@ -940,52 +1052,85 @@ moused(void) debug("activity : buttons 0x%08x dx %d dy %d dz %d", action2.button, action2.dx, action2.dy, action2.dz); + if (rodent.flags & VirtualScroll) { + /* + * If *only* the middle button is pressed AND we are moving + * the stick/trackpoint/nipple, scroll! + */ + if (scroll_state == SCROLL_PREPARE) { + /* Ok, Set we're really scrolling now.... */ + if (action2.dy || action2.dx) + scroll_state = SCROLL_SCROLLING; + } + if (scroll_state == SCROLL_SCROLLING) { + scroll_movement += action2.dy; + debug("SCROLL: %d", scroll_movement); + + if (scroll_movement < -rodent.scrollthreshold) { + /* Scroll down */ + action2.dz = -1; + scroll_movement = 0; + } + else if (scroll_movement > rodent.scrollthreshold) { + /* Scroll up */ + action2.dz = 1; + scroll_movement = 0; + } + + /* Don't move while scrolling */ + action2.dx = action2.dy = 0; + } + } + if (extioctl) { - r_click(&action2); - if (action2.flags & MOUSE_POSCHANGED) { - mouse.operation = MOUSE_MOTION_EVENT; - mouse.u.data.buttons = action2.button; - mouse.u.data.x = action2.dx * rodent.accelx; - mouse.u.data.y = action2.dy * rodent.accely; - mouse.u.data.z = action2.dz; + /* Defer clicks until we aren't VirtualScroll'ing. */ + if (scroll_state == SCROLL_NOTSCROLLING) + r_click(&action2); + + if (action2.flags & MOUSE_POSCHANGED) { + mouse.operation = MOUSE_MOTION_EVENT; + mouse.u.data.buttons = action2.button; + mouse.u.data.x = action2.dx * rodent.accelx; + mouse.u.data.y = action2.dy * rodent.accely; + mouse.u.data.z = action2.dz; if (debug < 2) - ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); - } + ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); + } } else { - mouse.operation = MOUSE_ACTION; - mouse.u.data.buttons = action2.button; - mouse.u.data.x = action2.dx * rodent.accelx; - mouse.u.data.y = action2.dy * rodent.accely; - mouse.u.data.z = action2.dz; + mouse.operation = MOUSE_ACTION; + mouse.u.data.buttons = action2.button; + mouse.u.data.x = action2.dx * rodent.accelx; + mouse.u.data.y = action2.dy * rodent.accely; + mouse.u.data.z = action2.dz; if (debug < 2) - ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); + ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); } - /* - * If the Z axis movement is mapped to a imaginary physical + /* + * If the Z axis movement is mapped to an imaginary physical * button, we need to cook up a corresponding button `up' event * after sending a button `down' event. */ - if ((rodent.zmap[0] > 0) && (action.dz != 0)) { + if ((rodent.zmap[0] > 0) && (action.dz != 0)) { action.obutton = action.button; action.dx = action.dy = action.dz = 0; - r_map(&action, &action2); - debug("activity : buttons 0x%08x dx %d dy %d dz %d", + r_map(&action, &action2); + debug("activity : buttons 0x%08x dx %d dy %d dz %d", action2.button, action2.dx, action2.dy, action2.dz); - if (extioctl) { - r_click(&action2); - } else { - mouse.operation = MOUSE_ACTION; - mouse.u.data.buttons = action2.button; + if (extioctl) { + r_click(&action2); + } else { + mouse.operation = MOUSE_ACTION; + mouse.u.data.buttons = action2.button; mouse.u.data.x = mouse.u.data.y = mouse.u.data.z = 0; if (debug < 2) - ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); - } + ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); + } } } } - /* NOTREACHED */ + /* NOT REACHED */ } static void @@ -994,7 +1139,7 @@ hup(int sig) longjmp(env, 1); } -static void +static void cleanup(int sig) { if (rodent.rtype == MOUSE_PROTO_X10MOUSEREM) @@ -1012,12 +1157,36 @@ usage(void) { fprintf(stderr, "%s\n%s\n%s\n%s\n", "usage: moused [-DRcdfs] [-I file] [-F rate] [-r resolution] [-S baudrate]", - " [-a X [,Y]] [-C threshold] [-m N=M] [-w N] [-z N]", - " [-t ] [-3 [-E timeout]] -p ", + " [-V [-U threshold]] [-a X [,Y]] [-C threshold] [-m N=M] [-w N]", + " [-z N] [-t ] [-l level] [-3 [-E timeout]] -p ", " moused [-d] -i -p "); exit(1); } +/* + * Output an error message to syslog or stderr as appropriate. If + * `errnum' is non-zero, append its string form to the message. + */ +static void +log_or_warn(int log_pri, int errnum, const char *fmt, ...) +{ + va_list ap; + char buf[256]; + + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + if (errnum) { + strlcat(buf, ": ", sizeof(buf)); + strlcat(buf, strerror(errnum), sizeof(buf)); + } + + if (background) + syslog(log_pri, "%s", buf); + else + warnx("%s", buf); +} + /** ** Mouse interface code, courtesy of XFree86 3.1.2. ** @@ -1070,20 +1239,20 @@ usage(void) /* the following table must be ordered by MOUSE_PROTO_XXX in mouse.h */ static unsigned char proto[][7] = { /* hd_mask hd_id dp_mask dp_id bytes b4_mask b4_id */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00 }, /* MicroSoft */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00 }, /* MicroSoft */ { 0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* MouseSystems */ { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* Logitech */ { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* MMSeries */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* MouseMan */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* MouseMan */ { 0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* Bus */ { 0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* InPort */ { 0xc0, 0x00, 0x00, 0x00, 3, 0x00, 0xff }, /* PS/2 mouse */ { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* MM HitTablet */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* GlidePoint */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x3f, 0x00 }, /* IntelliMouse */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* ThinkingMouse */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* GlidePoint */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x3f, 0x00 }, /* IntelliMouse */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* ThinkingMouse */ { 0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* sysmouse */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00 }, /* X10 MouseRem */ + { 0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00 }, /* X10 MouseRem */ { 0x80, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* KIDSPAD */ { 0xc3, 0xc0, 0x00, 0x00, 6, 0x00, 0xff }, /* VersaPad */ { 0x00, 0x00, 0x00, 0x00, 1, 0x00, 0xff }, /* JogDial */ @@ -1109,7 +1278,7 @@ r_identify(void) rodent.level = (ioctl(rodent.mfd, MOUSE_GETLEVEL, &level) == 0) ? level : 0; /* - * Interrogate the driver and get some intelligence on the device... + * Interrogate the driver and get some intelligence on the device... * The following ioctl functions are not always supported by device * drivers. When the driver doesn't support them, we just trust the * user to supply valid information. @@ -1119,77 +1288,77 @@ r_identify(void) ioctl(rodent.mfd, MOUSE_GETHWINFO, &rodent.hw); if (rodent.rtype != MOUSE_PROTO_UNKNOWN) - bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); + bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); rodent.mode.protocol = MOUSE_PROTO_UNKNOWN; rodent.mode.rate = -1; rodent.mode.resolution = MOUSE_RES_UNKNOWN; rodent.mode.accelfactor = 0; rodent.mode.level = 0; if (ioctl(rodent.mfd, MOUSE_GETMODE, &rodent.mode) == 0) { - if ((rodent.mode.protocol == MOUSE_PROTO_UNKNOWN) + if ((rodent.mode.protocol == MOUSE_PROTO_UNKNOWN) || (rodent.mode.protocol >= sizeof(proto)/sizeof(proto[0]))) { logwarnx("unknown mouse protocol (%d)", rodent.mode.protocol); return MOUSE_PROTO_UNKNOWN; - } else { + } else { /* INPORT and BUS are the same... */ if (rodent.mode.protocol == MOUSE_PROTO_INPORT) - rodent.mode.protocol = MOUSE_PROTO_BUS; + rodent.mode.protocol = MOUSE_PROTO_BUS; if (rodent.mode.protocol != rodent.rtype) { /* Hmm, the driver doesn't agree with the user... */ - if (rodent.rtype != MOUSE_PROTO_UNKNOWN) - logwarnx("mouse type mismatch (%s != %s), %s is assumed", - r_name(rodent.mode.protocol), r_name(rodent.rtype), - r_name(rodent.mode.protocol)); - rodent.rtype = rodent.mode.protocol; - bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); + if (rodent.rtype != MOUSE_PROTO_UNKNOWN) + logwarnx("mouse type mismatch (%s != %s), %s is assumed", + r_name(rodent.mode.protocol), r_name(rodent.rtype), + r_name(rodent.mode.protocol)); + rodent.rtype = rodent.mode.protocol; + bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); } - } - cur_proto[4] = rodent.mode.packetsize; - cur_proto[0] = rodent.mode.syncmask[0]; /* header byte bit mask */ - cur_proto[1] = rodent.mode.syncmask[1]; /* header bit pattern */ + } + cur_proto[4] = rodent.mode.packetsize; + cur_proto[0] = rodent.mode.syncmask[0]; /* header byte bit mask */ + cur_proto[1] = rodent.mode.syncmask[1]; /* header bit pattern */ } - /* maybe this is an PnP mouse... */ + /* maybe this is a PnP mouse... */ if (rodent.mode.protocol == MOUSE_PROTO_UNKNOWN) { - if (rodent.flags & NoPnP) - return rodent.rtype; + if (rodent.flags & NoPnP) + return rodent.rtype; if (((len = pnpgets(pnpbuf)) <= 0) || !pnpparse(&pnpid, pnpbuf, len)) - return rodent.rtype; + return rodent.rtype; - debug("PnP serial mouse: '%*.*s' '%*.*s' '%*.*s'", - pnpid.neisaid, pnpid.neisaid, pnpid.eisaid, - pnpid.ncompat, pnpid.ncompat, pnpid.compat, + debug("PnP serial mouse: '%*.*s' '%*.*s' '%*.*s'", + pnpid.neisaid, pnpid.neisaid, pnpid.eisaid, + pnpid.ncompat, pnpid.ncompat, pnpid.compat, pnpid.ndescription, pnpid.ndescription, pnpid.description); /* we have a valid PnP serial device ID */ - rodent.hw.iftype = MOUSE_IF_SERIAL; + rodent.hw.iftype = MOUSE_IF_SERIAL; t = pnpproto(&pnpid); if (t != NULL) { - rodent.mode.protocol = t->val; - rodent.hw.model = t->val2; + rodent.mode.protocol = t->val; + rodent.hw.model = t->val2; } else { - rodent.mode.protocol = MOUSE_PROTO_UNKNOWN; + rodent.mode.protocol = MOUSE_PROTO_UNKNOWN; } if (rodent.mode.protocol == MOUSE_PROTO_INPORT) rodent.mode.protocol = MOUSE_PROTO_BUS; - /* make final adjustment */ + /* make final adjustment */ if (rodent.mode.protocol != MOUSE_PROTO_UNKNOWN) { if (rodent.mode.protocol != rodent.rtype) { /* Hmm, the device doesn't agree with the user... */ - if (rodent.rtype != MOUSE_PROTO_UNKNOWN) - logwarnx("mouse type mismatch (%s != %s), %s is assumed", - r_name(rodent.mode.protocol), r_name(rodent.rtype), - r_name(rodent.mode.protocol)); - rodent.rtype = rodent.mode.protocol; - bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); + if (rodent.rtype != MOUSE_PROTO_UNKNOWN) + logwarnx("mouse type mismatch (%s != %s), %s is assumed", + r_name(rodent.mode.protocol), r_name(rodent.rtype), + r_name(rodent.mode.protocol)); + rodent.rtype = rodent.mode.protocol; + bcopy(proto[rodent.rtype], cur_proto, sizeof(cur_proto)); } } } debug("proto params: %02x %02x %02x %02x %d %02x %02x", - cur_proto[0], cur_proto[1], cur_proto[2], cur_proto[3], + cur_proto[0], cur_proto[1], cur_proto[2], cur_proto[3], cur_proto[4], cur_proto[5], cur_proto[6]); return rodent.rtype; @@ -1207,7 +1376,7 @@ r_if(int iftype) static char * r_name(int type) { - return ((type == MOUSE_PROTO_UNKNOWN) + return ((type == MOUSE_PROTO_UNKNOWN) || (type > sizeof(rnames)/sizeof(rnames[0]) - 1)) ? "unknown" : rnames[type]; } @@ -1231,7 +1400,7 @@ r_init(void) int i; /** - ** This comment is a little out of context here, but it contains + ** This comment is a little out of context here, but it contains ** some useful information... ******************************************************************** ** @@ -1276,9 +1445,9 @@ r_init(void) switch (rodent.rtype) { case MOUSE_PROTO_LOGI: - /* + /* * The baud rate selection command must be sent at the current - * baud rate; try all likely settings + * baud rate; try all likely settings */ setmousespeed(9600, rodent.baudrate, rodentcflags[rodent.rtype]); setmousespeed(4800, rodent.baudrate, rodentcflags[rodent.rtype]); @@ -1330,16 +1499,16 @@ r_init(void) usleep(50000); /* Resolution is in 'lines per inch' on the Hitachi tablet */ - if (rodent.resolution == MOUSE_RES_LOW) c = 'g'; + if (rodent.resolution == MOUSE_RES_LOW) c = 'g'; else if (rodent.resolution == MOUSE_RES_MEDIUMLOW) c = 'e'; else if (rodent.resolution == MOUSE_RES_MEDIUMHIGH) c = 'h'; else if (rodent.resolution == MOUSE_RES_HIGH) c = 'd'; - else if (rodent.resolution <= 40) c = 'g'; - else if (rodent.resolution <= 100) c = 'd'; - else if (rodent.resolution <= 200) c = 'e'; - else if (rodent.resolution <= 500) c = 'h'; - else if (rodent.resolution <= 1000) c = 'j'; - else c = 'd'; + else if (rodent.resolution <= 40) c = 'g'; + else if (rodent.resolution <= 100) c = 'd'; + else if (rodent.resolution <= 200) c = 'e'; + else if (rodent.resolution <= 500) c = 'h'; + else if (rodent.resolution <= 1000) c = 'j'; + else c = 'd'; write(rodent.mfd, &c, 1); usleep(50000); @@ -1362,7 +1531,7 @@ r_init(void) read(rodent.mfd, &c, 1); debug("%c", c); if (c != *s) - break; + break; } break; @@ -1373,17 +1542,17 @@ r_init(void) if (rodent.flags & ClearDTR) { i = TIOCM_DTR; ioctl(rodent.mfd, TIOCMBIC, &i); - } - if (rodent.flags & ClearRTS) { + } + if (rodent.flags & ClearRTS) { i = TIOCM_RTS; ioctl(rodent.mfd, TIOCMBIC, &i); - } + } break; case MOUSE_PROTO_SYSMOUSE: if (rodent.hw.iftype == MOUSE_IF_SYSMOUSE) setmousespeed(1200, rodent.baudrate, rodentcflags[rodent.rtype]); - /* fall through */ + /* FALLTHROUGH */ case MOUSE_PROTO_BUS: case MOUSE_PROTO_INPORT: @@ -1442,83 +1611,83 @@ static int r_protocol(u_char rBuf, mousestatus_t *act) { /* MOUSE_MSS_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ - static int butmapmss[4] = { /* Microsoft, MouseMan, GlidePoint, + static int butmapmss[4] = { /* Microsoft, MouseMan, GlidePoint, IntelliMouse, Thinking Mouse */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, }; - static int butmapmss2[4] = { /* Microsoft, MouseMan, GlidePoint, + static int butmapmss2[4] = { /* Microsoft, MouseMan, GlidePoint, Thinking Mouse */ - 0, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, + 0, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, }; /* MOUSE_INTELLI_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ static int butmapintelli[4] = { /* IntelliMouse, NetMouse, Mie Mouse, MouseMan+ */ - 0, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, + 0, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, }; /* MOUSE_MSC_BUTTON?UP -> MOUSE_BUTTON?DOWN */ - static int butmapmsc[8] = { /* MouseSystems, MMSeries, Logitech, + static int butmapmsc[8] = { /* MouseSystems, MMSeries, Logitech, Bus, sysmouse */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN }; /* MOUSE_PS2_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ static int butmapps2[8] = { /* PS/2 */ - 0, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, + 0, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN }; /* for Hitachi tablet */ static int butmaphit[8] = { /* MM HitTablet */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON5DOWN, - MOUSE_BUTTON6DOWN, - MOUSE_BUTTON7DOWN, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON5DOWN, + MOUSE_BUTTON6DOWN, + MOUSE_BUTTON7DOWN, }; /* for serial VersaPad */ static int butmapversa[8] = { /* VersaPad */ - 0, - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + 0, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, }; /* for PS/2 VersaPad */ static int butmapversaps2[8] = { /* VersaPad */ - 0, - MOUSE_BUTTON3DOWN, - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + 0, + MOUSE_BUTTON3DOWN, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, }; static int pBufP = 0; static unsigned char pBuf[8]; @@ -1557,7 +1726,7 @@ r_protocol(u_char rBuf, mousestatus_t *act) { pBufP = 0; /* skip package */ } - + if (pBufP == 0 && (rBuf & cur_proto[0]) != cur_proto[1]) return 0; @@ -1580,37 +1749,37 @@ r_protocol(u_char rBuf, mousestatus_t *act) * Even worse, different MouseMen and TrackMen differ in the 4th * byte: some will send 0x00/0x20, others 0x01/0x21, or even * 0x02/0x22, so I have to strip off the lower bits. - * - * [JCH-96/01/21] - * HACK for ALPS "fourth button". (It's bit 0x10 of the "fourth byte" - * and it is activated by tapping the glidepad with the finger! 8^) - * We map it to bit bit3, and the reverse map in xf86Events just has - * to be extended so that it is identified as Button 4. The lower - * half of the reverse-map may remain unchanged. + * + * [JCH-96/01/21] + * HACK for ALPS "fourth button". (It's bit 0x10 of the "fourth byte" + * and it is activated by tapping the glidepad with the finger! 8^) + * We map it to bit bit3, and the reverse map in xf86Events just has + * to be extended so that it is identified as Button 4. The lower + * half of the reverse-map may remain unchanged. */ - /* + /* * [KY-97/08/03] * Receive the fourth byte only when preceding three bytes have * been detected (pBufP >= cur_proto[4]). In the previous * versions, the test was pBufP == 0; thus, we may have mistakingly - * received a byte even if we didn't see anything preceding + * received a byte even if we didn't see anything preceding * the byte. */ if ((rBuf & cur_proto[5]) != cur_proto[6]) { - pBufP = 0; + pBufP = 0; return 0; } switch (rodent.rtype) { #if notyet case MOUSE_PROTO_MARIQUA: - /* + /* * This mouse has 16! buttons in addition to the standard * three of them. They return 0x10 though 0x1f in the * so-called `ten key' mode and 0x30 though 0x3f in the - * `function key' mode. As there are only 31 bits for + * `function key' mode. As there are only 31 bits for * button state (including the standard three), we ignore * the bit 0x20 and don't distinguish the two modes. */ @@ -1618,9 +1787,9 @@ r_protocol(u_char rBuf, mousestatus_t *act) act->obutton = act->button; rBuf &= 0x1f; act->button = (1 << (rBuf - 13)) - | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); - /* - * FIXME: this is a button "down" event. There needs to be + | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); + /* + * FIXME: this is a button "down" event. There needs to be * a corresponding button "up" event... XXX */ break; @@ -1631,11 +1800,11 @@ r_protocol(u_char rBuf, mousestatus_t *act) /* * IntelliMouse, NetMouse (including NetMouse Pro) and Mie Mouse * always send the fourth byte, whereas the fourth byte is - * optional for GlidePoint and ThinkingMouse. The fourth byte - * is also optional for MouseMan+ and FirstMouse+ in their - * native mode. It is always sent if they are in the IntelliMouse + * optional for GlidePoint and ThinkingMouse. The fourth byte + * is also optional for MouseMan+ and FirstMouse+ in their + * native mode. It is always sent if they are in the IntelliMouse * compatible mode. - */ + */ case MOUSE_PROTO_INTELLI: /* IntelliMouse, NetMouse, Mie Mouse, MouseMan+ */ act->dx = act->dy = 0; @@ -1657,28 +1826,28 @@ r_protocol(u_char rBuf, mousestatus_t *act) act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0) | (act->obutton ^ act->button); - pBufP = 0; + pBufP = 0; return act->flags; } - + if (pBufP >= cur_proto[4]) pBufP = 0; pBuf[pBufP++] = rBuf; if (pBufP != cur_proto[4]) return 0; - + /* * assembly full package */ debug("assembled full packet (len %d) %x,%x,%x,%x,%x,%x,%x,%x", - cur_proto[4], - pBuf[0], pBuf[1], pBuf[2], pBuf[3], + cur_proto[4], + pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7]); act->dz = 0; act->obutton = act->button; - switch (rodent.rtype) + switch (rodent.rtype) { case MOUSE_PROTO_MS: /* Microsoft */ case MOUSE_PROTO_LOGIMOUSEMAN: /* MouseMan/TrackMan */ @@ -1686,25 +1855,25 @@ r_protocol(u_char rBuf, mousestatus_t *act) act->button = act->obutton & MOUSE_BUTTON4DOWN; if (rodent.flags & ChordMiddle) act->button |= ((pBuf[0] & MOUSE_MSS_BUTTONS) == MOUSE_MSS_BUTTONS) - ? MOUSE_BUTTON2DOWN + ? MOUSE_BUTTON2DOWN : butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; else act->button |= (act->obutton & MOUSE_BUTTON2DOWN) | butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; - + /* Send X10 btn events to remote client (ensure -128-+127 range) */ - if ((rodent.rtype == MOUSE_PROTO_X10MOUSEREM) && + if ((rodent.rtype == MOUSE_PROTO_X10MOUSEREM) && ((pBuf[0] & 0xFC) == 0x44) && (pBuf[2] == 0x3F)) { if (rodent.mremcfd >= 0) { - unsigned char key = (signed char)(((pBuf[0] & 0x03) << 6) | + unsigned char key = (signed char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); - write( rodent.mremcfd, &key, 1 ); + write(rodent.mremcfd, &key, 1); } return 0; } - act->dx = (char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); - act->dy = (char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); + act->dx = (signed char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); + act->dy = (signed char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); break; case MOUSE_PROTO_GLIDEPOINT: /* GlidePoint */ @@ -1712,25 +1881,25 @@ r_protocol(u_char rBuf, mousestatus_t *act) case MOUSE_PROTO_INTELLI: /* IntelliMouse, NetMouse, Mie Mouse, MouseMan+ */ act->button = (act->obutton & (MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN)) - | butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; - act->dx = (char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); - act->dy = (char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); + | butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; + act->dx = (signed char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); + act->dy = (signed char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); break; - + case MOUSE_PROTO_MSC: /* MouseSystems Corp */ #if notyet case MOUSE_PROTO_MARIQUA: /* Mariqua */ #endif act->button = butmapmsc[(~pBuf[0]) & MOUSE_MSC_BUTTONS]; - act->dx = (char)(pBuf[1]) + (char)(pBuf[3]); - act->dy = - ((char)(pBuf[2]) + (char)(pBuf[4])); + act->dx = (signed char)(pBuf[1]) + (signed char)(pBuf[3]); + act->dy = - ((signed char)(pBuf[2]) + (signed char)(pBuf[4])); break; case MOUSE_PROTO_JOGDIAL: /* JogDial */ if (rBuf == 0x6c) - act->dz=-1; + act->dz = -1; if (rBuf == 0x72) - act->dz=1; + act->dz = 1; if (rBuf == 0x64) act->button = MOUSE_BUTTON1DOWN; if (rBuf == 0x75) @@ -1749,7 +1918,7 @@ r_protocol(u_char rBuf, mousestatus_t *act) act->dx = (pBuf[0] & MOUSE_MM_XPOSITIVE) ? pBuf[1] : - pBuf[1]; act->dy = (pBuf[0] & MOUSE_MM_YPOSITIVE) ? - pBuf[2] : pBuf[2]; break; - + case MOUSE_PROTO_VERSAPAD: /* VersaPad */ act->button = butmapversa[(pBuf[0] & MOUSE_VERSA_BUTTONS) >> 3]; act->button |= (pBuf[0] & MOUSE_VERSA_TAP) ? MOUSE_BUTTON4DOWN : 0; @@ -1777,8 +1946,8 @@ r_protocol(u_char rBuf, mousestatus_t *act) case MOUSE_PROTO_BUS: /* Bus */ case MOUSE_PROTO_INPORT: /* InPort */ act->button = butmapmsc[(~pBuf[0]) & MOUSE_MSC_BUTTONS]; - act->dx = (char)pBuf[1]; - act->dy = - (char)pBuf[2]; + act->dx = (signed char)pBuf[1]; + act->dy = - (signed char)pBuf[2]; break; case MOUSE_PROTO_PS2: /* PS/2 */ @@ -1788,8 +1957,8 @@ r_protocol(u_char rBuf, mousestatus_t *act) /* * Moused usually operates the psm driver at the operation level 1 * which sends mouse data in MOUSE_PROTO_SYSMOUSE protocol. - * The following code takes effect only when the user explicitly - * requets the level 2 at which wheel movement and additional button + * The following code takes effect only when the user explicitly + * requets the level 2 at which wheel movement and additional button * actions are encoded in model-dependent formats. At the level 0 * the following code is no-op because the psm driver says the model * is MOUSE_MODEL_GENERIC. @@ -1807,7 +1976,7 @@ r_protocol(u_char rBuf, mousestatus_t *act) case MOUSE_MODEL_INTELLI: case MOUSE_MODEL_NET: /* wheel data is in the fourth byte */ - act->dz = (char)pBuf[3]; + act->dz = (signed char)pBuf[3]; if ((act->dz >= 7) || (act->dz <= -7)) act->dz = 0; /* some compatible mice may have additional buttons */ @@ -1862,11 +2031,11 @@ r_protocol(u_char rBuf, mousestatus_t *act) break; case 0: /* device type packet - shouldn't happen */ - /* FALL THROUGH */ + /* FALLTHROUGH */ default: act->dx = act->dy = 0; act->button = act->obutton; - debug("unknown PS2++ packet type %d: 0x%02x 0x%02x 0x%02x\n", + debug("unknown PS2++ packet type %d: 0x%02x 0x%02x 0x%02x\n", MOUSE_PS2PLUS_PACKET_TYPE(pBuf), pBuf[0], pBuf[1], pBuf[2]); break; @@ -1954,10 +2123,10 @@ r_protocol(u_char rBuf, mousestatus_t *act) case MOUSE_PROTO_SYSMOUSE: /* sysmouse */ act->button = butmapmsc[(~pBuf[0]) & MOUSE_SYS_STDBUTTONS]; - act->dx = (char)(pBuf[1]) + (char)(pBuf[3]); - act->dy = - ((char)(pBuf[2]) + (char)(pBuf[4])); + act->dx = (signed char)(pBuf[1]) + (signed char)(pBuf[3]); + act->dy = - ((signed char)(pBuf[2]) + (signed char)(pBuf[4])); if (rodent.level == 1) { - act->dz = ((char)(pBuf[5] << 1) + (char)(pBuf[6] << 1))/2; + act->dz = ((signed char)(pBuf[5] << 1) + (signed char)(pBuf[6] << 1)) >> 1; act->button |= ((~pBuf[7] & MOUSE_SYS_EXTBUTTONS) << 3); } break; @@ -1965,7 +2134,7 @@ r_protocol(u_char rBuf, mousestatus_t *act) default: return 0; } - /* + /* * We don't reset pBufP here yet, as there may be an additional data * byte in some protocols. See above. */ @@ -1993,7 +2162,7 @@ r_statetrans(mousestatus_t *a1, mousestatus_t *a2, int trans) if (rodent.flags & Emulate3Button) { if (debug > 2) - debug("state:%d, trans:%d -> state:%d", + debug("state:%d, trans:%d -> state:%d", mouse_button_state, trans, states[mouse_button_state].s[trans]); /* @@ -2035,8 +2204,8 @@ r_statetrans(mousestatus_t *a1, mousestatus_t *a2, int trans) /* phisical to logical button mapping */ static int p2l[MOUSE_MAXBUTTON] = { - MOUSE_BUTTON1DOWN, MOUSE_BUTTON2DOWN, MOUSE_BUTTON3DOWN, MOUSE_BUTTON4DOWN, - MOUSE_BUTTON5DOWN, MOUSE_BUTTON6DOWN, MOUSE_BUTTON7DOWN, MOUSE_BUTTON8DOWN, + MOUSE_BUTTON1DOWN, MOUSE_BUTTON2DOWN, MOUSE_BUTTON3DOWN, MOUSE_BUTTON4DOWN, + MOUSE_BUTTON5DOWN, MOUSE_BUTTON6DOWN, MOUSE_BUTTON7DOWN, MOUSE_BUTTON8DOWN, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00010000, 0x00020000, 0x00040000, 0x00080000, @@ -2092,8 +2261,8 @@ r_installmap(char *arg) static void r_map(mousestatus_t *act1, mousestatus_t *act2) { - int pb; - int pbuttons; + register int pb; + register int pbuttons; int lbuttons; pbuttons = act1->button; @@ -2177,32 +2346,32 @@ r_timestamp(mousestatus_t *act) /* double click threshold */ tv2.tv_sec = rodent.clickthreshold/1000; tv2.tv_usec = (rodent.clickthreshold%1000)*1000; - timersub(&tv1, &tv2, &tv); + 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); + timersub(&tv1, &tv2, &tv3); button = MOUSE_BUTTON1DOWN; for (i = 0; (i < MOUSE_MAXBUTTON) && (mask != 0); ++i) { - if (mask & 1) { - if (act->button & button) { - /* the button is down */ - debug(" : %ld %ld", + if (mask & 1) { + if (act->button & button) { + /* the button is down */ + debug(" : %ld %ld", bstate[i].tv.tv_sec, bstate[i].tv.tv_usec); if (timercmp(&tv, &bstate[i].tv, >)) { - bstate[i].count = 1; - } else { - ++bstate[i].count; - } + bstate[i].count = 1; + } else { + ++bstate[i].count; + } bstate[i].tv = tv1; - } else { - /* the button is up */ - bstate[i].tv = tv1; - } - } else { + } else { + /* the button is up */ + bstate[i].tv = tv1; + } + } else { if (act->button & button) { /* the button has been down */ if (timercmp(&tv3, &bstate[i].tv, >)) { @@ -2232,7 +2401,7 @@ r_timeout(void) gettimeofday(&tv1, NULL); tv2.tv_sec = rodent.button2timeout/1000; tv2.tv_usec = (rodent.button2timeout%1000)*1000; - timersub(&tv1, &tv2, &tv); + timersub(&tv1, &tv2, &tv); return timercmp(&tv, &mouse_button_state_tv, >); } @@ -2250,21 +2419,21 @@ r_click(mousestatus_t *act) button = MOUSE_BUTTON1DOWN; for (i = 0; (i < MOUSE_MAXBUTTON) && (mask != 0); ++i) { - if (mask & 1) { + if (mask & 1) { debug("mstate[%d]->count:%d", i, mstate[i]->count); - if (act->button & button) { - /* the button is down */ - mouse.u.event.value = mstate[i]->count; - } else { - /* the button is up */ - mouse.u.event.value = 0; - } + if (act->button & button) { + /* the button is down */ + mouse.u.event.value = mstate[i]->count; + } else { + /* the button is up */ + mouse.u.event.value = 0; + } mouse.operation = MOUSE_BUTTON_EVENT; mouse.u.event.id = button; if (debug < 2) - ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); + ioctl(rodent.cfd, CONS_MOUSECTL, &mouse); debug("button %d count %d", i + 1, mouse.u.event.value); - } + } button <<= 1; mask >>= 1; } @@ -2279,19 +2448,19 @@ r_click(mousestatus_t *act) * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of David Dawes - * not be used in advertising or publicity pertaining to distribution of + * documentation, and that the name of David Dawes + * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. - * David Dawes makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or + * David Dawes makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or * implied warranty. * - * DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL DAVID DAWES BE LIABLE FOR - * ANY SPECIAL, 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 + * DAVID DAWES DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL DAVID DAWES BE LIABLE FOR + * ANY SPECIAL, 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. * */ @@ -2305,7 +2474,7 @@ setmousespeed(int old, int new, unsigned cflag) if (tcgetattr(rodent.mfd, &tty) < 0) { - logwarn("unable to get status of mouse fd", 0); + logwarn("unable to get status of mouse fd"); return; } @@ -2338,7 +2507,7 @@ setmousespeed(int old, int new, unsigned cflag) if (tcsetattr(rodent.mfd, TCSADRAIN, &tty) < 0) { - logwarn("unable to set status of mouse fd", 0); + logwarn("unable to set status of mouse fd"); return; } @@ -2366,42 +2535,42 @@ setmousespeed(int old, int new, unsigned cflag) cfsetospeed(&tty, B1200); } - if (rodent.rtype == MOUSE_PROTO_LOGIMOUSEMAN + if (rodent.rtype == MOUSE_PROTO_LOGIMOUSEMAN || rodent.rtype == MOUSE_PROTO_LOGI) { if (write(rodent.mfd, c, 2) != 2) { - logwarn("unable to write to mouse fd", 0); + logwarn("unable to write to mouse fd"); return; } } usleep(100000); if (tcsetattr(rodent.mfd, TCSADRAIN, &tty) < 0) - logwarn("unable to set status of mouse fd", 0); + logwarn("unable to set status of mouse fd"); } -/* - * PnP COM device support - * +/* + * PnP COM device support + * * It's a simplistic implementation, but it works :-) * KY, 31/7/97. */ /* - * Try to elicit a PnP ID as described in - * Microsoft, Hayes: "Plug and Play External COM Device Specification, + * Try to elicit a PnP ID as described in + * Microsoft, Hayes: "Plug and Play External COM Device Specification, * rev 1.00", 1995. * * The routine does not fully implement the COM Enumerator as par Section * 2.1 of the document. In particular, we don't have idle state in which - * the driver software monitors the com port for dynamic connection or - * removal of a device at the port, because `moused' simply quits if no + * the driver software monitors the com port for dynamic connection or + * removal of a device at the port, because `moused' simply quits if no * device is found. * - * In addition, as PnP COM device enumeration procedure slightly has + * In addition, as PnP COM device enumeration procedure slightly has * changed since its first publication, devices which follow earlier - * revisions of the above spec. may fail to respond if the rev 1.0 + * revisions of the above spec. may fail to respond if the rev 1.0 * procedure is used. XXX */ static int @@ -2411,7 +2580,7 @@ pnpwakeup1(void) fd_set fds; int i; - /* + /* * This is the procedure described in rev 1.0 of PnP COM device spec. * Unfortunately, some devices which comform to earlier revisions of * the spec gets confused and do not return the ID string... @@ -2426,8 +2595,8 @@ pnpwakeup1(void) usleep(240000); /* - * The PnP COM device spec. dictates that the mouse must set DSR - * in response to DTR (by hardware or by software) and that if DSR is + * The PnP COM device spec. dictates that the mouse must set DSR + * in response to DTR (by hardware or by software) and that if DSR is * not asserted, the host computer should think that there is no device * at this serial port. But some mice just don't do that... */ @@ -2535,12 +2704,11 @@ pnpgets(char *buf) if (!pnpwakeup1() && !pnpwakeup2()) { /* - * According to PnP spec, we should set DTR = 1 and RTS = 0 while - * in idle state. But, `moused' shall set DTR = RTS = 1 and proceed, - * assuming there is something at the port even if it didn't + * According to PnP spec, we should set DTR = 1 and RTS = 0 while + * in idle state. But, `moused' shall set DTR = RTS = 1 and proceed, + * assuming there is something at the port even if it didn't * respond to the PnP enumeration procedure. */ -disconnect_idle: i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ ioctl(rodent.mfd, TIOCMBIS, &i); return 0; @@ -2553,12 +2721,12 @@ disconnect_idle: while (read(rodent.mfd, &c, 1) == 1) { /* we may see "M", or "M3..." before `Begin ID' */ buf[i++] = c; - if ((c == 0x08) || (c == 0x28)) { /* Begin ID */ + if ((c == 0x08) || (c == 0x28)) { /* Begin ID */ debug("begin-id %02x", c); begin = i - 1; break; - } - debug("%c %02x", c, c); + } + debug("%c %02x", c, c); if (i >= 256) break; } @@ -2569,15 +2737,15 @@ disconnect_idle: ++c; /* make it `End ID' */ for (;;) { - FD_ZERO(&fds); - FD_SET(rodent.mfd, &fds); - timeout.tv_sec = 0; - timeout.tv_usec = 240000; - if (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) <= 0) + FD_ZERO(&fds); + FD_SET(rodent.mfd, &fds); + timeout.tv_sec = 0; + timeout.tv_usec = 240000; + if (select(FD_SETSIZE, &fds, NULL, NULL, &timeout) <= 0) break; read(rodent.mfd, &buf[i], 1); - if (buf[i++] == c) /* End ID */ + if (buf[i++] == c) /* End ID */ break; if (i >= 256) break; @@ -2593,7 +2761,7 @@ disconnect_idle: return i; /* a valid PnP string */ /* - * According to PnP spec, we should set DTR = 1 and RTS = 0 while + * According to PnP spec, we should set DTR = 1 and RTS = 0 while * in idle state. But, `moused' shall leave the modem control lines * as they are. See above. */ @@ -2661,46 +2829,46 @@ pnpparse(pnpid_t *id, char *buf, int len) id->revision = ((buf[1] & 0x3f) << 6) | (buf[2] & 0x3f); debug("PnP rev %d.%02d", id->revision / 100, id->revision % 100); - /* EISA vendor and product ID */ + /* EISA vender and product ID */ id->eisaid = &buf[3]; id->neisaid = 7; /* option strings */ i = 10; if (buf[i] == '\\') { - /* device serial # */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') + /* device serial # */ + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') break; - } + } if (i >= len) i -= 3; if (i - j == 8) { - id->serial = &buf[j]; - id->nserial = 8; + id->serial = &buf[j]; + id->nserial = 8; } } if (buf[i] == '\\') { - /* PnP class */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') + /* PnP class */ + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') break; - } + } if (i >= len) i -= 3; if (i > j + 1) { - id->class = &buf[j]; - id->nclass = i - j; - } + id->class = &buf[j]; + id->nclass = i - j; + } } if (buf[i] == '\\') { /* compatible driver */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') break; - } + } /* - * PnP COM spec prior to v0.96 allowed '*' in this field, + * PnP COM spec prior to v0.96 allowed '*' in this field, * it's not allowed now; just igore it. */ if (buf[j] == '*') @@ -2708,39 +2876,39 @@ pnpparse(pnpid_t *id, char *buf, int len) if (i >= len) i -= 3; if (i > j + 1) { - id->compat = &buf[j]; - id->ncompat = i - j; - } + id->compat = &buf[j]; + id->ncompat = i - j; + } } if (buf[i] == '\\') { /* product description */ - for (j = ++i; i < len; ++i) { - if (buf[i] == ';') + for (j = ++i; i < len; ++i) { + if (buf[i] == ';') break; - } + } if (i >= len) i -= 3; if (i > j + 1) { - id->description = &buf[j]; - id->ndescription = i - j; - } + id->description = &buf[j]; + id->ndescription = i - j; + } } /* checksum exists if there are any optional fields */ if ((id->nserial > 0) || (id->nclass > 0) || (id->ncompat > 0) || (id->ndescription > 0)) { - debug("PnP checksum: 0x%X", sum); - sprintf(s, "%02X", sum & 0x0ff); - if (strncmp(s, &buf[len - 3], 2) != 0) { + debug("PnP checksum: 0x%X", sum); + sprintf(s, "%02X", sum & 0x0ff); + if (strncmp(s, &buf[len - 3], 2) != 0) { #if 0 - /* - * I found some mice do not comply with the PnP COM device + /* + * I found some mice do not comply with the PnP COM device * spec regarding checksum... XXX */ - logwarnx("PnP checksum error", 0); + logwarnx("PnP checksum error", 0); return FALSE; #endif - } + } } return TRUE; @@ -2753,15 +2921,15 @@ pnpproto(pnpid_t *id) int i, j; if (id->nclass > 0) - if ( strncmp(id->class, "MOUSE", id->nclass) != 0 && - strncmp(id->class, "TABLET", id->nclass) != 0) + if (strncmp(id->class, "MOUSE", id->nclass) != 0 && + strncmp(id->class, "TABLET", id->nclass) != 0) /* this is not a mouse! */ return NULL; if (id->neisaid > 0) { - t = gettoken(pnpprod, id->eisaid, id->neisaid); + t = gettoken(pnpprod, id->eisaid, id->neisaid); if (t->val != MOUSE_PROTO_UNKNOWN) - return t; + return t; } /* @@ -2771,13 +2939,13 @@ pnpproto(pnpid_t *id) if (id->ncompat <= 0) return NULL; for (i = 0; i < id->ncompat; ++i) { - for (j = i; id->compat[i] != ','; ++i) - if (i >= id->ncompat) + for (j = i; id->compat[i] != ','; ++i) + if (i >= id->ncompat) break; - if (i > j) { - t = gettoken(pnpprod, id->compat + j, i - j); + if (i > j) { + t = gettoken(pnpprod, id->compat + j, i - j); if (t->val != MOUSE_PROTO_UNKNOWN) - return t; + return t; } } @@ -2840,18 +3008,18 @@ typedef enum { static int kidspad(u_char rxc, mousestatus_t *act) { - static buf[5]; + static int buf[5]; static int buflen = 0, b_prev = 0 , x_prev = -1, y_prev = -1 ; static k_status status = S_IDLE ; static struct timeval old, now ; int x, y ; - if (buflen > 0 && (rxc & 0x80) ) { + if (buflen > 0 && (rxc & 0x80)) { fprintf(stderr, "invalid code %d 0x%x\n", buflen, rxc); buflen = 0 ; } - if (buflen == 0 && (rxc & 0xb8) != 0xb8 ) { + if (buflen == 0 && (rxc & 0xb8) != 0xb8) { fprintf(stderr, "invalid code 0 0x%x\n", rxc); return 0 ; /* invalid code, no action */ } @@ -2873,7 +3041,7 @@ kidspad(u_char rxc, mousestatus_t *act) act->obutton = act->button ; act->dx = act->dy = act->dz = 0 ; gettimeofday(&now, NULL); - if ( buf[0] & 0x40 ) /* pen went out of reach */ + if (buf[0] & 0x40) /* pen went out of reach */ status = S_IDLE ; else if (status == S_IDLE) { /* pen is newly near the tablet */ act->flags |= MOUSE_POSCHANGED ; /* force update */ @@ -2890,9 +3058,9 @@ kidspad(u_char rxc, mousestatus_t *act) y_prev = y ; if (b_prev != 0 && b_prev != buf[0]) { /* possibly record button change */ act->button = 0 ; - if ( buf[0] & 0x01 ) /* tip pressed */ + if (buf[0] & 0x01) /* tip pressed */ act->button |= MOUSE_BUTTON1DOWN ; - if ( buf[0] & 0x02 ) /* button pressed */ + if (buf[0] & 0x02) /* button pressed */ act->button |= MOUSE_BUTTON2DOWN ; act->flags |= MOUSE_BUTTONSCHANGED ; } @@ -2900,33 +3068,33 @@ kidspad(u_char rxc, mousestatus_t *act) return act->flags ; } -static void -mremote_serversetup(void) +static void +mremote_serversetup() { struct sockaddr_un ad; /* Open a UNIX domain stream socket to listen for mouse remote clients */ - unlink(_PATH_MOUSEREMOTE); + unlink(_PATH_MOUSEREMOTE); - if ( (rodent.mremsfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + if ((rodent.mremsfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) logerrx(1, "unable to create unix domain socket %s",_PATH_MOUSEREMOTE); umask(0111); - + bzero(&ad, sizeof(ad)); ad.sun_family = AF_UNIX; strcpy(ad.sun_path, _PATH_MOUSEREMOTE); #ifndef SUN_LEN -#define SUN_LEN(unp) ( ((char *)(unp)->sun_path - (char *)(unp)) + \ - strlen((unp)->path) ) +#define SUN_LEN(unp) (((char *)(unp)->sun_path - (char *)(unp)) + \ + strlen((unp)->path)) #endif - if (bind(rodent.mremsfd, (struct sockaddr *) &ad, SUN_LEN(&ad)) < 0) + if (bind(rodent.mremsfd, (struct sockaddr *) &ad, SUN_LEN(&ad)) < 0) logerrx(1, "unable to bind unix domain socket %s", _PATH_MOUSEREMOTE); listen(rodent.mremsfd, 1); } -static void +static void mremote_clientchg(int add) { struct sockaddr_un ad; @@ -2935,14 +3103,14 @@ mremote_clientchg(int add) if (rodent.rtype != MOUSE_PROTO_X10MOUSEREM) return; - if ( add ) { + if (add) { /* Accept client connection, if we don't already have one */ ad_len = sizeof(ad); fd = accept(rodent.mremsfd, (struct sockaddr *) &ad, &ad_len); if (fd < 0) logwarnx("failed accept on mouse remote socket"); - if ( rodent.mremcfd < 0 ) { + if (rodent.mremcfd < 0) { rodent.mremcfd = fd; debug("remote client connect...accepted"); } @@ -2954,9 +3122,7 @@ mremote_clientchg(int add) else { /* Client disconnected */ debug("remote client disconnected"); - close( rodent.mremcfd ); + close(rodent.mremcfd); rodent.mremcfd = -1; } } - - -- 2.11.4.GIT