Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alt as control #791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 9 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,18 @@ 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