mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-11-24 14:56:40 +00:00
Adjust default window sizes for fractional scaling on Windows
GTK3 only supports integer scaling, so at e.g. 125% or 250% system scaling the UI is rendered at 1x / 2x. Store the full system scale percentage and scale the default (glade) window sizes by the remaining fractional ratio, and increase the font size by the fractional amount. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
871cd51e8a
commit
cb5b1284be
11 files changed
+357
-13
No files matched your search
@@ -11,6 +11,8 @@ Copyright:
|
||||
|
||||
#include "gui_utils.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -191,4 +193,59 @@ bool gui_is_dark_theme_active()
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
/// Storage for Windows fractional scaling percentage (0 if no fractional scaling)
|
||||
int g_windows_fractional_scaling_percent = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int app_get_windows_fractional_scaling_percent()
|
||||
{
|
||||
return g_windows_fractional_scaling_percent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void app_set_windows_fractional_scaling_percent(int percent)
|
||||
{
|
||||
g_windows_fractional_scaling_percent = percent;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void app_apply_fractional_scaling_to_default_size(Gtk::Window* window, int config_size_w, int config_size_h)
|
||||
{
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size_w = config_size_w;
|
||||
int size_h = config_size_h;
|
||||
|
||||
// Apply fractional scaling adjustment on Windows if no custom size is configured
|
||||
// This compensates for GTK3's lack of fractional scaling support
|
||||
const int full_percent = g_windows_fractional_scaling_percent;
|
||||
if (full_percent > 0 && size_w == 0 && size_h == 0) {
|
||||
// Get the default size from glade and scale it
|
||||
int glade_w = 0, glade_h = 0;
|
||||
window->get_default_size(glade_w, glade_h);
|
||||
if (glade_w > 0 && glade_h > 0) {
|
||||
const double system_scale = static_cast<double>(full_percent) / 100.0;
|
||||
const int integer_ui_scale = full_percent / 100; // GTK3 uses floor (integer) scaling
|
||||
const double correction = system_scale / static_cast<double>(integer_ui_scale);
|
||||
size_w = static_cast<int>(std::lround(glade_w * correction));
|
||||
size_h = static_cast<int>(std::lround(glade_h * correction));
|
||||
}
|
||||
}
|
||||
|
||||
if (size_w > 0 && size_h > 0) {
|
||||
window->set_default_size(size_w, size_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @}
|
||||
Reference in new issue
Block a user