Refreshing dwm status bar using signals. (#332)

Refreshing the status bar is now done using signals.
This commit is contained in:
msinkec 2019-06-12 21:08:38 +02:00 committed by Luke Smith
parent b5925045a3
commit 2e33d77b15
2 changed files with 18 additions and 8 deletions

View file

@ -3,6 +3,9 @@
# This script sets the statusbar with the xsetroot command at the end. Have it # This script sets the statusbar with the xsetroot command at the end. Have it
# started by ~/.xinitrc or ~/.xprofile. # started by ~/.xinitrc or ~/.xprofile.
# Handle SIGTRAP signals sent by refbar to update the status bar immediately.
trap 'update' 5
# Set the deliminter character. # Set the deliminter character.
delim="|" delim="|"
@ -66,20 +69,28 @@ status() { \
date '+%Y %b %d (%a) %I:%M%p' date '+%Y %b %d (%a) %I:%M%p'
} }
while :; do update() { \
# So all that big status function was just a command that quicking gets # So all that big status function was just a command that quicking gets
# what we want to be the statusbar. This xsetroot command is what sets # what we want to be the statusbar. This xsetroot command is what sets
# it. Note that the tr command replaces newlines with spaces. This is # it. Note that the tr command replaces newlines with spaces. This is
# to prevent some weird issues that cause significant slowing of # to prevent some weird issues that cause significant slowing of
# everything in dwm. Note entirely sure of the cause, but again, the tr # everything in dwm. Note entirely sure of the cause, but again, the tr
# command easily avoids it. # command easily avoids it.
xsetroot -name "$(status | tr '\n' ' ')" xsetroot -name "$(status | tr '\n' ' ')" &
wait
# Check to see if new weather report is needed. # Check to see if new weather report is needed.
testweather & testweather &
wait
}
while :; do
update
# Sleep for a minute after changing the status bar before updating it # Sleep for a minute after changing the status bar before updating it
# again. Note that the `refbar` "refreshes" the statusbar by killing # again. We run sleep in the background and use wait until it finishes,
# this command. Feel free to change the time interval if you want. # because traps can interrupt wait immediately, but they can't do that
sleep 1m # with sleep.
sleep 1m &
wait
done done

View file

@ -1,6 +1,5 @@
#!/bin/sh #!/bin/sh
# Refresh the dwmbar. # Refresh the dwmbar.
# Right now, now this is done is by killing the sleep in the bar script. # Send SIGTRAP signal to dwmbar script, which will handle it with a trap.
pkill -SIGTRAP dwmbar
kill "$(pstree -lp | grep -- -dwmbar\([0-9] | sed "s/.*sleep(\([0-9]\+\)).*/\1/")"