diff options
author | nanahi <130121847+na-na-hi@users.noreply.github.com> | 2024-01-05 00:25:28 -0500 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2024-01-10 00:33:05 +0100 |
commit | a504e696c8a45df50cb2dd21e21445221a551555 (patch) | |
tree | b3bb6678de9f424175edfb1db20089f2e79a19c4 /video/out/x11_common.c | |
parent | 485221ba22674045d1af822b08fa193862dd835b (diff) | |
download | mpv-a504e696c8a45df50cb2dd21e21445221a551555.tar.bz2 mpv-a504e696c8a45df50cb2dd21e21445221a551555.tar.xz |
x11_common: allow DPI scale in unit of 0.5
~144 DPI displays are pretty common and neither 1x nor 2x scales are
the right size for it. Allow DPI scale in unit of 0.5 to fix this.
Additionally, add a note about the current behavior of the API used
to get the scale factor.
Diffstat (limited to 'video/out/x11_common.c')
-rw-r--r-- | video/out/x11_common.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/video/out/x11_common.c b/video/out/x11_common.c index bae2918157..3b99602033 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -603,6 +603,29 @@ static void vo_x11_get_bounding_monitors(struct vo_x11_state *x11, long b[4]) } } +// Get the dpi scale of the x11 screen. Almost no GUI programs use this value +// nowadays, and it has inconsistent behavior for different drivers. +// (it returns the physical display DPI for proprietary NVIDIA driver only, +// but essentially a user-set prefrence value everywhere else) +static void vo_x11_get_x11_screen_dpi_scale(struct vo_x11_state *x11) +{ + int w_mm = DisplayWidthMM(x11->display, x11->screen); + int h_mm = DisplayHeightMM(x11->display, x11->screen); + double dpi_x = x11->ws_width * 25.4 / w_mm; + double dpi_y = x11->ws_height * 25.4 / h_mm; + double base_dpi = 96; + if (isfinite(dpi_x) && isfinite(dpi_y) && x11->opts->hidpi_window_scale) { + int s_x = lrint(MPCLAMP(2 * dpi_x / base_dpi, 0, 20)); + int s_y = lrint(MPCLAMP(2 * dpi_y / base_dpi, 0, 20)); + if (s_x == s_y && s_x > 2 && s_x < 20) { + x11->dpi_scale = s_x / 2.0; + MP_VERBOSE(x11, "Using X11 screen DPI scale %g for prescaling. This can " + "be disabled with --hidpi-window-scale=no.\n", + x11->dpi_scale); + } + } +} + bool vo_x11_init(struct vo *vo) { char *dispName; @@ -667,21 +690,7 @@ bool vo_x11_init(struct vo *vo) x11->ws_width, x11->ws_height, dispName, x11->display_is_local ? "local" : "remote"); - int w_mm = DisplayWidthMM(x11->display, x11->screen); - int h_mm = DisplayHeightMM(x11->display, x11->screen); - double dpi_x = x11->ws_width * 25.4 / w_mm; - double dpi_y = x11->ws_height * 25.4 / h_mm; - double base_dpi = 96; - if (isfinite(dpi_x) && isfinite(dpi_y) && x11->opts->hidpi_window_scale) { - int s_x = lrint(MPCLAMP(dpi_x / base_dpi, 0, 10)); - int s_y = lrint(MPCLAMP(dpi_y / base_dpi, 0, 10)); - if (s_x == s_y && s_x > 1 && s_x < 10) { - x11->dpi_scale = s_x; - MP_VERBOSE(x11, "Assuming DPI scale %d for prescaling. This can " - "be disabled with --hidpi-window-scale=no.\n", - x11->dpi_scale); - } - } + vo_x11_get_x11_screen_dpi_scale(x11); x11->wm_type = vo_wm_detect(vo); |