feat: replace conky by sbar and pactl by wpctl

This commit is contained in:
AngeD 2023-02-10 16:25:46 +01:00
parent 897a049f47
commit ae3db45cc7
9 changed files with 121 additions and 43 deletions

View File

@ -1,14 +0,0 @@
conky.config = {
background = false,
out_to_console = true,
out_to_x = false,
short_units = true,
top_cpu_separate = true,
total_run_times = 0,
update_interval = 2,
use_spacer = 'none',
};
conky.text = [[
 ${loadavg 1} |  $memeasyfree |  $acpitemp |  $pa_sink_volume |  ${battery_percent BAT1} | ${time %a %m/%d %R}
]]

@ -1 +1 @@
Subproject commit 902d6aa31450d26e11bedcbef8af5b6fe2e1ffe8
Subproject commit aeb76066212b09c7c01a3abb42fe82f0130ef402

@ -1 +1 @@
Subproject commit f0a70e0993acbb348c32a52a88058cc60c160992
Subproject commit a55d0b62326341bf6ac0538d2d88836ac1cd77e5

@ -1 +1 @@
Subproject commit 69867ffe7e05559fdb055f6b5a2589fc6bee1070
Subproject commit f6df07be122de665fb363476cc3680c90f5bdf05

@ -1 +1 @@
Subproject commit f8bf8f0029a475831ebfba0799975ede20e08742
Subproject commit 041c35ffc8cd97dd6327f44e35fa777af6f8e845

View File

@ -9,8 +9,8 @@ numlockx
xrandr \
--output "${LAPTOP_SCREEN}" --mode 1920x1080 --rate 60 --primary
# --output DisplayPort-1-1 --auto --right-of eDP \
# --output DisplayPort-1-2 --auto --right-of DisplayPort-1-1
# --output DisplayPort-1-1 --auto --pos 1920x0 \
# --output DisplayPort-1-2 --auto --pos 3840x0
)
# startup
@ -19,11 +19,9 @@ picom &
redshift &
feh --bg-tile "$XDG_CONFIG_HOME/wallpapers/landscape.png" --no-fehbg
dunst &
sbar &
xset dpms 300 15 # dim 5m, lock 5m15s
xss-lock lock &
#bar
(conky | while read LINE; do xsetroot -name "$LINE"; done) &
exec dwm
exec dbus-launch dwm

84
bin/sbar Executable file
View File

@ -0,0 +1,84 @@
#!/bin/bash
# INIT
printf "$$" > "$HOME/.cache/pidofbar"
# MODULES
update_crypto() {
crypto="$(crypto)"
}
update_cpu() {
cpu=" $(grep -o "^[^ ]*" /proc/loadavg)"
}
update_memory() {
memory=" $(free -h | sed -n '2s/\([^ ]* *\)\{2\}\([^ ]*\).*/\2/p')"
}
update_bat() {
bat="$(grep -q Charging /sys/class/power_supply/BAT1/status && printf '' || printf '')"
bat="$bat $(cat /sys/class/power_supply/BAT1/capacity)%"
}
update_vol() {
local v="$(wpctl get-volume '@DEFAULT_AUDIO_SINK@')"
if grep -q 'MUTED' <<< "$v"; then
vol='🔇'
else
vol=" $((10#$(tr -dc '[0-9]' <<< "$v")))"
fi
}
update_backlight() {
local actual_brightness
local max_brightness
read -r actual_brightness </sys/class/backlight/*/actual_brightness
read -r max_brightness </sys/class/backlight/*/max_brightness
backlight=" $((actual_brightness * 100 / max_brightness))%"
}
update_time() {
time="$(date "+%a %m/%d %R")"
}
# For calcurse users, refer https://github.com/pystardust/automeet
#update_event () {
# event="$(calcurse -n | sed 1d | \
# sed -E "s_^ *\[(.*):(.*)\] ([^\t]*)\t?.*_[\1h \2m->\3]_")"
# [ "[]" = "$event" ] && event=""
#}
# modules that don't update on their own need to be run at the start for getting their initial value
update_vol
update_backlight
display() {
xsetroot -name "$crypto | $cpu | $memory | $vol | $backlight | $bat | $time"
}
# SIGNALING
# trap "<function>;display" "RTMIN+n"
trap "update_vol;display" "RTMIN"
trap "update_backlight;display" "RTMIN+1"
trap "update_bat;display" "RTMIN+2"
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
# where m = 34 + n
sec=0
while true; do
sleep 1 & wait && {
[ $((sec % 3600)) -eq 0 ] && update_crypto
[ $((sec % 1 )) -eq 0 ] && update_time
[ $((sec % 5 )) -eq 0 ] && update_cpu
[ $((sec % 5 )) -eq 0 ] && update_memory
[ $((sec % 5 )) -eq 0 ] && update_bat
[ $((sec % 5 )) -eq 0 ] && display
sec="$((sec + 1))"
}
done

View File

@ -41,6 +41,9 @@ done
echo "$NEW" > "$CUR_FILE"
# update sbar
kill -35 "$(cat "$HOME/.cache/pidofbar")"
if [ -t 1 ]; then
echo "$NEW"
fi

View File

@ -1,29 +1,36 @@
#!/bin/bash
set -e
SINK='@DEFAULT_SINK@'
SINK='@DEFAULT_AUDIO_SINK@'
VOL="$(pactl get-sink-volume "$SINK")"
VOL="$(grep -Po '\d+(?=%)' <<< "$VOL" | head -n 1)"
VOL="$((VOL - VOL % "$1"))"
if [ "$1" == 'm' ]; then
wpctl set-mute "$SINK" toggle
else
VOL="$((10#$(wpctl get-volume "$SINK" | tr -dc '[0-9]')))"
[ -n "$1" ] && VOL="$((VOL - VOL % $1))"
case "${1:0:1}" in
'')
exit 1
;;
'+'|'-')
VOL="$((VOL + "$1"))"
;;
*)
VOL="$1"
;;
esac
case "${1:0:1}" in
'')
echo "$VOL"
exit
;;
'+'|'-')
VOL="$((VOL + $1))"
;;
*)
VOL="$1"
;;
esac
[ "$VOL" -lt 0 ] && VOL=0
[ "$VOL" -gt 100 ] && VOL=100
[ "$VOL" -lt 0 ] && VOL=0
[ "$VOL" -gt 100 ] && VOL=100
pactl set-sink-volume "$SINK" "$VOL%"
pactl set-sink-mute "$SINK" 0
wpctl set-volume "$SINK" "$VOL%"
wpctl set-mute "$SINK" 0
fi
# update sbar
kill -34 "$(cat "$HOME/.cache/pidofbar")"
if [ -t 1 ]; then
echo "$VOL"