2024-01-25 23:04:09 +01:00
|
|
|
#include "mouse_aoa.h"
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2024-12-20 20:58:41 +01:00
|
|
|
#include <stddef.h>
|
2024-01-25 23:04:09 +01:00
|
|
|
|
|
|
|
|
#include "hid/hid_mouse.h"
|
|
|
|
|
#include "input_events.h"
|
|
|
|
|
#include "util/log.h"
|
|
|
|
|
|
|
|
|
|
/** Downcast mouse processor to mouse_aoa */
|
|
|
|
|
#define DOWNCAST(MP) container_of(MP, struct sc_mouse_aoa, mouse_processor)
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sc_mouse_processor_process_mouse_motion(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_motion_event *event) {
|
|
|
|
|
struct sc_mouse_aoa *mouse = DOWNCAST(mp);
|
|
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
struct sc_hid_input hid_input;
|
|
|
|
|
sc_hid_mouse_generate_input_from_motion(&hid_input, event);
|
2024-01-25 23:04:09 +01:00
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
if (!sc_aoa_push_input(mouse->aoa, &hid_input)) {
|
2024-09-06 23:08:08 +02:00
|
|
|
LOGW("Could not push AOA HID input (mouse motion)");
|
2024-01-25 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sc_mouse_processor_process_mouse_click(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_click_event *event) {
|
|
|
|
|
struct sc_mouse_aoa *mouse = DOWNCAST(mp);
|
|
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
struct sc_hid_input hid_input;
|
|
|
|
|
sc_hid_mouse_generate_input_from_click(&hid_input, event);
|
2024-01-25 23:04:09 +01:00
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
if (!sc_aoa_push_input(mouse->aoa, &hid_input)) {
|
2024-09-06 23:08:08 +02:00
|
|
|
LOGW("Could not push AOA HID input (mouse click)");
|
2024-01-25 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sc_mouse_processor_process_mouse_scroll(struct sc_mouse_processor *mp,
|
|
|
|
|
const struct sc_mouse_scroll_event *event) {
|
|
|
|
|
struct sc_mouse_aoa *mouse = DOWNCAST(mp);
|
|
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
struct sc_hid_input hid_input;
|
2025-06-29 18:22:46 +02:00
|
|
|
if (!sc_hid_mouse_generate_input_from_scroll(&mouse->hid, &hid_input,
|
|
|
|
|
event)) {
|
2025-06-18 18:26:13 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2024-01-25 23:04:09 +01:00
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
if (!sc_aoa_push_input(mouse->aoa, &hid_input)) {
|
2024-09-06 23:08:08 +02:00
|
|
|
LOGW("Could not push AOA HID input (mouse scroll)");
|
2024-01-25 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {
|
|
|
|
|
mouse->aoa = aoa;
|
|
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
struct sc_hid_open hid_open;
|
|
|
|
|
sc_hid_mouse_generate_open(&hid_open);
|
|
|
|
|
|
2024-09-06 23:08:08 +02:00
|
|
|
bool ok = sc_aoa_push_open(aoa, &hid_open, true);
|
2024-01-25 23:04:09 +01:00
|
|
|
if (!ok) {
|
2024-09-06 23:08:08 +02:00
|
|
|
LOGW("Could not push AOA HID open (mouse)");
|
2024-01-25 23:04:09 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 18:22:46 +02:00
|
|
|
sc_hid_mouse_init(&mouse->hid);
|
|
|
|
|
|
2024-01-25 23:04:09 +01:00
|
|
|
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,
|
|
|
|
|
.process_mouse_scroll = sc_mouse_processor_process_mouse_scroll,
|
|
|
|
|
// Touch events not supported (coordinates are not relative)
|
|
|
|
|
.process_touch = NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mouse->mouse_processor.ops = &ops;
|
|
|
|
|
|
|
|
|
|
mouse->mouse_processor.relative_mode = true;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
sc_mouse_aoa_destroy(struct sc_mouse_aoa *mouse) {
|
2024-09-06 23:08:08 +02:00
|
|
|
(void) mouse;
|
|
|
|
|
// Do nothing, mouse->aoa will automatically unregister all devices
|
2024-01-25 23:04:09 +01:00
|
|
|
}
|