From 2e50b364c43a9a8d8794cc838d5fca25c57416cb Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Tue, 1 Aug 2023 23:58:29 +0200 Subject: [PATCH] adbmouse: emulate single button mouse. --- devices/common/adb/adbmouse.cpp | 24 +++++++++++++++++------- devices/common/adb/adbmouse.h | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/devices/common/adb/adbmouse.cpp b/devices/common/adb/adbmouse.cpp index deea27c..05e81cf 100644 --- a/devices/common/adb/adbmouse.cpp +++ b/devices/common/adb/adbmouse.cpp @@ -34,6 +34,9 @@ void AdbMouse::event_handler(const MouseEvent& event) { if (event.flags & MOUSE_EVENT_MOTION) { this->x_rel += event.xrel; this->y_rel += event.yrel; + } else if (event.flags & MOUSE_EVENT_BUTTON) { + this->buttons_state = event.buttons_state; + this->changed = true; } } @@ -42,19 +45,25 @@ void AdbMouse::reset() { this->dev_handler_id = 1; this->exc_event_flag = 1; this->srq_flag = 1; // enable service requests + this->x_rel = 0; + this->y_rel = 0; + this->buttons_state = 0; + this->changed = false; } bool AdbMouse::get_register_0() { - if (this->x_rel || this->y_rel) { + if (this->x_rel || this->y_rel || this->changed) { uint8_t* out_buf = this->host_obj->get_output_buf(); + uint8_t button1_state = (this->buttons_state ^ 1) << 7; + // report Y-axis motion if (this->y_rel < -64) - out_buf[0] = 0x40 | 0x80; + out_buf[0] = 0x40 | button1_state; else if (this->y_rel > 63) - out_buf[0] = 0x3F | 0x80; + out_buf[0] = 0x3F | button1_state; else - out_buf[0] = (this->y_rel & 0x7F) | 0x80; + out_buf[0] = (this->y_rel & 0x7F) | button1_state; // report X-axis motion if (this->x_rel < -64) @@ -64,9 +73,10 @@ bool AdbMouse::get_register_0() { else out_buf[1] = (this->x_rel & 0x7F) | 0x80; - // reset accumulated motion data - this->x_rel = 0; - this->y_rel = 0; + // reset accumulated motion data and button change flag + this->x_rel = 0; + this->y_rel = 0; + this->changed = false; this->host_obj->set_output_count(2); return true; diff --git a/devices/common/adb/adbmouse.h b/devices/common/adb/adbmouse.h index d987903..48e4b40 100644 --- a/devices/common/adb/adbmouse.h +++ b/devices/common/adb/adbmouse.h @@ -49,6 +49,8 @@ public: private: int32_t x_rel = 0; int32_t y_rel = 0; + uint8_t buttons_state = 0; + bool changed = false; }; #endif // ADB_MOUSE_H