From 5ca60b282f2d9a86f545b0560b7cc07bb25fd8a9 Mon Sep 17 00:00:00 2001 From: Beau Hastings Date: Sun, 11 Oct 2020 11:30:57 +0800 Subject: [PATCH] feat: herbe notifications Signed-off-by: Beau Hastings --- README.md | 13 +++++++++---- volume | 56 ++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 33f2d1a..bae1a26 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ Use your keyboard volume keys to increase, decrease, or mute your volume. If you | ------------ | ------- | ----- | | ![notify-osd notifications](https://user-images.githubusercontent.com/195790/95647280-c3558780-0b00-11eb-987e-5924f2522bdb.png) | ![dunst notifications](https://user-images.githubusercontent.com/195790/95647273-afaa2100-0b00-11eb-8e2c-eb3eede89d7c.png) | ![xob notifications](https://user-images.githubusercontent.com/195790/95647285-d0727680-0b00-11eb-9600-56e4371b9a58.png) | -| [xosd] | -| ------ | -| ![xosd notifications](https://user-images.githubusercontent.com/195790/95656224-60371580-0b3f-11eb-9463-54698dadfd44.png) | +| [xosd] | [herbe] | +| ------ | ------- | +| ![xosd notifications](https://user-images.githubusercontent.com/195790/95656224-60371580-0b3f-11eb-9463-54698dadfd44.png) | ![herbe notifications](https://user-images.githubusercontent.com/195790/95669559-c6aa4b00-0bb4-11eb-8516-6beb500222f3.png) | Read about [notifications](https://github.com/hastinbe/i3-volume/wiki/Notifications) for more information. @@ -44,7 +44,7 @@ Options: -m toggle mute -M specify mixer (ex: Headphone), default Master -n show notifications - -N notification method (default: libnotify) + -N notification method (default: libnotify) -o output the volume according to the provided output format: generic = output the volume i3blocks = output the volume for i3blocks @@ -75,6 +75,10 @@ See our [example blocklet](https://github.com/hastinbe/i3-volume/wiki/Usage-with [xosd] notifications can be used by specifying the `-N xosd` option to your volume commands. [See an example](https://github.com/hastinbe/i3-volume/wiki/Usage-with-XOSD). +## herbe + +[herbe] notifications can be used by specifying the `-N herbe` option to your volume commands. [See an example](https://github.com/hastinbe/i3-volume/wiki/Usage-with-herbe). + ## Help Having a problem? Try reading our [common issues](https://github.com/hastinbe/i3-volume/wiki/Common-Issues) or open an [issue](https://github.com/hastinbe/i3-volume/issues/new). @@ -86,6 +90,7 @@ Copyright (C) 1989, 1991 Free Software Foundation, Inc. [alsa-utils]: https://alsa.opensrc.org/Alsa-utils [dunst]: https://dunst-project.org +[herbe]: https://github.com/dudik/herbe [i3blocks]: https://github.com/vivien/i3blocks [i3status]: https://github.com/i3/i3status [i3wm]: https://i3wm.org diff --git a/volume b/volume index 0aa8e9c..44d5fdf 100755 --- a/volume +++ b/volume @@ -327,17 +327,26 @@ notify_muted() { icon=${icons_symbolic[0]} fi - if $opt_use_dunstify; then - dunstify -i $icon -t $expires -h int:value:0 -h string:synchronous:volume "Volume muted" -r 1000 - else - if [ "$notification_method" = "xosd" ]; then + case "$notification_method" in + xosd) local delay=$(($expires / 1000)) osd_cat --align center -b percentage -P 0 -d $delay -p top -A center -c "$COLOR_MUTED" -T "Volume muted" -O 2 -u "$COLOR_XOSD_OUTLINE" - else - # libnotify - notify-send -i $icon -t $expires -h int:value:0 -h string:synchronous:volume "Volume muted" -h string:x-canonical-private-synchronous:i3-volume - fi - fi + ;; + + # There is a patch with a notify-send script for herbe, not in the current version at this time but would make this option irrelevant. See https://github.com/dudik/herbe/pull/10 + herbe) + # Dismiss existing/pending notifications to prevent queuing + pkill -SIGUSR1 herbe + herbe "Volume muted" & + ;; + *) # libnotify + if $opt_use_dunstify; then + dunstify -i $icon -t $expires -h int:value:0 -h string:synchronous:volume "Volume muted" -r 1000 + else + notify-send -i $icon -t $expires -h int:value:0 -h string:synchronous:volume "Volume muted" -h string:x-canonical-private-synchronous:i3-volume + fi + ;; + esac } # Display a notification indicating the current volume. @@ -351,18 +360,27 @@ notify_volume() { text="$text $progress" fi - if $opt_use_dunstify; then - dunstify -i "$icon" -t $expires -h int:value:"$vol" -h string:synchronous:volume "$text" -r 1000 - else - if [ "$notification_method" = "xosd" ]; then + case "$notification_method" in + xosd) local color=$(volume_color $vol) local delay=$(($expires / 1000)) osd_cat --align center -b percentage -P "$vol" -d $delay -p top -A center -c "$color" -T "$text" -O 2 -u "$COLOR_XOSD_OUTLINE" & - else - #libnotify - notify-send -i "$icon" -t $expires -h int:value:"$vol" -h string:synchronous:volume "$text" -h string:x-canonical-private-synchronous:i3-volume - fi - fi + ;; + + # There is a patch with a notify-send script for herbe, not in the current version at this time but would make this option irrelevant. See https://github.com/dudik/herbe/pull/10 + herbe) + # Dismiss existing/pending notifications to prevent queuing + pkill -SIGUSR1 herbe + herbe "$text" & + ;; + *) # libnotify + if $opt_use_dunstify; then + dunstify -i "$icon" -t $expires -h int:value:"$vol" -h string:synchronous:volume "$text" -r 1000 + else + notify-send -i "$icon" -t $expires -h int:value:"$vol" -h string:synchronous:volume "$text" -h string:x-canonical-private-synchronous:i3-volume + fi + ;; + esac } # Updates the status line. @@ -527,7 +545,7 @@ Options: -m toggle mute -M specify mixer (ex: Headphone), default Master -n show notifications - -N notification method (default: libnotify) + -N notification method (default: libnotify) -o output the volume according to the provided output format: generic = output the volume i3blocks = output the volume for i3blocks