# $Id: openbsd-btms_supress_spurious.diff,v 1.1 2009/05/07 03:41:35 jcs Exp $ # # the mouse wheel on my apple bluetooth mouse is also a button, so frequently # when trying to push the button, the wheel moves and triggers a scrolling # event at the same time or right before or after it. in firefox, clicking the # wheel to try to open a link in a new tab results in the page scrolling a bit # just before clicking and the link moves out from under the cursor. in # xterms, trying to paste by clicking the wheel results in it pasting and then # scrolling up a bit. # # try to supress this annoying behavior by keeping track of the last time the # wheel was scrolled in either direction (w/z) and which direction it was last # scrolled. if the direction changes (for the first event only), the time # between scrolls was more than a second, or any buttons are being pressed, # supress the wheel event. # # i suppose this could go in wscons so it applies to other mice but i don't # know that any are as sensitive as the apple mighty mouse. # # jcs@jcs.org # Index: dev/bluetooth/btms.c =================================================================== RCS file: /cvs/src/sys/dev/bluetooth/btms.c,v retrieving revision 1.4 diff -u -p -r1.4 btms.c --- dev/bluetooth/btms.c 22 Nov 2008 04:42:58 -0000 1.4 +++ dev/bluetooth/btms.c 7 May 2009 03:26:46 -0000 @@ -71,6 +71,7 @@ #include #include #include +#include #include @@ -102,6 +103,11 @@ struct btms_softc { struct hid_location sc_loc_w; struct hid_location sc_loc_button[MAX_BUTTONS]; + struct timeval sc_time_z; + struct timeval sc_time_w; + + int sc_last_dir; + int sc_num_buttons; uint32_t sc_buttons; }; @@ -210,6 +216,9 @@ btms_attach(struct device *parent, struc /* Put Z on the W coordinate */ zloc = &sc->sc_loc_w; } + + getmicrotime(&sc->sc_time_z); + getmicrotime(&sc->sc_time_w); } hl = hid_locate(ba->ba_desc, ba->ba_dlen, @@ -314,9 +323,11 @@ void btms_input(struct bthidev *self, uint8_t *data, int len) { struct btms_softc *sc = (struct btms_softc *)self; + struct timeval tv, tm; int dx, dy, dz, dw; uint32_t buttons; int i, s; + int supress = 0; if (sc->sc_wsmouse == NULL || sc->sc_enabled == 0) return; @@ -336,6 +347,37 @@ btms_input(struct bthidev *self, uint8_t if (dx != 0 || dy != 0 || dz != 0 || dw != 0 || buttons != sc->sc_buttons) { + if (buttons == sc->sc_buttons && (dz || dw)) { + if (buttons) + /* the wheel should never move while buttons + * are being pressed */ + supress = 1; + else { + getmicrotime(&tm); + + if (dz == -1 || dz == 1) + timersub(&tm, &sc->sc_time_z, &tv); + else if (dw == -1 || dw == 1) + timersub(&tm, &sc->sc_time_w, &tv); + + if (tv.tv_sec >= 1 || + sc->sc_last_dir != (dz ? 1 : 2)) + /* time between wheel moves or the + * direction changed */ + supress = 1; + + if (dz) + getmicrotime(&sc->sc_time_z); + else if (dw) + getmicrotime(&sc->sc_time_w); + } + + sc->sc_last_dir = (buttons ? 0 : (dz ? 1 : 2)); + + if (supress) + return; + } + sc->sc_buttons = buttons; s = spltty();