From aa95ed306f3d001d15f350c94e28a1a07940a8bd Mon Sep 17 00:00:00 2001 From: nirenjan Date: Sat, 18 Mar 2023 00:43:17 -0700 Subject: [PATCH] Fix multiple virtual wheel events with noisy input Prior to this change, the x52d virtual mouse logic was assuming that the joystick would only send one report with the wheel button state as "on", and subsequent reports would be "off". However, with some joysticks, the other axis sensors could be faulty or noisy, and the joystick could send multiple reports with the mouse button "on", without an "off" state in between. This was causing scroll events to be much faster than would be expected (1 mouse scroll to 1 screen scroll event) This change should fix the problem, by comparing the value of the previous button state. This should now trigger a wheel event only on a rising edge (from "off" to "on"). See #46 --- daemon/x52d_mouse_evdev.c | 6 ++++-- po/libx52.pot | 18 +++++++++--------- po/xx_PL.po | 18 +++++++++--------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/daemon/x52d_mouse_evdev.c b/daemon/x52d_mouse_evdev.c index 58e2009..f48c06d 100644 --- a/daemon/x52d_mouse_evdev.c +++ b/daemon/x52d_mouse_evdev.c @@ -52,13 +52,15 @@ static int report_wheel(void) { int rc = 1; int wheel = 0; + bool old_scroll_up = old_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]; bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]; + bool old_scroll_dn = old_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]; bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]; - if (scroll_up) { + if (scroll_up && (scroll_up != old_scroll_up)) { // Scroll up event wheel = 1 * mouse_scroll_dir; - } else if (scroll_dn) { + } else if (scroll_dn && (scroll_dn != old_scroll_dn)) { // Scroll down event wheel = -1 * mouse_scroll_dir; } diff --git a/po/libx52.pot b/po/libx52.pot index 94b4eaa..c903061 100644 --- a/po/libx52.pot +++ b/po/libx52.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: libx52 0.3.0\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" -"POT-Creation-Date: 2023-01-04 08:39-0800\n" +"POT-Creation-Date: 2023-03-18 00:49-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -861,38 +861,38 @@ msgstr "" msgid "Error writing mouse button event (button %d, state %d)" msgstr "" -#: daemon/x52d_mouse_evdev.c:69 +#: daemon/x52d_mouse_evdev.c:71 #, c-format msgid "Error writing mouse wheel event %d" msgstr "" -#: daemon/x52d_mouse_evdev.c:102 +#: daemon/x52d_mouse_evdev.c:104 #, c-format msgid "Error writing mouse axis event (axis %d, value %d)" msgstr "" -#: daemon/x52d_mouse_evdev.c:115 +#: daemon/x52d_mouse_evdev.c:117 msgid "Error writing mouse sync event" msgstr "" -#: daemon/x52d_mouse_evdev.c:134 +#: daemon/x52d_mouse_evdev.c:136 msgid "Starting X52 virtual mouse driver thread" msgstr "" -#: daemon/x52d_mouse_evdev.c:157 +#: daemon/x52d_mouse_evdev.c:159 #, c-format msgid "Error %d initializing mouse thread: %s" msgstr "" -#: daemon/x52d_mouse_evdev.c:164 +#: daemon/x52d_mouse_evdev.c:166 msgid "Shutting down X52 virtual mouse driver thread" msgstr "" -#: daemon/x52d_mouse_evdev.c:171 +#: daemon/x52d_mouse_evdev.c:173 msgid "Virtual mouse not created. Ignoring thread state change" msgstr "" -#: daemon/x52d_mouse_evdev.c:236 +#: daemon/x52d_mouse_evdev.c:238 #, c-format msgid "Error %d creating X52 virtual mouse: %s" msgstr "" diff --git a/po/xx_PL.po b/po/xx_PL.po index 09f9a7b..ac1b3b1 100644 --- a/po/xx_PL.po +++ b/po/xx_PL.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: libx52 0.2.3\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" -"POT-Creation-Date: 2023-01-04 08:39-0800\n" +"POT-Creation-Date: 2023-03-18 00:49-0700\n" "PO-Revision-Date: 2023-01-04 08:40-0800\n" "Last-Translator: Nirenjan Krishnan \n" "Language-Team: Dummy Language for testing i18n\n" @@ -914,38 +914,38 @@ msgstr "Ettingsay ousemay everseray ollscray otay %s" msgid "Error writing mouse button event (button %d, state %d)" msgstr "Erroray itingwray ousemay uttonbay eventay (uttonbay %d, atestay %d)" -#: daemon/x52d_mouse_evdev.c:69 +#: daemon/x52d_mouse_evdev.c:71 #, c-format msgid "Error writing mouse wheel event %d" msgstr "Erroray itingwray ousemay eelwhay eventay %d" -#: daemon/x52d_mouse_evdev.c:102 +#: daemon/x52d_mouse_evdev.c:104 #, c-format msgid "Error writing mouse axis event (axis %d, value %d)" msgstr "Erroray itingwray ousemay axisay eventay (axisay %d, aluevay %d)" -#: daemon/x52d_mouse_evdev.c:115 +#: daemon/x52d_mouse_evdev.c:117 msgid "Error writing mouse sync event" msgstr "Erroray itingwray ousemay yncsay eventay" -#: daemon/x52d_mouse_evdev.c:134 +#: daemon/x52d_mouse_evdev.c:136 msgid "Starting X52 virtual mouse driver thread" msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray" -#: daemon/x52d_mouse_evdev.c:157 +#: daemon/x52d_mouse_evdev.c:159 #, c-format msgid "Error %d initializing mouse thread: %s" msgstr "Erroray %d initializingay ousemay eadthray: %s" -#: daemon/x52d_mouse_evdev.c:164 +#: daemon/x52d_mouse_evdev.c:166 msgid "Shutting down X52 virtual mouse driver thread" msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray" -#: daemon/x52d_mouse_evdev.c:171 +#: daemon/x52d_mouse_evdev.c:173 msgid "Virtual mouse not created. Ignoring thread state change" msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay" -#: daemon/x52d_mouse_evdev.c:236 +#: daemon/x52d_mouse_evdev.c:238 #, c-format msgid "Error %d creating X52 virtual mouse: %s" msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"