player: add --auto-window-resize option

mpv's window resizing logic always automatically resized the window
whenever the video resolution changed (i.e. advancing forward in a
playlist). This simply introduces the option to make this behavior
configurable. Every windowing backend would need to implement this
behavior in their code since a reconfigure event must always be a
resize. The params of the frame changed so you either have to resize the
window to the new size of the params or make the params the same size as
the window. This commit implements it for wayland, win32, and x11.
This commit is contained in:
Dudemanguy 2021-10-19 21:47:23 -05:00
parent cd02b5ccf6
commit c993d5c0ce
8 changed files with 34 additions and 14 deletions

View File

@ -58,6 +58,7 @@ Interface changes
- change type of `--brightness`, `--saturation`, `--contrast`, `--hue` and
`--gamma` to float.
- add `platform` property
- add `--auto-window-resize`
--- mpv 0.35.0 ---
- add the `--vo=gpu-next` video output driver, as well as the options
`--allow-delayed-peak-detect`, `--builtin-scalers`,

View File

@ -3266,6 +3266,13 @@ Window
there is a change in video parameters, video stream or file. This used to
be the default behavior. Currently only affects X11 VOs.
``--auto-window-resize=<yes|no>``
(Wayland, Win32, and X11)
By default, mpv will automatically resize itself if the video's size changes
(i.e. advancing forward in a playlist). Setting this to ``no`` disables this
behavior so the window size never changes automatically. This option does
not have any impact on the ``--autofit`` or ``--geometry`` options.
``--no-keepaspect``, ``--keepaspect``
``--no-keepaspect`` will always stretch the video to window size, and will
disable the window manager hints that force the window aspect ratio.

View File

@ -118,6 +118,7 @@ static const m_option_t mp_vo_opt_list[] = {
{"autofit", OPT_SIZE_BOX(autofit)},
{"autofit-larger", OPT_SIZE_BOX(autofit_larger)},
{"autofit-smaller", OPT_SIZE_BOX(autofit_smaller)},
{"auto-window-resize", OPT_BOOL(auto_window_resize)},
{"window-scale", OPT_DOUBLE(window_scale), M_RANGE(0.001, 100)},
{"window-minimized", OPT_BOOL(window_minimized)},
{"window-maximized", OPT_BOOL(window_maximized)},
@ -201,6 +202,7 @@ const struct m_sub_options vo_sub_opts = {
.panscan = 0.0f,
.scale_x = 1.0f,
.scale_y = 1.0f,
.auto_window_resize = true,
.keepaspect = true,
.keepaspect_window = true,
.hidpi_window_scale = true,

View File

@ -48,6 +48,7 @@ typedef struct mp_vo_opts {
struct m_geometry autofit_smaller;
double window_scale;
bool auto_window_resize;
bool keepaspect;
bool keepaspect_window;
bool hidpi_window_scale;

View File

@ -1438,8 +1438,9 @@ static void gui_thread_reconfig(void *ptr)
vo_calc_window_geometry3(vo, &screen, &mon, w32->dpi_scale, &geo);
vo_apply_window_geometry(vo, &geo);
bool reset_size = w32->o_dwidth != vo->dwidth ||
w32->o_dheight != vo->dheight;
bool reset_size = (w32->o_dwidth != vo->dwidth ||
w32->o_dheight != vo->dheight) &&
w32->opts->auto_window_resize;
w32->o_dwidth = vo->dwidth;
w32->o_dheight = vo->dheight;

View File

@ -2217,7 +2217,11 @@ bool vo_wayland_reconfig(struct vo *vo)
wl->pending_vo_events |= VO_EVENT_DPI;
}
set_geometry(wl, false);
if (wl->vo_opts->auto_window_resize || mp_rect_w(wl->geometry) == 0 ||
mp_rect_h(wl->geometry) == 0)
{
set_geometry(wl, false);
}
if (wl->opts->configure_bounds)
set_window_bounds(wl);

View File

@ -1092,9 +1092,9 @@ static void vo_x11_check_net_wm_state_change(struct vo *vo)
XFree(elems);
}
if (opts->window_maximized && !is_maximized && x11->pending_geometry_change) {
if (opts->window_maximized && !is_maximized && x11->geometry_change) {
x11->geometry_change = false;
vo_x11_config_vo_window(vo);
x11->pending_geometry_change = false;
}
opts->window_minimized = is_minimized;
@ -1722,6 +1722,10 @@ void vo_x11_config_vo_window(struct vo *vo)
assert(x11->window);
// Don't attempt to change autofit/geometry on maximized windows.
if (x11->geometry_change && opts->window_maximized)
return;
vo_x11_update_screeninfo(vo);
struct vo_win_geometry geo;
@ -1735,7 +1739,9 @@ void vo_x11_config_vo_window(struct vo *vo)
rc = (struct mp_rect){0, 0, RC_W(x11->winrc), RC_H(x11->winrc)};
}
bool reset_size = x11->old_dw != RC_W(rc) || x11->old_dh != RC_H(rc);
bool reset_size = (x11->old_dw != RC_W(rc) || x11->old_dh != RC_H(rc)) &&
(opts->auto_window_resize || x11->geometry_change);
x11->old_dw = RC_W(rc);
x11->old_dh = RC_H(rc);
@ -1746,6 +1752,8 @@ void vo_x11_config_vo_window(struct vo *vo)
vo_x11_highlevel_resize(vo, rc);
}
x11->geometry_change = false;
if (opts->ontop)
vo_x11_setlayer(vo, opts->ontop);
@ -1961,11 +1969,8 @@ static void vo_x11_set_geometry(struct vo *vo)
if (!x11->window)
return;
if (x11->opts->window_maximized) {
x11->pending_geometry_change = true;
} else {
vo_x11_config_vo_window(vo);
}
x11->geometry_change = true;
vo_x11_config_vo_window(vo);
}
bool vo_x11_check_visible(struct vo *vo) {

View File

@ -118,9 +118,8 @@ struct vo_x11_state {
bool size_changed_during_fs;
bool pos_changed_during_fs;
/* The geometry/autofit option was changed while the window was maximized.
* Wait until the state changes to resize. */
bool pending_geometry_change;
/* One of the autofit/geometry options changed at runtime. */
bool geometry_change;
XComposeStatus compose_status;