From 746ebf9b028a6a84996a66efb807c96f5498f615 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Wed, 6 Nov 2024 13:57:59 +0400 Subject: [PATCH] Windows: Re-enable dpi awareness and scale up the font in case of fractional scaling. --- src/gui/gsc_init.cpp | 26 ++++++++++++++++++++++++-- src/gui/gsmartcontrol.exe.in.manifest | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/gui/gsc_init.cpp b/src/gui/gsc_init.cpp index f0f8339..ddff9fc 100644 --- a/src/gui/gsc_init.cpp +++ b/src/gui/gsc_init.cpp @@ -479,8 +479,6 @@ bool app_init_and_loop(int& argc, char**& argv) } } - - // Windows "Classic" theme is broken under GTK+3's "win32" theme. // Make sure we fall back to Adwaita (which works, but looks non-native) // for platforms which support "Classic" theme - Windows Server and Windows Vista / 7. @@ -501,6 +499,30 @@ bool app_init_and_loop(int& argc, char**& argv) } } + // The application is dpi-aware in Windows. + // However, Gtk3 does not support fractional scaling, so at 250% scaling in system settings, the UI will use 200%. + // + if constexpr(BuildEnv::is_kernel_family_windows()) { + double h_ppi = 0; + #if _WIN32 + // Get system DPI (we don't support per-monitor dpi) + HDC screen = GetDC(nullptr); + h_ppi = GetDeviceCaps(screen, LOGPIXELSX); + ReleaseDC(nullptr, screen); + #endif + if (h_ppi > 0) { + const double scale = h_ppi / 96.0; + debug_out_info("app", "Windows system DPI: " << h_ppi << ", scale: " << scale << "\n"); + const int fraction_percent = static_cast(std::round(scale * 100)) % 100; + if (fraction_percent != 0) { // fractional scaling + // Increase the font size by fraction + debug_out_dump("app", "Fractional scaling detected, increasing font size by " << fraction_percent << "%.\n"); + Gtk::Settings::get_default()->property_gtk_font_name() + .set_value("Segoe UI " + hz::number_to_string_nolocale(9 * (1. + fraction_percent/100.))); + } + } + } + // Set default icon for all windows. // Win32 version has its icon compiled-in, so no need to set it there. if constexpr(BuildEnv::is_kernel_family_windows()) { diff --git a/src/gui/gsmartcontrol.exe.in.manifest b/src/gui/gsmartcontrol.exe.in.manifest index 154b874..4596d0d 100644 --- a/src/gui/gsmartcontrol.exe.in.manifest +++ b/src/gui/gsmartcontrol.exe.in.manifest @@ -28,7 +28,7 @@ Copyright: (e.g. 250%), making them too small on such displays --> - false + true