diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-01 11:11:15 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2024-03-01 11:11:15 +0100 |
| commit | 0eef561e7b9bf54b764e7e7254b98530aac5384f (patch) | |
| tree | 09755aca065c60ee7f7a2a1f430841f640221765 | |
| parent | 5f2069871d00575717d998a2e1e3d398ec9137ef (diff) | |
Windows: make Ctrl/+/-/0/ scaling system-wide if all screens have same DPI
| -rw-r--r-- | src/Fl.cxx | 9 | ||||
| -rw-r--r-- | src/Fl_Screen_Driver.cxx | 14 | ||||
| -rw-r--r-- | src/Fl_win32.cxx | 12 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 4 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx | 1 |
5 files changed, 32 insertions, 8 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx index c9a2972d2..dcf4be3bc 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -2266,8 +2266,13 @@ float Fl::screen_scale(int n) { Also sets the scale factor value of all windows mapped to screen number \p n, if any. */ void Fl::screen_scale(int n, float factor) { - if (!Fl::screen_scaling_supported() || n < 0 || n >= Fl::screen_count()) return; - Fl::screen_driver()->rescale_all_windows_from_screen(n, factor); + Fl_Screen_Driver::APP_SCALING_CAPABILITY capability = Fl::screen_driver()->rescalable(); + if (!capability || n < 0 || n >= Fl::screen_count()) return; + if (capability == Fl_Screen_Driver::SYSTEMWIDE_APP_SCALING) { + for (int s = 0; s < Fl::screen_count(); s++) { + Fl::screen_driver()->rescale_all_windows_from_screen(s, factor); + } + } else Fl::screen_driver()->rescale_all_windows_from_screen(n, factor); } /** diff --git a/src/Fl_Screen_Driver.cxx b/src/Fl_Screen_Driver.cxx index 623db30f6..fbb4aa4c2 100644 --- a/src/Fl_Screen_Driver.cxx +++ b/src/Fl_Screen_Driver.cxx @@ -386,8 +386,7 @@ void Fl_Screen_Driver::rescale_all_windows_from_screen(int screen, float f) int i = 0, count = 0; // count top-level windows, except transient scale-displaying window Fl_Window *win = Fl::first_window(); while (win) { - if (!win->parent() && - (Fl_Window_Driver::driver(win)->screen_num() == screen || rescalable() == SYSTEMWIDE_APP_SCALING) && + if (!win->parent() && (Fl_Window_Driver::driver(win)->screen_num() == screen) && win->user_data() != &Fl_Screen_Driver::transient_scale_display) { count++; } @@ -398,8 +397,7 @@ void Fl_Screen_Driver::rescale_all_windows_from_screen(int screen, float f) Fl_Window **win_array = new Fl_Window*[count]; win = Fl::first_window(); // memorize all top-level windows while (win) { - if (!win->parent() && - (Fl_Window_Driver::driver(win)->screen_num() == screen || rescalable() == SYSTEMWIDE_APP_SCALING) && + if (!win->parent() && (Fl_Window_Driver::driver(win)->screen_num() == screen) && win->user_data() != &Fl_Screen_Driver::transient_scale_display) { win_array[i++] = win; } @@ -541,7 +539,13 @@ int Fl_Screen_Driver::scale_handler(int event) f = scaling_values[i]; } if (f == old_f) return 1; - screen_dr->rescale_all_windows_from_screen(screen, f * initial_scale); + if (screen_dr->rescalable() == SYSTEMWIDE_APP_SCALING) { + for (int i = 0; i < Fl::screen_count(); i++) { + screen_dr->rescale_all_windows_from_screen(i, f * initial_scale); + } + } else { + screen_dr->rescale_all_windows_from_screen(screen, f * initial_scale); + } Fl_Screen_Driver::transient_scale_display(f, screen); Fl::handle(FL_ZOOM_EVENT, NULL); return 1; diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index a88a57c19..9aa564650 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -521,6 +521,16 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() { } +void Fl_WinAPI_Screen_Driver::update_scaling_capability() { + scaling_capability = SYSTEMWIDE_APP_SCALING; + for (int ns = 1; ns < screen_count(); ns++) { + if (scale(ns) != scale(0)) { + scaling_capability = PER_SCREEN_APP_SCALING; + break; + } + } +} + void Fl_WinAPI_Screen_Driver::desktop_scale_factor() { typedef HRESULT(WINAPI * GetDpiForMonitor_type)(HMONITOR, int, UINT *, UINT *); typedef HMONITOR(WINAPI * MonitorFromRect_type)(LPCRECT, DWORD); @@ -544,6 +554,7 @@ void Fl_WinAPI_Screen_Driver::desktop_scale_factor() { scale(ns, dpiX / 96.f); // fprintf(LOG, "desktop_scale_factor ns=%d factor=%.2f dpi=%.1f\n", ns, scale(ns), dpi[ns][0]); } + update_scaling_capability(); } @@ -1207,6 +1218,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar float old_f = float(r.right) / window->w(); Fl::screen_driver()->scale(ns, f); Fl_Window_Driver::driver(window)->resize_after_scale_change(ns, old_f, f); + sd->update_scaling_capability(); } return 0; } diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 3bbd51d59..816b667f6 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -41,6 +41,8 @@ protected: public: float dpi[MAX_SCREENS][2]; + enum APP_SCALING_CAPABILITY scaling_capability; + void update_scaling_capability(); Fl_WinAPI_Screen_Driver(); // --- display management int visual(int flags) FL_OVERRIDE; @@ -72,7 +74,7 @@ public: void open_display_platform() FL_OVERRIDE; void offscreen_size(Fl_Offscreen off, int &width, int &height) FL_OVERRIDE; APP_SCALING_CAPABILITY rescalable() FL_OVERRIDE { - return PER_SCREEN_APP_SCALING; + return scaling_capability; } float scale(int n) FL_OVERRIDE { return scale_of_screen[n]; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx index 452815afb..83f8f8973 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx @@ -48,6 +48,7 @@ static Fl_Text_Editor::Key_Binding extra_bindings[] = { Fl_WinAPI_Screen_Driver::Fl_WinAPI_Screen_Driver() : Fl_Screen_Driver() { text_editor_extra_key_bindings = extra_bindings; for (int i = 0; i < MAX_SCREENS; i++) scale_of_screen[i] = 1; + scaling_capability = SYSTEMWIDE_APP_SCALING; } int Fl_WinAPI_Screen_Driver::visual(int flags) |
