URI:
       theme: offload mood/pastel to external scripts - scripts - various script and utils
  HTML git clone git://z3bra.org/scripts
   DIR Log
   DIR Files
   DIR Refs
       ---
   DIR commit 0ae7dc742ea74d83efe20d16915e9b1e45c6b315
   DIR parent 728ebcf1e66d874a29bfb13e438bf70822d646e7
  HTML Author: Willy Goiffon <dev@z3bra.org>
       Date:   Sat, 29 Aug 2026 08:11:28 +0000
       
       theme: offload mood/pastel to external scripts
       
       Diffstat:
         M theme                               |      24 +++---------------------
       
       1 file changed, 3 insertions(+), 21 deletions(-)
       ---
   DIR diff --git a/theme b/theme
       @@ -17,25 +17,6 @@ preset() {
                ln -sf $img $HOME/.bg.png
        }
        
       -# Compute perceived brightness of an #RGB color
       -# https://en.wikipedia.org/wiki/Rec._709#The_Y'C'BC'R_color_space
       -mood() {
       -        hex=${1#\#}
       -        r="0x$(echo $hex|cut -b1-2)"
       -        g="0x$(echo $hex|cut -b3-4)"
       -        b="0x$(echo $hex|cut -b5-6)"
       -        l=$(printf '%d*0.2126 + %d*0.7152 + %d*0.0722\n' $r $g $b|bc|cut -d. -f1)
       -        [ $l -gt 128 ] && echo 'light' || echo 'dark'
       -}
       -
       -pastel() {
       -        printf '#'
       -        case $mood in
       -        dark)  seq 0 96|shuf|head -n3|xargs printf '%02x';;
       -        light) seq 170 240|shuf|head -n3|xargs printf '%02x';;
       -        esac
       -}
       -
        mktheme() {
                if [ ! -e "$img" ]; then
                        printf '%s: No such file or directory\n' "$image" >&2
       @@ -106,7 +87,7 @@ setup_tofi() {
        setup_waybar() {
                # Make sure waybar contrasts with the background filling color
                # When theme is "light", fg/bg colors are swapped
       -        [ "$mood" = "$(mood $fill)" ] && c=$hl || c=$dm
       +        [ "$mood" = "$(colorscheme $fill)" ] && c=$hl || c=$dm
                sed -ri "/^#(clock|battery)/s/color:.*;/color:${c};/" $HOME/.config/waybar/style.css
        }
        
       @@ -155,6 +136,7 @@ dm=${bg#*,}
        fg=${fg%,*}
        bg=${bg%,*}
        
       +
        # Use first pixel to compute filler color using raw farbfeld.
        # Pixelspace is 16 bits, so we must do a quick cut(1) dance to get the
        # color as 8 bits
       @@ -163,7 +145,7 @@ rgb=$(<$img png2ff|xxd -c0 -p|cut -b33-34,37-38,41-42)
        
        # Use random pastel colors for transparent pixel (unless specified in theme)
        case "$alpha" in
       -00) fill=${fill:-$(pastel)} ;;
       +00) fill=${fill:-$(pastel -m $mood)} ;;
         *) fill="#${rgb}" ;;
        esac