Skip to content

Commit

Permalink
alt_as_control
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Jan 4, 2024
1 parent 72f833d commit 18e8959
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/rime/gear/key_binding_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class KeyBindingProcessor {

enum FallbackOptions {
None = 0,
ShiftAsControl = (1 << 0),
IgnoreShift = (1 << 1),
All = ShiftAsControl | IgnoreShift,
AltAsControl = (1 << 0),
ShiftAsControl = (1 << 1),
IgnoreShift = (1 << 2),
All = AltAsControl | ShiftAsControl | IgnoreShift
};

struct ActionDef {
Expand Down
12 changes: 10 additions & 2 deletions src/rime/gear/key_binding_processor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ ProcessResult KeyBindingProcessor<T, N>::ProcessKeyEvent(
return kAccepted;
}
// try to match the fallback options
if (key_event.ctrl() || key_event.alt()) {
if (key_event.ctrl() || key_event.super()) {
return kNoop;
}
if (key_event.alt() && (fallback_options & AltAsControl)) {
KeyEvent alt_as_control{
key_event.keycode(),
(key_event.modifier() & ~kAltMask) | kControlMask};
if (Accept(alt_as_control, ctx, keymap)) {
return kAccepted;
}
}
if (key_event.shift()) {
if ((fallback_options & ShiftAsControl) != 0) {
if ((fallback_options & ShiftAsControl) && !key_event.alt()) {
KeyEvent shift_as_control{
key_event.keycode(),
(key_event.modifier() & ~kShiftMask) | kControlMask};
Expand Down

0 comments on commit 18e8959

Please sign in to comment.