Commit eb4f2ec4 authored by Glen Mével's avatar Glen Mével

`bell` now fallbacks to using paplay

parent 2ffbc6e5
......@@ -15,7 +15,7 @@ THRESHOLD_CRITICAL=3
# Brightness at various stages of depletion, in percents.
BRIGHTNESS_NORMAL=20 # unused
BRIGHTNESS_SAVING=0.02
BRIGHTNESS_SAVING=1
# Frequency at which to check the status of the battery.
FREQUENCY=30s
......@@ -27,7 +27,6 @@ command -V acpi >/dev/null || return 1
# It relies on an external program being available, whose usage is as follows:
# bell $percent $pitch $duration
# I have one among my personal scripts.
# TODO: Fall back to paplay with some sounds from /usr/share/sounds/.
mybell() {
duration="$1"
command bell 100 800 "$duration"
......
......@@ -16,6 +16,11 @@ EVDEV_DEFAULT_DURATION=100
# Evdev device representing the PC speaker:
EVDEV_DEVICE='/dev/input/by-path/platform-pcspkr-evet-spkr'
# Sound file for the PulseAudio method:
AUDIO_FILE='/usr/share/sounds/freedesktop/stereo/bell.oga'
# This alarm sound brings more attention:
#AUDIO_FILE='/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga'
function is_integer() {
case "$1" in
*[!0-9]*) return 1 ;;
......@@ -85,8 +90,41 @@ function console_bell()
[ -w /dev/console ] && echo -ne '\a' >> /dev/console
}
# The PulseAudio method.
function paplay_bell()
{
# Only try this method if the required commands and files are available.
command -v paplay >/dev/null || return 1
[ -r "$AUDIO_FILE" ] || return 1
declare has_amixer=false
if command -v amixer >/dev/null ; then
has_amixer=true
# Save the sound settings.
declare -a settings
settings=( $(amixer -D pulse get Master | awk -F"[][]" '/%]/ { print $2" "$4 }') )
declare -i percent_left="${settings[0]%\%}"
declare enabled_left="${settings[1]}"
declare -i percent_right="${settings[2]%\%}"
declare enabled_right="${settings[3]}"
# Set up the volume.
declare -i percent_max="$percent_left"
[ "$percent_left" -lt "$percent_right" ] && percent_max="$percent_right"
[ "$percent" -eq 0 ] && percent="${percent_max/#0/"$X_DEFAULT_VOLUME"}"
amixer -D pulse set Master "$percent%" on || true
fi
# Play the sound file.
paplay "$AUDIO_FILE" || return 1
if [ "$has_amixer" = true ] ; then
# Restore the sound settings.
amixer -D pulse set Master "$percent_left%,$percent_right%" "$enabled_left,$enable_right" || true
fi
}
# Try all methods in order.
graphical_bell && exit
# FIXME: On my laptop, the X server method shows no error but does not work.
#graphical_bell && exit
evdev_bell && exit
console_bell && exit
paplay_bell && exit 2
exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment