mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-26 05:45:35 +00:00
Windows: Re-enable dpi awareness and scale up the font in case of fractional scaling.
This commit is contained in:
+24
-2
@@ -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()) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user