From nobody@FreeBSD.org  Thu Mar 16 15:31:40 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C58BC16A425
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Mar 2006 15:31:40 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9287943D53
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Mar 2006 15:31:40 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k2GFVeQx037552
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Mar 2006 15:31:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k2GFVexq037551;
	Thu, 16 Mar 2006 15:31:40 GMT
	(envelope-from nobody)
Message-Id: <200603161531.k2GFVexq037551@www.freebsd.org>
Date: Thu, 16 Mar 2006 15:31:40 GMT
From: Krzysztof Jedruczyk <beaker@hot.pl>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Wrong mouse button mapping in bthidd
X-Send-Pr-Version: www-2.3

>Number:         94577
>Category:       bin
>Synopsis:       [bluetooth] [patch] Wrong mouse button mapping in bthidd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    emax
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 16 23:20:37 GMT 2006
>Closed-Date:    Mon Oct 09 21:10:48 GMT 2006
>Last-Modified:  Mon Oct 09 21:10:48 GMT 2006
>Originator:     Krzysztof Jedruczyk
>Release:        6.1-PRERELEASE
>Organization:
>Environment:
FreeBSD pipboy2000 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #3: Wed Mar 15 12:59:31 CET 2006     beaker@pipboy2000:/usr/obj/usr/src/sys/PIPBOY  i386
>Description:
Connecting bluetooth mouse through bthidd daemon gives wrong button mapping:
right button is swapped with middle button.

Looking at HID Usage Tables and 'xev' output it seems to me HID that hid
"usage" value is incorrectly being used as button index. Since ps2 mouse
seems to map right button to 3 and middle button to 2, apropriate fixup has
to be done (similar fixup seems to be done in ums.c). Following patch makes
all 5 butons work in my setup (including mouse wheel buttons).
>How-To-Repeat:
Just configure bthid mouse and try to invoke right-click action in some
graphical interface.
>Fix:
--- /usr/src/usr.sbin/bluetooth/bthidd/hid.c.orig       Sun Mar 12 22:04:51 2006
+++ /usr/src/usr.sbin/bluetooth/bthidd/hid.c    Sun Mar 12 22:04:54 2006
@@ -130,6 +130,8 @@
                        mouse_x, mouse_y, mouse_z, mouse_butt,
                        mevents, kevents;

+#define HID_BUT(i) ((i) < 3 ? (((i) ^ 3) % 3) : (i))
+
        assert(s != NULL);
        assert(s->srv != NULL);
        assert(data != NULL);
@@ -216,7 +218,7 @@
                        break;

                case HUP_BUTTON:
-                       mouse_butt |= (val << (usage - 1));
+                       mouse_butt |= (val << HID_BUT(usage - 1));
                        mevents ++;
                        break;





>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->emax 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Mar 17 08:58:46 UTC 2006 
Responsible-Changed-Why:  
Assign to author of the code. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94577 
State-Changed-From-To: open->patched 
State-Changed-By: emax 
State-Changed-When: Tue Mar 21 18:43:10 UTC 2006 
State-Changed-Why:  
Patch committed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94577 

From: Phil Pennock <phil-freebsd-bugs+94577@spodhuis.org>
To: bug-followup@FreeBSD.org, beaker@hot.pl
Cc:  
Subject: Re: bin/94577: [bluetooth] [patch] Wrong mouse button mapping in bthidd
Date: Tue, 29 Aug 2006 00:45:58 +0200

 In case anyone wants to put in a comment to explain this mapping, it's
 more than just what works for the original poster.
 
 According to the HID Usage Tables, Hut1_12.pdf (from usb.org), page 69
 section 12, button 2 is what's normally thought of as the right button
 and button 3 the middle one, so it's defined with the opposite semantics
 to what's normal under X/Unix.  Hence the mapping is required by
 specification, not just for some models.
 
 ----------------------------8< cut here >8------------------------------
 * Button 1, Primary Button. Used for object selecting, dragging, and
   double click activation. On MacOS, this is the only button. Microsoft
   operating systems call this a logical left button, because it is not
   necessarily physically located on the left of the pointing device.
 
 * Button 2, Secondary Button. Used by newer graphical user interfaces to
   browse object properties.  Exposed by systems to applications that
   typically assign application-specific functionality.
 
 * Button 3, Tertiary Button. Optional control. Exposed to applications,
   but seldom assigned functionality due to prevalence of two- and
   one-button devices.
 
 * Buttons 4 – 255. As the button number increases, its significance as a
   selector decreases.
 ----------------------------8< cut here >8------------------------------
 
 I found this whilst looking for what's going on, since this patch isn't
 in FreeBSD 6.1 and it affected me, so I arrived at the solution
 independently.
 
 Does this make the bug-fix a candidate for merging into a stable branch?
 
 Hopefully this provides the necessary reference for a documentation
 comment in the code to explain why the weird mapping is now happening.
 :^)
State-Changed-From-To: patched->closed 
State-Changed-By: emax 
State-Changed-When: Mon Oct 9 21:10:13 UTC 2006 
State-Changed-Why:  
updated bthidd(8) code in 7.0-CURRENT and 6-STABLE takes care of it 

http://www.freebsd.org/cgi/query-pr.cgi?pr=94577 
>Unformatted:
