commit 8954c818991a0b585440f9f6436c4777a5a3146f Spenser Truex <truex@equwal.com> 2025-09-10 23:02:50 -0700 Fix up intel backlight
dintel-backlight | 28 ++++++++++++++++++++++++---- intel-backlight | 13 ++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/dintel-backlight b/dintel-backlight index bf8ee64..ca7fe78 100755 --- a/dintel-backlight +++ b/dintel-backlight @@ -1,7 +1,27 @@ #!/bin/sh -SELECTOR="$(which wjt)" # a sliding bar that resembles dmenu, 0-100 -SELECTOR=${SELECTOR:- $(which dmenu)} -OUT="$(echo "up\ndown\nmin\nmax\noff" | "$SELECTOR" -p 'intel-backlight command:')" -[ -z "$OUT" ] && OUT=0 # hack for wjt no output if not touched +echo "dintel-backlight-aux starting" >&2 +if command -v wjt >/dev/null 2>&1; then + echo "wjt found, using wjt interface" >&2 + OUT="$(wjt -p 'intel-backlight (0-100):')" + echo "Raw wjt output: '$OUT'" >&2 + # wjt returns empty string for 0, so treat empty as min + [ -z "$OUT" ] && OUT="min" && echo "Empty output treated as min" >&2 + # wjt outputs one value per line as user moves slider, get only the last line + OUT="$(echo "$OUT" | tail -1)" + echo "Extracted last value: '$OUT'" >&2 + # If no numeric value found, treat as min + [ -z "$OUT" ] && OUT="min" && echo "No numeric value found, using min" >&2 + # Ensure wjt output is a valid number or command + echo "wjt output after cleanup: '$OUT'" >&2 + case "$OUT" in + ''|min|max|up|down|off) ;; # valid commands + *[!0-9]*) echo "Invalid output: '$OUT'" >&2; exit 1 ;; # exit if not a number or valid command + esac + echo "Calling intel-backlight with: '$OUT'" >&2 +else + SELECTOR="$(which dmenu)" + OUT="$(echo "up\ndown\nmin\nmax\noff" | "$SELECTOR" -p 'intel-backlight command:')" + [ -z "$OUT" ] && exit 0 # exit if no selection from dmenu +fi "$HOME"/src/sh/intel-backlight "$OUT" diff --git a/intel-backlight b/intel-backlight index 6acdc03..990320e 100755 --- a/intel-backlight +++ b/intel-backlight @@ -8,6 +8,8 @@ fi [ -z "$1" ] && echo "No argument." && exit 1 +echo "intel-backlight called with: '$1'" >&2 + [[ ! -d /sys/class/backlight/intel_backlight ]] && exit current=$(< /sys/class/backlight/intel_backlight/brightness) @@ -16,8 +18,13 @@ min=$((max / 50)) step=$((max / 10)) if [[ "$1" =~ ^[0-9]+$ ]]; then - current=$(( ( ($1 * max) / 100 ) < min ? min : (($1 * max) / 100 ))) - echo $max $current $min + if [[ "$1" -eq 0 ]]; then + current=0 + elif [[ "$1" -eq 100 ]]; then + current=$max + else + current=$(( ( ($1 * max) / 100 ) < min ? min : (($1 * max) / 100 ))) + fi else case $1 in up) ((current+=step)) ;; @@ -30,7 +37,7 @@ else fi -if (( current < min )) && [[ $1 != off ]] +if (( current < min )) && [[ $1 != off ]] && [[ $1 != 0 ]] then current=$min elif (( current > max ))