diff --git a/.config/hypr/hypridle.conf b/.config/hypr/hypridle.conf index 876c076..16d1edf 100644 --- a/.config/hypr/hypridle.conf +++ b/.config/hypr/hypridle.conf @@ -1,34 +1,48 @@ +# Idle / lock for SWAY (wlroots), not Hyprland. +# +# Two things in the original Hyprland template silently did nothing under sway: +# * `loginctl lock-session` -> sway implements no freedesktop login1 Session +# Lock protocol, so it is a no-op. Lock directly. +# * `hyprctl dispatch dpms` -> "HYPRLAND_INSTANCE_SIGNATURE not set!". +# Use `swaymsg "output * power on|off"`. +# Also: a hyprlock instance can outlive a sway session and then make the +# `pidof hyprlock || hyprlock` guard a permanent no-op; the sway config kills +# leftovers at login (`exec --no-startup-id pkill -x hyprlock`). + general { - lock_cmd = pidof hyprlock || hyprlock # avoid starting multiple hyprlock instances. - before_sleep_cmd = loginctl lock-session # lock before suspend. - after_sleep_cmd = hyprctl dispatch dpms on # to avoid having to press a key twice to turn on the display. + lock_cmd = pidof hyprlock || hyprlock + # pre-suspend uses swaylock: fast, sway-native, exits cleanly (no leak) + before_sleep_cmd = swaylock -f -c 000000 + # DPMS "power on" alone does not clear a post-resume eDP page-flip stall + # ("Atomic commit failed: Device or resource busy" for tens of minutes). + # The script does a full disable/enable (forced modeset) but ONLY when the + # journal actually shows the stall -- it used to fire unconditionally, which + # risked the shikane VariantInProgress deadlock on healthy resumes. The + # original i915 PSR2/DC4 cause is gone; this laptop uses the `xe` driver. + # Lid-aware so it does not race shikane's "External Display" profile. + after_sleep_cmd = /home/work/.config/sway/scripts/recover-output-after-resume.sh } listener { - timeout = 150 # 2.5min. - on-timeout = brightnessctl -s set 10 # set monitor backlight to minimum, avoid 0 on OLED monitor. - on-resume = brightnessctl -r # monitor backlight restore. + timeout = 150 # 2.5min + on-timeout = brightnessctl -s set 10 + on-resume = brightnessctl -r } -# turn off keyboard backlight, comment out this section if you dont have a keyboard backlight. -listener { - timeout = 150 # 2.5min. - on-timeout = brightnessctl -sd rgb:kbd_backlight set 0 # turn off keyboard backlight. - on-resume = brightnessctl -rd rgb:kbd_backlight # turn on keyboard backlight. +# keyboard backlight +listener { + timeout = 150 + on-timeout = brightnessctl -sd rgb:kbd_backlight set 0 + on-resume = brightnessctl -rd rgb:kbd_backlight } listener { - timeout = 300 # 5min - on-timeout = loginctl lock-session # lock screen when timeout has passed + timeout = 300 # 5min -> lock + on-timeout = pidof hyprlock || hyprlock } listener { - timeout = 330 # 5.5min - on-timeout = hyprctl dispatch dpms off # screen off when timeout has passed - on-resume = hyprctl dispatch dpms on && brightnessctl -r # screen on when activity is detected after timeout has fired. -} - -listener { - timeout = 1800 # 30min - on-timeout = systemctl suspend # suspend pc + timeout = 330 # 5.5min -> output power off + on-timeout = swaymsg "output * power off" + on-resume = swaymsg "output * power on" && brightnessctl -r } diff --git a/.config/sway/scripts/recover-output-after-resume.sh b/.config/sway/scripts/recover-output-after-resume.sh new file mode 100755 index 0000000..253a87c --- /dev/null +++ b/.config/sway/scripts/recover-output-after-resume.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# recover-output-after-resume -- clear a post-resume eDP page-flip stall. +# +# Symptom (see journalctl --user --since -5m | grep 'Atomic commit failed'): +# [wlr] backend/drm/atomic.c:82 connector eDP-1: Atomic commit failed: +# Device or resource busy +# [sway] desktop/output.c:307 Page-flip failed on output eDP-1 +# ...repeatedly for tens of minutes after a resume. +# +# HISTORY: this was originally a workaround for the old ThinkPad's +# /etc/modprobe.d/i915.conf, which forced PSR2 and the deepest display C-states +# (options i915 enable_guc=3 enable_psr=2 enable_dc=4 enable_rc6=1 -- both of +# which taint the kernel). With PSR2 forced on, the flip pending across suspend +# never completed, so every later commit returned EBUSY, and DPMS "power on" +# alone did not clear it -- only a full modeset did. +# +# STATUS: that file is gone. This machine is a Framework Laptop 13 Pro whose +# iGPU is driven by `xe` (Panther Lake has no i915 support at all), so the +# original cause cannot recur. The modeset below is therefore CONDITIONAL and +# only fires when the stall is actually present in the journal. +# +# Why conditional: an unconditional disable/enable plus `shikanectl reload` +# after every resume is exactly the sequence that re-triggers the shikane +# 1.1.1 VariantInProgress deadlock (see shikane-watchdog.sh). No point paying +# that risk on resumes that are already healthy. +# +# Lid-aware on purpose: a blind `output eDP-1 enable` raced shikane's +# "External Display" profile (which keeps eDP-1 off) and caused +# "Atomic commit failed: Device or resource busy" churn in clamshell mode. +# See the note in clamshell-mode.sh. + +set -u + +LID_STATE="${LID_STATE:-/proc/acpi/button/lid/LID/state}" +OUTPUT="${OUTPUT:-eDP-1}" + +# Always undo the idle DPMS-off first (this is what after_sleep_cmd used to do). +swaymsg "output * power on" 2>/dev/null + +# Only escalate to a modeset if the page-flip stall is actually being reported. +# sway runs inside the user session, so its stderr is in the user journal. +if command -v journalctl >/dev/null 2>&1; then + if ! journalctl --user --since '-3 min' --no-pager 2>/dev/null \ + | grep -qE 'Atomic commit failed|Page-flip failed on output'; then + exit 0 # healthy resume -> do not disturb shikane + fi +fi + +# The modeset below is lid-gated only. +[ -r "$LID_STATE" ] || exit 0 +grep -q 'open' "$LID_STATE" || exit 0 # lid closed -> leave layout to shikane + +# Give the driver a moment to finish re-training the link before we modeset. +sleep 1 +swaymsg "output $OUTPUT disable" 2>/dev/null +sleep 1 +swaymsg "output $OUTPUT enable" 2>/dev/null +# Re-assert the shikane profile (mode/scale/position) on top of the modeset. +command -v shikanectl >/dev/null 2>&1 && shikanectl reload 2>/dev/null +exit 0