summaryrefslogtreecommitdiff
path: root/src/drivers/X11
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-02-20 14:07:53 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-02-20 14:07:53 +0100
commit8d716f7254fbcf652642a47cefa7c9f58b538dbe (patch)
tree0756a2fa6cd9f28cba827ab604e29b50c2ff6007 /src/drivers/X11
parent95f5135b4dad392a7287e28c7503ec8b7637e121 (diff)
Use also the Xft.dpi resource to initialize the GUI scale factor.
Diffstat (limited to 'src/drivers/X11')
-rw-r--r--src/drivers/X11/Fl_X11_Screen_Driver.cxx31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
index f2f5f3d4f..3cf368d2d 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -1211,23 +1211,38 @@ static bool is_name_in_list(const char *name, const char **list) {
}
-static bool use_monitors_xml(float &factor, int width, int height) {
- // read file $HOME/.config/monitors.xml, search configuration with given width & height,
+static bool use_xrdb_or_monitors_xml(float &factor, int width, int height) {
+ // First, try reading the Xft.dpi resource from command xrdb
+ bool found = false, in_config = false;
+ FILE *in = popen("xrdb -query", "r");
+ char path[FL_PATH_MAX], line[100], *p;
+ if (in) {
+ while (fgets(line, sizeof(line), in)) {
+ if ((p = strstr(line, "Xft.dpi:"))) {
+ int dpi = 96;
+ sscanf(p+8, "%d", &dpi);
+ factor = dpi / 96.;
+ found = true;
+ break;
+ }
+ }
+ pclose(in);
+ if (found) return true;
+ }
+ // Next, read file $HOME/.config/monitors.xml, search configuration with given width & height,
// read <scale>#</scale> data therein, and use it for factor
// return false if not found
- char path[FL_PATH_MAX], line[100], *p;
- bool found = false, in_config = false;
int w, h;
float f = 1;
p = getenv("HOME");
if (!p) return false;
strcpy(path, p);
strcat(path, "/.config/monitors.xml");
- FILE *in = fopen(path, "r");
+ in = fopen(path, "r");
if (!in) return false;
p = fgets(line, sizeof(line), in);
if (p && strstr(line, "<monitors version=\"2\">")) {
- while ( (!found) && fgets(line, sizeof(line), in)) {
+ while (fgets(line, sizeof(line), in)) {
if (strstr(line, "<configuration>")) in_config = true;
if (strstr(line, "</configuration>")) {in_config = false; f = 1;}
if (in_config && (p = strstr(line, "<scale>")) && strstr(p, "</scale>") ) {
@@ -1241,7 +1256,7 @@ static bool use_monitors_xml(float &factor, int width, int height) {
if (p && w == width && h == height) {
found = true;
factor = f;
- //fprintf(stderr, "%dx%d f=%.1f found=%d\n", w, h, f, found);
+ break;
}
}
}
@@ -1441,7 +1456,7 @@ float Fl_X11_Screen_Driver::desktop_scale_factor()
{
float factor = 1;
#if HAVE_DLSYM && HAVE_DLFCN_H
- if (!use_monitors_xml(factor, screens[0].width, screens[0].height)) {
+ if (!use_xrdb_or_monitors_xml(factor, screens[0].width, screens[0].height)) {
gnome_scale_factor(factor);
}
#endif