Skip to content

Commit

Permalink
Add --no-cleanup option
Browse files Browse the repository at this point in the history
It might be useful not to cleanup on exit, for example to leave the
screen turned off, or keep the server binary on the device (via the
server option "cleanup=false").

Fixes #1764 <#1764>
PR #3020 <#3020>
  • Loading branch information
rom1v committed Feb 15, 2022
1 parent bb991f8 commit ccbe370
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/scrcpy.1
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ It may only work over USB, and is currently only supported on Linux.

Also see \fB\-\-hid\-keyboard\fR.

.TP
.B \-\-no\-cleanup
By default, scrcpy removes the server binary from the device and restores the device state (show touches, stay awake and power mode) on exit.

This option disables this cleanup.

.TP
.B \-\-no\-clipboard\-autosync
By default, scrcpy automatically synchronizes the computer clipboard to the device clipboard before injecting Ctrl+v, and the device clipboard to the computer clipboard whenever it changes.
Expand Down
12 changes: 12 additions & 0 deletions app/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define OPT_RAW_KEY_EVENTS 1034
#define OPT_NO_DOWNSIZE_ON_ERROR 1035
#define OPT_OTG 1036
#define OPT_NO_CLEANUP 1037

struct sc_option {
char shortopt;
Expand Down Expand Up @@ -250,6 +251,14 @@ static const struct sc_option options[] = {
"is preserved.\n"
"Default is 0 (unlimited).",
},
{
.longopt_id = OPT_NO_CLEANUP,
.longopt = "no-cleanup",
.text = "By default, scrcpy removes the server binary from the device "
"and restores the device state (show touches, stay awake and "
"power mode) on exit.\n"
"This option disables this cleanup."
},
{
.longopt_id = OPT_NO_CLIPBOARD_AUTOSYNC,
.longopt = "no-clipboard-autosync",
Expand Down Expand Up @@ -1535,6 +1544,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
case OPT_NO_DOWNSIZE_ON_ERROR:
opts->downsize_on_error = false;
break;
case OPT_NO_CLEANUP:
opts->cleanup = false;
break;
case OPT_OTG:
#ifdef HAVE_USB
opts->otg = true;
Expand Down
1 change: 1 addition & 0 deletions app/src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ const struct scrcpy_options scrcpy_options_default = {
.tcpip_dst = NULL,
.select_tcpip = false,
.select_usb = false,
.cleanup = true,
};
1 change: 1 addition & 0 deletions app/src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ struct scrcpy_options {
const char *tcpip_dst;
bool select_usb;
bool select_tcpip;
bool cleanup;
};

extern const struct scrcpy_options scrcpy_options_default;
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ scrcpy(struct scrcpy_options *options) {
.downsize_on_error = options->downsize_on_error,
.tcpip = options->tcpip,
.tcpip_dst = options->tcpip_dst,
.cleanup = options->cleanup,
};

static const struct sc_server_callbacks cbs = {
Expand Down
4 changes: 4 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ execute_server(struct sc_server *server,
// By default, downsize_on_error is true
ADD_PARAM("downsize_on_error=false");
}
if (!params->cleanup) {
// By default, cleanup is true
ADD_PARAM("cleanup=false");
}

#undef ADD_PARAM

Expand Down
1 change: 1 addition & 0 deletions app/src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct sc_server_params {
const char *tcpip_dst;
bool select_usb;
bool select_tcpip;
bool cleanup;
};

struct sc_server {
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Options {
private boolean powerOffScreenOnClose;
private boolean clipboardAutosync = true;
private boolean downsizeOnError = true;
private boolean cleanup = true;

// Options not used by the scrcpy client, but useful to use scrcpy-server directly
private boolean sendDeviceMeta = true; // send device name and size
Expand Down Expand Up @@ -155,6 +156,14 @@ public void setDownsizeOnError(boolean downsizeOnError) {
this.downsizeOnError = downsizeOnError;
}

public boolean getCleanup() {
return cleanup;
}

public void setCleanup(boolean cleanup) {
this.cleanup = cleanup;
}

public boolean getSendDeviceMeta() {
return sendDeviceMeta;
}
Expand Down
16 changes: 11 additions & 5 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ private static void initAndCleanUp(Options options) {
}
}

try {
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
options.getPowerOffScreenOnClose());
} catch (IOException e) {
Ln.e("Could not configure cleanup", e);
if (options.getCleanup()) {
try {
CleanUp.configure(options.getDisplayId(), restoreStayOn, mustDisableShowTouchesOnCleanUp, restoreNormalPowerMode,
options.getPowerOffScreenOnClose());
} catch (IOException e) {
Ln.e("Could not configure cleanup", e);
}
}
}

Expand Down Expand Up @@ -243,6 +245,10 @@ private static Options createOptions(String... args) {
boolean downsizeOnError = Boolean.parseBoolean(value);
options.setDownsizeOnError(downsizeOnError);
break;
case "cleanup":
boolean cleanup = Boolean.parseBoolean(value);
options.setCleanup(cleanup);
break;
case "send_device_meta":
boolean sendDeviceMeta = Boolean.parseBoolean(value);
options.setSendDeviceMeta(sendDeviceMeta);
Expand Down

0 comments on commit ccbe370

Please sign in to comment.