Skip to content

Commit

Permalink
💄 Improve display of keybindings (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfrenoy committed Feb 28, 2021
1 parent 0ce2262 commit c69737d
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions lib/PACKeyBindings.pm
Expand Up @@ -83,7 +83,9 @@ sub GetKeyMask {
my $ctrl = $state * ['control-mask'] ? 'Ctrl' : '';
my $alt = $state * ['mod1-mask'] ? 'Alt' : '';

#print "$keyval : $unicode : $ctrl : $shift\n";
if ($self->{verbose}) {
print "INFO: GETKEYMASK: $keyval, $unicode, $ctrl / $shift\n";
}

# Test special keys
if ($keyval =~ /^KP_(.+)/) {
Expand Down Expand Up @@ -325,7 +327,7 @@ sub update {
if ($kb =~ /^undef-/) {
$kb = '';
}
push(@{$$self{frame}{keylist}{'data'}}, {value => ["<b>$$wk{$k}[0]</b>", $$wk{$k}[2], $kb, $$wk{$k}[1], $w], children => []});
push(@{$$self{frame}{keylist}{'data'}}, {value => ["<b>$$wk{$k}[0]</b>", $$wk{$k}[2], $self->stringifyKeybind($kb), $$wk{$k}[1], $w], children => []});
}
}
}
Expand All @@ -336,6 +338,50 @@ sub get_cfg {
return $self->{cfg};
}

sub stringifyKeybind {
my $self = shift;
my $kb = shift;

if ($kb =~ /\+[A-Z]$/) {
$kb = 'Shift+' . $kb;
$kb =~ s/(.*)\+([A-Z])$/$1\+\L$2/;
}
if ($kb =~ /CtrlShift\+/) {
$kb =~ s/(.*)CtrlShift\+(.*)/$1Shift\+Ctrl\+$2/;
}
if ($kb =~ /AltCtrl\+/) {
$kb =~ s/(.*)AltCtrl\+(.*)/$1Alt\+Ctrl\+$2/;
}
if ($kb =~ /CtrlAlt\+/) {
$kb =~ s/(.*)CtrlAlt\+(.*)/$1Alt\+Ctrl\+$2/;
}
if ($kb =~ /Shift\+Ctrl\+/) {
$kb =~ s/(.*)Shift\+Ctrl\+(.*)/$1Ctrl\+Shift\+$2/;
}

return $kb;
}

sub unStringifyKeybind {
my $self = shift;
my $kb = shift;

if ($kb =~ /Shift\+[a-z]$/) {
$kb =~ s/(.*)Shift\+([a-z])$/$1\U$2/;
}
if ($kb =~ /Ctrl\+Shift\+/) {
$kb =~ s/(.*)Ctrl\+Shift\+(.*)/$1Shift\+Ctrl\+$2/;
}
if ($kb =~ /Alt\+Ctrl\+/) {
$kb =~ s/(.*)Alt\+Ctrl\+(.*)/$1AltCtrl\+$2/;
}
if ($kb =~ /Shift\+Ctrl\+/) {
$kb =~ s/(.*)Shift\+Ctrl\+(.*)/$1CtrlShift\+$2/;
}

return $kb;
}

# END: Public class methods
###################################################################

Expand Down Expand Up @@ -539,6 +585,8 @@ sub _buildGUI {
my ($window, $desc, $keybind, $action, $pacwin) = $model->get($model->get_iter($paths[0]));
my ($keyval, $unicode, $keymask) = $self->GetKeyMask($widget, $event);

$keybind = $self->unStringifyKeybind($keybind);

if ($self->{verbose}) {
print "INFO: KEY: $keyval, $unicode, $keymask\n";
print "INFO: ROW: $window : $desc : $keybind : $action : $pacwin\n";
Expand Down Expand Up @@ -595,7 +643,7 @@ sub _updateKeyBinding {
} else {
$warning = "This keybind will not be available for window <b>$$cfg{$w}{$keynew}[0]</b>\nwhen <b>$other</b> is visible.";
}
_wMessage($self->{parent}, "<i>$keynew</i> used in\n\n<b>$$cfg{$w}{$keynew}[0]</b> : $$cfg{$w}{$keynew}[2]\n\n$warning");
_wMessage($self->{parent}, "<i>" . $self->stringifyKeybind($keynew) . "</i> used in\n\n<b>$$cfg{$w}{$keynew}[0]</b> : $$cfg{$w}{$keynew}[2]\n\n$warning");
}
}
}
Expand All @@ -609,7 +657,7 @@ sub _updateKeyBinding {
if ($undef) {
$keynew = '';
}
$model->set_value($model->get_iter($path), 2, Glib::Object::Introspection::GValueWrapper->new('Glib::String', $keynew));
$model->set_value($model->get_iter($path), 2, Glib::Object::Introspection::GValueWrapper->new('Glib::String', $self->stringifyKeybind($keynew)));
}

# END: Private Methods
Expand Down

0 comments on commit c69737d

Please sign in to comment.