From imdave@mcs.net  Tue Dec 16 09:58:27 1997
Received: from base486.home.org (root@imdave.pr.mcs.net [205.164.3.77])
          by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id JAA13725
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 1997 09:58:24 -0800 (PST)
          (envelope-from imdave@mcs.net)
Received: from base586.home.org (root@base586.home.org [10.0.0.2])
	by base486.home.org (8.8.8/8.8.8) with ESMTP id LAA11944
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Dec 1997 11:58:38 -0600 (CST)
Received: (from imdave@localhost)
	by base586.home.org (8.8.8/8.8.8) id EAA04581;
	Tue, 16 Dec 1997 04:27:14 -0600 (CST)
Message-Id: <199712161027.EAA04581@base586.home.org>
Date: Tue, 16 Dec 1997 04:27:14 -0600 (CST)
From: Dave Bodenstab <imdave@mcs.net>
Reply-To: imdave@mcs.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: moused enhancement for logitech 4-button mouseman plus
X-Send-Pr-Version: 3.2

>Number:         5320
>Category:       bin
>Synopsis:       moused enhancement for logitech 4-button mouseman plus
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yokota
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 16 10:00:01 PST 1997
>Closed-Date:    Wed Jan 7 05:56:26 PST 1998
>Last-Modified:  Wed Jan  7 05:58:09 PST 1998
>Originator:     Dave Bodenstab
>Release:        FreeBSD 2.2.5-RELEASE i386
>Organization:
home
>Environment:

	moused with a logitech mouseman plus 4-button mouse

>Description:

	Logitech is now producing 4-button mice -- some have a goofy
	wheel where the middle button is, and a fourth button inconveniently
	placed on the left side under ones thumb.  I returned that one, and
	replaced it with what at first appeared to be a normal 3-button
	rodent, but it turned out that it still had the fouth button on the side.  

	One would expect that the left, middle and right buttons would
	correspond to buttons 1, 2 and 3.  But no... this is a windoze 95
	mouse... so the left, thumb and right buttons are 1, 2 and 3.  The
	*middle* button is actually the additional fourth button.

	This is very inconvenient since one has to squeeze the mouse with
	ones thumb to press button two.  In addition, it's too easy to 
	accidently press the button as the mouse is moved.

	What drugs were the logitech designers taking when this layout was
	conceived?

	This patch maps the middle button back to button 2.  The thumb button
	becomes a fourth button (using bitmask 0x08.)  I haven't gotten
	X11 running yet -- el cheapo vga card is not supported by xfree --
	so I haven't been able to see what effect this fourth button has
	or even if X11 can be coaxed into using it.  At least I no longer
	get a cramp in my hand from squeezing the dumb thumb button.

>How-To-Repeat:
>Fix:
	
	This patch assumes my previously submitted bug-fix for simultaneous
	button presses is applied.

--- moused.c.orig	Tue Dec 16 03:33:04 1997
+++ moused.c	Tue Dec 16 03:8:12 1997
@@ -76,8 +76,9 @@
 #define R_LOGITECH	4
 #define R_BUSMOUSE	5
 #define R_LOGIMAN	6
-#define R_PS_2		7
-#define R_MMHITAB	8
+#define R_LOGIMAN4	7	/* Logitech Mouseman (4-button) */
+#define R_PS_2		8
+#define R_MMHITAB	9
 
 char	*rnames[] = {
     "xxx",
@@ -87,6 +88,7 @@
     "logitech",
     "busmouse",
     "mouseman",
+    "mouseman+",
     "ps/2",
     "mmhitab",
     NULL
@@ -101,6 +103,7 @@
     (CS8 | CSTOPB	   | CREAD | CLOCAL | HUPCL ),	/* Logitech */
     0,							/* BusMouse */
     (CS7		   | CREAD | CLOCAL | HUPCL ),	/* MouseMan */
+    (CS7		   | CREAD | CLOCAL | HUPCL ),	/* MouseMan 4-button */
     0,							/* PS/2 */
     (CS8		   | CREAD | CLOCAL | HUPCL ),	/* MMHitTablet */
 };
@@ -375,11 +378,11 @@
      */
 
   
-    if (rodent.rtype == R_LOGIMAN)
+    if (rodent.rtype == R_LOGIMAN || rodent.rtype == R_LOGIMAN4)
     {
-	setmousespeed(1200, 1200, rodentcflags[R_LOGIMAN]);
+	setmousespeed(1200, 1200, rodentcflags[rodent.rtype]);
 	write(rodent.mfd, "*X", 2);
-	setmousespeed(1200, rodent.baudrate, rodentcflags[R_LOGIMAN]);
+	setmousespeed(1200, rodent.baudrate, rodentcflags[rodent.rtype]);
     } else {
 	if ((rodent.rtype != R_BUSMOUSE) && (rodent.rtype != R_PS_2))
 	{
@@ -469,6 +472,7 @@
     {	0xe0,	0x80,	0x80,	0x00,	3	},  /* Logitech */
     {	0xf8,	0x80,	0x00,	0x00,	5	},  /* BusMouse */
     { 	0x40,	0x40,	0x40,	0x00,	3 	},  /* MouseMan */
+    { 	0x40,	0x40,	0x40,	0x00,	3 	},  /* MouseMan 4-button */
     {	0xc0,	0x00,	0x00,	0x00,	3	},  /* PS/2 mouse */
     {	0xe0,	0x80,	0x80,	0x00,	3	},  /* MM_HitTablet */
     };
@@ -508,7 +512,8 @@
 	(rBuf & proto[rodent.rtype][0]) != proto[rodent.rtype][1])
     {
 	/*
-	 * Hack for Logitech MouseMan Mouse - Middle button
+	 * Hack for Logitech MouseMan Mouse - Middle button, and Logitech
+	 * MouseMan - Middle button and thumb button
 	 *
 	 * Unfortunately this mouse has variable length packets: the standard
 	 * Microsoft 3 byte packet plus an optional 4th byte whenever the
@@ -533,6 +538,22 @@
 	    return(&act);
 	}
 
+	/*
+	 * The 4-button mouseman treats what one would expect to be the middle
+	 * button as an additional button: 0x00/0x10.  What used to be button 2 is
+	 * the obnoxious button on the side of the mouse (under ones right thumb).
+	 * Since this is totally inconsistent with what one would expect, we
+	 * will swap these two buttons.
+	 */
+	if (rodent.rtype == R_LOGIMAN4 && (char)(rBuf & ~0x33) == 0)
+	{
+	    act.buttons = ((int)(rBuf & 0x20) >> 2)  /* thumb button == button 4 */
+	        | ((int)(rBuf & 0x10) >> 3)	     /* middle button == button 2 */
+		| (rodent.lastbuttons & 0x05);
+	    rodent.lastbuttons = act.buttons;	/* save new button state */
+	    return(&act);
+	}
+
 	return(NULL);				/* skip package */
     }
         
@@ -561,6 +582,19 @@
 	act.dx = (char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F));
 	act.dy = (char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F));
 	break;
+
+    case R_LOGIMAN4:		/* MouseMan with thumb button */
+	if (rodent.flags & ChordMiddle)
+	    act.buttons = (((int) pBuf[0] & 0x30) == 0x30) ? 2 :
+		           ((int)(pBuf[0]&0x20)>>3) | ((int)(pBuf[0]&0x10)>>4);
+	else
+	    act.buttons =   (rodent.lastbuttons & 0x0a)
+		          | ((int)(pBuf[0] & 0x20) >> 3)
+		          | ((int)(pBuf[0] & 0x10) >> 4);
+	rodent.lastbuttons = act.buttons;	/* save new button state */
+	act.dx = (char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F));
+	act.dy = (char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F));
+	break;
       
     case R_MOUSESYS:		/* Mouse Systems Corp */
 	act.buttons = (~pBuf[0]) & 0x07;
@@ -698,7 +732,8 @@
 		cfsetospeed(&tty, B1200);
 	}
 
