Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/omarchy-hyprland-monitor-external-active
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# omarchy:summary=Returns true when Hyprland has an active external monitor
# omarchy:hidden=true

hyprctl monitors all -j | jq -e '.[] | select(.name | test("^(eDP|LVDS|DSI)-") | not) | select(.disabled == false)' >/dev/null 2>&1
# Hyprland creates FALLBACK when no real output is active. Counting it as an
# external monitor prevents recovery of the disabled laptop panel after undocking.
hyprctl monitors all -j | jq -e '.[] | select(.name | test("^(eDP|LVDS|DSI)-") | not) | select(.name != "FALLBACK") | select(.disabled == false)' >/dev/null 2>&1
69 changes: 69 additions & 0 deletions test/shell.d/monitor-fallback-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

require_command jq
temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT
mkdir -p "$temp_dir/bin"
export MONITOR_FIXTURE="$temp_dir/monitors.json"
export MONITOR_ACTIONS="$temp_dir/actions"
export PATH="$temp_dir/bin:$ROOT/bin:$PATH"

cat >"$temp_dir/bin/hyprctl" <<'SH'
#!/bin/bash
if [[ $1 == "monitors" ]]; then
[[ $* == "monitors all -j" ]] || exit 1
cat "$MONITOR_FIXTURE"
else
printf '%s\n' "$*" >>"$MONITOR_ACTIONS"
fi
SH
cat >"$temp_dir/bin/omarchy-hyprland-toggle-enabled" <<'SH'
#!/bin/bash
exit 0
SH
cat >"$temp_dir/bin/omarchy-hyprland-toggle" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >>"$MONITOR_ACTIONS"
SH
chmod +x "$temp_dir/bin/"*

cat >"$MONITOR_FIXTURE" <<'JSON'
[
{"name":"eDP-2","disabled":true},
{"name":"FALLBACK","disabled":false}
]
JSON
if omarchy-hyprland-monitor-external-active; then
fail "FALLBACK does not count as an external monitor"
fi
omarchy-hyprland-monitor-internal recover
grep -Fx 'internal-monitor-disable off' "$MONITOR_ACTIONS" >/dev/null || fail "undocking clears the internal display disable flag"
grep -F 'dpms' "$MONITOR_ACTIONS" >/dev/null || fail "undocking wakes the recovered display"
pass "disabled laptop panel recovers when only FALLBACK remains"

for connector in eDP-1 LVDS-1 DSI-1; do
printf '[{"name":"%s","disabled":false}]\n' "$connector" >"$MONITOR_FIXTURE"
if omarchy-hyprland-monitor-external-active; then
fail "internal connector $connector does not count as external"
fi
done
pass "internal connectors do not count as external monitors"

for disabled in true false; do
printf '[{"name":"FALLBACK","disabled":false},{"name":"DP-1","disabled":%s,"mirrorOf":"eDP-2"}]\n' "$disabled" >"$MONITOR_FIXTURE"
if [[ $disabled == "true" ]]; then
if omarchy-hyprland-monitor-external-active; then
fail "disabled external output does not prevent recovery"
fi
else
omarchy-hyprland-monitor-external-active || fail "active mirrored external output still counts"
: >"$MONITOR_ACTIONS"
omarchy-hyprland-monitor-internal recover
[[ ! -s $MONITOR_ACTIONS ]] || fail "active external output keeps the internal panel disabled"
fi
done
pass "external monitor detection preserves disabled and mirrored output behavior"