mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-01-28 10:04:27 +01:00
Introduce hid_open and hid_close events
This allows to handle HID open/close reports at the same place as HID input reports (in the HID layer). This will be especially useful to manage HID gamepads, to avoid implementing one part in the HID layer and another part in the gamepad processor implementation. PR #5270 <https://github.com/Genymobile/scrcpy/pull/5270>
This commit is contained in:
@@ -230,8 +230,7 @@ sc_aoa_push_input_with_ack_to_wait(struct sc_aoa *aoa,
|
||||
}
|
||||
|
||||
bool
|
||||
sc_aoa_push_open(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
const uint8_t *report_desc, uint16_t report_desc_size) {
|
||||
sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open) {
|
||||
// TODO log verbose
|
||||
|
||||
sc_mutex_lock(&aoa->mutex);
|
||||
@@ -247,9 +246,7 @@ sc_aoa_push_open(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
}
|
||||
|
||||
aoa_event->type = SC_AOA_EVENT_TYPE_OPEN;
|
||||
aoa_event->open.hid_id = accessory_id;
|
||||
aoa_event->open.report_desc = report_desc;
|
||||
aoa_event->open.report_desc_size = report_desc_size;
|
||||
aoa_event->open.hid = *hid_open;
|
||||
|
||||
if (was_empty) {
|
||||
sc_cond_signal(&aoa->event_cond);
|
||||
@@ -261,7 +258,7 @@ sc_aoa_push_open(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
}
|
||||
|
||||
bool
|
||||
sc_aoa_push_close(struct sc_aoa *aoa, uint16_t accessory_id) {
|
||||
sc_aoa_push_close(struct sc_aoa *aoa, const struct sc_hid_close *hid_close) {
|
||||
// TODO log verbose
|
||||
|
||||
sc_mutex_lock(&aoa->mutex);
|
||||
@@ -277,7 +274,7 @@ sc_aoa_push_close(struct sc_aoa *aoa, uint16_t accessory_id) {
|
||||
}
|
||||
|
||||
aoa_event->type = SC_AOA_EVENT_TYPE_CLOSE;
|
||||
aoa_event->close.hid_id = accessory_id;
|
||||
aoa_event->close.hid = *hid_close;
|
||||
|
||||
if (was_empty) {
|
||||
sc_cond_signal(&aoa->event_cond);
|
||||
@@ -316,29 +313,31 @@ sc_aoa_process_event(struct sc_aoa *aoa, struct sc_aoa_event *event) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ok = sc_aoa_send_hid_event(aoa, &event->input.hid);
|
||||
struct sc_hid_input *hid_input = &event->input.hid;
|
||||
bool ok = sc_aoa_send_hid_event(aoa, hid_input);
|
||||
if (!ok) {
|
||||
LOGW("Could not send HID event to USB device: %" PRIu16,
|
||||
event->input.hid.hid_id);
|
||||
hid_input->hid_id);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SC_AOA_EVENT_TYPE_OPEN: {
|
||||
bool ok = sc_aoa_setup_hid(aoa, event->open.hid_id,
|
||||
event->open.report_desc,
|
||||
event->open.report_desc_size);
|
||||
struct sc_hid_open *hid_open = &event->open.hid;
|
||||
bool ok = sc_aoa_setup_hid(aoa, hid_open->hid_id,
|
||||
hid_open->report_desc,
|
||||
hid_open->report_desc_size);
|
||||
if (!ok) {
|
||||
LOGW("Could not open AOA device: %" PRIu16, event->open.hid_id);
|
||||
LOGW("Could not open AOA device: %" PRIu16, hid_open->hid_id);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case SC_AOA_EVENT_TYPE_CLOSE: {
|
||||
bool ok = sc_aoa_unregister_hid(aoa, event->close.hid_id);
|
||||
struct sc_hid_close *hid_close = &event->close.hid;
|
||||
bool ok = sc_aoa_unregister_hid(aoa, hid_close->hid_id);
|
||||
if (!ok) {
|
||||
LOGW("Could not close AOA device: %" PRIu16,
|
||||
event->close.hid_id);
|
||||
LOGW("Could not close AOA device: %" PRIu16, hid_close->hid_id);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -23,12 +23,10 @@ struct sc_aoa_event {
|
||||
enum sc_aoa_event_type type;
|
||||
union {
|
||||
struct {
|
||||
uint16_t hid_id;
|
||||
const uint8_t *report_desc; // pointer to static memory
|
||||
uint16_t report_desc_size;
|
||||
struct sc_hid_open hid;
|
||||
} open;
|
||||
struct {
|
||||
uint16_t hid_id;
|
||||
struct sc_hid_close hid;
|
||||
} close;
|
||||
struct {
|
||||
struct sc_hid_input hid;
|
||||
@@ -75,11 +73,10 @@ sc_aoa_join(struct sc_aoa *aoa);
|
||||
// report_desc must be a pointer to static memory, accessed at any time from
|
||||
// another thread
|
||||
bool
|
||||
sc_aoa_push_open(struct sc_aoa *aoa, uint16_t accessory_id,
|
||||
const uint8_t *report_desc, uint16_t report_desc_size);
|
||||
sc_aoa_push_open(struct sc_aoa *aoa, const struct sc_hid_open *hid_open);
|
||||
|
||||
bool
|
||||
sc_aoa_push_close(struct sc_aoa *aoa, uint16_t accessory_id);
|
||||
sc_aoa_push_close(struct sc_aoa *aoa, const struct sc_hid_close *hid_close);
|
||||
|
||||
bool
|
||||
sc_aoa_push_input_with_ack_to_wait(struct sc_aoa *aoa,
|
||||
|
||||
@@ -66,9 +66,10 @@ bool
|
||||
sc_keyboard_aoa_init(struct sc_keyboard_aoa *kb, struct sc_aoa *aoa) {
|
||||
kb->aoa = aoa;
|
||||
|
||||
bool ok = sc_aoa_push_open(aoa, SC_HID_ID_KEYBOARD,
|
||||
SC_HID_KEYBOARD_REPORT_DESC,
|
||||
SC_HID_KEYBOARD_REPORT_DESC_LEN);
|
||||
struct sc_hid_open hid_open;
|
||||
sc_hid_keyboard_generate_open(&hid_open);
|
||||
|
||||
bool ok = sc_aoa_push_open(aoa, &hid_open);
|
||||
if (!ok) {
|
||||
LOGW("Could not push AOA keyboard open request");
|
||||
return false;
|
||||
@@ -97,7 +98,10 @@ sc_keyboard_aoa_init(struct sc_keyboard_aoa *kb, struct sc_aoa *aoa) {
|
||||
|
||||
void
|
||||
sc_keyboard_aoa_destroy(struct sc_keyboard_aoa *kb) {
|
||||
bool ok = sc_aoa_push_close(kb->aoa, SC_HID_ID_KEYBOARD);
|
||||
struct sc_hid_close hid_close;
|
||||
sc_hid_keyboard_generate_close(&hid_close);
|
||||
|
||||
bool ok = sc_aoa_push_close(kb->aoa, &hid_close);
|
||||
if (!ok) {
|
||||
LOGW("Could not push AOA keyboard close request");
|
||||
}
|
||||
|
||||
@@ -52,9 +52,10 @@ bool
|
||||
sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {
|
||||
mouse->aoa = aoa;
|
||||
|
||||
bool ok = sc_aoa_push_open(aoa, SC_HID_ID_MOUSE,
|
||||
SC_HID_MOUSE_REPORT_DESC,
|
||||
SC_HID_MOUSE_REPORT_DESC_LEN);
|
||||
struct sc_hid_open hid_open;
|
||||
sc_hid_mouse_generate_open(&hid_open);
|
||||
|
||||
bool ok = sc_aoa_push_open(aoa, &hid_open);
|
||||
if (!ok) {
|
||||
LOGW("Could not push AOA mouse open request");
|
||||
return false;
|
||||
@@ -77,7 +78,10 @@ sc_mouse_aoa_init(struct sc_mouse_aoa *mouse, struct sc_aoa *aoa) {
|
||||
|
||||
void
|
||||
sc_mouse_aoa_destroy(struct sc_mouse_aoa *mouse) {
|
||||
bool ok = sc_aoa_push_close(mouse->aoa, SC_HID_ID_MOUSE);
|
||||
struct sc_hid_close hid_close;
|
||||
sc_hid_mouse_generate_close(&hid_close);
|
||||
|
||||
bool ok = sc_aoa_push_close(mouse->aoa, &hid_close);
|
||||
if (!ok) {
|
||||
LOGW("Could not push AOA mouse close request");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user