From f346fc82ac642772cbf296f4127357918f5294d2 Mon Sep 17 00:00:00 2001 From: Beau Hastings Date: Sat, 10 Oct 2020 21:02:30 +0800 Subject: [PATCH] feat: xosd support. notification method option (-N) Signed-off-by: Beau Hastings --- README.md | 60 +++++++++++++++++++++++++------------------ volume | 76 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 82 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index efbd291..7c73ca2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ 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) | + Read about [notifications](https://github.com/hastinbe/i3-volume/wiki/Notifications) for more information. ### Standalone @@ -31,31 +35,32 @@ Usage: volume [options] Control volume and related notifications. Options: - -a use alsa-utils instead of pulseaudio-utils for volume control - -c card number to control (amixer only) - -d decrease volume - -e expiration time of notifications, in milliseconds - -i increase volume - -l use fullcolor instead of symbolic icons - -m toggle mute - -M specify mixer (amixer only, default: Master) - -n show notifications - -o - output the volume according to the provided output format: - generic = output the volume - i3blocks = output the volume for i3blocks - "format" = output using a format string. substitutions: - %v = current volume - -p show text volume progress bar - -s symbolic name of sink (pulseaudio only) - -S add a suffix to symbolic icon names - -t name of status line process. must be used with -u - -u update status line using signal. must be used with -t - -v set volume - -x set maximum volume - -X set maximum amplification (if the device supports it. default: 2) - -y use dunstify instead of notify-send - -h display this help and exit + -a use alsa-utils instead of pulseaudio-utils for volume control + -c card number to control (amixer only) + -d decrease volume + -e expiration time of notifications, in milliseconds + -i increase volume + -l use fullcolor instead of symbolic icons + -m toggle mute + -M specify mixer (ex: Headphone), default Master + -n show notifications + -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 + xob = output the volume for xob + "format" = output using a format string. substitutions: + %v = current volume + -p show text volume progress bar + -s symbolic name of sink (pulseaudio only) + -S add a suffix to symbolic icon names + -t name of status line process. must be used with -u + -u update status line using signal. must be used with -t + -v set volume + -x set maximum volume + -X set maximum amplification (if the device supports it. default: 2) + -y use dunstify instead of notify-send + -h display this help and exit ``` ## i3blocks @@ -66,6 +71,10 @@ See our [example blocklet](https://github.com/hastinbe/i3-volume/wiki/Usage-with [xob] requires extra steps to use for notifications. See our [guide](https://github.com/hastinbe/i3-volume/wiki/Usage-with-xob) for how to set that up. +## xosd + +[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). + ## 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). @@ -88,3 +97,4 @@ Copyright (C) 1989, 1991 Free Software Foundation, Inc. [pulseaudio-utils]: https://www.freedesktop.org/wiki/Software/PulseAudio/ [wiki]: https://github.com/hastinbe/i3-volume/wiki [xob]: https://github.com/florentc/xob +[xosd]: https://sourceforge.net/projects/libxosd/ diff --git a/volume b/volume index cd11254..bdcc50f 100755 --- a/volume +++ b/volume @@ -330,7 +330,13 @@ notify_muted() { 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 + if [ "$notification_method" = "xosd" ]; then + 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 } @@ -348,7 +354,14 @@ notify_volume() { 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 + if [ "$notification_method" = "xosd" ]; then + 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 } @@ -505,32 +518,32 @@ usage() { Control volume and related notifications. Options: - -a use alsa-utils instead of pulseaudio-utils for volume control - -c card number to control (amixer only) - -d decrease volume - -e expiration time of notifications, in milliseconds - -i increase volume - -l use fullcolor instead of symbolic icons - -m toggle mute - -M specify mixer (ex: Headphone), default Master - -n show notifications - -o - output the volume according to the provided output format: - generic = output the volume - i3blocks = output the volume for i3blocks - xob = output the volume for xob - \"format\" = output using a format string. substitutions: - %v = current volume - -p show text volume progress bar - -s symbolic name of sink (pulseaudio only) - -S add a suffix to symbolic icon names - -t name of status line process. must be used with -u - -u update status line using signal. must be used with -t - -v set volume - -x set maximum volume - -X set maximum amplification (if the device supports it. default: 2) - -y use dunstify instead of notify-send - -h display this help and exit + -a use alsa-utils instead of pulseaudio-utils for volume control + -c card number to control (amixer only) + -d decrease volume + -e expiration time of notifications, in milliseconds + -i increase volume + -l use fullcolor instead of symbolic icons + -m toggle mute + -M specify mixer (ex: Headphone), default Master + -n show notifications + -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 + xob = output the volume for xob + \"format\" = output using a format string. substitutions: + %v = current volume + -p show text volume progress bar + -s symbolic name of sink (pulseaudio only) + -S add a suffix to symbolic icon names + -t name of status line process. must be used with -u + -u update status line using signal. must be used with -t + -v set volume + -x set maximum volume + -X set maximum amplification (if the device supports it. default: 2) + -y use dunstify instead of notify-send + -h display this help and exit " 1>&2 exit 1 } @@ -568,6 +581,7 @@ COLOR_MUTED_TO_BASE=${COLOR_MUTED_TO_BASE:-"#00FF00"} COLOR_BASE_TO_NORM=${COLOR_BASE_TO_NORM:-"#FFFF00"} COLOR_NORM_TO_MAX=${COLOR_NORM_TO_MAX:-"#FF0000"} COLOR_OTHER=${COLOR_OTHER:-"#FFFFFF"} +COLOR_XOSD_OUTLINE=${COLOR_XOSD_OUTLINE:-"#222222"} ########################################################### # Command line option variables @@ -593,8 +607,9 @@ max_volume="" max_amplification="2" symbolic_icon_suffix="" output_mode="" +notification_method="libnotify" -while getopts ":ac:d:e:hi:lmM:no:ps:S:t:u:v:x:X:y" o; do +while getopts ":ac:d:e:hi:lmM:nN:o:ps:S:t:u:v:x:X:y" o; do case "$o" in a) opt_use_amixer=true @@ -625,6 +640,9 @@ while getopts ":ac:d:e:hi:lmM:no:ps:S:t:u:v:x:X:y" o; do n) opt_notification=true ;; + N) + notification_method="${OPTARG}" + ;; o) output_mode="${OPTARG}" ;;