From e7b3127af1a1042d40730dbb6ea3deb144e64bb8 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 Jun 2018 18:20:09 +0200 Subject: [PATCH] Send out the mouse position and wheel values continuously if the report is not zeros, but only send the mouse button states when they change --- right/src/usb_report_updater.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/right/src/usb_report_updater.c b/right/src/usb_report_updater.c index 2c6377b..45790aa 100644 --- a/right/src/usb_report_updater.c +++ b/right/src/usb_report_updater.c @@ -408,33 +408,29 @@ void UpdateUsbReports(void) updateActiveUsbReports(); - bool HasUsbBasicKeyboardReportChanged = false; - if (memcmp(ActiveUsbBasicKeyboardReport, GetInactiveUsbBasicKeyboardReport(), sizeof(usb_basic_keyboard_report_t)) != 0) { - HasUsbBasicKeyboardReportChanged = true; + bool HasUsbBasicKeyboardReportChanged = memcmp(ActiveUsbBasicKeyboardReport, GetInactiveUsbBasicKeyboardReport(), sizeof(usb_basic_keyboard_report_t)) != 0; + if (HasUsbBasicKeyboardReportChanged) { UsbBasicKeyboardAction(); } - bool HasUsbMediaKeyboardReportChanged = false; - if (memcmp(ActiveUsbMediaKeyboardReport, GetInactiveUsbMediaKeyboardReport(), sizeof(usb_media_keyboard_report_t)) != 0) { - HasUsbMediaKeyboardReportChanged = true; + bool HasUsbMediaKeyboardReportChanged = memcmp(ActiveUsbMediaKeyboardReport, GetInactiveUsbMediaKeyboardReport(), sizeof(usb_media_keyboard_report_t)) != 0; + if (HasUsbMediaKeyboardReportChanged) { UsbMediaKeyboardAction(); } - bool HasUsbSystemKeyboardReportChanged = false; - if (memcmp(ActiveUsbSystemKeyboardReport, GetInactiveUsbSystemKeyboardReport(), sizeof(usb_system_keyboard_report_t)) != 0) { - HasUsbSystemKeyboardReportChanged = true; + bool HasUsbSystemKeyboardReportChanged = memcmp(ActiveUsbSystemKeyboardReport, GetInactiveUsbSystemKeyboardReport(), sizeof(usb_system_keyboard_report_t)) != 0; + if (HasUsbSystemKeyboardReportChanged) { UsbSystemKeyboardAction(); } - // Send out the report continuously if the report was not zeros - bool HasUsbMouseReportChanged = false; - uint8_t zeroBuf[sizeof(usb_mouse_report_t)] = { 0 }; - if (memcmp(ActiveUsbMouseReport, zeroBuf, sizeof(usb_mouse_report_t)) != 0) { - HasUsbMouseReportChanged = true; + // Send out the mouse position and wheel values continuously if the report is not zeros, but only send the mouse button states when they change. + bool HasUsbMouseReportChanged = memcmp(ActiveUsbMouseReport, GetInactiveUsbMouseReport(), sizeof(usb_mouse_report_t)) != 0; + if (HasUsbMouseReportChanged || ActiveUsbMouseReport->x || ActiveUsbMouseReport->y || + ActiveUsbMouseReport->wheelX || ActiveUsbMouseReport->wheelY) { usbMouseAction(); } - if ((previousLayer != LayerId_Base || HasUsbBasicKeyboardReportChanged || HasUsbMediaKeyboardReportChanged || HasUsbSystemKeyboardReportChanged || HasUsbMouseReportChanged) && IsHostSleeping) { + if (IsHostSleeping && (previousLayer != LayerId_Base || HasUsbBasicKeyboardReportChanged || HasUsbMediaKeyboardReportChanged || HasUsbSystemKeyboardReportChanged || HasUsbMouseReportChanged)) { WakeUpHost(true); // Wake up the host if any key is pressed and the computer is sleeping. } }