Fix HDMI recovery dispatches for Lua Hyprland sessions

This commit is contained in:
admin committed 2026-09-23 15:46:21 +02:00
1 parent d963224cb7
commit 34bae045c3
7 files changed
+163 -10

No files matched your search

+38 -2
View File
@@ -44,9 +44,44 @@ monitor_present() {
jq -e --arg name "$MONITOR" 'any(.[]; .name == $name)' >/dev/null 2>&1
}
select_dispatch_syntax() {
local status provider
DISPATCH_SYNTAX=hyprlang
# The active config provider, not the version, determines dispatch syntax.
# Older Hyprland versions do not expose `status`; their dispatch is legacy.
if status="$(timeout 5 hyprctl -j status 2>/dev/null)" &&
provider="$(jq -er '.configProvider | select(type == "string")' <<< "$status" 2>/dev/null)"; then
case "$provider" in
lua|hyprlang) DISPATCH_SYNTAX="$provider" ;;
*) log "Unsupported Hyprland config provider: $provider"; return 1 ;;
esac
else
log 'Hyprland config provider unavailable; trying legacy dispatch syntax'
fi
log "Using $DISPATCH_SYNTAX dispatch syntax"
}
dispatch_checked() {
local action="$1" reply status
shift
reply="$(timeout 5 hyprctl dispatch "$@" 2>&1)"
status=$?
# Some hyprctl versions return exit 0 even for an IPC error response.
if (( status != 0 )) || [[ "$reply" != ok ]]; then
log "Hyprland $action failed (exit $status): ${reply:-no response}"
return 1
fi
}
refresh_monitor() {
timeout 5 hyprctl dispatch dpms on "$MONITOR" >/dev/null 2>&1 &&
timeout 5 hyprctl dispatch focusmonitor "$MONITOR" >/dev/null 2>&1
if [[ "$DISPATCH_SYNTAX" == lua ]]; then
# MONITOR is restricted to alphanumeric characters, underscores and '-'.
dispatch_checked DPMS "hl.dsp.dpms({ action = \"on\", monitor = \"$MONITOR\" })" &&
dispatch_checked focus "hl.dsp.focus({ monitor = \"$MONITOR\" })"
else
dispatch_checked DPMS dpms on "$MONITOR" &&
dispatch_checked focus focusmonitor "$MONITOR"
fi
}
log "Recovery started for $MONITOR on VT $GRAPHICAL_VT"
@@ -55,6 +90,7 @@ if ! monitor_present; then
log "Hyprland IPC unavailable or configured output $MONITOR absent - recovery aborted"
exit 1
fi
select_dispatch_syntax || exit 1
if ! refresh_monitor; then
log 'Hyprland refresh failed - recovery aborted'
exit 1