From b538dd545a5cef8931fe076089d3edc7b3daaa3b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 4 Aug 2026 13:42:38 -0500 Subject: [PATCH] Persist integer GDK_SCALE when monitor scale is fractional GTK only honors whole-number GDK_SCALE values, so persisting 1.6 or 1.25 verbatim left GTK apps without a usable scale. Round to the nearest whole factor when writing monitors.lua. Co-Authored-By: Claude Fable 5 --- bin/omarchy-hyprland-monitor-scaling | 7 +++++-- test/shell.d/monitor-scaling-test.sh | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bin/omarchy-hyprland-monitor-scaling b/bin/omarchy-hyprland-monitor-scaling index 24060ecc..240a1ea5 100755 --- a/bin/omarchy-hyprland-monitor-scaling +++ b/bin/omarchy-hyprland-monitor-scaling @@ -81,6 +81,9 @@ set_scale() { local height="$(echo "$monitor_info" | jq -r '.height')" local refresh_rate="$(echo "$monitor_info" | jq -r '.refreshRate')" local new_scale="$(clean_scale "$requested_scale" "$width" "$height")" + # GTK only honors integer GDK_SCALE values, so persist the nearest whole + # factor even when the monitor scale itself is fractional. + local new_gdk_scale="$(awk -v scale="$new_scale" 'BEGIN { printf "%d", int(scale + 0.5) }')" local monitor_lua="$HOME/.config/hypr/monitors.lua" hyprctl eval "hl.monitor({ output = \"$active_monitor\", mode = \"${width}x${height}@${refresh_rate}\", position = \"auto\", scale = $new_scale })" >/dev/null @@ -91,12 +94,12 @@ set_scale() { if [[ -f $monitor_lua ]] && grep -q '^local omarchy_monitor_scale = ' "$monitor_lua"; then sed -i -E \ -e "s|^local omarchy_monitor_scale = .*|local omarchy_monitor_scale = ${new_scale}|" \ - -e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = ${new_scale}|" \ + -e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = ${new_gdk_scale}|" \ "$monitor_lua" elif [[ -f $monitor_lua ]] && grep -Eq '^hl\.monitor\(\{ output = "", mode = "preferred", position = "auto", scale = ("auto"|[0-9.]+) \}\)' "$monitor_lua"; then sed -i -E \ -e "s|^(hl\.monitor\(\{ output = \"\", mode = \"preferred\", position = \"auto\", scale = )([^ ]+)( \}\))|\\1${new_scale}\\3|" \ - -e 's|^hl\.env\("GDK_SCALE", ".*"\)|hl.env("GDK_SCALE", "'"$new_scale"'")|' \ + -e 's|^hl\.env\("GDK_SCALE", ".*"\)|hl.env("GDK_SCALE", "'"$new_gdk_scale"'")|' \ "$monitor_lua" fi } diff --git a/test/shell.d/monitor-scaling-test.sh b/test/shell.d/monitor-scaling-test.sh index 4a0519cf..96f81171 100644 --- a/test/shell.d/monitor-scaling-test.sh +++ b/test/shell.d/monitor-scaling-test.sh @@ -68,8 +68,24 @@ write_monitor_config OMARCHY_TEST_MONITOR_SCALE=2 run_scaling 3 grep -F 'scale = 3' "$eval_out" >/dev/null || fail "monitor scaling explicit 3x remains available" grep -Fx 'local omarchy_monitor_scale = 3' "$monitor_lua" >/dev/null || fail "monitor scaling explicit 3x persists" +grep -Fx 'local omarchy_gdk_scale = 3' "$monitor_lua" >/dev/null || fail "monitor scaling explicit 3x persists GDK scale" pass "monitor scaling explicit 3x remains available" +# GTK only honors integer GDK_SCALE, so fractional monitor scales persist a +# rounded GDK scale. +write_monitor_config +OMARCHY_TEST_MONITOR_SCALE=2 run_scaling 1.6 +grep -F 'scale = 1.6' "$eval_out" >/dev/null || fail "monitor scaling explicit 1.6x remains available" +grep -Fx 'local omarchy_monitor_scale = 1.6' "$monitor_lua" >/dev/null || fail "monitor scaling explicit 1.6x persists" +grep -Fx 'local omarchy_gdk_scale = 2' "$monitor_lua" >/dev/null || fail "monitor scaling 1.6x persists integer GDK scale 2" +pass "monitor scaling 1.6x persists integer GDK scale 2" + +write_monitor_config +OMARCHY_TEST_MONITOR_SCALE=2 run_scaling 1.25 +grep -Fx 'local omarchy_monitor_scale = 1.25' "$monitor_lua" >/dev/null || fail "monitor scaling explicit 1.25x persists" +grep -Fx 'local omarchy_gdk_scale = 1' "$monitor_lua" >/dev/null || fail "monitor scaling 1.25x persists integer GDK scale 1" +pass "monitor scaling 1.25x persists integer GDK scale 1" + scale=$(OMARCHY_TEST_MONITOR_SCALE=3 run_scaling) [[ $scale == "3" ]] || fail "monitor scaling reports explicit 3x scale" "actual: $scale" pass "monitor scaling reports explicit 3x scale"