Add horizontal scrolling support for HID mouse

PR #6172 <https://github.com/Genymobile/scrcpy/pull/6172>
This commit is contained in:
Romain Vimont 2025-06-18 18:29:04 +02:00
commit 4841fdd1ef

View file

@ -3,8 +3,8 @@
#include <stdint.h> #include <stdint.h>
// 1 byte for buttons + padding, 1 byte for X position, 1 byte for Y position, // 1 byte for buttons + padding, 1 byte for X position, 1 byte for Y position,
// 1 byte for wheel motion // 1 byte for wheel motion, 1 byte for hozizontal scrolling
#define SC_HID_MOUSE_INPUT_SIZE 4 #define SC_HID_MOUSE_INPUT_SIZE 5
/** /**
* Mouse descriptor from the specification: * Mouse descriptor from the specification:
@ -75,6 +75,21 @@ static const uint8_t SC_HID_MOUSE_REPORT_DESC[] = {
// Input (Data, Variable, Relative): 3 position bytes (X, Y, Wheel) // Input (Data, Variable, Relative): 3 position bytes (X, Y, Wheel)
0x81, 0x06, 0x81, 0x06,
// Usage Page (Consumer Page)
0x05, 0x0C,
// Usage(AC Pan)
0x0A, 0x38, 0x02,
// Logical Minimum (-127)
0x15, 0x81,
// Logical Maximum (127)
0x25, 0x7F,
// Report Size (8)
0x75, 0x08,
// Report Count (1)
0x95, 0x01,
// Input (Data, Variable, Relative): 1 byte (AC Pan)
0x81, 0x06,
// End Collection // End Collection
0xC0, 0xC0,
@ -160,7 +175,8 @@ sc_hid_mouse_generate_input_from_motion(struct sc_hid_input *hid_input,
data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state); data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state);
data[1] = CLAMP(event->xrel, -127, 127); data[1] = CLAMP(event->xrel, -127, 127);
data[2] = CLAMP(event->yrel, -127, 127); data[2] = CLAMP(event->yrel, -127, 127);
data[3] = 0; // wheel coordinates only used for scrolling data[3] = 0; // no vertical scrolling
data[4] = 0; // no horizontal scrolling
} }
void void
@ -172,13 +188,14 @@ sc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,
data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state); data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state);
data[1] = 0; // no x motion data[1] = 0; // no x motion
data[2] = 0; // no y motion data[2] = 0; // no y motion
data[3] = 0; // wheel coordinates only used for scrolling data[3] = 0; // no vertical scrolling
data[4] = 0; // no horizontal scrolling
} }
bool bool
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input, sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
const struct sc_mouse_scroll_event *event) { const struct sc_mouse_scroll_event *event) {
if (!event->vscroll_int) { if (!event->vscroll_int && !event->hscroll_int) {
// Need a full integral value for HID // Need a full integral value for HID
return false; return false;
} }
@ -190,7 +207,7 @@ sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
data[1] = 0; // no x motion data[1] = 0; // no x motion
data[2] = 0; // no y motion data[2] = 0; // no y motion
data[3] = CLAMP(event->vscroll_int, -127, 127); data[3] = CLAMP(event->vscroll_int, -127, 127);
// Horizontal scrolling ignored data[4] = CLAMP(event->hscroll_int, -127, 127);
return true; return true;
} }