diff --git a/tools/fmt-bindings b/tools/fmt-bindings index 55fe42710d..be1b23bf52 100755 --- a/tools/fmt-bindings +++ b/tools/fmt-bindings @@ -4,6 +4,7 @@ use Getopt::Long; $semicolon = ";"; # help out stupid emacs +$title = "Ardour Shortcuts"; $in_group_def = 0; $group_name; $group_text; @@ -14,12 +15,22 @@ $group_number = 0; %group_bindings; %modifier_map; %group_numbering; +%merge_bindings; $platform = linux; +$winkey = 'Mod4> \$platform); +GetOptions ("platform=s" => \$platform, + "winkey=s" => \$winkey, + "cheatsheet" => \$make_cheatsheet, + "accelmap" => \$make_accelmap, + "merge=s" => \$merge_from); if ($platform eq "osx") { + $gtk_modifier_map{'PRIMARY'} = 'meta'; $gtk_modifier_map{'SECONDARY'} = 'Mod1'; $gtk_modifier_map{'TERTIARY'} = 'Shift'; @@ -27,24 +38,39 @@ if ($platform eq "osx") { $gtk_modifier_map{'WINDOW'} = 'Mod1'; $cs_modifier_map{'PRIMARY'} = 'Command'; - $cs_modifier_map{'SECONDARY'} = 'Alt'; + $cs_modifier_map{'SECONDARY'} = 'Opt'; $cs_modifier_map{'TERTIARY'} = 'Shift'; $cs_modifier_map{'LEVEL4'} = 'Control'; - $cs_modifier_map{'WINDOW'} = 'Alt'; + $cs_modifier_map{'WINDOW'} = 'Opt'; + + $mouse_modifier_map{'PRIMARY'} = 'Cmd'; + $mouse_modifier_map{'SECONDARY'} = 'Opt'; + $mouse_modifier_map{'TERTIARY'} = 'Shift'; + $mouse_modifier_map{'LEVEL4'} = 'Control'; + $mouse_modifier_map{'WINDOW'} = 'Opt'; } else { $gtk_modifier_map{'PRIMARY'} = 'Control'; $gtk_modifier_map{'SECONDARY'} = 'Alt'; $gtk_modifier_map{'TERTIARY'} = 'Shift'; - $gtk_modifier_map{'LEVEL4'} = 'Mod4'; + $gtk_modifier_map{'LEVEL4'} = $winkey; $gtk_modifier_map{'WINDOW'} = 'Alt'; + $gtk_modifier_map{$winkey} => 'Win'; $cs_modifier_map{'PRIMARY'} = 'Control'; $cs_modifier_map{'SECONDARY'} = 'Alt'; $cs_modifier_map{'TERTIARY'} = 'Shift'; $cs_modifier_map{'LEVEL4'} = 'Win'; $cs_modifier_map{'WINDOW'} = 'Alt'; + $cs_modifier_map{$winkey} => 'Win'; + + $mouse_modifier_map{'PRIMARY'} = 'Ctl'; + $mouse_modifier_map{'SECONDARY'} = 'Alt'; + $mouse_modifier_map{'TERTIARY'} = 'Shift'; + $mouse_modifier_map{'LEVEL4'} = 'Win'; + $mouse_modifier_map{'WINDOW'} = 'Alt'; + $mouse_modifier_map{$winkey} => 'Win'; } %keycodes = ( @@ -55,6 +81,7 @@ if ($platform eq "osx") { 'braceleft' => '\\{', 'braceright' => '\\}', 'backslash' => '$\\backslash$', + 'slash' => '/', 'rightanglebracket' => '>', 'leftanglebracket' => '<', 'ampersand' => '\\&', @@ -73,12 +100,37 @@ if ($platform eq "osx") { 'Page_Down' => 'Page Down', 'Page_Up' => 'Page Up', 'space' => 'space', - 'KP_' => 'KP$\_$' + 'KP_' => 'KP$\_$', ); +if ($merge_from) { + open (BINDINGS, $merge_from) || die ("merge from bindings: file not readable"); + while () { + next if (/^$semicolon/); + if (/^\(gtk_accel/) { + chop; # newline + chop; # closing parenthesis + s/"//g; + ($junk, $action, $binding) = split; + $merge_bindings{$action} = $binding; + } + } + close (BINDINGS); +} + +if ($make_accelmap && !$merge_from) { + print ";; this accelmap was produced by tools/fmt-bindings\n"; +} + while (<>) { next if /^$semicolon/; + if (/^\$/) { + s/^\$//; + $title = $_; + next; + } + if (/^%/) { if ($in_group_def) { @@ -125,9 +177,15 @@ while (<>) { $gtk_binding = $binding; - foreach $k (keys %gtk_modifier_map) { - $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/; - } + if ($merge_from) { + $lookup = "/" . $action; + if ($merge_bindings{$lookup}) { + $binding = $merge_bindings{$lookup}; + } else { + # this action is not defined in the merge from set, so forget it + next; + } + } # print the accelmap output @@ -136,7 +194,12 @@ while (<>) { $key =~ s/^\+//; } else { # include this in the accelmap - # print "(gtk_accel_map \"/$action\" \"$gtk_binding\")\n"; + if (!$merge_from && $make_accelmap) { + foreach $k (keys %gtk_modifier_map) { + $gtk_binding =~ s/\@$k\@/$gtk_modifier_map{$k}/; + } + print "(gtk_accel_map \"/$action\" \"$gtk_binding\")\n"; + } } if ($key =~ /^-/) { @@ -153,6 +216,10 @@ while (<>) { next; } +if ($make_accelmap || !$make_cheatsheet) { + exit 0; +} + # Now print the cheatsheet $boilerplate_header = < $group_numbering{$b} } keys %group_numbering; @@ -226,7 +309,7 @@ foreach $gk (@groups_sorted_by_number) { $bref = $group_bindings{$gk}; if (scalar @$bref > 1) { - print "\\section*{$group_names{$gk}}\n"; + print "\\section{$group_names{$gk}}\n"; if (!($group_text{$gk} eq "")) { print "$group_text{$gk}\n\\par\n"; @@ -244,6 +327,12 @@ foreach $gk (@groups_sorted_by_number) { for $bbref (@$bref) { # $bbref is a reference to an array $text = @$bbref[1]; + + # + # if there is a linebreak, just use everything up the linebreak + # to determine the width + # + if ($text =~ /\\linebreak/) { $matchtext = s/\\linebreak.*//; } else { @@ -255,7 +344,12 @@ foreach $gk (@groups_sorted_by_number) { } } - $maxtext .= "...."; + if ($gk =~ /^m/) { + # mouse mode: don't extend max text at all - space it tight + $maxtext .= "."; + } else { + $maxtext .= "...."; + } # set up the table @@ -264,9 +358,10 @@ foreach $gk (@groups_sorted_by_number) { \@{}p{\\linewidth-\\the\\MyLen}% \@{}}\n"; - # now print the bindings + # sort the array of arrays by the descriptive text for nicer appearance, + # and print them - for $bbref (@$bref) { + for $bbref (sort { @$a[1] cmp @$b[1] } @$bref) { # $bbref is a reference to an array $binding = @$bbref[0]; @@ -276,14 +371,21 @@ foreach $gk (@groups_sorted_by_number) { ($binding,$where) = split (/:/, $binding, 2); } + if ($gk =~ /^m/) { + # mouse mode - use shorter abbrevs + foreach $k (keys %mouse_modifier_map) { + $binding =~ s/\@$k\@/$mouse_modifier_map{$k}/; + } + } else { + foreach $k (keys %cs_modifier_map) { + $binding =~ s/\@$k\@/$cs_modifier_map{$k}/; + } + } + $binding =~ s/>/\+/; - foreach $k (keys %cs_modifier_map) { - $binding =~ s/\@$k\@/$cs_modifier_map{$k}/; - } - # substitute keycode names for something printable $re = qr/${ \(join'|', map quotemeta, keys %keycodes)}/;