Add option for disabling screensaver
PR #1502 <https://github.com/Genymobile/scrcpy/pull/1502> Fixes #1370 <https://github.com/Genymobile/scrcpy/issues/1370> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
1e4ee547b5
commit
dc7b60e619
5 changed files with 37 additions and 4 deletions
11
README.md
11
README.md
|
@ -479,6 +479,17 @@ scrcpy -t
|
||||||
Note that it only shows _physical_ touches (with the finger on the device).
|
Note that it only shows _physical_ touches (with the finger on the device).
|
||||||
|
|
||||||
|
|
||||||
|
#### Disable screensaver
|
||||||
|
|
||||||
|
By default, scrcpy does not prevent the screensaver to run on the computer.
|
||||||
|
|
||||||
|
To disable it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scrcpy --disable-screensaver
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Input control
|
### Input control
|
||||||
|
|
||||||
#### Rotate device screen
|
#### Rotate device screen
|
||||||
|
|
|
@ -43,6 +43,10 @@ The values are expressed in the device natural orientation (typically, portrait
|
||||||
.B \-\-max\-size
|
.B \-\-max\-size
|
||||||
value is computed on the cropped size.
|
value is computed on the cropped size.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI "\-\-disable-screensaver"
|
||||||
|
Disable screensaver while scrcpy is running.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BI "\-\-display " id
|
.BI "\-\-display " id
|
||||||
Specify the display id to mirror.
|
Specify the display id to mirror.
|
||||||
|
|
|
@ -45,6 +45,9 @@ scrcpy_print_usage(const char *arg0) {
|
||||||
" (typically, portrait for a phone, landscape for a tablet).\n"
|
" (typically, portrait for a phone, landscape for a tablet).\n"
|
||||||
" Any --max-size value is computed on the cropped size.\n"
|
" Any --max-size value is computed on the cropped size.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" --disable-screensaver\n"
|
||||||
|
" Disable screensaver while scrcpy is running.\n"
|
||||||
|
"\n"
|
||||||
" --display id\n"
|
" --display id\n"
|
||||||
" Specify the display id to mirror.\n"
|
" Specify the display id to mirror.\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -526,6 +529,7 @@ guess_record_format(const char *filename) {
|
||||||
#define OPT_NO_MIPMAPS 1017
|
#define OPT_NO_MIPMAPS 1017
|
||||||
#define OPT_CODEC_OPTIONS 1018
|
#define OPT_CODEC_OPTIONS 1018
|
||||||
#define OPT_FORCE_ADB_FORWARD 1019
|
#define OPT_FORCE_ADB_FORWARD 1019
|
||||||
|
#define OPT_DISABLE_SCREENSAVER 1020
|
||||||
|
|
||||||
bool
|
bool
|
||||||
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
|
@ -534,6 +538,8 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
|
||||||
{"bit-rate", required_argument, NULL, 'b'},
|
{"bit-rate", required_argument, NULL, 'b'},
|
||||||
{"codec-options", required_argument, NULL, OPT_CODEC_OPTIONS},
|
{"codec-options", required_argument, NULL, OPT_CODEC_OPTIONS},
|
||||||
{"crop", required_argument, NULL, OPT_CROP},
|
{"crop", required_argument, NULL, OPT_CROP},
|
||||||
|
{"disable-screensaver", no_argument, NULL,
|
||||||
|
OPT_DISABLE_SCREENSAVER},
|
||||||
{"display", required_argument, NULL, OPT_DISPLAY_ID},
|
{"display", required_argument, NULL, OPT_DISPLAY_ID},
|
||||||
{"force-adb-forward", no_argument, NULL,
|
{"force-adb-forward", no_argument, NULL,
|
||||||
OPT_FORCE_ADB_FORWARD},
|
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:
|
case OPT_FORCE_ADB_FORWARD:
|
||||||
opts->force_adb_forward = true;
|
opts->force_adb_forward = true;
|
||||||
break;
|
break;
|
||||||
|
case OPT_DISABLE_SCREENSAVER:
|
||||||
|
opts->disable_screensaver = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// getopt prints the error message on stderr
|
// getopt prints the error message on stderr
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -63,7 +63,8 @@ BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
|
||||||
|
|
||||||
// init SDL and set appropriate hints
|
// init SDL and set appropriate hints
|
||||||
static bool
|
static bool
|
||||||
sdl_init_and_configure(bool display, const char *render_driver) {
|
sdl_init_and_configure(bool display, const char *render_driver,
|
||||||
|
bool disable_screensaver) {
|
||||||
uint32_t flags = display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS;
|
uint32_t flags = display ? SDL_INIT_VIDEO : SDL_INIT_EVENTS;
|
||||||
if (SDL_Init(flags)) {
|
if (SDL_Init(flags)) {
|
||||||
LOGC("Could not initialize SDL: %s", SDL_GetError());
|
LOGC("Could not initialize SDL: %s", SDL_GetError());
|
||||||
|
@ -112,8 +113,13 @@ sdl_init_and_configure(bool display, const char *render_driver) {
|
||||||
LOGW("Could not disable minimize on focus loss");
|
LOGW("Could not disable minimize on focus loss");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not disable the screensaver when scrcpy is running
|
if (disable_screensaver) {
|
||||||
SDL_EnableScreenSaver();
|
LOGD("Screensaver disabled");
|
||||||
|
SDL_DisableScreenSaver();
|
||||||
|
} else {
|
||||||
|
LOGD("Screensaver enabled");
|
||||||
|
SDL_EnableScreenSaver();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -321,7 +327,8 @@ scrcpy(const struct scrcpy_options *options) {
|
||||||
bool controller_initialized = false;
|
bool controller_initialized = false;
|
||||||
bool controller_started = 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_screensaver)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct scrcpy_options {
|
||||||
bool mipmaps;
|
bool mipmaps;
|
||||||
bool stay_awake;
|
bool stay_awake;
|
||||||
bool force_adb_forward;
|
bool force_adb_forward;
|
||||||
|
bool disable_screensaver;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCRCPY_OPTIONS_DEFAULT { \
|
#define SCRCPY_OPTIONS_DEFAULT { \
|
||||||
|
@ -81,6 +82,7 @@ struct scrcpy_options {
|
||||||
.mipmaps = true, \
|
.mipmaps = true, \
|
||||||
.stay_awake = false, \
|
.stay_awake = false, \
|
||||||
.force_adb_forward = false, \
|
.force_adb_forward = false, \
|
||||||
|
.disable_screensaver = false, \
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue