#!/bin/bash
STATE_FILE="$HOME/.cache/brightness_state"
TEMP_FILE="$HOME/.cache/bluelight_state"

CURRENT=$(cat "$STATE_FILE" 2>/dev/null || echo "1.0")
NEW=$(echo "$CURRENT - 0.1" | bc -l)
if (($(echo "$NEW < 0.3" | bc -l))); then NEW=0.3; fi

TEMP=$(cat "$TEMP_FILE" 2>/dev/null || echo "6500")

pkill -9 gammastep
gammastep -O $TEMP -b "$NEW" &>/dev/null &

echo "$NEW" >"$STATE_FILE"
notify-send "Brightness" "$(printf '%.0f%%' $(echo "$NEW * 100" | bc))" -t 1000
