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
This commit is contained in:
parent
a7a3c5b429
commit
d988930461
@ -175,8 +175,8 @@ public:
|
||||
void rescale_all_windows_from_screen(int screen, float f);
|
||||
static void transient_scale_display(float f, int nscreen);
|
||||
static int scale_handler(int event);
|
||||
virtual float desktop_scale_factor() {return 1;}
|
||||
float use_startup_scale_factor();
|
||||
virtual void desktop_scale_factor() {}
|
||||
void use_startup_scale_factor();
|
||||
enum APP_SCALING_CAPABILITY {
|
||||
NO_APP_SCALING = 0, ///< The platform does not support rescaling.
|
||||
SYSTEMWIDE_APP_SCALING, ///< The platform supports rescaling with the same factor for all screens.
|
||||
|
@ -434,20 +434,15 @@ int Fl_Screen_Driver::scale_handler(int event)
|
||||
|
||||
|
||||
// use the startup time scaling value
|
||||
float Fl_Screen_Driver::use_startup_scale_factor()
|
||||
void Fl_Screen_Driver::use_startup_scale_factor()
|
||||
{
|
||||
float factor;
|
||||
char *p = 0;
|
||||
char *p;
|
||||
desktop_scale_factor();
|
||||
if ((p = fl_getenv("FLTK_SCALING_FACTOR"))) {
|
||||
float factor = 1;
|
||||
sscanf(p, "%f", &factor);
|
||||
for (int i = 0; i < screen_count(); i++) scale(i, factor * scale(i));
|
||||
}
|
||||
else {
|
||||
factor = desktop_scale_factor();
|
||||
}
|
||||
// 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;
|
||||
return factor;
|
||||
}
|
||||
|
||||
|
||||
@ -457,10 +452,8 @@ void Fl_Screen_Driver::open_display()
|
||||
static bool been_here = false;
|
||||
if (!been_here) {
|
||||
been_here = true;
|
||||
int scount = screen_count(); // keep here
|
||||
if (rescalable()) {
|
||||
float factor = use_startup_scale_factor();
|
||||
if (factor) for (int i = 0; i < scount; i++) scale(i, factor);
|
||||
use_startup_scale_factor();
|
||||
Fl::add_handler(Fl_Screen_Driver::scale_handler);
|
||||
int mx, my;
|
||||
int ns = Fl::screen_driver()->get_mouse(mx, my);
|
||||
|
@ -548,8 +548,7 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() {
|
||||
const int PROCESS_PER_MONITOR_DPI_AWARE = 2;
|
||||
if (fl_SetProcessDpiAwareness) {
|
||||
HRESULT hr = fl_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
if (hr == S_OK) init_screen_scale_factors();
|
||||
else fl_SetProcessDpiAwareness = NULL;
|
||||
if (hr != S_OK) fl_SetProcessDpiAwareness = NULL;
|
||||
}
|
||||
}
|
||||
OleInitialize(0L);
|
||||
@ -558,11 +557,11 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() {
|
||||
}
|
||||
|
||||
|
||||
void Fl_WinAPI_Screen_Driver::init_screen_scale_factors() {
|
||||
void Fl_WinAPI_Screen_Driver::desktop_scale_factor() {
|
||||
typedef HRESULT(WINAPI * GetDpiForMonitor_type)(HMONITOR, int, UINT *, UINT *);
|
||||
HMODULE hMod = LoadLibrary("Shcore.DLL");
|
||||
GetDpiForMonitor_type fl_GetDpiForMonitor = NULL;
|
||||
if (hMod)
|
||||
if (hMod && fl_SetProcessDpiAwareness)
|
||||
fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(hMod, "GetDpiForMonitor");
|
||||
if (fl_GetDpiForMonitor) {
|
||||
for (int ns = 0; ns < screen_count(); ns++) {
|
||||
|
@ -1255,9 +1255,9 @@ static void react_to_screen_reconfiguration() {
|
||||
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();
|
||||
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);
|
||||
Fl::screen_driver()->rescale_all_windows_from_screen(screen, Fl::screen_driver()->scale(screen));
|
||||
}
|
||||
delete[] scales;
|
||||
#endif // USE_XFT
|
||||
|
@ -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.;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user