Enable Forward and Back Buttons On 5 Button Mouse
On NetBSD by default the side buttons of a five button mouse are mapped to button 4 and 5, the same as the scroll wheel. So instead of going a page back or forward in a browser, it would go page up or down.
You can workaround this limitation if you have a 7 button mouse, by mapping the functions of the side buttons to the horizontal wheel button in xorg.conf but with a five button mouse this is not possible, because of lack of buttons to map.
I had figured out to make forward/back button work, it needs to emit button 8 and 9, like it does on Linux and FreeBSD. In NetBSD and OpenBSD the side buttons would emit 4 and 5 the same as the scroll wheel.
But instead of hacking the Xorg mouse driver, which gets the information from /dev/wsmouse I modified wsmouse.c briefly to send a different button number, when using the side buttons. The code is just adding 4, when button number is >= 3 (the btnno is -1 in wscons). This way, Xorg gets the correct button number and Chrome and Firefox can utilize it by default.
Please note, the code is just a simple workaround. In reality, the HID descriptor tells the usage of those buttons and that context gets probably lost in the ums to wsmouse conversion.
Here is my diff for wsmouse.c
index 288be3344bc1..d1aeccb0068d 100644
--- a/sys/dev/wscons/wsmouse.c
+++ b/sys/dev/wscons/wsmouse.c
@@ -291,6 +291,7 @@ wsmouse_attach(device_t parent, device_t self, void *aux)
#endif
aprint_naive("\n");
+ aprint_normal("hello world ! here is wsmouse attach\n");
aprint_normal("\n");
if (!pmf_device_register(self, NULL, NULL))
@@ -461,6 +462,7 @@ wsmouse_input(device_t wsmousedev, u_int btns /* 0 is up */,
}
mb = sc->sc_mb;
+
while ((d = mb ^ ub) != 0) {
int btnno;
@@ -481,6 +483,7 @@ wsmouse_input(device_t wsmousedev, u_int btns /* 0 is up */,
* it into the event queue.
*/
btnno = ffs(d) - 1;
+
KASSERT(btnno >= 0);
if (nevents >= __arraycount(events)) {
@@ -490,11 +493,19 @@ wsmouse_input(device_t wsmousedev, u_int btns /* 0 is up */,
break;
}
+ if (btnno >= 3) {
+ btnno += 4;
+ }
+
events[nevents].type =
(mb & d) ? WSCONS_EVENT_MOUSE_DOWN : WSCONS_EVENT_MOUSE_UP;
events[nevents].value = btnno;
nevents++;
+ if (btnno >= 3) {
+ btnno -= 4;
+ }
+
ub ^= (1 << btnno);
/*