From 17d9abd08fb77d3a33b4717b29257a27ee6bab47 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Tue, 13 Feb 2024 17:11:00 -0600 Subject: player/command: handle runtime toggling of hidpi-window-scale Wayland was the only backend that attempted this, but it can be done in a centralized place for anything that supports this. hidpi-window-scale is just the same as a normal window scale but with the OS DPI as the factor. --- player/command.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'player') diff --git a/player/command.c b/player/command.c index e81874010b..a286dc2d4a 100644 --- a/player/command.c +++ b/player/command.c @@ -2626,6 +2626,26 @@ static int mp_property_hidpi_scale(void *ctx, struct m_property *prop, return m_property_double_ro(action, arg, cmd->cached_window_scale); } +static void update_hidpi_window_scale(struct MPContext *mpctx, bool hidpi_scale) +{ + struct command_ctx *cmd = mpctx->command_ctx; + struct vo *vo = mpctx->video_out; + if (!vo || cmd->cached_window_scale <= 0) + return; + + double scale = hidpi_scale ? cmd->cached_window_scale : 1 / cmd->cached_window_scale; + + int s[2]; + if (vo_control(vo, VOCTRL_GET_UNFS_WINDOW_SIZE, s) <= 0 || s[0] < 1 || s[1] < 1) + return; + + s[0] *= scale; + s[1] *= scale; + if (s[0] <= 0 || s[1] <= 0) + return; + vo_control(vo, VOCTRL_SET_UNFS_WINDOW_SIZE, s); +} + static int mp_property_focused(void *ctx, struct m_property *prop, int action, void *arg) { @@ -7192,6 +7212,9 @@ 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); + if (opt_ptr == &opts->vo->hidpi_window_scale) + update_hidpi_window_scale(mpctx, opts->vo->hidpi_window_scale); + if (opt_ptr == &opts->cursor_autohide_delay) mpctx->mouse_timer = 0; -- cgit v1.2.3