From 8d4ff03b7feab7123dd5483f16ff282fddbb425d Mon Sep 17 00:00:00 2001 From: CapsLock Date: Fri, 1 Feb 2019 22:53:24 +0100 Subject: [PATCH] Added a new option : -n/--no-window This option allows scrcpy to be run headless : we can now use scrcpy only for screen recording as an example --- app/src/main.c | 13 ++++++++++++- app/src/scrcpy.c | 8 +++++++- app/src/scrcpy.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 0603fef5..877c3ca3 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -13,6 +13,7 @@ struct args { const char *crop; const char *record_filename; SDL_bool fullscreen; + SDL_bool no_window; SDL_bool help; SDL_bool version; SDL_bool show_touches; @@ -50,6 +51,11 @@ static void usage(const char *arg0) { " is preserved.\n" " Default is %d%s.\n" "\n" + " -n, --no-window\n" + " Do not show window. This is useful, as an example\n" + " combined with -r/--record option to record screen without displaying\n" + " video feedback\n" + "\n" " -p, --port port\n" " Set the TCP port the client listens on.\n" " Default is %d.\n" @@ -209,6 +215,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { {"bit-rate", required_argument, NULL, 'b'}, {"crop", required_argument, NULL, 'c'}, {"fullscreen", no_argument, NULL, 'f'}, + {"no-window", no_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {"max-size", required_argument, NULL, 'm'}, {"port", required_argument, NULL, 'p'}, @@ -219,7 +226,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { {NULL, 0, NULL, 0 }, }; int c; - while ((c = getopt_long(argc, argv, "b:c:fhm:p:r:s:tv", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "b:c:fnhm:p:r:s:tv", long_options, NULL)) != -1) { switch (c) { case 'b': if (!parse_bit_rate(optarg, &args->bit_rate)) { @@ -232,6 +239,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { case 'f': args->fullscreen = SDL_TRUE; break; + case 'n': + args->no_window = SDL_TRUE; + break; case 'h': args->help = SDL_TRUE; break; @@ -324,6 +334,7 @@ int main(int argc, char *argv[]) { .bit_rate = args.bit_rate, .show_touches = args.show_touches, .fullscreen = args.fullscreen, + .no_window = args.no_window }; int res = scrcpy(&options) ? 0 : 1; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 0e9bcba0..e5e40600 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -33,6 +33,8 @@ static struct controller controller; static struct file_handler file_handler; static struct recorder recorder; +SDL_bool no_window; + static struct input_manager input_manager = { .controller = &controller, .frames = &frames, @@ -80,7 +82,9 @@ static SDL_bool event_loop(void) { if (!screen.has_frame) { screen.has_frame = SDL_TRUE; // this is the very first frame, show the window - screen_show_window(&screen); + if (!no_window) { + screen_show_window(&screen); + } } if (!screen_update_frame(&screen, &frames)) { return SDL_FALSE; @@ -237,6 +241,8 @@ SDL_bool scrcpy(const struct scrcpy_options *options) { screen_switch_fullscreen(&screen); } + no_window = options->no_window; + ret = event_loop(); LOGD("quit..."); diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 89945e6c..eacc7e09 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -12,6 +12,7 @@ struct scrcpy_options { Uint32 bit_rate; SDL_bool show_touches; SDL_bool fullscreen; + SDL_bool no_window; }; SDL_bool scrcpy(const struct scrcpy_options *options);