summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2020-11-07 18:36:26 -0600
committerDudemanguy <random342@airmail.cc>2021-08-05 19:13:10 +0000
commit873ae0de2af3bb84a11e5e57f6e3a8942b2263c2 (patch)
tree566387964502e2ce0a4e649717476997a6f3ee87 /player
parent41650203c32e179e5f3cf89e176ef6caccba05d9 (diff)
downloadmpv-873ae0de2af3bb84a11e5e57f6e3a8942b2263c2.tar.bz2
mpv-873ae0de2af3bb84a11e5e57f6e3a8942b2263c2.tar.xz
command: make current-window-scale writeable
Somewhat confusingly, mpv has both a window-scale option and a current-window-scale property. The documentation lists window-scale under properties (and it is technically is one), but at its core it is actually an option which means it behaves subtly different. Options in mpv are runtime-configurable, but they only change anything if the value of the option itself changes. window-scale is an option and not meant to keep track of the actual scale of the window (intended behavior introduced by d07b7f0). This causes window-scale to do nothing in certain cases (ex: the window is manually resized and window-scale is set to 1.00 again). This is logical and consistent with the behavior of the rest of the mpv options, but it also makes it a poor candidate for setting the mpv window scale dynamically. As a remedy, we can just make current-window-scale writeable instead. current-window-scale is intended to always report the actual scale of the window and keep track of any window size changes made by the user. By making this property also writeable, it allows the user to have more intuitive behavior (i.e. setting current-window-scale to 1.00 always sets the window to a scale of 1). Additionally, the default input.conf is changed to use current-window-scale instead of window-scale. The window-scale documentation under property list is removed since it is already documented under options and users should probably set the current-window-scale property instead in most cases.
Diffstat (limited to 'player')
-rw-r--r--player/command.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/player/command.c b/player/command.c
index 5119857986..0a66bbcbac 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2316,46 +2316,55 @@ static int mp_property_video_frame_info(void *ctx, struct m_property *prop,
return m_property_read_sub(props, action, arg);
}
-static int mp_property_current_window_scale(void *ctx, struct m_property *prop,
- int action, void *arg)
+static int update_window_scale(struct MPContext *mpctx, double scale)
{
- MPContext *mpctx = ctx;
struct vo *vo = mpctx->video_out;
if (!vo)
- return M_PROPERTY_UNAVAILABLE;
+ return -1;
struct mp_image_params params = get_video_out_params(mpctx);
int vid_w, vid_h;
mp_image_params_get_dsize(&params, &vid_w, &vid_h);
if (vid_w < 1 || vid_h < 1)
- return M_PROPERTY_UNAVAILABLE;
-
- int s[2];
- if (vo_control(vo, VOCTRL_GET_UNFS_WINDOW_SIZE, s) <= 0 ||
- s[0] < 1 || s[1] < 1)
- return M_PROPERTY_UNAVAILABLE;
+ return -1;
- double xs = (double)s[0] / vid_w;
- double ys = (double)s[1] / vid_h;
- return m_property_double_ro(action, arg, (xs + ys) / 2);
+ int s[2] = {vid_w * scale, vid_h * scale};
+ if (s[0] > 0 && s[1] > 0)
+ vo_control(vo, VOCTRL_SET_UNFS_WINDOW_SIZE, s);
+ return 0;
}
-static void update_window_scale(struct MPContext *mpctx)
+static int mp_property_current_window_scale(void *ctx, struct m_property *prop,
+ int action, void *arg)
{
+ MPContext *mpctx = ctx;
struct vo *vo = mpctx->video_out;
if (!vo)
- return;
+ return M_PROPERTY_UNAVAILABLE;
- struct mp_image_params params = get_video_out_params(mpctx);
- int vid_w, vid_h;
- mp_image_params_get_dsize(&params, &vid_w, &vid_h);
- if (vid_w < 1 || vid_h < 1)
- return;
+ switch (action) {
+ case M_PROPERTY_SET:
+ if (update_window_scale(mpctx, *(double *)arg) < 0)
+ return M_PROPERTY_UNAVAILABLE;
+ return M_PROPERTY_OK;
+ case M_PROPERTY_GET_TYPE:
+ case M_PROPERTY_GET: ;
+ struct mp_image_params params = get_video_out_params(mpctx);
+ int vid_w, vid_h;
+ mp_image_params_get_dsize(&params, &vid_w, &vid_h);
+ if (vid_w < 1 || vid_h < 1)
+ return M_PROPERTY_UNAVAILABLE;
- double scale = mpctx->opts->vo->window_scale;
- int s[2] = {vid_w * scale, vid_h * scale};
- if (s[0] > 0 && s[1] > 0)
- vo_control(vo, VOCTRL_SET_UNFS_WINDOW_SIZE, s);
+ int s[2];
+ if (vo_control(vo, VOCTRL_GET_UNFS_WINDOW_SIZE, s) <= 0 ||
+ s[0] < 1 || s[1] < 1)
+ return M_PROPERTY_UNAVAILABLE;
+
+ double xs = (double)s[0] / vid_w;
+ double ys = (double)s[1] / vid_h;
+ return m_property_double_ro(action, arg, (xs + ys) / 2);
+ }
+ return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_display_fps(void *ctx, struct m_property *prop,
@@ -6701,7 +6710,7 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
}
if (opt_ptr == &opts->vo->window_scale)
- update_window_scale(mpctx);
+ update_window_scale(mpctx, opts->vo->window_scale);
if (opt_ptr == &opts->cursor_autohide_delay)
mpctx->mouse_timer = 0;