From e1bea3564e395c0dd7f046ca30327977065a5eb9 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 13 May 2026 13:43:11 +0100 Subject: feat(sway): auto-lock on idle and before suspend - logind: IdleAction=lock, IdleActionSec=5min. systemd emits a lock signal at 5min idle (session becomes locked from logind PoV; swayidle listens and invokes swaylock). - swayidle: lock at 5min, blank display at 6min, lock before sleep. Closes the gap where lid-close or manual suspend would wake to an unlocked session. - swaylock: add -i (--ignore-empty-password) to ignore accidental Enter. - meta/wayland: add swayidle. --- dot_config/sway/config | 9 +++++++- etc/systemd/logind.conf | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ meta/wayland.txt | 1 + 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 etc/systemd/logind.conf diff --git a/dot_config/sway/config b/dot_config/sway/config index 119849d..d780023 100644 --- a/dot_config/sway/config +++ b/dot_config/sway/config @@ -136,7 +136,7 @@ bindsym Print exec grim -g "$(slurp)" ~/pics/screenshots/$(date +%Y-%m-%d-%H-%M- bindsym Shift+Print exec grim ~/pics/screenshots/$(date +%Y-%m-%d-%H-%M-%S).png # Lock & pause -bindsym $mod+Shift+s exec "playerctl -a pause; swaylock -f -c 282828" +bindsym $mod+Shift+s exec "playerctl -a pause; swaylock -f -i -c 282828" # Notifications bindsym $mod+n exec makoctl dismiss @@ -155,3 +155,10 @@ exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CU exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP exec "sleep 2 && ~/.config/sway/display-toggle.sh init" exec systemctl --user start sway-session.target + +# Idle: lock at 5min (matches IdleActionSec), blank at 6min, lock before sleep. +exec swayidle -w \ + timeout 300 'swaylock -f -i -c 282828' \ + timeout 360 'swaymsg "output * power off"' \ + resume 'swaymsg "output * power on"' \ + before-sleep 'playerctl -a pause; swaylock -f -i -c 282828' diff --git a/etc/systemd/logind.conf b/etc/systemd/logind.conf new file mode 100644 index 0000000..37c0b1f --- /dev/null +++ b/etc/systemd/logind.conf @@ -0,0 +1,57 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it under the +# terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) +# any later version. +# +# Entries in this file show the compile time defaults. Local configuration +# should be created by either modifying this file (or a copy of it placed in +# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in +# the /etc/systemd/logind.conf.d/ directory. The latter is generally +# recommended. Defaults can be restored by simply deleting the main +# configuration file and all drop-ins located in /etc/. +# +# Use 'systemd-analyze cat-config systemd/logind.conf' to display the full config. +# +# See logind.conf(5) for details. + +[Login] +#NAutoVTs=6 +#ReserveVT=6 +#KillUserProcesses=no +#KillOnlyUsers= +#KillExcludeUsers=root +#InhibitDelayMaxSec=5 +#UserStopDelaySec=10 +#SleepOperation=suspend-then-hibernate suspend +#HandlePowerKey=poweroff +#HandlePowerKeyLongPress=ignore +#HandleRebootKey=reboot +#HandleRebootKeyLongPress=poweroff +#HandleSuspendKey=suspend +#HandleSuspendKeyLongPress=hibernate +#HandleHibernateKey=hibernate +#HandleHibernateKeyLongPress=ignore +#HandleLidSwitch=suspend +#HandleLidSwitchExternalPower=suspend +#HandleLidSwitchDocked=ignore +#HandleSecureAttentionKey=secure-attention-key +#PowerKeyIgnoreInhibited=no +#SuspendKeyIgnoreInhibited=no +#HibernateKeyIgnoreInhibited=no +#LidSwitchIgnoreInhibited=yes +#RebootKeyIgnoreInhibited=no +#HoldoffTimeoutSec=30s +#IdleAction=ignore +IdleAction=lock +#IdleActionSec=30min +IdleActionSec=5min +#RuntimeDirectorySize=10% +#RuntimeDirectoryInodesMax= +#RemoveIPC=yes +#InhibitorsMax=8192 +#SessionsMax=8192 +#StopIdleSessionSec=infinity +#DesignatedMaintenanceTime= +#WallMessages=yes diff --git a/meta/wayland.txt b/meta/wayland.txt index 773b901..1ca642c 100644 --- a/meta/wayland.txt +++ b/meta/wayland.txt @@ -16,6 +16,7 @@ poweralertd # Lock screen swaylock +swayidle # Clipboard wl-clipboard -- cgit v1.3.1