Use Xlib to read resources (#142)
This commit is contained in:
+27
-8
@@ -7,7 +7,10 @@
|
||||
#include <windows.h>
|
||||
#elif __linux__
|
||||
#include <unistd.h>
|
||||
#include "xrdb_parse.h"
|
||||
#include <SDL_syswm.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xresource.h>
|
||||
#elif __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
@@ -16,16 +19,32 @@
|
||||
SDL_Window *window;
|
||||
|
||||
static double get_scale(void) {
|
||||
#if _WIN32
|
||||
#ifdef _WIN32
|
||||
float dpi;
|
||||
SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
|
||||
return dpi / 96.0;
|
||||
#elif __unix__
|
||||
int xft_dpi = xrdb_find_dpi();
|
||||
if (xft_dpi > 0) {
|
||||
return xft_dpi / 96.0;
|
||||
}
|
||||
return 1.0;
|
||||
#elif __linux__
|
||||
SDL_SysWMinfo info;
|
||||
XrmDatabase db;
|
||||
XrmValue value;
|
||||
char *type = NULL;
|
||||
|
||||
SDL_VERSION(&info.version);
|
||||
if (!SDL_GetWindowWMInfo(window, &info)
|
||||
|| info.subsystem != SDL_SYSWM_X11)
|
||||
return 1.0;
|
||||
|
||||
char *resource = XResourceManagerString(info.info.x11.display);
|
||||
if (resource == NULL)
|
||||
return 1.0;
|
||||
|
||||
XrmInitialize();
|
||||
db = XrmGetStringDatabase(resource);
|
||||
if (XrmGetResource(db, "Xft.dpi", "String", &type, &value) == False
|
||||
|| value.addr == NULL)
|
||||
return 1.0;
|
||||
|
||||
return atof(value.addr) / 96.0;
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user