aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-21 21:28:08 -0400
committerDavid Robillard <d@drobilla.net>2022-05-21 22:03:22 -0400
commitfdd6de0d12ea17f713ec3e73e7968198339b7b6d (patch)
tree800b75e676f8320c2e22b3590751a63be3741fc5 /src/x11.c
parenta88b470d9c954073fcfcfeca2242809532eaf048 (diff)
downloadpugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.tar.gz
pugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.tar.bz2
pugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.zip
Add puglGetScaleFactor()
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)
{