From a425a90450c5901b136ecae52b993e5337b4d789 Mon Sep 17 00:00:00 2001 From: Ivan Keliukh Date: Sat, 13 Jun 2020 15:10:41 +0300 Subject: [PATCH] implement option for disabling screen saver --- app/scrcpy.1 | 4 ++++ app/src/cli.c | 9 +++++++++ app/src/scrcpy.c | 14 ++++++++++---- app/src/scrcpy.h | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 776d78ae85..7525117bf3 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -43,6 +43,10 @@ The values are expressed in the device natural orientation (typically, portrait .B \-\-max\-size value is computed on the cropped size. +.TP +.BI "\-\-disable-screen-saver" +Disable screen saver while scrcpy is running. Convenient if the \fI--no-control\fR option is used. + .TP .BI "\-\-display " id Specify the display id to mirror. diff --git a/app/src/cli.c b/app/src/cli.c index be0b7c238c..0ebb8252cf 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -45,6 +45,10 @@ scrcpy_print_usage(const char *arg0) { " (typically, portrait for a phone, landscape for a tablet).\n" " Any --max-size value is computed on the cropped size.\n" "\n" + " --disable-screen-saver\n" + " Disable screen saver while scrcpy is running. Convenient if\n" + " the --no-control option is used\n" + "\n" " --display id\n" " Specify the display id to mirror.\n" "\n" @@ -526,6 +530,7 @@ guess_record_format(const char *filename) { #define OPT_NO_MIPMAPS 1017 #define OPT_CODEC_OPTIONS 1018 #define OPT_FORCE_ADB_FORWARD 1019 +#define OPT_DISABLE_SCREEN_SAVER 1020 bool scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { @@ -534,6 +539,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { {"bit-rate", required_argument, NULL, 'b'}, {"codec-options", required_argument, NULL, OPT_CODEC_OPTIONS}, {"crop", required_argument, NULL, OPT_CROP}, + {"disable-screen-saver", no_argument, NULL, OPT_DISABLE_SCREEN_SAVER}, {"display", required_argument, NULL, OPT_DISPLAY_ID}, {"force-adb-forward", no_argument, NULL, OPT_FORCE_ADB_FORWARD}, @@ -716,6 +722,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) { case OPT_FORCE_ADB_FORWARD: opts->force_adb_forward = true; break; + case OPT_DISABLE_SCREEN_SAVER: + opts->disable_screen_saver = true; + break; default: // getopt prints the error message on stderr return false; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 67ebf8c0cd..17aa043c30 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -63,7 +63,7 @@ BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) { // init SDL and set appropriate hints static bool -sdl_init_and_configure(bool display, const char *render_driver) { +sdl_init_and_configure(bool display, const char *render_driver, bool disable_screen_saver) { uint32_t flags = display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS; if (SDL_Init(flags)) { LOGC("Could not initialize SDL: %s", SDL_GetError()); @@ -112,8 +112,14 @@ sdl_init_and_configure(bool display, const char *render_driver) { LOGW("Could not disable minimize on focus loss"); } - // Do not disable the screensaver when scrcpy is running - SDL_EnableScreenSaver(); + if (disable_screen_saver) + { + SDL_DisableScreenSaver(); + } + else + { + SDL_EnableScreenSaver(); + } return true; } @@ -321,7 +327,7 @@ scrcpy(const struct scrcpy_options *options) { bool controller_initialized = false; bool controller_started = false; - if (!sdl_init_and_configure(options->display, options->render_driver)) { + if (!sdl_init_and_configure(options->display, options->render_driver, options->disable_screen_saver)) { goto end; } diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 70d99433ca..72944c04e5 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -43,6 +43,7 @@ struct scrcpy_options { bool mipmaps; bool stay_awake; bool force_adb_forward; + bool disable_screen_saver; }; #define SCRCPY_OPTIONS_DEFAULT { \ @@ -81,6 +82,7 @@ struct scrcpy_options { .mipmaps = true, \ .stay_awake = false, \ .force_adb_forward = false, \ + .disable_screen_saver = false, \ } bool