slitaz-configs rev 274

Add tazvolume
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 11 14:44:02 2016 +0200 (2016-03-11)
parents b975ae9cc394
children f7bdf041bb02
files rootfs/etc/xdg/openbox/rc.xml rootfs/usr/bin/tazvolume
line diff
     1.1 --- a/rootfs/etc/xdg/openbox/rc.xml	Wed Feb 24 17:14:20 2016 +0100
     1.2 +++ b/rootfs/etc/xdg/openbox/rc.xml	Fri Mar 11 14:44:02 2016 +0200
     1.3 @@ -295,17 +295,17 @@
     1.4      </keybind>
     1.5      <keybind key="XF86AudioMute">
     1.6        <action name="Execute">
     1.7 -        <command>amixer set Master toggle</command>
     1.8 +        <command>tazvolume toggle</command>
     1.9        </action>
    1.10      </keybind>
    1.11      <keybind key="XF86AudioRaiseVolume">
    1.12        <action name="Execute">
    1.13 -        <command>amixer set Master 5%+</command>
    1.14 +        <command>tazvolume +</command>
    1.15        </action>
    1.16      </keybind>
    1.17      <keybind key="XF86AudioLowerVolume">
    1.18        <action name="Execute">
    1.19 -        <command>amixer set Master 5%-</command>
    1.20 +        <command>tazvolume -</command>
    1.21        </action>
    1.22      </keybind>
    1.23      <keybind key="A-Print">
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/rootfs/usr/bin/tazvolume	Fri Mar 11 14:44:02 2016 +0200
     2.3 @@ -0,0 +1,55 @@
     2.4 +#!/bin/sh
     2.5 +# Change sound volume with notifications
     2.6 +# SliTaz GNU/Linux
     2.7 +# Aleksej Bobylev <al.bobylev@gmail.com>, March, 2016
     2.8 +
     2.9 +# Deal with commands: "toggle" (for mute/unmute), "+" and "-" (+- 5%), or number (set volume %)
    2.10 +case $1 in
    2.11 +	toggle) amixer set Master toggle;;
    2.12 +	"+") amixer set Master 5%+;;
    2.13 +	"-") amixer set Master 5%-;;
    2.14 +	*)   amixer set Master "$1%";;
    2.15 +esac >/dev/null
    2.16 +
    2.17 +
    2.18 +[ -z $(which notify-send) ] && exit
    2.19 +# Deal with Freedesktop notification system
    2.20 +
    2.21 +# Get current volume (0..100)
    2.22 +vol=$(amixer sget Master | tail -n1 | sed -n 's|.*\[\([0-9]*\)%.*|\1|p')
    2.23 +[ -z "$vol" ] && vol='0'
    2.24 +
    2.25 +# Get notification ID to replace
    2.26 +nid='/var/run/notify.id'
    2.27 +if [ -f "$nid" ]; then
    2.28 +	old=$(($(date -u +%s) - $(date -ur "$nid" +%s)))
    2.29 +	# remove if older than 3 seconds
    2.30 +	[ $old -gt 3 ] && rm "$nid"
    2.31 +fi
    2.32 +replace=''
    2.33 +[ -f "$nid" ] && replace="--replace-id=$(cat "$nid")"
    2.34 +
    2.35 +# Define notification icon
    2.36 +muted=''
    2.37 +if [ $vol -eq  0 ] || amixer sget Master | tail -n1 | fgrep -q '[off]'; then
    2.38 +	icon='audio-volume-muted'; muted="(muted)"
    2.39 +elif [ $vol -le 50 ]; then
    2.40 +	icon='audio-volume-low';
    2.41 +elif [ $vol -le 75 ]; then
    2.42 +	icon='audio-volume-medium';
    2.43 +else
    2.44 +	icon='audio-volume-high';
    2.45 +fi
    2.46 +
    2.47 +# Use hints to show gauge in Canonical's notify-osd
    2.48 +# Use text for other notify implementations
    2.49 +notify-send \
    2.50 +	--hint=string:x-canonical-private-synchronous:yes \
    2.51 +	--hint=int:value:$vol \
    2.52 +	--icon=$icon \
    2.53 +	--urgency=low \
    2.54 +	--expire-time=2000 \
    2.55 +	$replace \
    2.56 +	--print-id \
    2.57 +	"Volume" "$vol% $muted" \
    2.58 +> "$nid"