From: Nick Bowler Date: Sun, 30 Jun 2019 14:41:08 +0000 (-0400) Subject: mpdmenu: Pass top menu name into submenu generation. X-Git-Url: https://git.draconx.ca/gitweb/mpdhacks.git/commitdiff_plain/82b8d686ad89f91d69f8bdcca3b469c4065e6b1c mpdmenu: Pass top menu name into submenu generation. This enables names based on the original menu name to be generated. Specifically, the KillMenuMPD function is now based on the original menu name, and the toplevel album menu is now actually the same menu as the corresponding entry in the artist menu. --- diff --git a/mpdmenu.pl b/mpdmenu.pl index 8e597e7..a12eb4c 100755 --- a/mpdmenu.pl +++ b/mpdmenu.pl @@ -38,9 +38,9 @@ my $port = $ENV{MPD_PORT} // "6600"; my $sock; my ($albumid, $trackid); -my %artistids; -my $menu; +my ($topmenu, $menu); my $mode = "top"; +my %artistids; # Quotes the argument so that it is presented as a single argument to MPD # at the protocol level. This also works OK for most FVWM arguments. @@ -112,7 +112,7 @@ sub fvwm_label_escape { sub make_submenu { my $name = shift; $name =~ s/-/_/g; - unshift @_, ("exec", $SELF, "--menu=$name"); + unshift @_, ("exec", $SELF, "--topmenu=$topmenu", "--menu=$name"); fvwm_cmd("DestroyFunc", "Make$name"); fvwm_cmd("AddToFunc", "Make$name"); @@ -120,14 +120,14 @@ sub make_submenu { fvwm_cmd("DestroyMenu", $name); fvwm_cmd("AddToMenu", $name, "DynamicPopupAction", "Make$name"); - fvwm_cmd("AddToFunc", "KillMenuMPD", "I", "DestroyMenu", $name); + fvwm_cmd("AddToFunc", "Kill$topmenu", "I", "DestroyMenu", $name); fvwm_cmd("DestroyFunc", "Make$name"); fvwm_cmd("AddToFunc", "Make$name"); fvwm_cmd("+", "I", "DestroyMenu", $name); fvwm_cmd("+", "I", "-PipeRead", join(' ', map { fvwm_shell_literal } @_)); - fvwm_cmd("AddToFunc", "KillMenuMPD", "I", "DestroyFunc", "Make$name"); + fvwm_cmd("AddToFunc", "Kill$topmenu", "I", "DestroyFunc", "Make$name"); return ("Popup", $name); } @@ -514,8 +514,16 @@ GetOptions( 'V|version' => sub { print_version(); exit }, 'H|help' => sub { print_help(); exit }, + + 'topmenu=s' => \$topmenu, # top menu name (for submenu generation) ) or do { print_usage; exit 1 }; +unless (defined $menu) { + $topmenu //= "MenuMPD"; + $menu = $topmenu . ($mode ne "top" ? $mode : ""); +} +$topmenu //= $menu; + # Connect to MPD. $sock = new IO::Socket::INET6( PeerAddr => $host, @@ -658,7 +666,8 @@ if ($mode eq "top") { my $entry = $matches->{$mbid}; my $thumb = shift @thumbs; - my @submenu = make_submenu("$menu-$mbid", "--album-id=$mbid"); + my @submenu = make_submenu("$topmenu-$mbid", + "--album-id=$mbid"); fvwm_cmd("AddToMenu", $menu, $thumb . fvwm_label_escape($entry->{Album}), @submenu);