Recently I made the concious decision to move from Windows to Linux permanently, after running it in a dual boot system for years. I might explain why in a future post, but for now I just want to share something simple that I made.
One of the tools in Windows that I would always install first was f.lux. It theoretically works on Linux, but as the developer said on the Github repository, it is barely maintained and you should use something else instead.
I ended up using gammastep, since this is a lightweight service that works on Wayland and changes the temperature gradually (this was a big requirement for me). The only f.lux feature it was missing (and one I use a lot) was to "temporarily disable" it.
After some tinkering in NeoVim, I managed to create a script that does exactly that. It checks if the service is running, and if it is it will kill it and start an at
job to restart it in an hour. It also makes sure you will not have this job queued multiple times and it will send a notification whenever it starts or stops.
#!/bin/bash
noti() {
notify-send -i ~/.local/share/gammastep/gammastep.svg -a "Gammastep" "Gammastep" "$@"
}
if [ -f "$HOME/.local/share/gammastep/at.id" ]; then
atrm $(cat $HOME/.local/share/gammastep/at.id)
rm $HOME/.local/share/gammastep/at.id
fi
GAMMAID=$(pidof gammastep)
if [ "$GAMMAID" == "" ];
then
noti "Starting service"
gammastep &!
else
noti "Stopping service, restarting in 1 hour"
kill -9 $GAMMAID
TID=`at now + 1 hour -f "$HOME/.local/bin/gammastep-toggle.sh" 2>&1 |awk '/job/ {print $2}'`
echo $TID > $HOME/.local/share/gammastep/at.id
fi
To bind this in Sway (or i3), you can use the binding bindsym Alt+End exec --no-startup-id ~/.local/bin/gammastep-toggle.sh
All of this assumes you put the script inside ~/.local/bin/gammastep-toggle.sh
and you have your gammastep configuration set up in ~/.local/share/gammastep