#!/bin/sh BACKLIGHT="/sys/class/backlight/amdgpu_bl0" current_brightness=$(cat "$BACKLIGHT/brightness") max_brightness=$(cat "$BACKLIGHT/max_brightness") if [ "$#" = "0" ]; then echo "$current_brightness" exit 0 fi val="$1" fc=$(echo "$1" | cut -c1-1) if [ "$fc" = "+" ] || [ "$fc" = "-" ]; then mode="$fc" val=$(echo "$1" | cut -c2-) fi fc=$(echo "$val" | cut -c1-1) if [ "$fc" = "%" ]; then percentage=$(echo "$val" | cut -c2-) val=$(("$max_brightness" * "$percentage")) val=$(("$val" / "100")) fi delta="0" if [ -z "$mode" ]; then delta=$(("$val" - "$current_brightness")) else delta="$mode$val" fi # Just apply the delta for now, might want to smooth it out later target_brightness=$(("$current_brightness" + "$delta")) # Clamp if [ "$target_brightness" -gt "$max_brightness" ]; then target_brightness="$max_brightness" elif [ "$target_brightness" -lt "0" ]; then target_brightness="0" fi echo "$target_brightness" > "$BACKLIGHT/brightness"