diff --git a/src/rime/gear/ascii_composer.cc b/src/rime/gear/ascii_composer.cc index 91b809f3b1..440db93b82 100644 --- a/src/rime/gear/ascii_composer.cc +++ b/src/rime/gear/ascii_composer.cc @@ -56,8 +56,8 @@ AsciiComposer::~AsciiComposer() { } ProcessResult AsciiComposer::ProcessKeyEvent(const KeyEvent& key_event) { - if ((key_event.shift() && key_event.ctrl()) || key_event.alt() || - key_event.hyper() || key_event.super()) { + if ((key_event.Shift() && key_event.Ctrl()) || key_event.Alt() || + key_event.Hyper() || key_event.Super()) { shift_key_pressed_ = ctrl_key_pressed_ = false; return kNoop; } @@ -103,7 +103,7 @@ ProcessResult AsciiComposer::ProcessKeyEvent(const KeyEvent& key_event) { // other keys shift_key_pressed_ = ctrl_key_pressed_ = false; // possible key binding: Control+x, Shift+space - if (key_event.ctrl() || (key_event.shift() && ch == XK_space)) { + if (key_event.Ctrl() || (key_event.Shift() && ch == XK_space)) { return kNoop; } Context* ctx = engine_->context(); @@ -135,19 +135,19 @@ ProcessResult AsciiComposer::ProcessCapsLock(const KeyEvent& key_event) { return kRejected; } } - toggle_with_caps_ = !key_event.caps(); + toggle_with_caps_ = !key_event.Caps(); // NOTE: for Linux, Caps Lock modifier is clear when we are about to // turn it on; for Windows it is the opposite: // Caps Lock modifier has been set before we process VK_CAPITAL. // here we assume IBus' behavior and invert caps with ! operation. - SwitchAsciiMode(!key_event.caps(), caps_lock_switch_style_); + SwitchAsciiMode(!key_event.Caps(), caps_lock_switch_style_); return kAccepted; } else { return kRejected; } } - if (key_event.caps()) { - if (!good_old_caps_lock_ && !key_event.release() && !key_event.ctrl() && + if (key_event.Caps()) { + if (!good_old_caps_lock_ && !key_event.release() && !key_event.Ctrl() && isascii(ch) && isalpha(ch)) { // output ascii characters ignoring Caps Lock if (islower(ch)) diff --git a/src/rime/gear/chord_composer.cc b/src/rime/gear/chord_composer.cc index 639fcbde44..d6aee0f02d 100644 --- a/src/rime/gear/chord_composer.cc +++ b/src/rime/gear/chord_composer.cc @@ -75,17 +75,17 @@ static const char map_to_base_layer[] = { inline static int get_base_layer_key_code(const KeyEvent& key_event) { int ch = key_event.keycode(); - bool is_shift = key_event.shift(); + 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) { - if (key_event.ctrl() || key_event.alt()) { + if (key_event.Ctrl() || key_event.Alt()) { raw_sequence_.clear(); } - if ((key_event.ctrl() && !use_control_) || (key_event.alt() && !use_alt_) || - (key_event.shift() && !use_shift_)) { + if ((key_event.Ctrl() && !use_control_) || (key_event.Alt() && !use_alt_) || + (key_event.Shift() && !use_shift_)) { ClearChord(); return kNoop; } diff --git a/src/rime/gear/editor.cc b/src/rime/gear/editor.cc index bec8ae1ff6..f40208a9d9 100644 --- a/src/rime/gear/editor.cc +++ b/src/rime/gear/editor.cc @@ -55,8 +55,8 @@ ProcessResult Editor::ProcessKeyEvent(const KeyEvent& key_event) { return result; } } - if (char_handler_ && !key_event.ctrl() && !key_event.alt() && - !key_event.super() && !key_event.hyper() && ch > 0x20 && ch < 0x7f) { + if (char_handler_ && !key_event.Ctrl() && !key_event.Alt() && + !key_event.Super() && !key_event.Hyper() && ch > 0x20 && ch < 0x7f) { DLOG(INFO) << "input char: '" << (char)ch << "', " << ch << ", '" << key_event.repr() << "'"; return RIME_THIS_CALL(char_handler_)(ctx, ch); diff --git a/src/rime/gear/key_binding_processor_impl.h b/src/rime/gear/key_binding_processor_impl.h index e283770b14..ad0b4947a2 100644 --- a/src/rime/gear/key_binding_processor_impl.h +++ b/src/rime/gear/key_binding_processor_impl.h @@ -21,10 +21,10 @@ ProcessResult KeyBindingProcessor::ProcessKeyEvent( return kAccepted; } // try to match the fallback options - if (key_event.ctrl() || key_event.alt()) { + if (key_event.Ctrl() || key_event.Alt()) { return kNoop; } - if (key_event.shift()) { + if (key_event.Shift()) { if ((fallback_options & ShiftAsControl) != 0) { KeyEvent shift_as_control{ key_event.keycode(), diff --git a/src/rime/gear/punctuator.cc b/src/rime/gear/punctuator.cc index 096caef605..53fa4e6490 100644 --- a/src/rime/gear/punctuator.cc +++ b/src/rime/gear/punctuator.cc @@ -1,4 +1,4 @@ -// encoding: utf-8 +// encoding: utf-8 // // Copyright RIME Developers // Distributed under the BSD License @@ -59,8 +59,8 @@ static bool punctuation_is_translated(Context* ctx) { } ProcessResult Punctuator::ProcessKeyEvent(const KeyEvent& key_event) { - if (key_event.release() || key_event.ctrl() || key_event.alt() || - key_event.hyper() || key_event.super()) + if (key_event.release() || key_event.Ctrl() || key_event.Alt() || + key_event.Hyper() || key_event.Super()) return kNoop; int ch = key_event.keycode(); if (ch < 0x20 || ch >= 0x7f) diff --git a/src/rime/gear/recognizer.cc b/src/rime/gear/recognizer.cc index aa8583a845..079c83f933 100644 --- a/src/rime/gear/recognizer.cc +++ b/src/rime/gear/recognizer.cc @@ -79,8 +79,8 @@ Recognizer::Recognizer(const Ticket& ticket) : Processor(ticket) { } ProcessResult Recognizer::ProcessKeyEvent(const KeyEvent& key_event) { - if (patterns_.empty() || key_event.ctrl() || key_event.alt() || - key_event.hyper() || key_event.super() || key_event.release()) { + if (patterns_.empty() || key_event.Ctrl() || key_event.Alt() || + key_event.Hyper() || key_event.Super() || key_event.release()) { return kNoop; } int ch = key_event.keycode(); diff --git a/src/rime/gear/selector.cc b/src/rime/gear/selector.cc index 70a1a9f672..89e2b1d26c 100644 --- a/src/rime/gear/selector.cc +++ b/src/rime/gear/selector.cc @@ -116,8 +116,8 @@ inline static bool is_linear_layout(Context* ctx) { } ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) { - if (key_event.release() || key_event.alt() || key_event.hyper() || - key_event.super()) + if (key_event.release() || key_event.Alt() || key_event.Hyper() || + key_event.Super()) return kNoop; Context* ctx = engine_->context(); if (ctx->composition().empty()) @@ -140,7 +140,7 @@ ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) { int ch = key_event.keycode(); int index = -1; const string& select_keys(engine_->schema()->select_keys()); - if (!select_keys.empty() && !key_event.ctrl() && ch >= 0x20 && ch < 0x7f) { + if (!select_keys.empty() && !key_event.Ctrl() && ch >= 0x20 && ch < 0x7f) { size_t pos = select_keys.find((char)ch); if (pos != string::npos) { index = static_cast(pos); diff --git a/src/rime/gear/shape.cc b/src/rime/gear/shape.cc index c90ca45688..15dfe08cd3 100644 --- a/src/rime/gear/shape.cc +++ b/src/rime/gear/shape.cc @@ -39,8 +39,8 @@ ProcessResult ShapeProcessor::ProcessKeyEvent(const KeyEvent& key_event) { if (!engine_->context()->get_option("full_shape")) { return kNoop; } - if (key_event.ctrl() || key_event.alt() || key_event.hyper() || - key_event.super() || key_event.release()) { + if (key_event.Ctrl() || key_event.Alt() || key_event.Hyper() || + key_event.Super() || key_event.release()) { return kNoop; } int ch = key_event.keycode(); diff --git a/src/rime/gear/speller.cc b/src/rime/gear/speller.cc index 85c13d17b4..0970891694 100644 --- a/src/rime/gear/speller.cc +++ b/src/rime/gear/speller.cc @@ -92,13 +92,13 @@ Speller::Speller(const Ticket& ticket) } ProcessResult Speller::ProcessKeyEvent(const KeyEvent& key_event) { - if (key_event.release() || key_event.ctrl() || key_event.alt() || - key_event.hyper() || key_event.super()) + if (key_event.release() || key_event.Ctrl() || key_event.Alt() || + key_event.Hyper() || key_event.Super()) return kNoop; int ch = key_event.keycode(); if (ch < 0x20 || ch >= 0x7f) // not a valid key for spelling return kNoop; - if (ch == XK_space && (!use_space_ || key_event.shift())) + if (ch == XK_space && (!use_space_ || key_event.Shift())) return kNoop; if (!belongs_to(ch, alphabet_) && !belongs_to(ch, delimiters_)) return kNoop; diff --git a/src/rime/key_event.h b/src/rime/key_event.h index 58b34305ff..fc0d79873d 100644 --- a/src/rime/key_event.h +++ b/src/rime/key_event.h @@ -1,4 +1,4 @@ -// encoding: utf-8 +// encoding: utf-8 // // Copyright RIME Developers // Distributed under the BSD License @@ -26,12 +26,12 @@ class KeyEvent { int modifier() const { return modifier_; } void modifier(int value) { modifier_ = value; } - bool shift() const { return (modifier_ & kShiftMask) != 0; } - bool ctrl() const { return (modifier_ & kControlMask) != 0; } - bool alt() const { return (modifier_ & kAltMask) != 0; } - bool caps() const { return (modifier_ & kLockMask) != 0; } - bool super() const { return (modifier_ & kSuperMask) != 0; } - bool hyper() const { return (modifier_ & kHyperMask) != 0; } + bool Shift() const { return (modifier_ & kShiftMask) != 0; } + bool Ctrl() const { return (modifier_ & kControlMask) != 0; } + bool Alt() const { return (modifier_ & kAltMask) != 0; } + bool Caps() const { return (modifier_ & kLockMask) != 0; } + bool Super() const { return (modifier_ & kSuperMask) != 0; } + bool Hyper() const { return (modifier_ & kHyperMask) != 0; } bool release() const { return (modifier_ & kReleaseMask) != 0; } // 按鍵表示為形如「狀態+鍵名」的文字 // 若無鍵名,則以四位或六位十六进制数形式的文字來標識 diff --git a/src/rime/switcher.cc b/src/rime/switcher.cc index 7f6741883b..0e2bac8034 100644 --- a/src/rime/switcher.cc +++ b/src/rime/switcher.cc @@ -67,7 +67,7 @@ ProcessResult Switcher::ProcessKeyEvent(const KeyEvent& key_event) { return result; } } - if (key_event.release() || key_event.ctrl() || key_event.alt()) { + if (key_event.release() || key_event.Ctrl() || key_event.Alt()) { return kAccepted; } int ch = key_event.keycode(); diff --git a/test/key_event_test.cc b/test/key_event_test.cc index 06eb740913..c0350f94d5 100644 --- a/test/key_event_test.cc +++ b/test/key_event_test.cc @@ -31,9 +31,9 @@ TEST(RimeKeyEventTest, BadKeyName) { TEST(RimeKeyEventTest, ModifiedKeyEvent) { KeyEvent ke(XK_A, kShiftMask | kControlMask | kReleaseMask); - EXPECT_TRUE(ke.shift()); - EXPECT_FALSE(ke.alt()); - EXPECT_TRUE(ke.ctrl()); + EXPECT_TRUE(ke.Shift()); + EXPECT_FALSE(ke.Alt()); + EXPECT_TRUE(ke.Ctrl()); EXPECT_TRUE(ke.release()); } @@ -48,16 +48,16 @@ TEST(RimeKeyEventTest, ParseKeyEventRepresentation) { KeyEvent ke; ASSERT_TRUE(ke.Parse("Shift+Control+Release+A")); EXPECT_EQ(XK_A, ke.keycode()); - EXPECT_TRUE(ke.shift()); - EXPECT_FALSE(ke.alt()); - EXPECT_TRUE(ke.ctrl()); + EXPECT_TRUE(ke.Shift()); + EXPECT_FALSE(ke.Alt()); + EXPECT_TRUE(ke.Ctrl()); EXPECT_TRUE(ke.release()); } TEST(RimeKeyEventTest, ConstructKeyEventFromRepresentation) { KeyEvent ke("Alt+F4"); EXPECT_EQ(XK_F4, ke.keycode()); - EXPECT_TRUE(ke.alt()); + EXPECT_TRUE(ke.Alt()); EXPECT_FALSE(ke.release()); } @@ -89,7 +89,7 @@ TEST(RimeKeySequenceTest, PlainString) { // "{Shift_L}{Shift+A}{Shift+Release+A}{Shift_L+Release}" // here we just focus on the information useful to the ime EXPECT_EQ(XK_A, ks[8].keycode()); - EXPECT_FALSE(ks[8].shift()); + EXPECT_FALSE(ks[8].Shift()); } TEST(RimeKeySequenceTest, KeySequenceWithNamedKeys) { @@ -104,15 +104,15 @@ TEST(RimeKeySequenceTest, KeySequenceWithModifiedKeys) { KeySequence ks("zyx 123{Shift+space}ABC{Control+Alt+Return}"); ASSERT_EQ(12, ks.size()); EXPECT_EQ(XK_space, ks[3].keycode()); - EXPECT_FALSE(ks[3].shift()); + EXPECT_FALSE(ks[3].Shift()); EXPECT_FALSE(ks[3].release()); EXPECT_EQ(XK_space, ks[7].keycode()); - EXPECT_TRUE(ks[7].shift()); + EXPECT_TRUE(ks[7].Shift()); EXPECT_FALSE(ks[7].release()); EXPECT_EQ(XK_Return, ks[11].keycode()); - EXPECT_FALSE(ks[11].shift()); - EXPECT_TRUE(ks[11].ctrl()); - EXPECT_TRUE(ks[11].alt()); + EXPECT_FALSE(ks[11].Shift()); + EXPECT_TRUE(ks[11].Ctrl()); + EXPECT_TRUE(ks[11].Alt()); EXPECT_FALSE(ks[11].release()); }