Skip to content

Commit

Permalink
feat(chord_composer): support chording with Shift keys
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Aug 23, 2020
1 parent 7c08a90 commit 94cf479
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,39 @@ ProcessResult ChordComposer::ProcessFunctionKey(const KeyEvent& key_event) {
return kNoop;
}

// Note: QWERTY layout only.
static const char map_to_base_layer[] = {
" 1'3457'908=,-./"
"0123456789;;,=./"
"2abcdefghijklmno"
"pqrstuvwxyz[\\]6-"
"`abcdefghijklmno"
"pqrstuvwxyz[\\]`"
};

inline static int get_base_layer_key_code(const KeyEvent& key_event) {
int ch = key_event.keycode();
bool is_shift = key_event.shift();
return (is_shift && ch >= 0x20 && ch <= 0x7e)
? map_to_base_layer[ch - 0x20] : ch;
}

ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
bool chording = !chord_.empty();
if (key_event.shift() || key_event.ctrl() || key_event.alt()) {
if (key_event.ctrl() || key_event.alt()) {
raw_sequence_.clear();
ClearChord();
return chording ? kAccepted : kNoop;
}
bool is_key_up = key_event.release();
int ch = key_event.keycode();
int ch = get_base_layer_key_code(key_event);
// non chording key
if (std::find(chording_keys_.begin(),
chording_keys_.end(),
KeyEvent{ch, 0}) == chording_keys_.end()) {
return chording ? kAccepted : kNoop;
}
// chording key
bool is_key_up = key_event.release();
if (is_key_up) {
if (pressed_.erase(ch) != 0 && pressed_.empty()) {
FinishChord();
Expand All @@ -95,6 +112,9 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
}

ProcessResult ChordComposer::ProcessKeyEvent(const KeyEvent& key_event) {
if (engine_->context()->get_option("ascii_mode")) {
return kNoop;
}
if (pass_thru_) {
return ProcessFunctionKey(key_event);
}
Expand Down

0 comments on commit 94cf479

Please sign in to comment.