From b42b72dc2648499470b89418ac629e40f41d3149 Mon Sep 17 00:00:00 2001 From: Kris Yotam <75515498+krisyotam@users.noreply.github.com> Date: Thu, 2 Jul 2026 01:53:44 -0500 Subject: [PATCH] sb-battery: match macsmc-battery by type, add low-battery dunst alerts; xprofile: caps:super --- .config/x11/xprofile | 2 +- .local/bin/statusbar/sb-battery | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.config/x11/xprofile b/.config/x11/xprofile index 6a339399dd500fe023d2be5e0a7d6715dde829ed..6df74d2a4dc8c78483a8d5ebb821000dee82d8b7 100644 --- a/.config/x11/xprofile +++ b/.config/x11/xprofile @@ -15,7 +15,7 @@ else xrandr --dpi 128 # Desktop 1440p scaled fi ~/.screenlayout/main.sh # Set up monitor layout -setxkbmap -option caps:none # Completely disable Caps Lock +setxkbmap -option caps:super # Caps Lock acts as Super xrdb -merge ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources # Load base Xresources # HiDPI: on laptops tell Xft apps (st, dmenu, dwm bar) the real DPI and scale # the cursor. Merged after the base so it wins. diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index da5dd5deb9d198eba8f7a4059b326ee446774052..f6bd5acd005c7f51926ce9c12c2484acea176eb1 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -16,8 +16,10 @@ case $BLOCK_BUTTON in 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -# Loop through all attached batteries and format the info -for battery in /sys/class/power_supply/BAT?*; do +# Loop through all attached batteries and format the info. Match by type +# rather than a BAT?* name glob so Asahi's "macsmc-battery" is picked up too. +for battery in /sys/class/power_supply/*; do + [ -r "$battery/type" ] && [ "$(cat "$battery/type")" = "Battery" ] || continue # If non-first battery, print a space separator. [ -n "${capacity+x}" ] && printf " " # Sets up the status and capacity @@ -50,6 +52,22 @@ for battery in /sys/class/power_supply/BAT?*; do esac # Will make a warn variable if discharging and low [ "$charging_status" = "Discharging" ] && [ "$capacity" -le 25 ] && warn="󱃍" + # Low-battery notifications to dunst at 20/10/5%. State file avoids + # re-notifying every refresh; only fires once per band while discharging. + statefile="${XDG_CACHE_HOME:-$HOME/.cache}/sb-battery-band" + if [ "$capacity" -le 5 ]; then band=5 + elif [ "$capacity" -le 10 ]; then band=10 + elif [ "$capacity" -le 20 ]; then band=20 + else band=0; fi + prevband=$(cat "$statefile" 2>/dev/null) || prevband=0 + if [ "$charging_status" = "Discharging" ] && [ "$band" -ne 0 ] && [ "$band" != "$prevband" ]; then + case "$band" in + 5) notify-send -u critical "󱃍 Battery critical" "$capacity% remaining -- plug in now" ;; + 10) notify-send -u critical "󰁺 Battery very low" "$capacity% remaining" ;; + 20) notify-send -u normal "󰁻 Battery low" "$capacity% remaining" ;; + esac + fi + printf '%s' "$band" > "$statefile" 2>/dev/null # Prints the info printf "%s%s %d%%" "$status" "$warn" "$capacity"; unset warn done && printf "\\n"