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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
caeffdc27b
commit
b538dd545a
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user