guix-config

Guix system and home config for XIII (librebooted T480)
git clone https://g1rls.strangled.net/guix-config.git
Log | Files | Refs | README

xiii-osd (1966B)


      1 #!/bin/sh
      2 set -eu
      3 runtime=${XDG_RUNTIME_DIR:-}
      4 display=${WAYLAND_DISPLAY:-wayland-0}
      5 dir=$runtime/xiii-wob-${display##*/}
      6 fifo=$dir/input
      7 cfg=$HOME/.cache/wallust/wob.ini
      8 [ -r "$cfg" ] || cfg=${XDG_CONFIG_HOME:-$HOME/.config}/wob/wob.ini
      9 sink=@DEFAULT_AUDIO_SINK@
     10 export LC_ALL=C
     11 
     12 start_wob() {
     13     [ -n "$runtime" ] && [ -d "$runtime" ] || exit 0
     14     mkdir -p "$dir"
     15     exec 9>"$dir/lock"
     16     flock -n 9 || exit 0
     17     [ -p "$fifo" ] || mkfifo "$fifo"
     18     if [ -r "$cfg" ]; then
     19         exec wob -c "$cfg" 0<>"$fifo"
     20     fi
     21     exec wob 0<>"$fifo"
     22 }
     23 
     24 case ${1:-} in
     25     start) start_wob ;;
     26     restart)
     27         pkill -x wob 2>/dev/null || true
     28         sleep 0.1
     29         nohup "$0" start >/dev/null 2>&1 &
     30         exit 0
     31         ;;
     32     volume-up) wpctl set-volume "$sink" 5%+ -l 1.0 ;;
     33     volume-down) wpctl set-volume "$sink" 5%- ;;
     34     volume-up-fine) wpctl set-volume "$sink" 1%+ -l 1.0 ;;
     35     volume-down-fine) wpctl set-volume "$sink" 1%- ;;
     36     volume-mute) wpctl set-mute "$sink" toggle ;;
     37     brightness-up) brightnessctl --class=backlight set +5% ;;
     38     brightness-down) brightnessctl --class=backlight set 5%- ;;
     39     brightness-up-fine) brightnessctl --class=backlight set +1% ;;
     40     brightness-down-fine) brightnessctl --class=backlight set 1%- ;;
     41     *) printf 'usage: %s {start|restart|volume-*|brightness-*}\n' "$0" >&2; exit 2 ;;
     42 esac
     43 
     44 [ -n "$runtime" ] && [ -p "$fifo" ] || exit 0
     45 case $1 in
     46     volume-*)
     47         val=$(wpctl get-volume "$sink" 2>/dev/null) || exit 0
     48         out=$(printf '%s\n' "$val" | awk '{pct=int($2*100+0.5); if(pct>100)pct=100; if(index($0,"[MUTED]"))printf "%d muted",pct; else printf "%d",pct}')
     49         ;;
     50     brightness-*)
     51         info=$(brightnessctl --class=backlight --machine-readable info 2>/dev/null) || exit 0
     52         out=$(printf '%s\n' "$info" | awk -F, 'NR==1{pct=$4; sub(/%/,"",pct); if(pct~/^[0-9]+$/)print pct}')
     53         ;;
     54 esac
     55 [ -n "$out" ] || exit 0
     56 { printf '%s\n' "$out" >"$fifo"; } 2>/dev/null || true