swaywm/swayidle

[FR?] Send SIGTERM to a timeout command

FunctionalHacker opened this issue · 2 comments

I have a script that I used to use with xss-lock (I think the script came with the program) that dims the screen. I want to run this after 5 minutes of inactivity, another 5 minutes later the screen is locked and turned off. This was working out of the box with xss-lock but not in swaidle.

I think the problem lies in the fact that the script waits for a TERM signal so it can set the screen brightness to the value it was before. Apparently xss-lock send this signal and swaidle does not, so I guess this is a feature request to add an option for this.

Here is the script I am using so you get a better idea:

#!/bin/bash
min_brightness=5
fade_steps=20
fade_step_time=0.05

get_brightness() {
	float=$(light -G $1)
	printf '%.*f\n' 0 $float
}

set_brightness() {
	light -S $1
}

fade_brightness() {
	local level
	for level in $(eval echo {$(get_brightness)..$1}); do
		set_brightness $level
		sleep $fade_step_time
	done
}

trap 'exit 0' TERM INT
trap "set_brightness $(get_brightness); kill %%" EXIT
fade_brightness $min_brightness
sleep 314151235 &
wait

I was using the same script with xss-lock. I wrote this script as a swayidle compatible replacement. It works just like the old script using this command

swayidle -w \
    timeout 120 'dim.sh -sd' \
    resume 'swaymsg "output * dpms on"; dim.sh -r' \
    timeout 180 'dim.sh -0; lock.sh; swaymsg "output * dpms off"' \
    before-sleep 'dim.sh -s0; lock.sh' \
    after-resume 'dim.sh -r'

Thanks! That did the trick