Skip to content

Display and control your Android device

Add option to disable window aspect ratio lock

Tech-Tac65153a09c367
diff --git a/app/data/bash-completion/scrcpy b/app/data/bash-completion/scrcpy
index 2673c62b..eedbd504 100644
--- a/app/data/bash-completion/scrcpy
+++ b/app/data/bash-completion/scrcpy
@@ -66,6 +66,7 @@ _scrcpy() {
--no-video
--no-video-playback
--no-window
+ --no-window-aspect-ratio-lock
--orientation=
--otg
-p --port=
diff --git a/app/data/zsh-completion/_scrcpy b/app/data/zsh-completion/_scrcpy
index e629e722..4bf3f9dc 100644
--- a/app/data/zsh-completion/_scrcpy
+++ b/app/data/zsh-completion/_scrcpy
@@ -72,6 +72,7 @@ arguments=(
'--no-video[Disable video forwarding]'
'--no-video-playback[Disable video playback]'
'--no-window[Disable scrcpy window]'
+ '--no-window-aspect-ratio-lock[Disable window aspect ratio lock]'
'--orientation=[Set the video orientation]:orientation values:(0 90 180 270 flip0 flip90 flip180 flip270)'
'--otg[Run in OTG mode \(simulating physical keyboard and mouse\)]'
{-p,--port=}'[\[port\[\:port\]\] Set the TCP port \(range\) used by the client to listen]'
diff --git a/app/scrcpy.1 b/app/scrcpy.1
index 673ceb30..e2a65bae 100644
--- a/app/scrcpy.1
+++ b/app/scrcpy.1
@@ -428,6 +428,10 @@ Disable video playback on the computer.
.B \-\-no\-window
Disable scrcpy window. Implies --no-video-playback.
+.TP
+.B \-\-no\-window\-aspect\-ratio\-lock
+Disable window aspect ratio lock.
+
.TP
.BI "\-\-orientation " value
Same as --display-orientation=value --record-orientation=value.
diff --git a/app/src/cli.c b/app/src/cli.c
index 9da0fc1f..8c5e09c9 100644
--- a/app/src/cli.c
+++ b/app/src/cli.c
@@ -105,6 +105,7 @@ enum {
OPT_CAMERA_TORCH,
OPT_CAMERA_ZOOM,
OPT_MIN_SIZE_ALIGNMENT,
+ OPT_NO_WINDOW_ASPECT_RATIO_LOCK,
};
struct sc_option {
@@ -669,6 +670,11 @@ static const struct sc_option options[] = {
.longopt = "no-window",
.text = "Disable scrcpy window. Implies --no-video-playback.",
},
+ {
+ .longopt_id = OPT_NO_WINDOW_ASPECT_RATIO_LOCK,
+ .longopt = "no-window-aspect-ratio-lock",
+ .text = "Disable window aspect ratio lock.",
+ },
{
.longopt_id = OPT_ORIENTATION,
.longopt = "orientation",
@@ -2758,6 +2764,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[],
return false;
}
break;
+ case OPT_NO_WINDOW_ASPECT_RATIO_LOCK:
+ opts->window_aspect_ratio_lock = false;
+ break;
default:
// getopt prints the error message on stderr
return false;
diff --git a/app/src/options.c b/app/src/options.c
index 51d2255f..9ef1bce7 100644
--- a/app/src/options.c
+++ b/app/src/options.c
@@ -84,6 +84,7 @@ const struct scrcpy_options scrcpy_options_default = {
.audio_playback = true,
.turn_screen_off = false,
.key_inject_mode = SC_KEY_INJECT_MODE_MIXED,
+ .window_aspect_ratio_lock = true,
.window_borderless = false,
.mipmaps = true,
.stay_awake = false,
diff --git a/app/src/options.h b/app/src/options.h
index b869da6b..abd09d61 100644
--- a/app/src/options.h
+++ b/app/src/options.h
@@ -294,6 +294,7 @@ struct scrcpy_options {
bool audio_playback;
bool turn_screen_off;
enum sc_key_inject_mode key_inject_mode;
+ bool window_aspect_ratio_lock;
bool window_borderless;
bool mipmaps;
bool stay_awake;
diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c
index a83702e3..8bb428c9 100644
--- a/app/src/scrcpy.c
+++ b/app/src/scrcpy.c
@@ -813,6 +813,7 @@ aoa_complete:
.window_y = options->window_y,
.window_width = options->window_width,
.window_height = options->window_height,
+ .window_aspect_ratio_lock = options->window_aspect_ratio_lock,
.window_borderless = options->window_borderless,
.orientation = options->display_orientation,
.mipmaps = options->mipmaps,
diff --git a/app/src/screen.c b/app/src/screen.c
index c5d12df1..b1bcdf3a 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -17,11 +17,15 @@
static void
set_window_size_ar(struct sc_screen *screen, struct sc_size window_size) {
assert(window_size.width && window_size.height);
- float ar = (float) window_size.width / window_size.height;
- bool ok = SDL_SetWindowAspectRatio(screen->window, ar, ar);
- if (!ok) {
- LOGW("Could not set window aspect ratio: %s", SDL_GetError());
+
+ if (screen->window_aspect_ratio_lock) {
+ float ar = (float) window_size.width / window_size.height;
+ bool ok = SDL_SetWindowAspectRatio(screen->window, ar, ar);
+ if (!ok) {
+ LOGW("Could not set window aspect ratio: %s", SDL_GetError());
+ }
}
+
sc_sdl_set_window_size(screen->window, window_size);
}
@@ -390,6 +394,7 @@ sc_screen_init(struct sc_screen *screen,
screen->video = params->video;
screen->camera = params->camera;
+ screen->window_aspect_ratio_lock = params->window_aspect_ratio_lock;
screen->req.x = params->window_x;
screen->req.y = params->window_y;
diff --git a/app/src/screen.h b/app/src/screen.h
index a97a8256..e04abefe 100644
--- a/app/src/screen.h
+++ b/app/src/screen.h
@@ -36,6 +36,7 @@ struct sc_screen {
bool video;
bool camera;
+ bool window_aspect_ratio_lock;
struct sc_texture tex;
struct sc_input_manager im;
@@ -106,6 +107,7 @@ struct sc_screen_params {
uint16_t window_width;
uint16_t window_height;
+ bool window_aspect_ratio_lock;
bool window_borderless;
enum sc_orientation orientation;
diff --git a/doc/window.md b/doc/window.md
index b72c716c..2bc13b47 100644
--- a/doc/window.md
+++ b/doc/window.md
@@ -25,6 +25,13 @@ The initial window position and size may be specified:
scrcpy --window-x=100 --window-y=100 --window-width=800 --window-height=600
```
+By default, the window aspect ratio is preserved when resizing. To disable this
+behavior:
+
+```bash
+scrcpy --no-window-aspect-ratio-lock
+```
+
## Borderless
To disable window decorations: