From 96867f831856e7baf421e4f2b5b28f62a08c3b81 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 19 Feb 2019 14:54:34 +0100 Subject: 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. --- src/drivers/X11/Fl_X11_Screen_Driver.cxx | 36 +++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src') 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 # 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 # 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, "")) { - while (fgets(line, sizeof(line), in)) { - if ( (p = strstr(line, "")) && strstr(p, "") ) { - p += 7; - sscanf(p, "%f", &factor); - if (factor == 2) { found = true; break; } + while ( (!found) && fgets(line, sizeof(line), in)) { + if (strstr(line, "")) in_config = true; + if (strstr(line, "")) {in_config = false; f = 1;} + if (in_config && (p = strstr(line, "")) && strstr(p, "") ) { + sscanf(p + 7, "%f", &f); + } + if ( in_config && (p = strstr(line, "")) && strstr(p, "") ) { + sscanf(p + 7, "%d", &w); + fgets(line, sizeof(line), in); + p = strstr(line, ""); + 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; } -- cgit v1.2.3