From 798dfd240e53e964094c656f4e365f0cef33b943 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 27a1c6be..4bbc8dca 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -639,17 +639,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 @@ -740,6 +729,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...");