summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-01-05 00:58:15 -0500
committersfan5 <sfan5@live.de>2024-01-10 00:33:05 +0100
commit4b691641472b487831a0b0f7637d5355d79387cd (patch)
tree2bed8fef95848dca150ba4312bdc54c87a562225 /video
parenta504e696c8a45df50cb2dd21e21445221a551555 (diff)
downloadmpv-4b691641472b487831a0b0f7637d5355d79387cd.tar.bz2
mpv-4b691641472b487831a0b0f7637d5355d79387cd.tar.xz
x11_common: prefer Xft.dpi for HiDPI scaling
Xft.dpi is much more widely used nowadays by GUI programs compared to the X11 screen DPI. This is the best we can get for a vendor-neutral scaling preference value under X11 in terms of adoption. If Xft.dpi isn't available, the X11 screen DPI is used as a fallback.
Diffstat (limited to 'video')
-rw-r--r--video/out/x11_common.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/video/out/x11_common.c b/video/out/x11_common.c
index 3b99602033..f4d5716bee 100644
--- a/video/out/x11_common.c
+++ b/video/out/x11_common.c
@@ -29,6 +29,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
+#include <X11/Xresource.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/XF86keysym.h>
@@ -626,6 +627,44 @@ static void vo_x11_get_x11_screen_dpi_scale(struct vo_x11_state *x11)
}
}
+// Get the dpi scale from the Xft.dpi resource. In practice, this value is much more
+// commonly used by GUI programs for scaling compared to the x11 screen dpi.
+// This is always a preference value so it's also more consistent.
+static bool vo_x11_get_xft_dpi_scale(struct vo_x11_state *x11)
+{
+ XrmInitialize();
+ char *resman = XResourceManagerString(x11->display);
+ if (!resman)
+ return false;
+
+ XrmDatabase db = XrmGetStringDatabase(resman);
+ if (!db)
+ return false;
+
+ XrmValue ret;
+ char *type;
+ double base_dpi = 96;
+ bool success = false;
+ if (XrmGetResource(db, "Xft.dpi", "String", &type, &ret) == True &&
+ ret.addr && !strcmp("String", type))
+ {
+ char *end;
+ long value = strtol(ret.addr, &end, 10);
+ if (*ret.addr && *end == '\0') {
+ int s = lrint(MPCLAMP(2 * value / base_dpi, 0, 20));
+ if (s > 2 && s < 20) {
+ x11->dpi_scale = s / 2.0;
+ MP_VERBOSE(x11, "Using Xft.dpi scale %g for prescaling. This can "
+ "be disabled with --hidpi-window-scale=no.\n",
+ x11->dpi_scale);
+ success = true;
+ }
+ }
+ }
+ XrmDestroyDatabase(db);
+ return success;
+}
+
bool vo_x11_init(struct vo *vo)
{
char *dispName;
@@ -690,7 +729,8 @@ bool vo_x11_init(struct vo *vo)
x11->ws_width, x11->ws_height, dispName,
x11->display_is_local ? "local" : "remote");
- vo_x11_get_x11_screen_dpi_scale(x11);
+ if (!vo_x11_get_xft_dpi_scale(x11))
+ vo_x11_get_x11_screen_dpi_scale(x11);
x11->wm_type = vo_wm_detect(vo);