aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/x11.c')
-rw-r--r--src/x11.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/x11.c b/src/x11.c
index 5ae6b12..c2e9e96 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -14,6 +14,7 @@
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
+#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
@@ -106,6 +107,33 @@ initXSync(PuglWorldInternals* const impl)
return false;
}
+static double
+puglX11GetDisplayScaleFactor(Display* const display)
+{
+ double dpi = 96.0;
+ const char* const rms = XResourceManagerString(display);
+ if (rms) {
+ XrmDatabase db = XrmGetStringDatabase(rms);
+ if (db) {
+ XrmValue value = {0u, NULL};
+ char* type = NULL;
+ if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &value)) {
+ if (!type || !strcmp(type, "String")) {
+ char* end = NULL;
+ const double xftDpi = strtod(value.addr, &end);
+ if (xftDpi > 0.0 && xftDpi < HUGE_VAL) {
+ dpi = xftDpi;
+ }
+ }
+ }
+
+ XrmDestroyDatabase(db);
+ }
+ }
+
+ return dpi / 96.0;
+}
+
PuglWorldInternals*
puglInitWorldInternals(const PuglWorldType type, const PuglWorldFlags flags)
{
@@ -121,7 +149,8 @@ puglInitWorldInternals(const PuglWorldType type, const PuglWorldFlags flags)
PuglWorldInternals* impl =
(PuglWorldInternals*)calloc(1, sizeof(PuglWorldInternals));
- impl->display = display;
+ impl->display = display;
+ impl->scaleFactor = puglX11GetDisplayScaleFactor(display);
// Intern the various atoms we will need
impl->atoms.CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
@@ -1367,6 +1396,12 @@ puglSetWindowTitle(PuglView* const view, const char* const title)
return PUGL_SUCCESS;
}
+double
+puglGetScaleFactor(const PuglView* const view)
+{
+ return view->world->impl->scaleFactor;
+}
+
PuglStatus
puglSetFrame(PuglView* const view, const PuglRect frame)
{