feat: sbar wlp module, dwm builtin set-light

This commit is contained in:
AngeD 2023-04-05 15:16:24 +02:00
parent 36576bb3cb
commit 0b54bbc089
10 changed files with 61 additions and 49 deletions

@ -1 +1 @@
Subproject commit 0bc0c38e1b11dfb6b5f1794d53869f89ccf9e78f Subproject commit 7179a46c2345050783d14397e672e7b152a7af4f

@ -1 +1 @@
Subproject commit 871f5665d92d59a369cf916e9aa4d321d466f1e3 Subproject commit 411e771d511442ab81670701f5c830f6c74aadd7

@ -1 +1 @@
Subproject commit d6372de826221674d1421ba3598aedc214183417 Subproject commit a259fb34124799ff99e62e97a0905592c42a82b8

@ -1 +1 @@
Subproject commit 8d23fbd6964b8446bbc73ff04507362d1fd49eb5 Subproject commit 25c2c3a4683be60c3526858be960ee6ce1249245

Binary file not shown.

2
bin/music Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
firefox -P music

View File

@ -17,7 +17,8 @@ update_memory() {
} }
update_bat() { update_bat() {
local dir="$(echo /sys/class/power_supply/BAT* | sort -n | tail -n1)" local dir; dir="$(echo /sys/class/power_supply/BAT*/ | sort -n | tail -n1)"
bat="$(grep -q Charging "$dir/status" && printf '' || printf '')" bat="$(grep -q Charging "$dir/status" && printf '' || printf '')"
bat="$bat $(cat "$dir/capacity")%" bat="$bat $(cat "$dir/capacity")%"
} }
@ -41,6 +42,21 @@ update_backlight() {
backlight=" $((actual_brightness * 100 / max_brightness))%" backlight=" $((actual_brightness * 100 / max_brightness))%"
} }
update_wlp() {
local sig; sig="$(grep wlp /proc/net/wireless | awk '{print $3 * 100}')"
local ssid; ssid="$(nmcli -t -f name,device connection show --active | grep wlp | cut -d: -f1)"
[ -z "$ssid" ] && wlp='⚠' && return
echo "$sig"
# https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/libnmc-base/nm-client-utils.c#L628
{ [ "$sig" -gt 5600 ] && wlp="▂▄▆█ $ssid"; } ||
{ [ "$sig" -gt 3850 ] && wlp="▂▄▆_ $ssid"; } ||
{ [ "$sig" -gt 1650 ] && wlp="▂▄__ $ssid"; } ||
{ [ "$sig" -gt 275 ] && wlp="▂___ $ssid"; } ||
{ wlp="____ $ssid"; }
}
update_time() { update_time() {
time="$(date "+%a %m/%d %R")" time="$(date "+%a %m/%d %R")"
} }
@ -59,29 +75,36 @@ done
update_vol update_vol
update_backlight update_backlight
reload_bar() {
sec=0
}
display() { display() {
xsetroot -name "$crypto | $cpu | $memory | $vol | $backlight | $bat | $time" xsetroot -name "$crypto | $cpu | $memory | $vol | $backlight | $wlp | $bat | $time"
} }
# SIGNALING # SIGNALING
# trap "<function>;display" "RTMIN+n" # trap '<function>;display' 'RTMIN+n'
trap "update_vol;display" "RTMIN" trap 'reload_bar;display' 'RTMIN'
trap "update_backlight;display" "RTMIN+1" trap 'update_vol;display' 'RTMIN+1'
trap "update_bat;display" "RTMIN+2" trap 'update_backlight;display' 'RTMIN+2'
trap 'update_crypto;display' 'RTMIN+3'
# to update it from external commands # to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)" ## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n # where m = 34 + n
sec=0 sec=0
while true; do while true; do
sleep 1 & wait && { [ "$((sec % 3600))" = 0 ] && update_crypto
[ $((sec % 3600)) -eq 0 ] && update_crypto [ "$((sec % 5 ))" = 0 ] && {
[ $((sec % 5 )) -eq 0 ] && update_time update_time
[ $((sec % 5 )) -eq 0 ] && update_cpu update_cpu
[ $((sec % 5 )) -eq 0 ] && update_memory update_memory
[ $((sec % 5 )) -eq 0 ] && update_bat update_bat
[ $((sec % 5 )) -eq 0 ] && display update_wlp
display
sec="$((sec + 1))"
} }
sleep 1 & wait
sec="$((sec + 1))"
done done

View File

@ -1,29 +0,0 @@
#!/bin/bash -e
shopt -s extglob nullglob
set_brightness() {
local max; max="$(cat "$1"/max_brightness)"
local file="$1"/brightness
local val="$(($2 * max / 100 + 1))"
[ "$val" -lt 0 ] && val=0
[ "$val" -gt "$max" ] && val="$max"
echo "$val" > "$file"
}
CUR_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/current_brightness"
CUR="$(cat "$CUR_FILE" 2> /dev/null || echo 50)"
case "${1:0:1}" in
'') echo "$CUR"; exit ;;
'+'|'-') NEW="$((CUR - CUR % $1 + $1))" ;;
*) NEW="$1" ;;
esac
for dev in /sys/class/backlight/*; do
set_brightness "$dev" "$NEW"
done
echo "$NEW" > "$CUR_FILE"
kill -35 "$(cat "$HOME/.cache/pidofbar")"

View File

@ -18,4 +18,4 @@ else
fi fi
# update sbar # update sbar
kill -34 "$(cat "$HOME/.cache/pidofbar")" kill -35 "$(cat "$HOME/.cache/pidofbar")"

16
bin/set-wlp Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash -e
if [ -n "$1" ]; then
nmcli device wifi con "$1"
else
readarray -t NET <<< \
"$(nmcli -f SSID,CHAN,RATE,SIGNAL,BARS,SECURITY dev wifi list \
| awk '!seen[$1]++')"
COLUMNS=1
select net in "${NET[@]}"; do
nmcli device wifi con "$(awk '{print $1}' <<< "$net")" && break
done
fi
kill -37 "$(cat "$HOME/.cache/pidofbar")"