mirror of https://github.com/mpv-player/mpv
player: add --autofit-smaller option
Fixes #1472. (Maybe these options should have been named --autofit-max and --autofit-min, but since --autofit-larger already exists, use --autofit-smaller for symmetry.)
This commit is contained in:
parent
c8052da7de
commit
1883b7cc0c
|
@ -1650,6 +1650,17 @@ Window
|
|||
screen height, make the window smaller until either its width is 90%
|
||||
of the screen, or its height is 80% of the screen.
|
||||
|
||||
``--autofit-smaller=<[W[xH]]>``
|
||||
This option behaves exactly like ``--autofit``, except that it sets the
|
||||
minimum size of the window (just as ``--autofit-larger`` sets the maximum).
|
||||
|
||||
.. admonition:: Example
|
||||
|
||||
``500x500``
|
||||
Make the window at least 500 pixels wide and 500 pixels high
|
||||
(depending on the video aspect ratio, the width or height will be
|
||||
larger than 500 in order to keep the aspect ratio the same).
|
||||
|
||||
``--autosync=<factor>``
|
||||
Gradually adjusts the A/V sync based on audio delay measurements.
|
||||
Specifying ``--autosync=0``, the default, will cause frame timing to be
|
||||
|
|
|
@ -394,6 +394,7 @@ const m_option_t mp_opts[] = {
|
|||
OPT_GEOMETRY("geometry", vo.geometry, 0),
|
||||
OPT_SIZE_BOX("autofit", vo.autofit, 0),
|
||||
OPT_SIZE_BOX("autofit-larger", vo.autofit_larger, 0),
|
||||
OPT_SIZE_BOX("autofit-smaller", vo.autofit_smaller, 0),
|
||||
OPT_FLAG("force-window-position", vo.force_window_position, 0),
|
||||
// vo name (X classname) and window title strings
|
||||
OPT_STRING("x11-name", vo.winname, 0),
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef struct mp_vo_opts {
|
|||
struct m_geometry geometry;
|
||||
struct m_geometry autofit;
|
||||
struct m_geometry autofit_larger;
|
||||
struct m_geometry autofit_smaller;
|
||||
|
||||
int keepaspect;
|
||||
int keepaspect_window;
|
||||
|
|
|
@ -37,7 +37,7 @@ static void calc_monitor_aspect(struct mp_vo_opts *opts, int scr_w, int scr_h,
|
|||
|
||||
// Fit *w/*h into the size specified by geo.
|
||||
static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
|
||||
struct m_geometry *geo, bool allow_upscale)
|
||||
struct m_geometry *geo, bool allow_up, bool allow_down)
|
||||
{
|
||||
if (!geo->wh_valid)
|
||||
return;
|
||||
|
@ -46,13 +46,16 @@ static void apply_autofit(int *w, int *h, int scr_w, int scr_h,
|
|||
int n_w = *w, n_h = *h;
|
||||
m_geometry_apply(&dummy, &dummy, &n_w, &n_h, scr_w, scr_h, geo);
|
||||
|
||||
if (!allow_upscale && *w <= n_w && *h <= n_h)
|
||||
if (!allow_up && *w <= n_w && *h <= n_h)
|
||||
return;
|
||||
if (!allow_down && *w >= n_w && *h >= n_h)
|
||||
return;
|
||||
|
||||
// If aspect mismatches, always make the window smaller than the fit box
|
||||
// (Or larger, if allow_down==false.)
|
||||
double asp = (double)*w / *h;
|
||||
double n_asp = (double)n_w / n_h;
|
||||
if (n_asp <= asp) {
|
||||
if ((n_asp <= asp) == allow_down) {
|
||||
*w = n_w;
|
||||
*h = n_w / asp;
|
||||
} else {
|
||||
|
@ -95,8 +98,9 @@ void vo_calc_window_geometry(struct vo *vo, const struct mp_rect *screen,
|
|||
|
||||
calc_monitor_aspect(opts, scr_w, scr_h, &out_geo->monitor_par, &d_w, &d_h);
|
||||
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true);
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false);
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit, true, true);
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_larger, false, true);
|
||||
apply_autofit(&d_w, &d_h, scr_w, scr_h, &opts->autofit_smaller, true, false);
|
||||
|
||||
out_geo->win.x0 = (int)(scr_w - d_w) / 2;
|
||||
out_geo->win.y0 = (int)(scr_h - d_h) / 2;
|
||||
|
|
Loading…
Reference in New Issue