From 7dca5078e75a913b76ecde794033791eaf1843f6 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 25 Jun 2021 21:43:44 +0200 Subject: [PATCH] Initialize controller even if there is no display The options --no-display and --no-control are independent. The controller was not initialized when no display was requested, because it was assumed that no control could occur without display. But that's not true (anymore): for example, it is possible to pass --turn-screen-off. Fixes #2426 --- app/src/scrcpy.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 4dcb412f..d0a22e77 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -343,19 +343,29 @@ scrcpy(const struct scrcpy_options *options) { stream_add_sink(&s->stream, &rec->packet_sink); } - if (options->display) { - if (options->control) { - if (!controller_init(&s->controller, s->server.control_socket)) { - goto end; - } - controller_initialized = true; - - if (!controller_start(&s->controller)) { - goto end; - } - controller_started = true; + if (options->control) { + if (!controller_init(&s->controller, s->server.control_socket)) { + 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) { const char *window_title = options->window_title ? options->window_title : device_name; @@ -379,16 +389,6 @@ scrcpy(const struct scrcpy_options *options) { screen_initialized = true; decoder_add_sink(&s->decoder, &s->screen.frame_sink); - - 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_V4L2