Skip to content

Commit f2fa461

Browse files
committed
wayland: only reuse old size if both width and height are 0
The protocol states that "If the width or height arguments are zero, it means the client should decide its own window dimension." Key point here is the omission of plurality from "dimension." This means a compositor could theoretically set width OR height to 0 and a specific size for the other dimension. There is no compositor out in the wild that does it but this is one proposed solution to mpv technically violating the letter of the protocol on Wayland when resizing while trying to keep the aspect ratio. mpv isn't allowed to make the window larger than size it receives in the configure event while the resizing event is set, but this means that it is impossible for the mpv window to grow if the user tries to resize from any side of the window (as opposed to corners). When the user attempts to grow the window from sides, mpv cannot keep the same aspect ratio without also growing on the other dimension. This is a protocol violation, though no compositor actually checks or enforces this. The solution to this is compositors setting the required size on one dimension to 0, so mpv can freely grow in that dimension to keep up with interactive resize. Related: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/33
1 parent 5ba7ee5 commit f2fa461

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

video/out/wayland_common.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,14 +1307,22 @@ static void handle_toplevel_config(void *data, struct xdg_toplevel *toplevel,
13071307
}
13081308
}
13091309

1310-
/* Reuse old size if either of these are 0. */
1311-
if (width == 0 || height == 0) {
1310+
/* Reuse old size if both of these are 0. */
1311+
if (width == 0 && height == 0) {
13121312
if (!wl->locked_size) {
13131313
wl->geometry = wl->window_size;
13141314
}
13151315
goto resize;
13161316
}
13171317

1318+
// If either of these is 0, we're allowed to grow in that dimension. Start
1319+
// at current window size in that case.
1320+
if (width == 0) {
1321+
width = mp_rect_w(wl->window_size);
1322+
} else if (height == 0) {
1323+
height = mp_rect_h(wl->window_size);
1324+
}
1325+
13181326
if (!wl->locked_size) {
13191327
apply_keepaspect(wl, &width, &height);
13201328
wl->window_size.x0 = 0;

0 commit comments

Comments
 (0)