+
+###--------------------------------------------------------------------------
+### User-facing operations.
+
+my %OP;
+
+$OP{"volume-up"} =
+ sub { run_discard_output "amixer", "sset", $C{mixer}, "5\%+"; };
+$OP{"volume-down"} =
+ sub { run_discard_output "amixer", "sset", $C{mixer}, "5\%-"; };
+
+$OP{"scratch"} = sub {
+ my $sk = configured_connection;
+ send_command $sk, "scratch";
+ close $sk;
+};
+
+$OP{"enable/disable"} = sub {
+ my $st = get_state;
+ my $sk =configured_connection;
+ if ($st->{play}) { send_command $sk, "disable"; }
+ else { send_command $sk, "enable"; }
+ close $sk;
+};
+
+$OP{"play/pause"} = sub {
+ my $st = get_state;
+ my $sk = configured_connection;
+ if (!$st->{play}) {
+ send_command $sk, "enable";
+ if ($st->{pause}) { send_command $sk, "resume"; }
+ } else {
+ if ($st->{pause}) { send_command $sk, "resume"; }
+ else { send_command $sk, "pause"; }
+ }
+ close $sk;
+};
+
+$OP{"watch"} = sub {
+ if (defined (my $lkpid = locked_by)) {
+ print STDERR "$0: already watched by pid $lkpid\n";
+ exit 2;
+ }
+ watch_and_notify 1;
+};
+
+$OP{"now-playing"} = sub {
+ my $sk = configured_connection;
+ my $info = get_now_playing $sk;
+ close $sk;
+ print format_now_playing %$info;
+ print "\n";
+};
+
+$OP{"notify-now-playing"} = sub {
+ my $sk = configured_connection;
+ my $info = get_now_playing $sk;
+ close $sk;
+ notify "$TITLE: Now playing", format_now_playing %$info;
+ unless (defined locked_by) {
+ fork and exit 0;
+ watch_and_notify 0;
+ }
+};
+
+$OP{"next-config"} = sub {
+ (my $dir = $C{config}) =~ s:/[^/]*$::;
+ my (@conf, $curr, $conf, $min);
+
+ if (-l $C{config} && (my $t = readlink $C{config}) =~ /^passwd\.(.*)$/)
+ { $curr = $1; }
+
+ opendir my $dh, +$dir;
+ FILE: while (my $f = readdir $dh)
+ { push @conf, $1 if $f =~ /^passwd\.(.*[^~])$/; }
+
+ for (my $i = 0; $i < @conf; $i++) {
+ $min = $conf[$i] if (!defined $min) || $conf[$i] lt $min;
+ $conf = $conf[$i]
+ if ((!defined $curr) || $curr lt $conf[$i]) &&
+ ((!defined $conf) || $conf[$i] lt $conf);
+ }
+ $conf = $min unless defined $conf;
+
+ try_unlink "$dir/passwd.new";
+ symlink "passwd.$conf", "$dir/passwd.new";
+ rename "$dir/passwd.new", "$dir/passwd";
+ notify "DisOrder configuration", "Switched to `$conf'";
+};
+
+###--------------------------------------------------------------------------
+### Main program.
+
+if (@ARGV != 1) { print STDERR "usage: $0 OP\n"; exit 2; }
+my $op = $ARGV[0];
+if (!exists $OP{$op}) { print STDERR "$0: unknown op `$op'\n"; exit 2; }
+$OP{$op}();
+
+###----- That's all, folks --------------------------------------------------