Turn on device screen when scrcpy window becomes active.

This commit is contained in:
Vladimir Chebotarev 2020-08-24 13:56:48 +03:00
commit ea63e7c279
3 changed files with 22 additions and 1 deletions

View file

@ -21,6 +21,9 @@ scrcpy_print_usage(const char *arg0) {
" --always-on-top\n" " --always-on-top\n"
" Make scrcpy window always on top (above other windows).\n" " Make scrcpy window always on top (above other windows).\n"
"\n" "\n"
" --auto-turn-on\n"
" Turn on device screen when scrcpy window become active.\n"
"\n"
" -b, --bit-rate value\n" " -b, --bit-rate value\n"
" Encode the video at the given bit-rate, expressed in bits/s.\n" " Encode the video at the given bit-rate, expressed in bits/s.\n"
" Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n" " Unit suffixes are supported: 'K' (x1000) and 'M' (x1000000).\n"
@ -651,11 +654,13 @@ guess_record_format(const char *filename) {
#define OPT_DISABLE_SCREENSAVER 1020 #define OPT_DISABLE_SCREENSAVER 1020
#define OPT_SHORTCUT_MOD 1021 #define OPT_SHORTCUT_MOD 1021
#define OPT_NO_KEY_REPEAT 1022 #define OPT_NO_KEY_REPEAT 1022
#define OPT_AUTO_TURN_ON 1023
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[]) {
static const struct option long_options[] = { static const struct option long_options[] = {
{"always-on-top", no_argument, NULL, OPT_ALWAYS_ON_TOP}, {"always-on-top", no_argument, NULL, OPT_ALWAYS_ON_TOP},
{"auto-turn-on", no_argument, NULL, OPT_AUTO_TURN_ON},
{"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},
@ -856,6 +861,9 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
return false; return false;
} }
break; break;
case OPT_AUTO_TURN_ON:
opts->auto_turn_on = true;
break;
default: default:
// getopt prints the error message on stderr // getopt prints the error message on stderr
return false; return false;

View file

@ -191,6 +191,17 @@ handle_event(SDL_Event *event, const struct scrcpy_options *options) {
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
screen_handle_window_event(&screen, &event->window); screen_handle_window_event(&screen, &event->window);
break; break;
case SDL_ACTIVEEVENT:
if (options->auto_turn_on && event->gain == 1) {
struct control_msg msg;
msg.type = CONTROL_MSG_TYPE_SET_SCREEN_POWER_MODE;
msg.set_screen_power_mode.mode = SCREEN_POWER_MODE_NORMAL;
if (!controller_push_msg(&controller, &msg)) {
LOGW("Could not request 'set screen power mode'");
}
}
break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
if (!options->control) { if (!options->control) {
break; break;
@ -422,7 +433,7 @@ scrcpy(const struct scrcpy_options *options) {
options->window_y, options->window_width, options->window_y, options->window_width,
options->window_height, options->window_height,
options->window_borderless, options->window_borderless,
options->rotation, options-> mipmaps)) { options->rotation, options->mipmaps)) {
goto end; goto end;
} }

View file

@ -79,6 +79,7 @@ struct scrcpy_options {
bool force_adb_forward; bool force_adb_forward;
bool disable_screensaver; bool disable_screensaver;
bool forward_key_repeat; bool forward_key_repeat;
bool auto_turn_on;
}; };
#define SCRCPY_OPTIONS_DEFAULT { \ #define SCRCPY_OPTIONS_DEFAULT { \
@ -123,6 +124,7 @@ struct scrcpy_options {
.force_adb_forward = false, \ .force_adb_forward = false, \
.disable_screensaver = false, \ .disable_screensaver = false, \
.forward_key_repeat = true, \ .forward_key_repeat = true, \
.auto_turn_on = false, \
} }
bool bool