Windows: Re-enable dpi awareness and scale up the font in case of fractional scaling.

This commit is contained in:
Alexander Shaduri
2024-11-06 13:57:59 +04:00
parent 1deffe6a98
commit 746ebf9b02
2 changed files with 25 additions and 3 deletions
+24 -2
View File
@@ -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<int>(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()) {
+1 -1
View File
@@ -28,7 +28,7 @@ Copyright:
(e.g. 250%), making them too small on such displays -->
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>false</dpiAware>
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>