Skip to content

Commit

Permalink
capitalization modifiers
Browse files Browse the repository at this point in the history
to bypass naming conflict (hyper) in Win
  • Loading branch information
groverlynn committed Aug 10, 2023
1 parent 816e14b commit cb6a299
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 49 deletions.
14 changes: 7 additions & 7 deletions src/rime/gear/ascii_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rime/gear/editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/rime/gear/key_binding_processor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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.Alt()) {
return kNoop;
}
if (key_event.shift()) {
if (key_event.Shift()) {
if ((fallback_options & ShiftAsControl) != 0) {
KeyEvent shift_as_control{
key_event.keycode(),
Expand Down
6 changes: 3 additions & 3 deletions src/rime/gear/punctuator.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// encoding: utf-8
// encoding: utf-8
//
// Copyright RIME Developers
// Distributed under the BSD License
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/rime/gear/recognizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/rime/gear/selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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<int>(pos);
Expand Down
4 changes: 2 additions & 2 deletions src/rime/gear/shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/rime/gear/speller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/rime/key_event.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// encoding: utf-8
// encoding: utf-8
//
// Copyright RIME Developers
// Distributed under the BSD License
Expand Down Expand Up @@ -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; }
// 按鍵表示為形如「狀態+鍵名」的文字
// 若無鍵名,則以四位或六位十六进制数形式的文字來標識
Expand Down
2 changes: 1 addition & 1 deletion src/rime/switcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 13 additions & 13 deletions test/key_event_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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());
}

Expand Down

0 comments on commit cb6a299

Please sign in to comment.