-	if (rodent.rtype == R_LOGIMAN || rodent.rtype == R_LOGITECH)
+	if (rodent.rtype == R_LOGIMAN || rodent.rtype == R_LOGIMAN4 ||
+	    rodent.rtype == R_LOGITECH)
 	{
 		if (write(rodent.mfd, c, 2) != 2)
 		{
--- moused.8.orig	Mon Sep 29 01:36:12 1997
+++ moused.8	Tue Dec 16 03:04:09 1997
@@ -84,6 +84,8 @@
 A bus mouse
 .It mouseman
 Logitech MouseMan and TrackMan
+.It mouseman+
+Logitech MouseMan with thumb button (as button 4)
 .It ps/2
 PS/2 mouse
 .It mmhittab

>Release-Note:
>Audit-Trail:

From: Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
To: imdave@mcs.net
Cc: FreeBSD-gnats-submit@freebsd.org, yokota@freebsd.org
Subject: Re: bin/5320: moused enhancement for logitech 4-button mouseman plus 
Date: Wed, 17 Dec 1997 10:02:24 +0900

 >>Number:         5320
 >>Category:       bin
 >>Synopsis:       moused enhancement for logitech 4-button mouseman plus
 >>Confidential:   no
 >>Severity:       non-critical
 >>Priority:       low
 >>Responsible:    freebsd-bugs
 >>State:          open
 >>Class:          change-request
 >>Submitter-Id:   current-users
 >>Arrival-Date:   Tue Dec 16 10:00:01 PST 1997
 >>Last-Modified:
 >>Originator:     Dave Bodenstab
 >>Organization:
 >home
 >>Release:        FreeBSD 2.2.5-RELEASE i386
 >>Environment:
 >
 >	moused with a logitech mouseman plus 4-button mouse
 >
 >>Description:
 >
 >	Logitech is now producing 4-button mice -- some have a goofy
 >	wheel where the middle button is, and a fourth button inconveniently
 >	placed on the left side under ones thumb.  I returned that one, and
 >	replaced it with what at first appeared to be a normal 3-button
 >	rodent, but it turned out that it still had the fouth button on the sid
 >e.  
 >
 >	One would expect that the left, middle and right buttons would
 >	correspond to buttons 1, 2 and 3.  But no... this is a windoze 95
 >	mouse... so the left, thumb and right buttons are 1, 2 and 3.  The
 >	*middle* button is actually the additional fourth button.
 
 Hello.
 
 I recently committed enhanced mouse support to the 3.0-CURRENT source
 tree.  It includes support for Logitech MouseMan+ and FirstMouse+ (the
 ones with a wheel). These mice too use the strange data format you
 described above.  But the new moused treats the wheel as the button 2
 (middle button) and the side button is handled as the button 4 as you
 suggest.
 
 I have not tested the code with the model of MouseMan+ without a
 wheel, because I have not seen it around here. But, I would expect the
 code will work with this mouse too.
 
 I also prepared a set of patches and documentation for 2.2.5-RELEASE
 systems to have the same functionalities as the mouse support in
 3.0-CURRENT.
 
 ftp://ftp.freebsd.org/pub/FreeBSD/incoming/mouse971212.tar.gz
 
 I would be grateful if you could try this package and send me some
 comments.
 
 moused is substantially modified. It detect the type of the serial
 mouse automatically if the mouse conforms to the PnP COM device
 standard.
 
 Once you apply the patches, please try
 
 moused -d -i all -p /dev/cuaa0
 
 (substitute /dev/cuaa0 with the name of the serial port which your
 mouse is on)
 
 If moused is able to identify the mouse automatically, you will see
 some information.  (MouseMan+ and FirstMouse+ are recognized as a
 variant of MS IntelliMouse.)  If it fails, it will say "unknown" (and
 probably the side button becomes the button 2 ;-<
 
 Please let me know the result of the above command.
 
 Kazu
 
 PS: the above package should also fix your another PR (bin/5321 moused
 loses simultaneous buttons for...)
 
 
Responsible-Changed-From-To: freebsd-bugs->yokota 
Responsible-Changed-By: yokota 
Responsible-Changed-When: Tue Dec 16 16:59:07 PST 1997 
Responsible-Changed-Why:  
I am currently working on moused. 
State-Changed-From-To: open->closed 
State-Changed-By: yokota 
State-Changed-When: Wed Jan 7 05:56:26 PST 1998 
State-Changed-Why:  
The support for this mouse has been added to moused (moused.c 1.13) 
in 3.0-CURRENT. 
>Unformatted:
