Apply mouse button events immediately

Prior to this change, the button change events were only happening on
periodic intervals corresponding to the change in the mouse REL_X and
REL_Y values. However, this has the issue that it tends to miss a few
events, especially those related to the scroll wheel.

This change reports button and wheel events immediately when receiving
the report, but it leaves the motion to be updated by the thread.
reverse-scroll
nirenjan 2021-09-14 23:35:05 -07:00
parent 53957d0813
commit 025a06351a
3 changed files with 51 additions and 46 deletions

View File

@ -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();
}

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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 <nirenjan@gmail.com>\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"