#!/bin/sh

_notify_brightness() {
	notify-send -u normal -t 1000 -a "Display brightness" \
		-h string:synchronous:backlight \
		-h string:x-canonical-private-synchronous:brightness \
		-i "${XDG_DATA_HOME:-$HOME/.local/share}/icons/notifications/idea.png" \
		-h int:value:"$1" \
		"Display brightness" "$1%"
}

if command -v brightnessctl >/dev/null; then
	case $1 in
		up) brightnessctl set 5%+ >/dev/null ;;
		down) brightnessctl set 5%- >/dev/null ;;
		*) ;;
	esac
	_notify_brightness "$(brightnessctl i | grep '%' | awk -F'(' '{print $2}' | awk -F'%' '{print $1}')"
elif command -v brillo >/dev/null; then
	case $1 in
		up) brillo -l -A 5 >/dev/null ;;
		down) brillo -l -U 5 >/dev/null ;;
		*) ;;
	esac
	_notify_brightness "$(brillo -G | cut -d '.' -f 1)"
fi
