Display and control your Android device
Fix HID mouse support with SDL precise scrolling
Romain Vimontfc75319bb291
diff --git a/app/src/hid/hid_mouse.c b/app/src/hid/hid_mouse.cindex 29cfc594..e1fff45b 100644--- a/app/src/hid/hid_mouse.c+++ b/app/src/hid/hid_mouse.c@@ -175,19 +175,23 @@ sc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,data[3] = 0; // wheel coordinates only used for scrolling}-void+boolsc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,const struct sc_mouse_scroll_event *event) {+ if (!event->vscroll_int) {+ // Need a full integral value for HID+ return false;+ }+sc_hid_mouse_input_init(hid_input);uint8_t *data = hid_input->data;data[0] = 0; // buttons state irrelevant (and unknown)data[1] = 0; // no x motiondata[2] = 0; // no y motion- // In practice, vscroll is always -1, 0 or 1, but in theory other values- // are possible- data[3] = CLAMP(event->vscroll, -127, 127);+ data[3] = CLAMP(event->vscroll_int, -127, 127);// Horizontal scrolling ignored+ return true;}void sc_hid_mouse_generate_open(struct sc_hid_open *hid_open) {diff --git a/app/src/hid/hid_mouse.h b/app/src/hid/hid_mouse.hindex 06c61dd1..4ae4bfd4 100644--- a/app/src/hid/hid_mouse.h+++ b/app/src/hid/hid_mouse.h@@ -22,7 +22,7 @@ voidsc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,const struct sc_mouse_click_event *event);-void+boolsc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,const struct sc_mouse_scroll_event *event);diff --git a/app/src/input_events.h b/app/src/input_events.hindex 0c022acc..1e34b50e 100644--- a/app/src/input_events.h+++ b/app/src/input_events.h@@ -393,6 +393,8 @@ struct sc_mouse_scroll_event {struct sc_position position;float hscroll;float vscroll;+ int32_t hscroll_int;+ int32_t vscroll_int;uint8_t buttons_state; // bitwise-OR of sc_mouse_button values};diff --git a/app/src/input_manager.c b/app/src/input_manager.cindex f7a787d1..3e4dd0f3 100644--- a/app/src/input_manager.c+++ b/app/src/input_manager.c@@ -903,6 +903,8 @@ sc_input_manager_process_mouse_wheel(struct sc_input_manager *im,.hscroll = event->x,.vscroll = event->y,#endif+ .hscroll_int = event->x,+ .vscroll_int = event->y,.buttons_state = im->mouse_buttons_state,};diff --git a/app/src/uhid/mouse_uhid.c b/app/src/uhid/mouse_uhid.cindex 7fed8383..869e48a4 100644--- a/app/src/uhid/mouse_uhid.c+++ b/app/src/uhid/mouse_uhid.c@@ -55,7 +55,9 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,struct sc_mouse_uhid *mouse = DOWNCAST(mp);struct sc_hid_input hid_input;- sc_hid_mouse_generate_input_from_scroll(&hid_input, event);+ if (!sc_hid_mouse_generate_input_from_scroll(&hid_input, event)) {+ return;+ }sc_mouse_uhid_send_input(mouse, &hid_input, "mouse scroll");}diff --git a/app/src/usb/mouse_aoa.c b/app/src/usb/mouse_aoa.cindex b64e9b12..fd5fa5e0 100644--- a/app/src/usb/mouse_aoa.c+++ b/app/src/usb/mouse_aoa.c@@ -42,7 +42,9 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,struct sc_mouse_aoa *mouse = DOWNCAST(mp);struct sc_hid_input hid_input;- sc_hid_mouse_generate_input_from_scroll(&hid_input, event);+ if (!sc_hid_mouse_generate_input_from_scroll(&hid_input, event)) {+ return;+ }if (!sc_aoa_push_input(mouse->aoa, &hid_input)) {LOGW("Could not push AOA HID input (mouse scroll)");diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.cindex 02edc3a3..5c580df9 100644--- a/app/src/usb/screen_otg.c+++ b/app/src/usb/screen_otg.c@@ -164,8 +164,15 @@ sc_screen_otg_process_mouse_wheel(struct sc_screen_otg *screen,struct sc_mouse_scroll_event evt = {// .position not used for HID events+#if SDL_VERSION_ATLEAST(2, 0, 18)+ .hscroll = event->preciseX,+ .vscroll = event->preciseY,+#else.hscroll = event->x,.vscroll = event->y,+#endif+ .hscroll_int = event->x,+ .vscroll_int = event->y,.buttons_state = sc_mouse_buttons_state_from_sdl(sdl_buttons_state),};