feat: restore portable layout on shutdown and before suspend
Add WriteConfig/Prepare backend methods (real for Hyprland, no-op for Sway), -apply/-prepare/-no-reload CLI flags, ExecStartPre cleanup and suspend systemd hooks so a stale docked config can never leave the built-in display disabled after resume.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=monitor-lets-go -- restore portable layout before suspend
|
||||
Documentation=https://github.com/mat/monitor-lets-go
|
||||
|
||||
# Run before the system enters sleep. The ExecStop action writes a portable
|
||||
# monitor config so that on resume the compositor never loads a stale docked
|
||||
# config that would leave the built-in display disabled.
|
||||
Before=sleep.target
|
||||
|
||||
[Service]
|
||||
# RemainAfterExit: ExecStop runs when the service is stopped (before sleep).
|
||||
# This is the standard pattern for systemd suspend hooks.
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
|
||||
ExecStart=/bin/true
|
||||
ExecStop=%h/.local/bin/monitor-lets-go -config %h/.config/monitor-lets-go/config.yaml -apply portable -no-reload
|
||||
|
||||
[Install]
|
||||
WantedBy=sleep.target
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
# system-sleep hook for monitor-lets-go
|
||||
# Install to /usr/lib/systemd/system-sleep/monitor-lets-go
|
||||
#
|
||||
# Writes the portable monitor config before suspend so the compositor
|
||||
# never loads a stale docked config on resume (prevents black screen).
|
||||
#
|
||||
# Requires: sudo (passwordless for the user's own commands)
|
||||
|
||||
case $1/$2 in
|
||||
pre/*)
|
||||
USER_NAME="$(logname 2>/dev/null || echo "${SUDO_USER:-$USER}")"
|
||||
USER_UID="$(id -u "$USER_NAME" 2>/dev/null || echo 1000)"
|
||||
|
||||
# Extract HYPRLAND_INSTANCE_SIGNATURE from the user's systemd session
|
||||
HYPR_ENV="$(systemctl --user -M "${USER_UID}@" show-environment 2>/dev/null)"
|
||||
HYPR_INSTANCE="$(echo "$HYPR_ENV" | grep HYPRLAND_INSTANCE_SIGNATURE | cut -d= -f2)"
|
||||
|
||||
if [ -n "$HYPR_INSTANCE" ] && [ -n "$USER_NAME" ]; then
|
||||
XDG_RUNTIME_DIR="/run/user/$USER_UID" \
|
||||
HYPRLAND_INSTANCE_SIGNATURE="$HYPR_INSTANCE" \
|
||||
sudo -u "$USER_NAME" \
|
||||
/home/mat/.local/bin/monitor-lets-go \
|
||||
-config /home/mat/.config/monitor-lets-go/config.yaml \
|
||||
-apply portable -no-reload
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
@@ -16,6 +16,11 @@ Requires=graphical-session.target
|
||||
Type=notify
|
||||
WatchdogSec=30
|
||||
|
||||
# Remove disabled entries from the monitor config before starting.
|
||||
# Prevents black screen if a stale docked config disables the built-in
|
||||
# display (e.g. after undocking while suspended).
|
||||
ExecStartPre=%h/.local/bin/monitor-lets-go -config %h/.config/monitor-lets-go/config.yaml -prepare
|
||||
|
||||
ExecStart=%h/.local/bin/monitor-lets-go -config %h/.config/monitor-lets-go/config.yaml
|
||||
|
||||
# Fast restart on failure: if the daemon crashes during docked mode,
|
||||
|
||||
Reference in New Issue
Block a user