diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-02-19 14:54:34 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-02-19 14:54:34 +0100 |
| commit | 96867f831856e7baf421e4f2b5b28f62a08c3b81 (patch) | |
| tree | fdab7c1d0c095c51259fd12c92796a795d557338 /src/drivers/X11/Fl_X11_Screen_Driver.cxx | |
| parent | 11ed18a52e4b27c74d1aab3813aa41b0d1507d3f (diff) | |
X11 + gnome: improve detection of the current display scale factor
Gnome now seems to store the value of the display scale factor in file
$HOME/.config/monitor.xml. Previously, that value was readable with
the gsettings command.
The present commit uses the information found in that file
and reverts back to the gsettings command if that information is not found.
Diffstat (limited to 'src/drivers/X11/Fl_X11_Screen_Driver.cxx')
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index 28083d8ca..f2f5f3d4f 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -1211,10 +1211,14 @@ static bool is_name_in_list(const char *name, const char **list) { } -static bool use_monitors_xml(float &factor) { - // read file $HOME/.config/monitors.xml, search <scale>#</scale> data therein, and use it +static bool use_monitors_xml(float &factor, int width, int height) { + // 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; + bool found = false, in_config = false; + int w, h; + float f = 1; p = getenv("HOME"); if (!p) return false; strcpy(path, p); @@ -1223,11 +1227,22 @@ static bool use_monitors_xml(float &factor) { if (!in) return false; p = fgets(line, sizeof(line), in); if (p && strstr(line, "<monitors version=\"2\">")) { - while (fgets(line, sizeof(line), in)) { - if ( (p = strstr(line, "<scale>")) && strstr(p, "</scale>") ) { - p += 7; - sscanf(p, "%f", &factor); - if (factor == 2) { found = true; break; } + while ( (!found) && 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>") ) { + sscanf(p + 7, "%f", &f); + } + if ( in_config && (p = strstr(line, "<width>")) && strstr(p, "</width>") ) { + sscanf(p + 7, "%d", &w); + fgets(line, sizeof(line), in); + p = strstr(line, "<height>"); + if (p) sscanf(p+8, "%d", &h); + if (p && w == width && h == height) { + found = true; + factor = f; + //fprintf(stderr, "%dx%d f=%.1f found=%d\n", w, h, f, found); + } } } } @@ -1361,7 +1376,6 @@ static bool gnome_scale_factor(float& factor) { } if (ubuntu) { - if (use_monitors_xml(factor)) return true; gvar = value_of_key_in_schema(known, "com.ubuntu.user-interface", "scale-factor"); if (gvar) { found = true; @@ -1427,7 +1441,9 @@ float Fl_X11_Screen_Driver::desktop_scale_factor() { float factor = 1; #if HAVE_DLSYM && HAVE_DLFCN_H - gnome_scale_factor(factor); + if (!use_monitors_xml(factor, screens[0].width, screens[0].height)) { + gnome_scale_factor(factor); + } #endif return factor; } |
