mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-11-24 14:56:40 +00:00
Scaling: Fix sub-100% scale handling, test real helpers
- Treat scales below 100% as non-fractional, avoiding a division by zero in the correction ratio and a bogus font size increase. - Add app_get_fractional_scaling_part_percent() and use it in gsc_init. - Move scaling tests to applib_tests and test the actual helper functions instead of duplicated inline math; remove the gui_tests target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb5b1284be
commit
08d200af94
9 files changed
+233
-271
No files matched your search
@@ -12,6 +12,7 @@ Copyright:
|
||||
#include "gui_utils.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
|
||||
|
||||
namespace {
|
||||
@@ -202,6 +203,59 @@ namespace {
|
||||
|
||||
|
||||
|
||||
bool app_is_fractional_scaling(int full_scale_percent)
|
||||
{
|
||||
// Scales below 100% are not handled (GTK3 never scales below 1x).
|
||||
return full_scale_percent > 100 && full_scale_percent % 100 != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int app_get_fractional_scaling_part_percent(int full_scale_percent)
|
||||
{
|
||||
if (!app_is_fractional_scaling(full_scale_percent)) {
|
||||
return 0;
|
||||
}
|
||||
return full_scale_percent % 100; // 250 -> 50, 125 -> 25
|
||||
}
|
||||
|
||||
|
||||
|
||||
double app_compute_fractional_scaling_correction(int full_scale_percent)
|
||||
{
|
||||
if (!app_is_fractional_scaling(full_scale_percent)) {
|
||||
return 0.0;
|
||||
}
|
||||
const double system_scale = static_cast<double>(full_scale_percent) / 100.0;
|
||||
const int integer_ui_scale = full_scale_percent / 100; // GTK3 uses floor (integer) scaling; >= 1 here
|
||||
return system_scale / static_cast<double>(integer_ui_scale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<int, int> app_apply_fractional_scaling_to_size(int base_w, int base_h, double correction)
|
||||
{
|
||||
if (correction <= 0.0 || base_w <= 0 || base_h <= 0) {
|
||||
return {base_w, base_h};
|
||||
}
|
||||
return {
|
||||
static_cast<int>(std::lround(base_w * correction)),
|
||||
static_cast<int>(std::lround(base_h * correction))
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
int app_compute_scaling_percent_from_dpi(double h_ppi)
|
||||
{
|
||||
if (h_ppi <= 0.0) {
|
||||
return 0;
|
||||
}
|
||||
return static_cast<int>(std::lround(h_ppi / 96.0 * 100.0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int app_get_windows_fractional_scaling_percent()
|
||||
{
|
||||
return g_windows_fractional_scaling_percent;
|
||||
@@ -232,13 +286,8 @@ void app_apply_fractional_scaling_to_default_size(Gtk::Window* window, int confi
|
||||
// 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));
|
||||
}
|
||||
const double correction = app_compute_fractional_scaling_correction(full_percent);
|
||||
std::tie(size_w, size_h) = app_apply_fractional_scaling_to_size(glade_w, glade_h, correction);
|
||||
}
|
||||
|
||||
if (size_w > 0 && size_h > 0) {
|
||||
|
||||
Reference in new issue
Block a user