119 lines
4.0 KiB
Bash
119 lines
4.0 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"
|
|
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
|
|
}
|
|
|
|
write_internal_monitor_config() {
|
|
cat >"$monitor_lua" <<'LUA'
|
|
hl.monitor({ output = "eDP-1", mode = "preferred", position = "0x0", scale = 1.25 })
|
|
hl.monitor({ output = "", mode = "preferred", position = "auto-right", scale = 1 })
|
|
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=3 run_clamshell
|
|
grep -F 'scale = 2' "$eval_log" >/dev/null || fail "clamshell recovery ignores transient auto scale"
|
|
! grep -F 'scale = "auto"' "$eval_log" >/dev/null || fail "clamshell recovery does not apply auto scale"
|
|
[[ ! -f $scale_state ]] || fail "clamshell recovery does not remember transient scale"
|
|
pass "clamshell recovery ignores transient auto scale"
|
|
|
|
write_auto_monitor_config
|
|
: >"$eval_log"
|
|
OMARCHY_TEST_INTERNAL_SCALE=2 run_clamshell
|
|
! grep -F 'scale = ' "$eval_log" >/dev/null || fail "clamshell recovery does not reapply matching scale"
|
|
pass "clamshell recovery avoids redundant scale apply"
|
|
|
|
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"
|
|
|
|
write_internal_monitor_config
|
|
: >"$eval_log"
|
|
OMARCHY_TEST_INTERNAL_DISABLED=true run_clamshell
|
|
grep -F 'position = "0x0"' "$eval_log" >/dev/null || fail "clamshell recovery uses configured internal position"
|
|
grep -F 'scale = 1.25' "$eval_log" >/dev/null || fail "clamshell recovery uses configured internal scale"
|
|
pass "clamshell recovery uses configured internal monitor rule"
|