Add a new option: -n/--no-window

This option will allow scrcpy to record the stream without display.

Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
CapsLock 2019-02-01 22:53:24 +01:00 committed by Romain Vimont
parent e6e011baaf
commit 421a1141e2
3 changed files with 23 additions and 1 deletions

View File

@ -16,6 +16,7 @@ struct args {
const char *record_filename;
enum recorder_format record_format;
SDL_bool fullscreen;
SDL_bool no_window;
SDL_bool help;
SDL_bool version;
SDL_bool show_touches;
@ -57,6 +58,9 @@ static void usage(const char *arg0) {
" is preserved.\n"
" Default is %d%s.\n"
"\n"
" -n, --no-window\n"
" Do not show window (only when screen recording is enabled).\n"
"\n"
" -p, --port port\n"
" Set the TCP port the client listens on.\n"
" Default is %d.\n"
@ -260,6 +264,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{"fullscreen", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{"max-size", required_argument, NULL, 'm'},
{"no-window", no_argument, NULL, 'n'},
{"port", required_argument, NULL, 'p'},
{"record", required_argument, NULL, 'r'},
{"record-format", required_argument, NULL, 'f'},
@ -269,7 +274,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:fF:hm:p:r:s:tTv", long_options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "b:c:fF:hm:np:r:s:tTv", long_options, NULL)) != -1) {
switch (c) {
case 'b':
if (!parse_bit_rate(optarg, &args->bit_rate)) {
@ -295,6 +300,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
return SDL_FALSE;
}
break;
case 'n':
args->no_window = SDL_TRUE;
break;
case 'p':
if (!parse_port(optarg, &args->port)) {
return SDL_FALSE;
@ -321,6 +329,16 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
}
}
if (args->no_window && !args->record_filename) {
LOGE("-n/--no-window requires screen recording (-r/--record)");
return SDL_FALSE;
}
if (args->no_window && args->fullscreen) {
LOGE("-f/--fullscreen-window is incompatible with -n/--no-window");
return SDL_FALSE;
}
int index = optind;
if (index < argc) {
LOGE("Unexpected additional argument: %s", argv[index]);
@ -401,6 +419,7 @@ int main(int argc, char *argv[]) {
.show_touches = args.show_touches,
.fullscreen = args.fullscreen,
.always_on_top = args.always_on_top,
.no_window = args.no_window,
};
int res = scrcpy(&options) ? 0 : 1;

View File

@ -15,6 +15,7 @@ struct scrcpy_options {
SDL_bool show_touches;
SDL_bool fullscreen;
SDL_bool always_on_top;
SDL_bool no_window;
};
SDL_bool scrcpy(const struct scrcpy_options *options);

View File

@ -17,6 +17,7 @@ struct screen {
struct size windowed_window_size;
SDL_bool has_frame;
SDL_bool fullscreen;
SDL_bool no_window;
};
#define SCREEN_INITIALIZER { \
@ -33,6 +34,7 @@ struct screen {
}, \
.has_frame = SDL_FALSE, \
.fullscreen = SDL_FALSE, \
.no_window = SDL_FALSE, \
}
// init SDL and set appropriate hints