Fix for STR#3475: X11 platform, re-use current screen scaling factor when processing a screen reconfiguration event.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12939 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2018-06-08 11:31:30 +00:00
parent f3971319b9
commit bfac49015c
3 changed files with 52 additions and 13 deletions

View File

@ -170,7 +170,7 @@ public:
static int scale_handler(int event); static int scale_handler(int event);
virtual void init_workarea() {} virtual void init_workarea() {}
virtual float desktop_scale_factor() {return 1;} virtual float desktop_scale_factor() {return 1;}
void use_startup_scale_factor(); float use_startup_scale_factor();
enum APP_SCALING_CAPABILITY { enum APP_SCALING_CAPABILITY {
NO_APP_SCALING = 0, ///< The platform does not support rescaling. NO_APP_SCALING = 0, ///< The platform does not support rescaling.
SYSTEMWIDE_APP_SCALING, ///< The platform supports rescaling with the same factor for all screens. SYSTEMWIDE_APP_SCALING, ///< The platform supports rescaling with the same factor for all screens.

View File

@ -295,7 +295,7 @@ int Fl_Screen_Driver::input_widget_handle_key(int key, unsigned mods, unsigned s
void Fl_Screen_Driver::rescale_all_windows_from_screen(int screen, float f) void Fl_Screen_Driver::rescale_all_windows_from_screen(int screen, float f)
{ {
float old_f = this->scale(screen); float old_f = this->scale(screen);
if (f == old_f) return; //if (f == old_f) return;
this->scale(screen, f); this->scale(screen, f);
Fl_Graphics_Driver *d = Fl_Display_Device::display_device()->driver(); Fl_Graphics_Driver *d = Fl_Display_Device::display_device()->driver();
d->scale(f); d->scale(f);
@ -428,7 +428,7 @@ int Fl_Screen_Driver::scale_handler(int event)
// use the startup time scaling value // use the startup time scaling value
void Fl_Screen_Driver::use_startup_scale_factor() float Fl_Screen_Driver::use_startup_scale_factor()
{ {
float factor; float factor;
char *p = 0; char *p = 0;
@ -441,9 +441,7 @@ void Fl_Screen_Driver::use_startup_scale_factor()
else { else {
factor = desktop_scale_factor(); factor = desktop_scale_factor();
} }
if (factor) { return factor;
for (int i = 0; i < screen_count(); i++) scale(i, factor);
}
} }
@ -455,7 +453,8 @@ void Fl_Screen_Driver::open_display()
been_here = true; been_here = true;
screen_count(); // initialize, but ignore return value screen_count(); // initialize, but ignore return value
if (rescalable()) { if (rescalable()) {
use_startup_scale_factor(); float factor = use_startup_scale_factor();
for (int i = 0; i < screen_count(); i++) scale(i, factor);
Fl::add_handler(Fl_Screen_Driver::scale_handler); Fl::add_handler(Fl_Screen_Driver::scale_handler);
int mx, my; int mx, my;
int ns = Fl::screen_driver()->get_mouse(mx, my); int ns = Fl::screen_driver()->get_mouse(mx, my);

View File

@ -1220,6 +1220,51 @@ static KeySym fl_KeycodeToKeysym(Display *d, KeyCode k, unsigned i) {
return XKeycodeToKeysym(d, k, i); return XKeycodeToKeysym(d, k, i);
} }
#if USE_XRANDR
static void react_to_screen_reconfiguration() {
#if USE_XFT
// memorize previous screen sizes and scales
int old_count = Fl::screen_count();
int (*sizes)[4] = new int[old_count][4];
float *scales = new float[old_count];
for (int screen = 0; screen < old_count; screen++) {
Fl::screen_xywh(sizes[screen][0], sizes[screen][1], sizes[screen][2], sizes[screen][3], screen);
scales[screen] = Fl::screen_scale(screen);
}
#endif // USE_XFT
Fl::call_screen_init(); // compute new screen sizes
#if USE_XFT
// detect whether screen sizes were unchanged
bool nochange = (old_count == Fl::screen_count());
if (nochange) {
for (int screen = 0; screen < old_count; screen++) {
int X,Y,W,H;
Fl::screen_xywh(X,Y,W,H, screen);
X /= scales[screen];
Y /= scales[screen];
W /= scales[screen];
H /= scales[screen];
if (X != sizes[screen][0] || Y != sizes[screen][1] || W != sizes[screen][2] || H != sizes[screen][3]) {
nochange = false;
break;
}
}
}
delete[] sizes;
if (nochange) { // screen sizes did not change: re-use previous screen scale values
for (int screen = 0; screen < old_count; screen++)
Fl::screen_driver()->scale(screen, scales[screen]);
} else {
float factor = Fl::screen_driver()->use_startup_scale_factor();
for (int screen = 0; screen < Fl::screen_count(); screen++)
Fl::screen_driver()->rescale_all_windows_from_screen(screen, factor);
}
delete[] scales;
#endif // USE_XFT
}
#endif // USE_XRANDR
int fl_handle(const XEvent& thisevent) int fl_handle(const XEvent& thisevent)
{ {
XEvent xevent = thisevent; XEvent xevent = thisevent;
@ -1251,12 +1296,7 @@ int fl_handle(const XEvent& thisevent)
#if USE_XRANDR #if USE_XRANDR
if( XRRUpdateConfiguration_f && xevent.type == randrEventBase + RRScreenChangeNotify) { if( XRRUpdateConfiguration_f && xevent.type == randrEventBase + RRScreenChangeNotify) {
XRRUpdateConfiguration_f(&xevent); XRRUpdateConfiguration_f(&xevent);
Fl::call_screen_init(); react_to_screen_reconfiguration();
#if USE_XFT
float factor = Fl::screen_driver()->desktop_scale_factor();
for (int screen = 0; screen <= Fl::screen_count(); screen++)
Fl::screen_driver()->rescale_all_windows_from_screen(screen, factor);
#endif // USE_XFT
Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL); Fl::handle(FL_SCREEN_CONFIGURATION_CHANGED, NULL);
} }
#endif // USE_XRANDR #endif // USE_XRANDR