Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ build/
/release-*/
.idea/
.gradle/
.cache/
.vscode/
/x/
local.properties
/scrcpy-server
1 change: 1 addition & 0 deletions app/data/bash-completion/scrcpy
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ _scrcpy() {
--screen-off-timeout=
--shortcut-mod=
--start-app=
--exit-on-close
-t --show-touches
--tcpip
--tcpip=
Expand Down
10 changes: 8 additions & 2 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,15 @@ Add a '+' prefix to force-stop before starting the app:

scrcpy --new-display --start-app=+org.mozilla.firefox

Both prefixes can be used, in that order:
All prefixes can be combined, in that order.

scrcpy --start-app=+?firefox
See also \fB\-\-exit\-on\-close\fR.

.TP
.B \-\-exit\-on\-close
Exit scrcpy when the app started with \fB\-\-start\-app\fR closes.

This option is only available with \fB\-\-start\-app\fR.

.TP
.B \-t, \-\-show\-touches
Expand Down
31 changes: 29 additions & 2 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <SDL2/SDL.h>

#include "config.h"

#include "options.h"
#include "util/log.h"
Expand Down Expand Up @@ -108,6 +111,7 @@ enum {
OPT_NEW_DISPLAY,
OPT_LIST_APPS,
OPT_START_APP,
OPT_EXIT_ON_CLOSE,
OPT_SCREEN_OFF_TIMEOUT,
OPT_CAPTURE_ORIENTATION,
OPT_ANGLE,
Expand Down Expand Up @@ -890,8 +894,14 @@ static const struct sc_option options[] = {
" scrcpy --start-app=?firefox\n"
"Add a '+' prefix to force-stop before starting the app:\n"
" scrcpy --new-display --start-app=+org.mozilla.firefox\n"
"Both prefixes can be used, in that order:\n"
" scrcpy --start-app=+?firefox",
"All prefixes can be combined, in that order.\n"
"See also --exit-on-close.",
},
{
.longopt_id = OPT_EXIT_ON_CLOSE,
.longopt = "exit-on-close",
.text = "Exit scrcpy when the app started with --start-app closes.\n"
"This option is only available with --start-app.",
},
{
.shortopt = 't',
Expand Down Expand Up @@ -2799,6 +2809,23 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
break;
case OPT_START_APP:
opts->start_app = optarg;
// Check if the app name ends with '-' to enable end execution
if (optarg && strlen(optarg) > 0 && optarg[strlen(optarg) - 1] == '-') {
opts->stop_app = true;
// Remove the trailing '-' from the app name
char *app_name = strdup(optarg);
if (app_name) {
app_name[strlen(app_name) - 1] = '\0';
opts->start_app = app_name;
}
}
break;
case OPT_EXIT_ON_CLOSE:
if (!opts->start_app) {
LOGE("--exit-on-close is only available with --start-app");
return false;
}
opts->exit_on_app_close = true;
break;
case OPT_SCREEN_OFF_TIMEOUT:
if (!parse_screen_off_timeout(optarg,
Expand Down
2 changes: 2 additions & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const struct scrcpy_options scrcpy_options_default = {
.audio_dup = false,
.new_display = NULL,
.start_app = NULL,
.exit_on_app_close = false,
.stop_app = false,
.angle = NULL,
.vd_destroy_content = true,
.vd_system_decorations = true,
Expand Down
2 changes: 2 additions & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ struct scrcpy_options {
bool audio_dup;
const char *new_display; // [<width>x<height>][/<dpi>] parsed by the server
const char *start_app;
bool exit_on_app_close;
bool stop_app;
bool vd_destroy_content;
bool vd_system_decorations;
};
Expand Down
Loading