diff --git a/src/unix/ibus/key_event_handler.cc b/src/unix/ibus/key_event_handler.cc index e7e3f0afd..e6b6bb4aa 100644 --- a/src/unix/ibus/key_event_handler.cc +++ b/src/unix/ibus/key_event_handler.cc @@ -62,6 +62,18 @@ bool KeyEventHandler::GetKeyEvent(uint keyval, uint keycode, uint modifiers, DCHECK(key); key->Clear(); + // Ignore key events with modifiers, except for the below; + // - Alt (Mod1) - Mozc uses Alt for shortcuts + // - NumLock (Mod2) - NumLock shouldn't impact shortcuts + // This is needed for handling shortcuts such as Super (Mod4) + Space, + // IBus's default for switching input methods. + // https://github.com/google/mozc/issues/853 + constexpr uint kExtraModMask = + IBUS_MOD3_MASK | IBUS_MOD4_MASK | IBUS_MOD5_MASK; + if (modifiers & kExtraModMask) { + return false; + } + if (!key_translator_->Translate(keyval, keycode, modifiers, preedit_method, layout_is_jp, key)) { LOG(ERROR) << "Translate failed"; diff --git a/src/unix/ibus/key_event_handler_test.cc b/src/unix/ibus/key_event_handler_test.cc index 8db8d6ea4..8e6bbda6e 100644 --- a/src/unix/ibus/key_event_handler_test.cc +++ b/src/unix/ibus/key_event_handler_test.cc @@ -180,6 +180,13 @@ TEST_F(KeyEventHandlerTest, GetKeyEvent) { EXPECT_NO_MODIFIERS_PRESSED(); } + { // Ignore Super (Mod4) + key.Clear(); + EXPECT_FALSE(handler_->GetKeyEvent(IBUS_space, kDummyKeycode, + IBUS_MOD4_MASK, config::Config::ROMAN, + true, &key)); + } + // This test fails in current implementation. // TODO(hsumita): Enables it. /*