#!/usr/bin/perl

$STATEFILE = "/etc/acpi/vol-mute-state.sh";

if ( -r $STATEFILE ) {
	system("DISPLAY=:0 /usr/local/bin/popup ' UNMUTE ' &");
	system("sh $STATEFILE");
	unlink($STATEFILE);
	exit;
}

system("DISPLAY=:0 /usr/local/bin/popup ' MUTE ' &");
open(MIXER, "amixer set Master mute|") || die "No mixer";
while (<MIXER>) {
	if (/Left:\s+Playback\s+(\d+)/) { $left = $1; }
	elsif (/Right:\s+Playback\s+(\d+)/) { $right = $1; }
}
close(MIXER);
$left += 0;
$right += 0;
open(STATE, ">$STATEFILE") || die "$STATEFILE: $!";
print STATE "amixer set Master $left,$right unmute\n";
close(STATE);
