From c00cbdbadeb9b0e3d2d5882bae5500e7a00fbe6c Mon Sep 17 00:00:00 2001 From: Marty Oehme <contact@martyoeh.me> Date: Tue, 25 Feb 2025 19:18:32 +0100 Subject: [PATCH] services: Add swayidle processing as service swayidle is now also presented as a user service managed by runit on voidlinux. It comes with the same defaults as before (300 seconds to lockscreen, 600 seconds to screen dimming and 900 seconds before suspending). Additionally the lockscreen script has been updated to correctly tell a wayland from a non-wayland session without logind being available on the system, though it still defaults to using loginctl if it finds it. The service runs as swayidle in the user services directory and can be confirured using a 'conf' file which would be placed in the 'swayidle' service directory. Timeouts can be set with `time_to_lockscreen`, `time_to_screendim` and `time_to_suspend`. --- desktop/.config/river/init | 7 +++---- scripts/.local/bin/lockscreen | 14 +++++++------- services/sv/swayidle/log/run | 3 +++ services/sv/swayidle/run | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100755 services/sv/swayidle/log/run create mode 100755 services/sv/swayidle/run diff --git a/desktop/.config/river/init b/desktop/.config/river/init index 8cd7000..7ad623e 100755 --- a/desktop/.config/river/init +++ b/desktop/.config/river/init @@ -340,16 +340,15 @@ if ! cat /etc/*-release | grep -q '^NAME=.*Void'; then unset loc fi -fi - -# start screen idle locking/dimming/sleep tool -should_start swayidle && riverctl spawn "swayidle \ + # start screen idle locking/dimming/sleep tool + should_start swayidle && riverctl spawn "swayidle \ timeout ${time_to_suspend} \"[ $(cat /sys/class/power_supply/AC/online) -eq 0 ] && systemctl suspend-then-hibernate\" timeout ${time_to_screendim} \"wlopm --off '*'\" \ resume \"wlopm --on '*'\" \ timeout ${time_to_lockscreen} \"pidof waylock || lockscreen\" \ after-resume \"wlopm --on '*'\" \ before-sleep \"pidof waylock || lockscreen\" &" +fi # bash ~/.config/bin/gtktheme # setting our gtk variables # killall polkit-gnome-authentication-agent-1 diff --git a/scripts/.local/bin/lockscreen b/scripts/.local/bin/lockscreen index 6bf7cf4..9894ee1 100755 --- a/scripts/.local/bin/lockscreen +++ b/scripts/.local/bin/lockscreen @@ -6,9 +6,9 @@ ## CONFIGURATION ############################################################## is_wayland() { - # alternative $(</proc/self/sessionid), see - # https://stackoverflow.com/questions/3214935/can-a-bash-script-tell-if-its-being-run-via-cron - if loginctl show-session "$(loginctl show-user "$(whoami)" -p Display --value)" -p Type --value | grep -q wayland; then + if command -v loginctl && loginctl show-session "$(loginctl show-user "$(whoami)" -p Display --value)" -p Type --value | grep -q wayland; then + true + elif [ "$XDG_SESSION_TYPE" = "wayland" ] || [ -n "$WAYLAND_DISPLAY" ]; then true else false @@ -22,12 +22,12 @@ waylock_options="-init-color 0x223344 -input-color 0x224444 -fail-color 0x554444 # Run before starting the locker pre_lock() { # pause all currently playing media and mute system - type mpc >/dev/null 2>&1 && mpc -q pause - type playerctl >/dev/null 2>&1 && playerctl -s pause - type amixer >/dev/null 2>&1 && amixer -q set Master mute + command -v mpc >/dev/null 2>&1 && mpc -q pause + command -v playerctl >/dev/null 2>&1 && playerctl -s pause + command -v amixer >/dev/null 2>&1 && amixer -q set Master mute # lock any pass coffins if we have them - type pass >/dev/null 2>&1 && pass close >/dev/null 2>&1 + command -v pass >/dev/null 2>&1 && pass close >/dev/null 2>&1 return } diff --git a/services/sv/swayidle/log/run b/services/sv/swayidle/log/run new file mode 100755 index 0000000..5de1af2 --- /dev/null +++ b/services/sv/swayidle/log/run @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec vlogger -t swayidle -p daemon diff --git a/services/sv/swayidle/run b/services/sv/swayidle/run new file mode 100755 index 0000000..fb9a063 --- /dev/null +++ b/services/sv/swayidle/run @@ -0,0 +1,20 @@ +#!/bin/sh + +time_to_lockscreen="${time_to_lockscreen:-300}" +time_to_screendim="${time_to_screendim:-600}" +time_to_suspend="${time_to_suspend:-900}" + +[ -r ./conf ] && . ./conf + +exec 2>&1 + +# usual setup: +# waylock -init-color 0x223344 -input-color 0x224444 -fail-color 0x554444 -fork-on-lock + +exec chpst -e "$TURNSTILE_ENV_DIR" swayidle \ + timeout "${time_to_suspend}" "[ $(cat /sys/class/power_supply/AC/online) -eq 0 ] && sudo zzz" \ + timeout "${time_to_screendim}" "wlopm --off '*'" \ + resume "wlopm --on '*'" \ + timeout "${time_to_lockscreen}" "pidof waylock || lockscreen" \ + after-resume "wlopm --on '*'" \ + before-sleep "pidof waylock || lockscreen"