From e471ecf2040d80f51caceb93c91a09518c377141 Mon Sep 17 00:00:00 2001 From: Yan Date: Sat, 8 Apr 2023 10:11:47 +0200 Subject: [PATCH] Turn device screen off after set up Sometimes it can take quite a while for everything to get set up and the screen to appear. PR #3902 Signed-off-by: Romain Vimont --- app/src/scrcpy.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index efa69d31..7970fb0f 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -630,17 +630,6 @@ aoa_hid_end: } controller_started = true; controller = &s->controller; - - if (options->turn_screen_off) { - struct sc_control_msg msg; - msg.type = SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE; - msg.set_screen_power_mode.mode = SC_SCREEN_POWER_MODE_OFF; - - if (!sc_controller_push_msg(&s->controller, &msg)) { - LOGW("Could not request 'set screen power mode'"); - } - } - } // There is a controller if and only if control is enabled @@ -728,6 +717,18 @@ aoa_hid_end: audio_demuxer_started = true; } + // If the device screen is to be turned off, send the control message after + // everything is set up + if (options->control && options->turn_screen_off) { + struct sc_control_msg msg; + msg.type = SC_CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE; + msg.set_screen_power_mode.mode = SC_SCREEN_POWER_MODE_OFF; + + if (!sc_controller_push_msg(&s->controller, &msg)) { + LOGW("Could not request 'set screen power mode'"); + } + } + ret = event_loop(s); LOGD("quit...");