summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-03-06 11:10:37 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-03-06 11:10:37 +0100
commitd988930461b449f8e0c29507048e3a3b205504d7 (patch)
treee55c5f117683397b75dde1ac7fc94dd5048e3434 /src/drivers
parenta7a3c5b4298a2f23de5deba7cfb87a73f4eec279 (diff)
Process env var FLTK_SCALING_FACTOR consistently across platforms.
The procedure to set screen scaling factors becomes: 1) each screen scaling factor is set to 1 2) the OS is queried according to each platform to get screen scaling factor values 3) The value of FLTK_SCALING_FACTOR, if present, is used to multiply scaling factors
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx1
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H3
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx5
-rw-r--r--src/drivers/X11/Fl_X11_Screen_Driver.H2
-rw-r--r--src/drivers/X11/Fl_X11_Screen_Driver.cxx26
5 files changed, 21 insertions, 16 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index ec24bc705..f701df93c 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -78,6 +78,7 @@ static Fl_Text_Editor::Key_Binding extra_bindings[] = {
Fl_Cocoa_Screen_Driver::Fl_Cocoa_Screen_Driver() {
text_editor_extra_key_bindings = extra_bindings;
+ scale_ = 1.;
}
diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H
index c86124a0e..82205cca7 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H
@@ -42,7 +42,6 @@ protected:
static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM);
BOOL screen_cb(HMONITOR mon, HDC, LPRECT r);
int get_mouse_unscaled(int &mx, int &my);
- void init_screen_scale_factors();
public:
Fl_WinAPI_Screen_Driver() : Fl_Screen_Driver() {
@@ -92,7 +91,7 @@ public:
virtual void scale(int n, float f) {
scale_of_screen[n] = f;
}
- virtual float desktop_scale_factor();
+ virtual void desktop_scale_factor();
};
diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
index cf5f30f5f..147933446 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
@@ -158,11 +158,6 @@ void Fl_WinAPI_Screen_Driver::init()
}
-float Fl_WinAPI_Screen_Driver::desktop_scale_factor() {
- return 0; //indicates each screen has already been assigned its scale factor value
-}
-
-
void Fl_WinAPI_Screen_Driver::screen_work_area(int &X, int &Y, int &W, int &H, int n)
{
if (num_screens < 0) init();
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H
index 65432d860..600a54584 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.H
+++ b/src/drivers/X11/Fl_X11_Screen_Driver.H
@@ -55,7 +55,7 @@ public:
virtual APP_SCALING_CAPABILITY rescalable() { return PER_SCREEN_APP_SCALING; }
virtual float scale(int n) {return screens[n].scale;}
virtual void scale(int n, float f) { screens[n].scale = f;}
- virtual float desktop_scale_factor();
+ virtual void desktop_scale_factor();
int screen_num_unscaled(int x, int y);
#endif
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
index 1afbebacd..80bf8eca7 100644
--- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -1435,23 +1435,33 @@ static bool gnome_scale_factor(float& factor) {
#endif // HAVE_DLSYM && HAVE_DLFCN_H
-// return the desktop's default scaling value
-float Fl_X11_Screen_Driver::desktop_scale_factor()
+// set the desktop's default scaling value
+void Fl_X11_Screen_Driver::desktop_scale_factor()
{
+ float factor = 1;
+ bool doit = false;
// First, try getting the Xft.dpi resource value
char *s = XGetDefault(fl_display, "Xft", "dpi");
if (s) {
int dpi = 96;
sscanf(s, "%d", &dpi);
- return dpi / 96.;
- }
- float factor = 1;
- if (!usemonitors_xml(factor, screens[0].width, screens[0].height)) {
+ factor = dpi / 96.;
+ doit = true;
+ } else {
+ screen_count(); // keep here
+ doit = usemonitors_xml(factor, screens[0].width, screens[0].height);
#if HAVE_DLSYM && HAVE_DLFCN_H
- gnome_scale_factor(factor);
+ if (!doit) {
+ doit = gnome_scale_factor(factor);
+ }
#endif
}
- return factor;
+ if (doit) {
+ // checks to prevent potential crash (factor <= 0) or very large factors
+ if (factor < 0.25) factor = 0.25;
+ else if (factor > 10.0) factor = 10.0;
+ for (int i = 0; i < screen_count(); i++) scale(i, factor);
+ }
}
#endif // USE_XFT