Created
February 6, 2026 03:39
-
-
Save christiangenco/c6ea4b873f76911035344e2a51734c94 to your computer and use it in GitHub Desktop.
Software brightness control for Hyprland via hyprsunset — gamma dimming with warm color shift at low levels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Software brightness control via hyprsunset | |
| # Usage: brightness up|down|set <value> | |
| # Stores state in ~/.local/state/brightness | |
| # | |
| # Two phases: | |
| # 100% → 15%: reduce gamma (dims the screen while maintaining contrast) | |
| # 15% → 0%: gamma stays at 15%, temperature shifts warm (6500K → 2000K) | |
| # This "dims" further by removing blue light, keeping readability | |
| STATE_FILE="$HOME/.local/state/brightness" | |
| STEP=5 | |
| MIN=0 | |
| MAX=100 | |
| # Below this gamma level, stop dimming and start warming instead | |
| GAMMA_FLOOR=20 | |
| # Warm color temp range | |
| TEMP_NEUTRAL=6500 | |
| TEMP_WARMEST=2000 | |
| # Read current brightness | |
| if [[ -f "$STATE_FILE" ]]; then | |
| current=$(cat "$STATE_FILE") | |
| else | |
| current=100 | |
| fi | |
| case "$1" in | |
| up) | |
| new=$((current + STEP)) | |
| [[ $new -gt $MAX ]] && new=$MAX | |
| ;; | |
| down) | |
| new=$((current - STEP)) | |
| [[ $new -lt $MIN ]] && new=$MIN | |
| ;; | |
| set) | |
| new=$2 | |
| [[ $new -gt $MAX ]] && new=$MAX | |
| [[ $new -lt $MIN ]] && new=$MIN | |
| ;; | |
| get) | |
| echo "$current" | |
| exit 0 | |
| ;; | |
| *) | |
| echo "Usage: brightness up|down|set <value>|get" | |
| exit 1 | |
| ;; | |
| esac | |
| # Save new value | |
| echo "$new" > "$STATE_FILE" | |
| # Calculate gamma and temperature | |
| if [[ $new -ge $GAMMA_FLOOR ]]; then | |
| # Phase 1: normal dimming, neutral color | |
| gamma=$new | |
| temp=$TEMP_NEUTRAL | |
| else | |
| # Phase 2: gamma stays at floor, temperature goes warm | |
| gamma=$GAMMA_FLOOR | |
| # Linear interpolation: at 15% = 6500K, at 0% = 2000K | |
| temp_range=$((TEMP_NEUTRAL - TEMP_WARMEST)) | |
| progress=$((GAMMA_FLOOR - new)) | |
| temp=$((TEMP_NEUTRAL - (progress * temp_range / GAMMA_FLOOR))) | |
| fi | |
| # Apply via hyprsunset (kill existing instance first) | |
| pkill -x hyprsunset 2>/dev/null | |
| sleep 0.1 | |
| if [[ $gamma -ge 100 && $temp -eq $TEMP_NEUTRAL ]]; then | |
| # Full brightness, no color shift — no need for hyprsunset | |
| : | |
| else | |
| hyprsunset -g "$gamma" -t "$temp" &>/dev/null & | |
| disown | |
| fi | |
| # Show OSD notification | |
| if [[ $new -ge $GAMMA_FLOOR ]]; then | |
| notify-send -t 1000 -h string:x-canonical-private-synchronous:brightness \ | |
| -h int:value:"$new" "Brightness ${new}%" | |
| else | |
| notify-send -t 1000 -h string:x-canonical-private-synchronous:brightness \ | |
| -h int:value:"$new" "Brightness ${new}% (${temp}K)" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment