Mathijs Futselaar - Sr. (Web)Developer

Blog - Emulate f.lux behaviour with gammastep

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.

 1#!/bin/bash
 2
 3noti() {
 4    notify-send -i ~/.local/share/gammastep/gammastep.svg -a "Gammastep" "Gammastep" "$@"
 5}
 6
 7if [ -f "$HOME/.local/share/gammastep/at.id" ]; then
 8    atrm $(cat $HOME/.local/share/gammastep/at.id)
 9    rm $HOME/.local/share/gammastep/at.id
10fi
11
12GAMMAID=$(pidof gammastep)
13
14if [ "$GAMMAID" == "" ];
15then
16    noti "Starting service"
17    gammastep &!
18else
19    noti "Stopping service, restarting in 1 hour"
20    kill -9 $GAMMAID
21    TID=`at now + 1 hour -f "$HOME/.local/bin/gammastep-toggle.sh" 2>&1 |awk '/job/ {print $2}'`
22    echo $TID > $HOME/.local/share/gammastep/at.id
23fi

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

Date:
Reading time: 2 min read