mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 06:14:28 +08:00
Thanks to Mike Qin for finding how to query the possibly changed DPI value of an X11 display while an FLTK app keeps running without running an external command in a pipe.
This commit is contained in:
+12
-16
@@ -1215,24 +1215,20 @@ static void react_to_screen_reconfiguration() {
|
|||||||
|
|
||||||
#if USE_XFT
|
#if USE_XFT
|
||||||
static void after_display_rescale(float *p_current_xft_dpi) {
|
static void after_display_rescale(float *p_current_xft_dpi) {
|
||||||
FILE *pipe = popen("xrdb -query", "r");
|
Display *new_dpy = XOpenDisplay(XDisplayString(fl_display));
|
||||||
if (!pipe) return;
|
if (!new_dpy) return;
|
||||||
char line[100];
|
char *s = XGetDefault(new_dpy, "Xft", "dpi");
|
||||||
while (fgets(line, sizeof(line), pipe) != NULL) {
|
float dpi;
|
||||||
if (memcmp(line, "Xft.dpi:", 8)) continue;
|
if (s && sscanf(s, "%f", &dpi) == 1) {
|
||||||
float dpi;
|
//printf("%s previous=%g dpi=%g \n", s, *p_current_xft_dpi, dpi);
|
||||||
if (sscanf(line+8, "%f", &dpi) == 1) {
|
if (fabs(dpi - *p_current_xft_dpi) > 0.1) {
|
||||||
//fprintf(stderr," previous=%g dpi=%g \n", *p_current_xft_dpi, dpi);
|
*p_current_xft_dpi = dpi;
|
||||||
if (fabs(dpi - *p_current_xft_dpi) > 0.01) {
|
float f = dpi / 96.;
|
||||||
*p_current_xft_dpi = dpi;
|
for (int i = 0; i < Fl::screen_count(); i++)
|
||||||
float f = dpi/96.;
|
Fl::screen_driver()->rescale_all_windows_from_screen(i, f, f);
|
||||||
for (int i = 0; i < Fl::screen_count(); i++)
|
|
||||||
Fl::screen_driver()->rescale_all_windows_from_screen(i, f, f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
pclose(pipe);
|
XCloseDisplay(new_dpy);
|
||||||
}
|
}
|
||||||
#endif // USE_XFT
|
#endif // USE_XFT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user