Skip to content

Commit

Permalink
feat: xosd support. notification method option (-N)
Browse files Browse the repository at this point in the history
Signed-off-by: Beau Hastings <[email protected]>
  • Loading branch information
hastinbe committed Oct 10, 2020
1 parent 4637ca2 commit f346fc8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 54 deletions.
60 changes: 35 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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> card number to control (amixer only)
-d <amount> decrease volume
-e <expires> expiration time of notifications, in milliseconds
-i <amount> increase volume
-l use fullcolor instead of symbolic icons
-m toggle mute
-M <mixer> specify mixer (amixer only, default: Master)
-n show notifications
-o <generic|i3blocks|xob|"format">
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 <sink_name> symbolic name of sink (pulseaudio only)
-S <suffix> add a suffix to symbolic icon names
-t <process_name> name of status line process. must be used with -u
-u <signal> update status line using signal. must be used with -t
-v <value> set volume
-x <value> set maximum volume
-X <value> 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> card number to control (amixer only)
-d <amount> decrease volume
-e <expires> expiration time of notifications, in milliseconds
-i <amount> increase volume
-l use fullcolor instead of symbolic icons
-m toggle mute
-M <mixer> specify mixer (ex: Headphone), default Master
-n show notifications
-N <libnotify|xosd> notification method (default: libnotify)
-o <generic|i3blocks|xob|"format"> 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 <sink_name> symbolic name of sink (pulseaudio only)
-S <suffix> add a suffix to symbolic icon names
-t <process_name> name of status line process. must be used with -u
-u <signal> update status line using signal. must be used with -t
-v <value> set volume
-x <value> set maximum volume
-X <value> set maximum amplification (if the device supports it. default: 2)
-y use dunstify instead of notify-send
-h display this help and exit
```

## i3blocks
Expand All @@ -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).
Expand All @@ -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/
76 changes: 47 additions & 29 deletions volume
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -505,32 +518,32 @@ usage() {
Control volume and related notifications.
Options:
-a use alsa-utils instead of pulseaudio-utils for volume control
-c <card> card number to control (amixer only)
-d <amount> decrease volume
-e <expires> expiration time of notifications, in milliseconds
-i <amount> increase volume
-l use fullcolor instead of symbolic icons
-m toggle mute
-M <mixer> specify mixer (ex: Headphone), default Master
-n show notifications
-o <generic|i3blocks|xob|\"format\">
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 <sink_name> symbolic name of sink (pulseaudio only)
-S <suffix> add a suffix to symbolic icon names
-t <process_name> name of status line process. must be used with -u
-u <signal> update status line using signal. must be used with -t
-v <value> set volume
-x <value> set maximum volume
-X <value> 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> card number to control (amixer only)
-d <amount> decrease volume
-e <expires> expiration time of notifications, in milliseconds
-i <amount> increase volume
-l use fullcolor instead of symbolic icons
-m toggle mute
-M <mixer> specify mixer (ex: Headphone), default Master
-n show notifications
-N <libnotify|xosd> notification method (default: libnotify)
-o <generic|i3blocks|xob|\"format\"> 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 <sink_name> symbolic name of sink (pulseaudio only)
-S <suffix> add a suffix to symbolic icon names
-t <process_name> name of status line process. must be used with -u
-u <signal> update status line using signal. must be used with -t
-v <value> set volume
-x <value> set maximum volume
-X <value> 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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}"
;;
Expand Down

0 comments on commit f346fc8

Please sign in to comment.