diff --git a/polybar-scripts/dunst-controller/README.md b/polybar-scripts/dunst-controller/README.md new file mode 100644 index 00000000..c5670516 --- /dev/null +++ b/polybar-scripts/dunst-controller/README.md @@ -0,0 +1,30 @@ +# dunstctl, a dunst controller script & module + +This script is written in [`fish`](https://fishshell.com/), and displays a bell +icon that can be used to interact with [`dunst`](https://github.com/dunst-project/dunst) +via `dunstctl`, and utilises `dunstify` to send notifications. + +Click to show historic notifications, middle-click to mute/unmute notifications, +and right-click to dismiss all. Double left click will show all notification history. + +`chmod +x $HOME/.config/polybar/scripts/dunstctl.sh` (or the path of your choice.) + +## Preview + +![dunst](dunstctl-0.png) +![dunst-pause](dunstctl-1.png) + +![dunst-notif](dunstctl-2.png) + +## Example module + +```ini +[module/dunstctl] +click-left = dunstctl history-pop +click-middle = $HOME/.config/polybar/scripts/dunstctl.sh toggle +click-right = dunstctl close-all +double-click-left = $HOME/.config/polybar/scripts/dunstctl.sh show-all +exec = $HOME/.config/polybar/scripts/dunstctl.sh +interval = 1.6 +type = custom/script +``` diff --git a/polybar-scripts/dunst-controller/dunstctl b/polybar-scripts/dunst-controller/dunstctl new file mode 100755 index 00000000..9fd98cbc --- /dev/null +++ b/polybar-scripts/dunst-controller/dunstctl @@ -0,0 +1,44 @@ +#! /usr/bin/env fish + +function unmute + dunstctl set-paused false && \ + dunstify 'dunst' 'Unmuted notifications.' -i polari -u low & +end + +function mute + dunstify 'dunst' 'Muting notifications...' -i polari -u low & + # We're about to mute notifications, so the above notification will + # effectively not show, since set-paused hides notifications. So, sleep + # for 2 seconds. + sleep 2 + # Close all to prevent notification from showing up once we unmute. + dunstctl close-all + dunstctl set-paused true +end + +function pop_all + for id in (dunstctl history | jq -r '.data[][].id.data') + dunstctl history-pop $id + end +end + +if test (dunstctl is-paused) = "true" + switch $argv[1] + case 'toggle' + unmute + case 'show-all' + unmute + pop_all + case '*' + echo ' '(dunstctl count waiting) + end +else + switch $argv[1] + case 'toggle' + mute + case 'show-all' + pop_all + case '*' + echo '' + end +end diff --git a/polybar-scripts/dunst-controller/dunstctl-0.png b/polybar-scripts/dunst-controller/dunstctl-0.png new file mode 100644 index 00000000..3470775e Binary files /dev/null and b/polybar-scripts/dunst-controller/dunstctl-0.png differ diff --git a/polybar-scripts/dunst-controller/dunstctl-1.png b/polybar-scripts/dunst-controller/dunstctl-1.png new file mode 100644 index 00000000..b6729793 Binary files /dev/null and b/polybar-scripts/dunst-controller/dunstctl-1.png differ diff --git a/polybar-scripts/dunst-controller/dunstctl-2.png b/polybar-scripts/dunst-controller/dunstctl-2.png new file mode 100644 index 00000000..b063f6fc Binary files /dev/null and b/polybar-scripts/dunst-controller/dunstctl-2.png differ diff --git a/polybar-scripts/dunst-controller/dunstctl.ini b/polybar-scripts/dunst-controller/dunstctl.ini new file mode 100644 index 00000000..dd2e115c --- /dev/null +++ b/polybar-scripts/dunst-controller/dunstctl.ini @@ -0,0 +1,8 @@ +[module/dunstctl] +click-left = dunstctl history-pop +click-middle = $HOME/.config/polybar/scripts/dunstctl.sh toggle +click-right = dunstctl close-all +double-click-left = $HOME/.config/polybar/scripts/dunstctl.sh show-all +exec = $HOME/.config/polybar/scripts/dunstctl.sh +interval = 1.6 +type = custom/script diff --git a/polybar-scripts/dunst-controller/dunstctl.sh b/polybar-scripts/dunst-controller/dunstctl.sh new file mode 100755 index 00000000..10f5e180 --- /dev/null +++ b/polybar-scripts/dunst-controller/dunstctl.sh @@ -0,0 +1,50 @@ +#! /usr/bin/env sh + +unmute() { + dunstctl set-paused false && \ + dunstify 'dunst' 'Unmuted notifications.' -i polari -u low & +} + +mute() { + dunstify 'dunst' 'Muting notifications...' -i polari -u low & + # We're about to mute notifications, so the above notification will + # effectively not show, since set-paused hides notifications. So, sleep + # for 2 seconds. + sleep 2 + # Close all to prevent notification from showing up once we unmute. + dunstctl close-all + dunstctl set-paused true +} + +pop_all() { + dunstctl history | jq '.data[][].id.data' | while IFS= read -r id; do + dunstctl history-pop "$id" + done +} + +if [ "$(dunstctl is-paused)" = 'true' ]; then + case $1 in + toggle) + unmute + ;; + show-all) + unmute + pop_all + ;; + *) + echo " $(dunstctl count waiting)" + ;; + esac +else + case $1 in + toggle) + mute + ;; + show-all) + pop_all + ;; + *) + echo '' + ;; + esac +fi