Addressing the scaling factor on linux. (#107)
Use xrdb and the Xft.dpi variable to find out DPI scaling on linux.
This commit is contained in:
parent
56a4584a1b
commit
27f3cb23d4
29
src/main.c
29
src/main.c
|
@ -7,6 +7,7 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +21,34 @@ static double get_scale(void) {
|
||||||
SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
|
SDL_GetDisplayDPI(0, NULL, &dpi, NULL);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
return dpi / 96.0;
|
return dpi / 96.0;
|
||||||
|
#elif __linux__
|
||||||
|
FILE *stream;
|
||||||
|
char *xrdb = "xrdb -query | grep dpi | cut -f 2";
|
||||||
|
|
||||||
|
// In case something goes wrong in popen (e.g., fork or exec calls) or any
|
||||||
|
// other calls listed below we return the dpi equal to 1.
|
||||||
|
if ((stream = popen(xrdb, "r")) == NULL)
|
||||||
|
return 1.0;
|
||||||
|
|
||||||
|
char *line = NULL;
|
||||||
|
size_t buffer = 0;
|
||||||
|
ssize_t length = getline(&line, &buffer, stream);
|
||||||
|
|
||||||
|
if (length == -1) {
|
||||||
|
free(line);
|
||||||
|
pclose(stream);
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pclose(stream)) {
|
||||||
|
free(line);
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dpi = strtol(line, NULL, 10) / 96.0;
|
||||||
|
free(line);
|
||||||
|
|
||||||
|
return dpi;
|
||||||
#else
|
#else
|
||||||
return 1.0;
|
return 1.0;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue