Add --no-vd-destroy-content

Add an option to disable the following flag for virtual displays:

    DisplayManager.VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL

With this option, when the virtual display is closed, the running apps
are moved to the main display rather than being destroyed.

PR #5615 <https://github.com/Genymobile/scrcpy/pull/5615>
This commit is contained in:
Romain Vimont 2024-12-05 21:02:50 +01:00
parent 988174805c
commit 6c6607d404
12 changed files with 53 additions and 2 deletions

View File

@ -57,6 +57,7 @@ _scrcpy() {
--no-mipmaps --no-mipmaps
--no-mouse-hover --no-mouse-hover
--no-power-on --no-power-on
--no-vd-destroy-content
--no-vd-system-decorations --no-vd-system-decorations
--no-video --no-video
--no-video-playback --no-video-playback

View File

@ -63,6 +63,7 @@ arguments=(
'--no-mipmaps[Disable the generation of mipmaps]' '--no-mipmaps[Disable the generation of mipmaps]'
'--no-mouse-hover[Do not forward mouse hover events]' '--no-mouse-hover[Do not forward mouse hover events]'
'--no-power-on[Do not power on the device on start]' '--no-power-on[Do not power on the device on start]'
'--no-vd-destroy-content[Disable virtual display "destroy content on removal" flag]'
'--no-vd-system-decorations[Disable virtual display system decorations flag]' '--no-vd-system-decorations[Disable virtual display system decorations flag]'
'--no-video[Disable video forwarding]' '--no-video[Disable video forwarding]'
'--no-video-playback[Disable video playback]' '--no-video-playback[Disable video playback]'

View File

@ -369,6 +369,12 @@ Do not forward mouse hover (mouse motion without any clicks) events.
.B \-\-no\-power\-on .B \-\-no\-power\-on
Do not power on the device on start. Do not power on the device on start.
.TP
.B \-\-no\-vd\-destroy\-content
Disable virtual display "destroy content on removal" flag.
With this option, when the virtual display is closed, the running apps are moved to the main display rather than being destroyed.
.TP .TP
.B \-\-no\-vd\-system\-decorations .B \-\-no\-vd\-system\-decorations
Disable virtual display system decorations flag. Disable virtual display system decorations flag.

View File

@ -110,6 +110,7 @@ enum {
OPT_CAPTURE_ORIENTATION, OPT_CAPTURE_ORIENTATION,
OPT_ANGLE, OPT_ANGLE,
OPT_NO_VD_SYSTEM_DECORATIONS, OPT_NO_VD_SYSTEM_DECORATIONS,
OPT_NO_VD_DESTROY_CONTENT,
}; };
struct sc_option { struct sc_option {
@ -659,6 +660,15 @@ static const struct sc_option options[] = {
.longopt = "no-power-on", .longopt = "no-power-on",
.text = "Do not power on the device on start.", .text = "Do not power on the device on start.",
}, },
{
.longopt_id = OPT_NO_VD_DESTROY_CONTENT,
.longopt = "no-vd-destroy-content",
.text = "Disable virtual display \"destroy content on removal\" "
"flag.\n"
"With this option, when the virtual display is closed, the "
"running apps are moved to the main display rather than being "
"destroyed.",
},
{ {
.longopt_id = OPT_NO_VD_SYSTEM_DECORATIONS, .longopt_id = OPT_NO_VD_SYSTEM_DECORATIONS,
.longopt = "no-vd-system-decorations", .longopt = "no-vd-system-decorations",
@ -2705,6 +2715,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
case OPT_ANGLE: case OPT_ANGLE:
opts->angle = optarg; opts->angle = optarg;
break; break;
case OPT_NO_VD_DESTROY_CONTENT:
opts->vd_destroy_content = false;
break;
case OPT_NO_VD_SYSTEM_DECORATIONS: case OPT_NO_VD_SYSTEM_DECORATIONS:
opts->vd_system_decorations = false; opts->vd_system_decorations = false;
break; break;

View File

@ -108,6 +108,7 @@ const struct scrcpy_options scrcpy_options_default = {
.new_display = NULL, .new_display = NULL,
.start_app = NULL, .start_app = NULL,
.angle = NULL, .angle = NULL,
.vd_destroy_content = true,
.vd_system_decorations = true, .vd_system_decorations = true,
}; };

View File

@ -310,6 +310,7 @@ struct scrcpy_options {
bool audio_dup; bool audio_dup;
const char *new_display; // [<width>x<height>][/<dpi>] parsed by the server const char *new_display; // [<width>x<height>][/<dpi>] parsed by the server
const char *start_app; const char *start_app;
bool vd_destroy_content;
bool vd_system_decorations; bool vd_system_decorations;
}; };

View File

@ -458,6 +458,7 @@ scrcpy(struct scrcpy_options *options) {
.power_on = options->power_on, .power_on = options->power_on,
.kill_adb_on_close = options->kill_adb_on_close, .kill_adb_on_close = options->kill_adb_on_close,
.camera_high_speed = options->camera_high_speed, .camera_high_speed = options->camera_high_speed,
.vd_destroy_content = options->vd_destroy_content,
.vd_system_decorations = options->vd_system_decorations, .vd_system_decorations = options->vd_system_decorations,
.list = options->list, .list = options->list,
}; };

View File

@ -377,6 +377,9 @@ execute_server(struct sc_server *server,
VALIDATE_STRING(params->new_display); VALIDATE_STRING(params->new_display);
ADD_PARAM("new_display=%s", params->new_display); ADD_PARAM("new_display=%s", params->new_display);
} }
if (!params->vd_destroy_content) {
ADD_PARAM("vd_destroy_content=false");
}
if (!params->vd_system_decorations) { if (!params->vd_system_decorations) {
ADD_PARAM("vd_system_decorations=false"); ADD_PARAM("vd_system_decorations=false");
} }

View File

@ -69,6 +69,7 @@ struct sc_server_params {
bool power_on; bool power_on;
bool kill_adb_on_close; bool kill_adb_on_close;
bool camera_high_speed; bool camera_high_speed;
bool vd_destroy_content;
bool vd_system_decorations; bool vd_system_decorations;
uint8_t list; uint8_t list;
}; };

View File

@ -50,3 +50,14 @@ any default launcher UI available in virtual displays.
Note that if no app is started, no content will be rendered, so no video frame Note that if no app is started, no content will be rendered, so no video frame
will be produced at all. will be produced at all.
## Destroy on close
By default, when the virtual display is closed, the running apps are destroyed.
To move them to the main display instead, use:
```
scrcpy --new-display --no-vd-destroy-content
```

View File

@ -60,6 +60,7 @@ public class Options {
private boolean powerOn = true; private boolean powerOn = true;
private NewDisplay newDisplay; private NewDisplay newDisplay;
private boolean vdDestroyContent = true;
private boolean vdSystemDecorations = true; private boolean vdSystemDecorations = true;
private Orientation.Lock captureOrientationLock = Orientation.Lock.Unlocked; private Orientation.Lock captureOrientationLock = Orientation.Lock.Unlocked;
@ -233,6 +234,10 @@ public class Options {
return captureOrientationLock; return captureOrientationLock;
} }
public boolean getVDDestroyContent() {
return vdDestroyContent;
}
public boolean getVDSystemDecorations() { public boolean getVDSystemDecorations() {
return vdSystemDecorations; return vdSystemDecorations;
} }
@ -466,6 +471,9 @@ public class Options {
case "new_display": case "new_display":
options.newDisplay = parseNewDisplay(value); options.newDisplay = parseNewDisplay(value);
break; break;
case "vd_destroy_content":
options.vdDestroyContent = Boolean.parseBoolean(value);
break;
case "vd_system_decorations": case "vd_system_decorations":
options.vdSystemDecorations = Boolean.parseBoolean(value); options.vdSystemDecorations = Boolean.parseBoolean(value);
break; break;

View File

@ -53,6 +53,7 @@ public class NewDisplayCapture extends SurfaceCapture {
private final boolean captureOrientationLocked; private final boolean captureOrientationLocked;
private final Orientation captureOrientation; private final Orientation captureOrientation;
private final float angle; private final float angle;
private final boolean vdDestroyContent;
private final boolean vdSystemDecorations; private final boolean vdSystemDecorations;
private VirtualDisplay virtualDisplay; private VirtualDisplay virtualDisplay;
@ -73,6 +74,7 @@ public class NewDisplayCapture extends SurfaceCapture {
this.captureOrientation = options.getCaptureOrientation(); this.captureOrientation = options.getCaptureOrientation();
assert captureOrientation != null; assert captureOrientation != null;
this.angle = options.getAngle(); this.angle = options.getAngle();
this.vdDestroyContent = options.getVDDestroyContent();
this.vdSystemDecorations = options.getVDSystemDecorations(); this.vdSystemDecorations = options.getVDSystemDecorations();
} }
@ -167,8 +169,10 @@ public class NewDisplayCapture extends SurfaceCapture {
int flags = VIRTUAL_DISPLAY_FLAG_PUBLIC int flags = VIRTUAL_DISPLAY_FLAG_PUBLIC
| VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
| VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH | VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH
| VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT | VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;
| VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL; if (vdDestroyContent) {
flags |= VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL;
}
if (vdSystemDecorations) { if (vdSystemDecorations) {
flags |= VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; flags |= VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS;
} }