diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-03-11 16:20:29 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2019-03-11 16:20:29 +0100 |
| commit | 4e2ba8c888d650f566d43f58a525566c97f55a35 (patch) | |
| tree | 96da156f00820720ee66e371dc4731fa4312cc5c /src/drivers/X11 | |
| parent | 347581e3b4d6ee47a05c9dacba79684a623f6f0f (diff) | |
X11 platform: follow when the OS changes the Xft.dpi resource
Under gnome, Tweaks -> Fonts ->Scaling factor allows to change
the size of all fonts handled by gnome.
With that change, FLTK apps obey to changes to Xft.dpi.
Diffstat (limited to 'src/drivers/X11')
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 20 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 600a54584..deaaafdcf 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -52,6 +52,7 @@ protected: public: #if USE_XFT // scaling does not work without Xft + float current_xft_dpi; // current value of the Xft.dpi X resource 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;} diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index 7875cc3c1..d71ef7486 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -116,6 +116,7 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() Fl_X11_Screen_Driver *d = new Fl_X11_Screen_Driver(); #if USE_XFT for (int i = 0; i < MAX_SCREENS; i++) d->screens[i].scale = 1; + d->current_xft_dpi = 0.; // means the value of the Xft.dpi resource is still unknown #else secret_input_character = '*'; #endif @@ -1403,16 +1404,15 @@ static void* value_of_key_in_schema(const char **known, const char *schema, cons // set the desktop's default scaling value void Fl_X11_Screen_Driver::desktop_scale_factor() { - float factor = 1; - int dpi; - // Try getting the Xft.dpi resource value - char *s = XGetDefault(fl_display, "Xft", "dpi"); - if (s && sscanf(s, "%d", &dpi) == 1) { - factor = dpi / 96.; - // 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); + if (this->current_xft_dpi == 0.) { // Try getting the Xft.dpi resource value + char *s = XGetDefault(fl_display, "Xft", "dpi"); + if (s && sscanf(s, "%f", &(this->current_xft_dpi)) == 1) { + float factor = this->current_xft_dpi / 96.; + // 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); + } } } |
