]> code.delx.au - mediapc-tools/blobdiff - mediawrap
ffclicker: load pages in Firefox
[mediapc-tools] / mediawrap
index ac712873a6aef3feafcf1d771db2cf6e32a43bf9..1c4c396cedbc183fc9b232fdd29ffb81072d3751 100755 (executable)
--- a/mediawrap
+++ b/mediawrap
@@ -1,29 +1,55 @@
 #!/bin/bash
 
+LOCKFILE="$HOME/.mediawrap.lock"
 PULSESTATE="$HOME/.pulseaudio.state"
-KEYPATH="/apps/gnome_settings_daemon/keybindings"
 
-# Disable volume keys
-gconftool --set --type string "$KEYPATH/volume_up" ''
-gconftool --set --type string "$KEYPATH/volume_down" ''
-gconftool --set --type string "$KEYPATH/volume_mute" ''
+(
+if ! flock -w 10 -x 200; then
+       echo "Failed to get a lock!"
+       exit 1
+fi
+echo "got lock"
 
 # Unmute everything and turn volume to full
-pacmd 'dump' | grep 'set-sink' > "$PULSESTATE"
-cat "$PULSESTATE" | grep 'set-sink-mute' | awk '{print $2;}' | \
-       while read device; do
-               pacmd "set-sink-volume $device 0x10000" > /dev/null
-               pacmd "set-sink-mute $device no" > /dev/null
-       done
+if [ "$1" = "--max-volume" ]; then
+       echo "max volume"
+       max_volume=1
+       shift
+       pacmd 'dump' | grep 'set-sink' > "$PULSESTATE"
+       cat "$PULSESTATE" | grep 'set-sink-mute' | awk '{print $2;}' | \
+               while read device; do
+                       pacmd "set-sink-volume $device 0x10000" > /dev/null
+                       pacmd "set-sink-mute $device no" > /dev/null
+               done
+fi
+
+# Switch volume keys to F9/F10 with xmodmap
+if [ "$1" = "--switch-volume-keys" ]; then
+       echo "switch volume"
+       switch_volume=1
+       shift
+       xmodmap -e 'keycode 122 = F9'
+       xmodmap -e 'keycode 123 = F10'
+fi
+
 
 # Run the program
-"$@"
+"$@" &> /dev/null
+
 
 # Restore volume levels and mute status
-cat "$PULSESTATE" | pacmd > /dev/null
+if [ -n "$max_volume" ]; then
+       cat "$PULSESTATE" | pacmd > /dev/null
+fi
+
+# Restore volume keys
+if [ -n "$switch_volume" ]; then
+       xmodmap -e 'keycode 122 = XF86AudioLowerVolume'
+       xmodmap -e 'keycode 123 = XF86AudioRaiseVolume'
+fi
+
+) 200>"$LOCKFILE"
 
-# Enable volume keys
-gconftool --set --type string "$KEYPATH/volume_up" 'XF86AudioRaiseVolume'
-gconftool --set --type string "$KEYPATH/volume_down" 'XF86AudioLowerVolume'
-gconftool --set --type string "$KEYPATH/volume_mute" 'XF86AudioMute'
+# Cleanup so other programs can start
+rm -f "$LOCKFILE"