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 17, 2024
1 parent abd1927 commit f87c73d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/unix/ibus/key_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
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 f87c73d

Please sign in to comment.