1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-19 18:05:21 +00:00

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.
This commit is contained in:
Dudemanguy 2024-02-13 17:11:00 -06:00
parent a3648ddac8
commit 17d9abd08f
2 changed files with 23 additions and 2 deletions

View File

@ -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;

View File

@ -2284,8 +2284,6 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
set_input_region(wl, opts->cursor_passthrough);
if (opt == &opts->fullscreen)
toggle_fullscreen(wl);
if (opt == &opts->hidpi_window_scale)
set_geometry(wl, true);
if (opt == &opts->window_maximized)
toggle_maximized(wl);
if (opt == &opts->window_minimized)