This commit is contained in:
Romain Vimont
2021-10-20 22:04:11 +02:00
parent c05054c52d
commit 0f0e577461
5 changed files with 41 additions and 3 deletions

View File

@@ -326,6 +326,7 @@ run_aoa_thread(void *data) {
(void) non_empty; (void) non_empty;
sc_mutex_unlock(&aoa->mutex); sc_mutex_unlock(&aoa->mutex);
LOGD("======= aoa_thread process event");
bool ok = process_hid_event(aoa, &event); bool ok = process_hid_event(aoa, &event);
hid_event_destroy(&event); hid_event_destroy(&event);
if (!ok) { if (!ok) {

View File

@@ -170,6 +170,21 @@ sdl_keymod_to_hid_modifiers(SDL_Keymod mod) {
return modifiers; return modifiers;
} }
static bool
gen(struct hid_keyboard *kb, struct hid_event *hid_event) {
hid_event->from_accessory_id = HID_KEYBOARD_ACCESSORY_ID;
hid_event->buffer = create_hid_keyboard_event();
if (!hid_event->buffer) {
return false;
}
hid_event->size = HID_KEYBOARD_EVENT_SIZE;
hid_event->buffer[HID_KEYBOARD_INDEX_KEYS] = 57; //CAPSLOCK
for (int i = 0; i < HID_KEYBOARD_EVENT_SIZE; ++i)
printf("%02x ", hid_event->buffer[i]);
printf("\n");
return true;
}
static bool static bool
convert_hid_keyboard_event(struct hid_keyboard *kb, struct hid_event *hid_event, convert_hid_keyboard_event(struct hid_keyboard *kb, struct hid_event *hid_event,
const SDL_KeyboardEvent *event) { const SDL_KeyboardEvent *event) {
@@ -276,9 +291,14 @@ sc_key_processor_process_text(struct sc_key_processor *kp,
} }
bool bool
hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa) { hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa, unsigned lock_mod) {
kb->aoa = aoa; kb->aoa = aoa;
// FIXME problem: aoa_setup_hid is executed from this thread, but events
// are sent from the aoa thread. Is this thread-safe?
// In practice, sending CAPS_LOCK immediately after fails with a Pipe error
// but we must know immediately if this fails or not
// TODO test with a simple mutex to confirm
bool ok = aoa_setup_hid(aoa, HID_KEYBOARD_ACCESSORY_ID, bool ok = aoa_setup_hid(aoa, HID_KEYBOARD_ACCESSORY_ID,
keyboard_report_desc, keyboard_report_desc,
ARRAY_LEN(keyboard_report_desc)); ARRAY_LEN(keyboard_report_desc));
@@ -297,6 +317,17 @@ hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa) {
kb->key_processor.ops = &ops; kb->key_processor.ops = &ops;
if (lock_mod & SC_MOD_CAPS_LOCK) {
struct hid_event event;
gen(kb, &event); // FIXME error handling
if (!aoa_push_hid_event(kb->aoa, &event)) {
LOGW("Could request HID event");
}
}
if (lock_mod & SC_MOD_NUM_LOCK) {
// TODO
}
return true; return true;
} }

View File

@@ -16,6 +16,9 @@
// 0x65 is Application, typically AT-101 Keyboard ends here. // 0x65 is Application, typically AT-101 Keyboard ends here.
#define HID_KEYBOARD_KEYS 0x66 #define HID_KEYBOARD_KEYS 0x66
#define SC_MOD_CAPS_LOCK 0x1
#define SC_MOD_NUM_LOCK 0x2
/** /**
* HID keyboard events are sequence-based, every time keyboard state changes * HID keyboard events are sequence-based, every time keyboard state changes
* it sends an array of currently pressed keys, the host is responsible for * it sends an array of currently pressed keys, the host is responsible for
@@ -36,7 +39,7 @@ struct hid_keyboard {
}; };
bool bool
hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa); hid_keyboard_init(struct hid_keyboard *kb, struct aoa *aoa, unsigned lock_mod);
void void
hid_keyboard_destroy(struct hid_keyboard *kb); hid_keyboard_destroy(struct hid_keyboard *kb);

View File

@@ -376,6 +376,8 @@ input_manager_process_key(struct input_manager *im,
bool smod = is_shortcut_mod(im, mod); bool smod = is_shortcut_mod(im, mod);
LOGD("=== %x", (int) mod);
if (down && !repeat) { if (down && !repeat) {
if (keycode == im->last_keycode && mod == im->last_mod) { if (keycode == im->last_keycode && mod == im->last_mod) {
++im->key_repeat; ++im->key_repeat;

View File

@@ -462,7 +462,8 @@ scrcpy(struct scrcpy_options *options) {
goto aoa_hid_end; goto aoa_hid_end;
} }
if (!hid_keyboard_init(&s->keyboard_hid, &s->aoa)) { unsigned mod = SC_MOD_CAPS_LOCK;
if (!hid_keyboard_init(&s->keyboard_hid, &s->aoa, mod)) {
aoa_join(&s->aoa); aoa_join(&s->aoa);
aoa_stop(&s->aoa); aoa_stop(&s->aoa);
aoa_destroy(&s->aoa); aoa_destroy(&s->aoa);