Add option to turn device screen off

In addition to the shortcut (Ctrl+o) to turn the device screen off, add
a command-line argument to turn it off on start.
This commit is contained in:
Romain Vimont
2019-06-05 00:55:46 +02:00
parent 7f07b13446
commit 8e66b33000
4 changed files with 35 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ struct args {
uint16_t max_size;
uint32_t bit_rate;
bool always_on_top;
bool turn_screen_off;
};
static void usage(const char *arg0) {
@@ -82,6 +83,9 @@ static void usage(const char *arg0) {
" The device serial number. Mandatory only if several devices\n"
" are connected to adb.\n"
"\n"
" -S, --turn-screen-off\n"
" Turn the device screen off immediately.\n"
"\n"
" -t, --show-touches\n"
" Enable \"show touches\" on start, disable on quit.\n"
" It only shows physical touches (not clicks from scrcpy).\n"
@@ -299,11 +303,12 @@ parse_args(struct args *args, int argc, char *argv[]) {
{"record-format", required_argument, NULL, 'f'},
{"serial", required_argument, NULL, 's'},
{"show-touches", no_argument, NULL, 't'},
{"turn-screen-off", no_argument, NULL, 'S'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0 },
};
int c;
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:tTv", long_options,
while ((c = getopt_long(argc, argv, "b:c:fF:hm:nNp:r:s:StTv", long_options,
NULL)) != -1) {
switch (c) {
case 'b':
@@ -347,6 +352,9 @@ parse_args(struct args *args, int argc, char *argv[]) {
case 's':
args->serial = optarg;
break;
case 'S':
args->turn_screen_off = true;
break;
case 't':
args->show_touches = true;
break;
@@ -417,6 +425,7 @@ main(int argc, char *argv[]) {
.always_on_top = false,
.no_control = false,
.no_display = false,
.turn_screen_off = false,
};
if (!parse_args(&args, argc, argv)) {
return 1;
@@ -457,6 +466,7 @@ main(int argc, char *argv[]) {
.always_on_top = args.always_on_top,
.control = !args.no_control,
.display = !args.no_display,
.turn_screen_off = args.turn_screen_off,
};
int res = scrcpy(&options) ? 0 : 1;