Skip to content

Commit

Permalink
Ignore Super and other modifier keys except for Alt
Browse files Browse the repository at this point in the history
Mozc doesn't know Super and other extra modifier keys except for Alt.
For example, "Super + Space" (IBus' default for switching input methods)
is recognized as "Space".

This change ignores key events that have these extra modifiers to let
others handle the events.

Fixes #853.
  • Loading branch information
kzys committed Sep 14, 2024
1 parent abd1927 commit 4913a3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/unix/ibus/key_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace mozc {
namespace ibus {

namespace {

bool IsModifierToBeSentOnKeyUp(const commands::KeyEvent &key_event) {
if (key_event.modifier_keys_size() == 0) {
return false;
Expand All @@ -62,6 +63,18 @@ bool KeyEventHandler::GetKeyEvent(uint keyval, uint keycode, uint modifiers,
DCHECK(key);
key->Clear();

// Mozc doesn't use modifier keys except for Mod1 (Alt).
// If the key is pressed with the modifiers, don't pass that to
// the translator.
// This is needed for handling shortcuts such as Super-Space,
// IBus's default for switching input methods.
// https://github.com/google/mozc/issues/853
constexpr uint kExtraModMask =
IBUS_MOD2_MASK | 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";
Expand Down
7 changes: 7 additions & 0 deletions src/unix/ibus/key_event_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/*
Expand Down

0 comments on commit 4913a3c

Please sign in to comment.