Hyprland can report a scale set to 3 as something like 3.0000000000000004. The previous directional comparison treated that as above the 3 preset, so Super+Alt+Slash (scale down) would stay at 3 instead of reaching 2. Snap the reported scale to the nearest preset first, then step up/down. Add a regression test for the floating-point case.
75 lines
2.8 KiB
Bash
75 lines
2.8 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
|
|
|
test_tmp=$(mktemp -d)
|
|
trap 'rm -rf "$test_tmp"' EXIT
|
|
|
|
stub_bin="$test_tmp/bin"
|
|
eval_out="$test_tmp/hyprctl-eval"
|
|
home_dir="$test_tmp/home"
|
|
monitor_lua="$home_dir/.config/hypr/monitors.lua"
|
|
scale_log="$home_dir/.local/state/omarchy/monitor-scaling.log"
|
|
|
|
mkdir -p "$stub_bin" "$home_dir/.config/hypr"
|
|
|
|
cat >"$stub_bin/hyprctl" <<'SH'
|
|
#!/bin/bash
|
|
|
|
if [[ $1 == "monitors" && $2 == "-j" ]]; then
|
|
printf '[{"name":"eDP-1","focused":true,"scale":%s,"width":2880,"height":1800,"refreshRate":120.0}]' "${OMARCHY_TEST_MONITOR_SCALE:-2}"
|
|
elif [[ $1 == "eval" ]]; then
|
|
printf '%s\n' "$2" >"$OMARCHY_TEST_HYPRCTL_EVAL_OUT"
|
|
else
|
|
exit 1
|
|
fi
|
|
SH
|
|
chmod +x "$stub_bin/hyprctl"
|
|
|
|
write_monitor_config() {
|
|
cat >"$monitor_lua" <<'LUA'
|
|
local omarchy_gdk_scale = 2
|
|
local omarchy_monitor_scale = 2
|
|
LUA
|
|
}
|
|
|
|
run_scaling() {
|
|
HOME="$home_dir" \
|
|
XDG_STATE_HOME="$home_dir/.local/state" \
|
|
PATH="$stub_bin:$PATH" \
|
|
OMARCHY_TEST_HYPRCTL_EVAL_OUT="$eval_out" \
|
|
OMARCHY_TEST_MONITOR_SCALE="${OMARCHY_TEST_MONITOR_SCALE:-2}" \
|
|
"$ROOT/bin/omarchy-hyprland-monitor-scaling" "$@"
|
|
}
|
|
|
|
write_monitor_config
|
|
OMARCHY_TEST_MONITOR_SCALE=2 run_scaling up
|
|
grep -F 'scale = 3' "$eval_out" >/dev/null || fail "monitor scaling up reaches 3x"
|
|
grep -Fx 'local omarchy_monitor_scale = 3' "$monitor_lua" >/dev/null || fail "monitor scaling up persists 3x"
|
|
grep -F $'requested=up\tcurrent=2\tnew=3\tmonitor=eDP-1' "$scale_log" >/dev/null || fail "monitor scaling up writes audit log"
|
|
pass "monitor scaling up reaches 3x"
|
|
|
|
write_monitor_config
|
|
OMARCHY_TEST_MONITOR_SCALE=3 run_scaling down
|
|
grep -F 'scale = 2' "$eval_out" >/dev/null || fail "monitor scaling down recovers 3x to 2x"
|
|
grep -Fx 'local omarchy_monitor_scale = 2' "$monitor_lua" >/dev/null || fail "monitor scaling down persists 2x from 3x"
|
|
pass "monitor scaling down recovers 3x to 2x"
|
|
|
|
write_monitor_config
|
|
OMARCHY_TEST_MONITOR_SCALE=3.0000000000000004 run_scaling down
|
|
grep -F 'scale = 2' "$eval_out" >/dev/null || fail "monitor scaling down snaps floating point 3x to 2x"
|
|
grep -Fx 'local omarchy_monitor_scale = 2' "$monitor_lua" >/dev/null || fail "monitor scaling down persists 2x from floating point 3x"
|
|
pass "monitor scaling down snaps floating point 3x to 2x"
|
|
|
|
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"
|
|
pass "monitor scaling explicit 3x remains available"
|
|
|
|
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"
|