Preserve internal scale during monitor recovery
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
#!/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"
|
||||
home_dir="$test_tmp/home"
|
||||
monitor_lua="$home_dir/.config/hypr/monitors.lua"
|
||||
eval_log="$test_tmp/hyprctl-eval.log"
|
||||
state_dir="$home_dir/.local/state/omarchy/toggles/hypr"
|
||||
scale_state="$state_dir/internal-monitor-scale"
|
||||
|
||||
mkdir -p "$stub_bin" "$home_dir/.config/hypr"
|
||||
|
||||
cat >"$stub_bin/hyprctl" <<'SH'
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $1 == "monitors" && $2 == "all" && $3 == "-j" ]]; then
|
||||
if [[ ${OMARCHY_TEST_INTERNAL_DISABLED:-false} == "true" ]]; then
|
||||
printf '[{"name":"eDP-1","disabled":true,"scale":null}]'
|
||||
else
|
||||
printf '[{"name":"eDP-1","disabled":false,"scale":%s}]' "${OMARCHY_TEST_INTERNAL_SCALE:-2}"
|
||||
fi
|
||||
elif [[ $1 == "eval" ]]; then
|
||||
printf '%s\n' "$2" >>"$OMARCHY_TEST_HYPRCTL_EVAL_LOG"
|
||||
elif [[ $1 == "reload" ]]; then
|
||||
printf 'reload\n' >>"$OMARCHY_TEST_HYPRCTL_EVAL_LOG"
|
||||
elif [[ $1 == "dispatch" ]]; then
|
||||
printf 'dispatch %s\n' "$2" >>"$OMARCHY_TEST_HYPRCTL_EVAL_LOG"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
SH
|
||||
|
||||
cat >"$stub_bin/omarchy-hyprland-monitor-internal" <<'SH'
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
SH
|
||||
|
||||
cat >"$stub_bin/omarchy-hyprland-monitor-internal-mirror" <<'SH'
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
SH
|
||||
|
||||
cat >"$stub_bin/omarchy-hyprland-monitor-external-active" <<'SH'
|
||||
#!/bin/bash
|
||||
[[ ${OMARCHY_TEST_EXTERNAL_ACTIVE:-false} == "true" ]]
|
||||
SH
|
||||
|
||||
cat >"$stub_bin/omarchy-hw-clamshell" <<'SH'
|
||||
#!/bin/bash
|
||||
[[ ${OMARCHY_TEST_CLAMSHELL:-false} == "true" ]]
|
||||
SH
|
||||
|
||||
chmod +x "$stub_bin"/*
|
||||
|
||||
write_auto_monitor_config() {
|
||||
cat >"$monitor_lua" <<'LUA'
|
||||
local omarchy_gdk_scale = 2
|
||||
local omarchy_monitor_scale = "auto"
|
||||
LUA
|
||||
}
|
||||
|
||||
run_clamshell() {
|
||||
HOME="$home_dir" \
|
||||
PATH="$stub_bin:$PATH" \
|
||||
OMARCHY_TEST_HYPRCTL_EVAL_LOG="$eval_log" \
|
||||
OMARCHY_TEST_INTERNAL_SCALE="${OMARCHY_TEST_INTERNAL_SCALE:-2}" \
|
||||
OMARCHY_TEST_INTERNAL_DISABLED="${OMARCHY_TEST_INTERNAL_DISABLED:-false}" \
|
||||
OMARCHY_TEST_EXTERNAL_ACTIVE="${OMARCHY_TEST_EXTERNAL_ACTIVE:-false}" \
|
||||
OMARCHY_TEST_CLAMSHELL="${OMARCHY_TEST_CLAMSHELL:-false}" \
|
||||
"$ROOT/bin/omarchy-hyprland-monitor-clamshell"
|
||||
}
|
||||
|
||||
write_auto_monitor_config
|
||||
: >"$eval_log"
|
||||
OMARCHY_TEST_INTERNAL_SCALE=2 run_clamshell
|
||||
grep -F 'scale = 2' "$eval_log" >/dev/null || fail "clamshell recovery uses current internal scale instead of auto"
|
||||
! grep -F 'scale = "auto"' "$eval_log" >/dev/null || fail "clamshell recovery does not apply auto scale"
|
||||
[[ -f $scale_state ]] || fail "clamshell recovery remembers current internal scale"
|
||||
[[ $(<"$scale_state") == "2" ]] || fail "clamshell recovery remembers current internal scale value"
|
||||
pass "clamshell recovery uses current internal scale instead of auto"
|
||||
|
||||
write_auto_monitor_config
|
||||
: >"$eval_log"
|
||||
OMARCHY_TEST_INTERNAL_SCALE=1.6 OMARCHY_TEST_EXTERNAL_ACTIVE=true OMARCHY_TEST_CLAMSHELL=true run_clamshell
|
||||
[[ -f $scale_state ]] || fail "clamshell disable remembers internal scale"
|
||||
[[ $(<"$scale_state") == "1.6" ]] || fail "clamshell disable remembers internal scale value"
|
||||
pass "clamshell disable remembers internal scale"
|
||||
|
||||
: >"$eval_log"
|
||||
OMARCHY_TEST_INTERNAL_DISABLED=true run_clamshell
|
||||
grep -F 'scale = 1.6' "$eval_log" >/dev/null || fail "clamshell recovery uses remembered internal scale"
|
||||
! grep -F 'scale = "auto"' "$eval_log" >/dev/null || fail "clamshell recovery avoids auto after disabled internal display"
|
||||
pass "clamshell recovery uses remembered internal scale"
|
||||
Reference in New Issue
Block a user