Add option to disable window aspect ratio lock

By default, the window aspect ratio is preserved when resizing.

Add `--no-window-aspect-ratio-lock` to disable this behavior.

PR #6761 <https://github.com/Genymobile/scrcpy/pull/6761>

Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
Tech-Tac 2026-04-08 18:34:20 +02:00 committed by Romain Vimont
parent 1b4fd67286
commit 65153a09c3
10 changed files with 36 additions and 4 deletions

View file

@ -66,6 +66,7 @@ _scrcpy() {
--no-video
--no-video-playback
--no-window
--no-window-aspect-ratio-lock
--orientation=
--otg
-p --port=

View file

@ -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]'

View file

@ -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.

View file

@ -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;

View file

@ -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,

View file

@ -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;

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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: