From c09b8a767d4a73e647a7946009edcea7722a1761 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 16 Nov 2024 22:45:38 +0100 Subject: [PATCH] Add --no-vd-system-decorations Add an option to disable the following flag for virtual displays: DisplayManager.VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS Some devices render a broken UI when this flag is enabled. --- app/data/bash-completion/scrcpy | 1 + app/data/zsh-completion/_scrcpy | 1 + app/scrcpy.1 | 4 ++++ app/src/cli.c | 9 +++++++++ app/src/options.c | 1 + app/src/options.h | 1 + app/src/scrcpy.c | 1 + app/src/server.c | 3 +++ app/src/server.h | 1 + doc/virtual_display.md | 10 ++++++++++ .../src/main/java/com/genymobile/scrcpy/Options.java | 8 ++++++++ .../com/genymobile/scrcpy/video/NewDisplayCapture.java | 8 ++++++-- 12 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy index c0bca144..8aa70a6b 100644 --- a/app/data/bash-completion/scrcpy +++ b/app/data/bash-completion/scrcpy @@ -57,6 +57,7 @@ _scrcpy() { --no-mipmaps --no-mouse-hover --no-power-on + --no-vd-system-decorations --no-video --no-video-playback --orientation= diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy index 552fd4b9..ac7222e2 100644 --- a/app/data/zsh-completion/_scrcpy +++ b/app/data/zsh-completion/_scrcpy @@ -63,6 +63,7 @@ arguments=( '--no-mipmaps[Disable the generation of mipmaps]' '--no-mouse-hover[Do not forward mouse hover events]' '--no-power-on[Do not power on the device on start]' + '--no-vd-system-decorations[Disable virtual display system decorations flag]' '--no-video[Disable video forwarding]' '--no-video-playback[Disable video playback]' '--orientation=[Set the video orientation]:orientation values:(0 90 180 270 flip0 flip90 flip180 flip270)' diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 4118ae17..ce543084 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -372,6 +372,10 @@ Do not forward mouse hover (mouse motion without any clicks) events. .B \-\-no\-power\-on Do not power on the device on start. +.TP +.B \-\-no\-vd\-system\-decorations +Disable virtual display system decorations flag. + .TP .B \-\-no\-video Disable video forwarding. diff --git a/app/src/cli.c b/app/src/cli.c index c973516b..2efdc53b 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -109,6 +109,7 @@ enum { OPT_SCREEN_OFF_TIMEOUT, OPT_CAPTURE_ORIENTATION, OPT_ANGLE, + OPT_NO_VD_SYSTEM_DECORATIONS, }; struct sc_option { @@ -660,6 +661,11 @@ static const struct sc_option options[] = { .longopt = "no-power-on", .text = "Do not power on the device on start.", }, + { + .longopt_id = OPT_NO_VD_SYSTEM_DECORATIONS, + .longopt = "no-vd-system-decorations", + .text = "Disable virtual display system decorations flag.", + }, { .longopt_id = OPT_NO_VIDEO, .longopt = "no-video", @@ -2702,6 +2708,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], case OPT_ANGLE: opts->angle = optarg; break; + case OPT_NO_VD_SYSTEM_DECORATIONS: + opts->vd_system_decorations = optarg; + break; default: // getopt prints the error message on stderr return false; diff --git a/app/src/options.c b/app/src/options.c index adc7ba0c..be3cf8d1 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -108,6 +108,7 @@ const struct scrcpy_options scrcpy_options_default = { .new_display = NULL, .start_app = NULL, .angle = NULL, + .vd_system_decorations = true, }; enum sc_orientation diff --git a/app/src/options.h b/app/src/options.h index 0692276e..eaeba2f2 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -310,6 +310,7 @@ struct scrcpy_options { bool audio_dup; const char *new_display; // [x][/] parsed by the server const char *start_app; + bool vd_system_decorations; }; extern const struct scrcpy_options scrcpy_options_default; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 48befb1d..dc9e237f 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -458,6 +458,7 @@ scrcpy(struct scrcpy_options *options) { .power_on = options->power_on, .kill_adb_on_close = options->kill_adb_on_close, .camera_high_speed = options->camera_high_speed, + .vd_system_decorations = options->vd_system_decorations, .list = options->list, }; diff --git a/app/src/server.c b/app/src/server.c index 9c81a7f6..ce7b1aaf 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -376,6 +376,9 @@ execute_server(struct sc_server *server, VALIDATE_STRING(params->new_display); ADD_PARAM("new_display=%s", params->new_display); } + if (!params->vd_system_decorations) { + ADD_PARAM("vd_system_decorations=false"); + } if (params->list & SC_OPTION_LIST_ENCODERS) { ADD_PARAM("list_encoders=true"); } diff --git a/app/src/server.h b/app/src/server.h index 9d46b354..6d9dbd4d 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -69,6 +69,7 @@ struct sc_server_params { bool power_on; bool kill_adb_on_close; bool camera_high_speed; + bool vd_system_decorations; uint8_t list; }; diff --git a/doc/virtual_display.md b/doc/virtual_display.md index 4ed5961f..97ac01b2 100644 --- a/doc/virtual_display.md +++ b/doc/virtual_display.md @@ -24,3 +24,13 @@ For example: ```bash scrcpy --new-display=1920x1080 --start-app=org.videolan.vlc ``` + +## System decorations + +By default, virtual display system decorations are enabled. But some devices +might display a broken UI; + +Use `--no-vd-system-decorations` to disable it. + +Note that if no app is started, no content will be rendered, so no video frame +will be produced at all. diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 6a59fbe7..43cc790d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -60,6 +60,7 @@ public class Options { private boolean powerOn = true; private NewDisplay newDisplay; + private boolean vdSystemDecorations = true; private Orientation.Lock captureOrientationLock = Orientation.Lock.Unlocked; private Orientation captureOrientation = Orientation.Orient0; @@ -232,6 +233,10 @@ public class Options { return captureOrientationLock; } + public boolean getVDSystemDecorations() { + return vdSystemDecorations; + } + public boolean getList() { return listEncoders || listDisplays || listCameras || listCameraSizes || listApps; } @@ -461,6 +466,9 @@ public class Options { case "new_display": options.newDisplay = parseNewDisplay(value); break; + case "vd_system_decorations": + options.vdSystemDecorations = Boolean.parseBoolean(value); + break; case "capture_orientation": Pair pair = parseCaptureOrientation(value); options.captureOrientationLock = pair.first; diff --git a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java index 71bacc5f..990027b4 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java @@ -53,6 +53,7 @@ public class NewDisplayCapture extends SurfaceCapture { private final boolean captureOrientationLocked; private final Orientation captureOrientation; private final float angle; + private final boolean vdSystemDecorations; private VirtualDisplay virtualDisplay; private Size videoSize; @@ -72,6 +73,7 @@ public class NewDisplayCapture extends SurfaceCapture { this.captureOrientation = options.getCaptureOrientation(); assert captureOrientation != null; this.angle = options.getAngle(); + this.vdSystemDecorations = options.getVDSystemDecorations(); } @Override @@ -158,8 +160,10 @@ public class NewDisplayCapture extends SurfaceCapture { | VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH | VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT - | VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL - | VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; + | VIRTUAL_DISPLAY_FLAG_DESTROY_CONTENT_ON_REMOVAL; + if (vdSystemDecorations) { + flags |= VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; + } if (Build.VERSION.SDK_INT >= AndroidVersions.API_33_ANDROID_13) { flags |= VIRTUAL_DISPLAY_FLAG_TRUSTED | VIRTUAL_DISPLAY_FLAG_OWN_DISPLAY_GROUP