Skip to content

Commit

Permalink
player/command: handle runtime toggling of hidpi-window-scale
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dudemanguy committed Feb 24, 2024
1 parent a3648dd commit 17d9abd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 23 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 17d9abd

Please sign in to comment.