diff --git a/daemon/x52d_mouse_evdev.c b/daemon/x52d_mouse_evdev.c index 98b2c70..2c7b47d 100644 --- a/daemon/x52d_mouse_evdev.c +++ b/daemon/x52d_mouse_evdev.c @@ -48,29 +48,23 @@ static int report_button_change(int button, int index) return rc; } -#define btn_change(btn) new_report.button[btn] != old_report.button[btn] - static int report_wheel(void) { int rc = 1; int wheel = 0; - bool scroll_up = (btn_change(LIBX52IO_BTN_MOUSE_SCROLL_UP)); - bool scroll_dn = (btn_change(LIBX52IO_BTN_MOUSE_SCROLL_DN)); + bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]; + bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]; if (scroll_up) { // Scroll up event - if (new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]) { - wheel = 1; - } + wheel = 1; } else if (scroll_dn) { // Scroll down event - if (new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]) { - wheel = -1; - } + wheel = -1; } if (wheel != 0) { - rc = libevdev_uinput_write_event(mouse_uidev, EV_REL, REL_WHEEL, 1); + rc = libevdev_uinput_write_event(mouse_uidev, EV_REL, REL_WHEEL, wheel); if (rc != 0) { PINELOG_ERROR(_("Error writing mouse wheel event %d"), wheel); } @@ -106,6 +100,17 @@ static int report_axis(int axis, int index) return rc; } +static void report_sync(void) +{ + int rc; + rc = libevdev_uinput_write_event(mouse_uidev, EV_SYN, SYN_REPORT, 0); + if (rc != 0) { + PINELOG_ERROR(_("Error writing mouse sync event")); + } else { + memcpy((void *)&old_report, (void *)&new_report, sizeof(old_report)); + } +} + static void reset_reports(void) { memset((void *)&old_report, 0, sizeof(old_report)); @@ -118,25 +123,15 @@ static void reset_reports(void) static void * x52_mouse_thr(void *param) { bool state_changed; - int rc; PINELOG_INFO(_("Starting X52 virtual mouse driver thread")); for (;;) { - /* Check if there are any changes in button state */ state_changed = false; - state_changed |= (0 == report_button_change(BTN_LEFT, LIBX52IO_BTN_MOUSE_PRIMARY)); - state_changed |= (0 == report_button_change(BTN_RIGHT, LIBX52IO_BTN_MOUSE_SECONDARY)); - state_changed |= (0 == report_wheel()); state_changed |= (0 == report_axis(REL_X, LIBX52IO_AXIS_THUMBX)); state_changed |= (0 == report_axis(REL_Y, LIBX52IO_AXIS_THUMBY)); if (state_changed) { - rc = libevdev_uinput_write_event(mouse_uidev, EV_SYN, SYN_REPORT, 0); - if (rc != 0) { - PINELOG_ERROR(_("Error writing mouse sync event")); - } else { - memcpy((void *)&old_report, (void *)&new_report, sizeof(old_report)); - } + report_sync(); } usleep(mouse_delay); @@ -191,8 +186,18 @@ void x52d_mouse_evdev_thread_control(bool enabled) void x52d_mouse_report_event(libx52io_report *report) { + bool state_changed; if (report) { memcpy((void *)&new_report, report, sizeof(new_report)); + + state_changed = false; + state_changed |= (0 == report_button_change(BTN_LEFT, LIBX52IO_BTN_MOUSE_PRIMARY)); + state_changed |= (0 == report_button_change(BTN_RIGHT, LIBX52IO_BTN_MOUSE_SECONDARY)); + state_changed |= (0 == report_wheel()); + + if (state_changed) { + report_sync(); + } } else { reset_reports(); } diff --git a/po/x52pro-linux.pot b/po/x52pro-linux.pot index 5aebadf..8bf28c0 100644 --- a/po/x52pro-linux.pot +++ b/po/x52pro-linux.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: x52pro-linux 0.2.2\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2021-09-14 17:33-0700\n" +"POT-Creation-Date: 2021-09-14 23:34-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -763,38 +763,38 @@ msgstr "" msgid "Error writing mouse button event (button %d, state %d)" msgstr "" -#: daemon/x52d_mouse_evdev.c:75 +#: daemon/x52d_mouse_evdev.c:69 #, c-format msgid "Error writing mouse wheel event %d" msgstr "" -#: daemon/x52d_mouse_evdev.c:101 +#: daemon/x52d_mouse_evdev.c:95 #, c-format msgid "Error writing mouse axis event (axis %d, value %d)" msgstr "" -#: daemon/x52d_mouse_evdev.c:123 -msgid "Starting X52 virtual mouse driver thread" -msgstr "" - -#: daemon/x52d_mouse_evdev.c:136 +#: daemon/x52d_mouse_evdev.c:108 msgid "Error writing mouse sync event" msgstr "" -#: daemon/x52d_mouse_evdev.c:155 +#: daemon/x52d_mouse_evdev.c:127 +msgid "Starting X52 virtual mouse driver thread" +msgstr "" + +#: daemon/x52d_mouse_evdev.c:150 #, c-format msgid "Error %d initializing mouse thread: %s" msgstr "" -#: daemon/x52d_mouse_evdev.c:162 +#: daemon/x52d_mouse_evdev.c:157 msgid "Shutting down X52 virtual mouse driver thread" msgstr "" -#: daemon/x52d_mouse_evdev.c:169 +#: daemon/x52d_mouse_evdev.c:164 msgid "Virtual mouse not created. Ignoring thread state change" msgstr "" -#: daemon/x52d_mouse_evdev.c:220 +#: daemon/x52d_mouse_evdev.c:225 #, c-format msgid "Error %d creating X52 virtual mouse: %s" msgstr "" diff --git a/po/xx_PL.po b/po/xx_PL.po index bc62d76..312745d 100644 --- a/po/xx_PL.po +++ b/po/xx_PL.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: x52pro-linux 0.2.1\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n" -"POT-Creation-Date: 2021-09-14 17:33-0700\n" +"POT-Creation-Date: 2021-09-14 23:34-0700\n" "PO-Revision-Date: 2021-09-14 17:07-0700\n" "Last-Translator: Nirenjan Krishnan \n" "Language-Team: Dummy Language for testing i18n\n" @@ -812,38 +812,38 @@ msgstr "Ignoringay ousemay eedspay %d outsideay upportedsay angeray (0-%d)" 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:75 +#: daemon/x52d_mouse_evdev.c:69 #, c-format msgid "Error writing mouse wheel event %d" msgstr "Erroray itingwray ousemay eelwhay eventay %d" -#: daemon/x52d_mouse_evdev.c:101 +#: daemon/x52d_mouse_evdev.c:95 #, 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:123 -msgid "Starting X52 virtual mouse driver thread" -msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray" - -#: daemon/x52d_mouse_evdev.c:136 +#: daemon/x52d_mouse_evdev.c:108 msgid "Error writing mouse sync event" msgstr "Erroray itingwray ousemay yncsay eventay" -#: daemon/x52d_mouse_evdev.c:155 +#: daemon/x52d_mouse_evdev.c:127 +msgid "Starting X52 virtual mouse driver thread" +msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray" + +#: daemon/x52d_mouse_evdev.c:150 #, c-format msgid "Error %d initializing mouse thread: %s" msgstr "Erroray %d initializingay ousemay eadthray: %s" -#: daemon/x52d_mouse_evdev.c:162 +#: daemon/x52d_mouse_evdev.c:157 msgid "Shutting down X52 virtual mouse driver thread" msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray" -#: daemon/x52d_mouse_evdev.c:169 +#: daemon/x52d_mouse_evdev.c:164 msgid "Virtual mouse not created. Ignoring thread state change" msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay" -#: daemon/x52d_mouse_evdev.c:220 +#: daemon/x52d_mouse_evdev.c:225 #, c-format msgid "Error %d creating X52 virtual mouse: %s" msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"