Reorder controller and HID initialization

This allows to merge two "#ifdef HAVE_AOA_HID" blocks to simplify.
This commit is contained in:
Romain Vimont 2022-01-01 19:38:27 +01:00
parent 6102a0b5bb
commit 5ce1ccde85

View file

@ -455,34 +455,10 @@ scrcpy(struct scrcpy_options *options) {
} }
acksync = &s->acksync; acksync = &s->acksync;
}
#endif
if (!controller_init(&s->controller, s->server.control_socket,
acksync)) {
goto end;
}
controller_initialized = true;
if (!controller_start(&s->controller)) {
goto end;
}
controller_started = true;
if (options->turn_screen_off) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_OFF;
if (!controller_push_msg(&s->controller, &msg)) {
LOGW("Could not request 'set screen power mode'");
}
}
#ifdef HAVE_AOA_HID
if (options->keyboard_input_mode == SC_KEYBOARD_INPUT_MODE_HID) {
bool aoa_hid_ok = false; bool aoa_hid_ok = false;
bool ok = sc_aoa_init(&s->aoa, serial, acksync); ok = sc_aoa_init(&s->aoa, serial, acksync);
if (!ok) { if (!ok) {
goto aoa_hid_end; goto aoa_hid_end;
} }
@ -524,6 +500,28 @@ aoa_hid_end:
sc_mouse_inject_init(&s->mouse_inject, &s->controller); sc_mouse_inject_init(&s->mouse_inject, &s->controller);
mp = &s->mouse_inject.mouse_processor; mp = &s->mouse_inject.mouse_processor;
if (!controller_init(&s->controller, s->server.control_socket,
acksync)) {
goto end;
}
controller_initialized = true;
if (!controller_start(&s->controller)) {
goto end;
}
controller_started = true;
if (options->turn_screen_off) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_OFF;
if (!controller_push_msg(&s->controller, &msg)) {
LOGW("Could not request 'set screen power mode'");
}
}
} }
if (options->display) { if (options->display) {