diff options
author | David Robillard <d@drobilla.net> | 2022-05-21 21:28:08 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-05-21 22:03:22 -0400 |
commit | fdd6de0d12ea17f713ec3e73e7968198339b7b6d (patch) | |
tree | 800b75e676f8320c2e22b3590751a63be3741fc5 /src/x11.c | |
parent | a88b470d9c954073fcfcfeca2242809532eaf048 (diff) | |
download | pugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.tar.gz pugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.tar.bz2 pugl-fdd6de0d12ea17f713ec3e73e7968198339b7b6d.zip |
Add puglGetScaleFactor()
Diffstat (limited to 'src/x11.c')
-rw-r--r-- | src/x11.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -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) { |