2
0
mirror of https://github.com/Genymobile/scrcpy synced 2025-08-22 18:07:24 +00:00

acc_scroll

This commit is contained in:
Romain Vimont 2025-06-16 23:11:40 +02:00
parent d74cfd5711
commit f9b3f973de
6 changed files with 44 additions and 9 deletions

View File

@ -151,6 +151,11 @@ sc_hid_buttons_from_buttons_state(uint8_t buttons_state) {
return c;
}
void
sc_hid_mouse_init(struct sc_hid_mouse *hid) {
hid->acc_vscroll = 0;
}
void
sc_hid_mouse_generate_input_from_motion(struct sc_hid_input *hid_input,
const struct sc_mouse_motion_event *event) {
@ -175,8 +180,9 @@ sc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,
data[3] = 0; // wheel coordinates only used for scrolling
}
void
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
bool
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_mouse *hid,
struct sc_hid_input *hid_input,
const struct sc_mouse_scroll_event *event) {
sc_hid_mouse_input_init(hid_input);
@ -184,9 +190,19 @@ sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
data[0] = 0; // buttons state irrelevant (and unknown)
data[1] = 0; // no x motion
data[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);
hid->acc_vscroll += event->vscroll;
if (hid->acc_vscroll > -1 && hid->acc_vscroll < 1) {
// Not enough scrolling to inject a scroll tick
return false;
}
hid->acc_vscroll = CLAMP(hid->acc_vscroll, -127, 127);
int8_t consume = hid->acc_vscroll; // truncate towards 0
assert(consume);
hid->acc_vscroll -= consume;
data[3] = consume;
return true;
// Horizontal scrolling ignored
}

View File

@ -8,6 +8,13 @@
#define SC_HID_ID_MOUSE 2
struct sc_hid_mouse {
float acc_vscroll;
};
void
sc_hid_mouse_init(struct sc_hid_mouse *hid);
void
sc_hid_mouse_generate_open(struct sc_hid_open *hid_open);
@ -22,8 +29,9 @@ void
sc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,
const struct sc_mouse_click_event *event);
void
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
bool
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_mouse *hid,
struct sc_hid_input *hid_input,
const struct sc_mouse_scroll_event *event);
#endif

View File

@ -55,7 +55,10 @@ 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(&mouse->hid, &hid_input,
event)) {
return;
}
sc_mouse_uhid_send_input(mouse, &hid_input, "mouse scroll");
}
@ -63,6 +66,8 @@ sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
bool
sc_mouse_uhid_init(struct sc_mouse_uhid *mouse,
struct sc_controller *controller) {
sc_hid_mouse_init(&mouse->hid);
mouse->controller = controller;
static const struct sc_mouse_processor_ops ops = {

View File

@ -4,11 +4,13 @@
#include <stdbool.h>
#include "controller.h"
#include "hid/hid_mouse.h"
#include "trait/mouse_processor.h"
struct sc_mouse_uhid {
struct sc_mouse_processor mouse_processor; // mouse processor trait
struct sc_hid_mouse hid;
struct sc_controller *controller;
};

View File

@ -42,7 +42,7 @@ 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);
sc_hid_mouse_generate_input_from_scroll(&mouse->hid, &hid_input, event);
if (!sc_aoa_push_input(mouse->aoa, &hid_input)) {
LOGW("Could not push AOA HID input (mouse scroll)");
@ -62,6 +62,8 @@ sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {
return false;
}
sc_hid_mouse_init(&mouse->hid);
static const struct sc_mouse_processor_ops ops = {
.process_mouse_motion = sc_mouse_processor_process_mouse_motion,
.process_mouse_click = sc_mouse_processor_process_mouse_click,

View File

@ -5,12 +5,14 @@
#include <stdbool.h>
#include "hid/hid_mouse.h"
#include "usb/aoa_hid.h"
#include "trait/mouse_processor.h"
struct sc_mouse_aoa {
struct sc_mouse_processor mouse_processor; // mouse processor trait
struct sc_hid_mouse hid;
struct sc_aoa *aoa;
};