Rewrite screensaver for Sway

This commit is contained in:
q3aql 2025-05-25 09:27:35 +02:00
parent bd6fcd3a67
commit 873d25085a
2 changed files with 93 additions and 47 deletions

View File

@ -2,9 +2,6 @@
# Basic configuration variables
ScreensaverTime="1200" # 20 minutes
monitorOne="DP-1" # First monitor
monitorTwo="DP-2" # Second monitor
monitorThree="" # Third monitor
# Load script for load monitors config quickly from resume
LoadConfigResume="${HOME}/.config/sway/startwlrrandr.sh"
@ -17,55 +14,16 @@ nwgWrapperRestart="${HOME}/.config/sway/nwg-wrapper-conky.sh"
# Function for sleep monitors
function sleepMonitors() {
# Check monitor 3
if [ -z "${monitorThree}" ] ; then
echo "Monitor 3 is empty or disabled"
else
echo "Sleep monitor 3"
wlr-randr --output ${monitorThree} --off
fi
# Check monitor 2
if [ -z "${monitorTwo}" ] ; then
echo "Monitor 2 is empty or disabled"
else
echo "Sleep monitor 2"
wlr-randr --output ${monitorTwo} --off
fi
# Check monitor 1
if [ -z "${monitorOne}" ] ; then
echo "Monitor 1 is empty or disabled"
else
echo "Sleep monitor 1"
wlr-randr --output ${monitorOne} --off
fi
#swaylock --color 000000 -f
swaymsg "output * dpms off"
echo "sleep" > ${stateFile}
}
# Function for resume monitors
function resumeMonitors() {
# Check monitor 3
if [ -z "${monitorThree}" ] ; then
echo "Monitor 3 is empty or disabled"
else
echo "Resume monitor 3"
wlr-randr --output ${monitorThree} --on
fi
# Check monitor 2
if [ -z "${monitorTwo}" ] ; then
echo "Monitor 2 is empty or disabled"
else
echo "Resume monitor 2"
wlr-randr --output ${monitorTwo} --on
fi
# Check monitor 1
if [ -z "${monitorOne}" ] ; then
echo "Monitor 1 is empty or disabled"
else
echo "Resume monitor 1"
wlr-randr --output ${monitorOne} --on
fi
swaymsg "output * dpms on"
# Load monitors config quickly
bash ${LoadConfigResume} screensaver
#bash ${LoadConfigResume} screensaver
echo "resume" > ${stateFile}
# Restart nwg-wrapper
sleep 2
@ -77,8 +35,8 @@ if [ -z "${1}" ] ; then
# Kill previous process
echo "# Trying to kill previous process"
killall -9 swayidle 2> /dev/null
sleep 3
# Init swayidle command
sleep 3
swayidle timeout ${ScreensaverTime} "bash ${0} sleep" resume "bash ${0} resume"
elif [ "${1}" == "sleep" ] ; then
sleepMonitors

View File

@ -0,0 +1,88 @@
#!/bin/bash
# Basic configuration variables
ScreensaverTime="1200" # 20 minutes
monitorOne="HDMI-A-1" # First monitor
monitorTwo="HDMI-A-2" # Second monitor
monitorThree="" # Third monitor
# Load script for load monitors config quickly from resume
LoadConfigResume="${HOME}/.config/sway/startwlrrandr.sh"
# StateFile variable
stateFile="${HOME}/.config/sway/screen-state"
# Start/Restart nwg-wrapper
nwgWrapperRestart="${HOME}/.config/sway/nwg-wrapper-conky.sh"
# Function for sleep monitors
function sleepMonitors() {
# Check monitor 3
if [ -z "${monitorThree}" ] ; then
echo "Monitor 3 is empty or disabled"
else
echo "Sleep monitor 3"
wlr-randr --output ${monitorThree} --off
fi
# Check monitor 2
if [ -z "${monitorTwo}" ] ; then
echo "Monitor 2 is empty or disabled"
else
echo "Sleep monitor 2"
wlr-randr --output ${monitorTwo} --off
fi
# Check monitor 1
if [ -z "${monitorOne}" ] ; then
echo "Monitor 1 is empty or disabled"
else
echo "Sleep monitor 1"
wlr-randr --output ${monitorOne} --off
fi
echo "sleep" > ${stateFile}
}
# Function for resume monitors
function resumeMonitors() {
# Check monitor 3
if [ -z "${monitorThree}" ] ; then
echo "Monitor 3 is empty or disabled"
else
echo "Resume monitor 3"
wlr-randr --output ${monitorThree} --on
fi
# Check monitor 2
if [ -z "${monitorTwo}" ] ; then
echo "Monitor 2 is empty or disabled"
else
echo "Resume monitor 2"
wlr-randr --output ${monitorTwo} --on
fi
# Check monitor 1
if [ -z "${monitorOne}" ] ; then
echo "Monitor 1 is empty or disabled"
else
echo "Resume monitor 1"
wlr-randr --output ${monitorOne} --on
fi
# Load monitors config quickly
bash ${LoadConfigResume} screensaver
echo "resume" > ${stateFile}
# Restart nwg-wrapper
sleep 2
bash ${nwgWrapperRestart}
}
# Boot parameters
if [ -z "${1}" ] ; then
# Kill previous process
echo "# Trying to kill previous process"
killall -9 swayidle 2> /dev/null
# Init swayidle command
sleep 3
swayidle timeout ${ScreensaverTime} "bash ${0} sleep" resume "bash ${0} resume"
elif [ "${1}" == "sleep" ] ; then
sleepMonitors
elif [ "${1}" == "resume" ] ; then
resumeMonitors
fi