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 | |
| 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')
| -rw-r--r-- | src/Fl_x.cxx | 28 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 20 |
3 files changed, 38 insertions, 11 deletions
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 212f14db2..0d63218cd 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -1267,6 +1267,28 @@ static void react_to_screen_reconfiguration() { } #endif // USE_XRANDR +#if USE_XFT +static void after_display_rescale(float *p_current_xft_dpi) { + FILE *pipe = popen("xrdb -query", "r"); + if (!pipe) return; + char line[100]; + while (fgets(line, sizeof(line), pipe) != NULL) { + if (memcmp(line, "Xft.dpi:", 8)) continue; + float dpi; + if (sscanf(line+8, "%f", &dpi) == 1) { + //fprintf(stderr," previous=%g dpi=%g \n", *p_current_xft_dpi, dpi); + if (fabs(dpi - *p_current_xft_dpi) > 0.01) { + *p_current_xft_dpi = dpi; + float f = dpi/96.; + for (int i = 0; i < Fl::screen_count(); i++) + Fl::screen_driver()->rescale_all_windows_from_screen(i, f); + } + } + break; + } + pclose(pipe); +} +#endif // USE_XFT int fl_handle(const XEvent& thisevent) { @@ -1305,7 +1327,11 @@ int fl_handle(const XEvent& thisevent) #endif // USE_XRANDR if (xevent.type == PropertyNotify && xevent.xproperty.atom == fl_NET_WORKAREA) { - ((Fl_X11_Screen_Driver*)Fl::screen_driver())->init_workarea(); + Fl_X11_Screen_Driver *d = (Fl_X11_Screen_Driver*)Fl::screen_driver(); + d->init_workarea(); +#if USE_XFT + after_display_rescale(&(d->current_xft_dpi)); +#endif // USE_XFT } switch (xevent.type) { 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); + } } } |
