Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore Super and other modifier keys except for Alt #1059

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

kzys
Copy link
Contributor

@kzys kzys commented Sep 13, 2024

Description

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.

Issue IDs

#853

Steps to test new behaviors (if any)

A clear and concise description about how to verify new behaviors (if any).

  • OS: Ubuntu 24.04 + Wayland
  • Steps:
    1. Switch to Japanese (Mozc) by pressing Super-Space
    2. Switch to English by pressing Super-Space again
    3. Confirm the switch (before this PR, a full-width space was inserted instead)

Additional context

Add any other context about the pull request here.

@kzys kzys changed the title Ignore Super and other modifier keys Ignore Super and other modifier keys except for Alt Sep 13, 2024
@phoepsilonix
Copy link
Contributor

phoepsilonix commented Sep 13, 2024

When using ibus-mozc with Japanese input mode enabled and set to full-width hiragana input mode, there is an issue where pressing Super+space inserts a full-width space instead of switching the input source. This PR resolves this issue. I tested it on Manjaro Linux(GNOME/Wayland) and confirmed that it works well.

#854

@hiroyuki-komatsu
Copy link
Collaborator

Hi kzys,

Thank you for your PR with tests! Overall, it looks good to me.
I left small comments regarding our coding style.

Thank you,

@@ -38,6 +38,10 @@ namespace mozc {
namespace ibus {

namespace {

// Mod1 is Alt, which is used by Mozc.
const uint kExtraModMask = IBUS_MOD2_MASK | IBUS_MOD3_MASK | IBUS_MOD4_MASK | IBUS_MOD5_MASK;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use constexper instead of const, and move this into the function.
Also please wrap the line within 80 chars.

  // Mod1 is Alt, which is used by Mozc.
  constexpr uint kExtraModMask =
      IBUS_MOD2_MASK | IBUS_MOD3_MASK | IBUS_MOD4_MASK | IBUS_MOD5_MASK;
  if (modifiers & kExtraModMask) {
    return false;
  }

@@ -62,6 +66,14 @@ bool KeyEventHandler::GetKeyEvent(uint keyval, uint keycode, uint modifiers,
DCHECK(key);
key->Clear();

// If the key is pressed with these extra modifiers that Mozc doesn't know,
// don't pass to the translator.
// This is needed to handle Super-Space, IBus's default for switching input methods.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the line within 80 chars.

  // If the key is pressed with these extra modifiers that Mozc doesn't know,
  // don't pass to the translator. This is needed to handle Super-Space, IBus's
  // default for switching input methods.
  // https://github.com/google/mozc/issues/853

@kzys
Copy link
Contributor Author

kzys commented Sep 14, 2024

Thanks! Addressed in the last revision.

@@ -38,6 +38,7 @@ namespace mozc {
namespace ibus {

namespace {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@phoepsilonix
Copy link
Contributor

I continued troubleshooting.
It might depend on keyboard layouts, but in my environment, adding IBUS_MOD2_MASK to kExtraModMask prevented the IME from being activated by the half-width/full-width key or the hiragana key.
Removing IBUS_MOD2_MASK from kExtraModMask and using only IBUS_MOD4_MASK, or adding either or both of IBUS_MOD3_MASK and IBUS_MOD5_MASK, allowed the IME to be activated.
Since this might be environment-dependent, I think it might be better to limit it to just IBUS_MOD4_MASK for the Super key to minimize potential impacts.

For your reference.

 * @IBUS_MOD1_MASK: Modifier 1 (Usually Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)) activated.
 * @IBUS_MOD2_MASK: Modifier 2 (Usually Num_Lock (0x4d)) activated.
 * @IBUS_MOD3_MASK: Modifier 3 activated.
 * @IBUS_MOD4_MASK: Modifier 4 (Usually Super_L (0xce),  Hyper_L (0xcf)) activated.
 * @IBUS_MOD5_MASK: Modifier 5 (ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)) activated.

@kzys
Copy link
Contributor Author

kzys commented Sep 15, 2024

It might depend on keyboard layouts, but in my environment, adding IBUS_MOD2_MASK to kExtraModMask prevented the IME from being activated by the half-width/full-width key or the hiragana key.

Thanks for testing. Let me check. I don't have a Japanese keyboard nearby though.

I don't know how these Japanese-specific keys get Mod2. Is it coming from XKB somehow?

https://github.com/ibus/ibus/blob/fa10c116c2f0dad5026fa6665e9513cd5dcded75/client/wayland/ibuswaylandim.c#L692-L693

@kzys
Copy link
Contributor Author

kzys commented Sep 15, 2024

@phoepsilonix Can you check xmodmap on your machine? I got the below.

% xmodmap 
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Alt_L (0xcc),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        ISO_Level5_Shift (0xcb)
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c)

@phoepsilonix
Copy link
Contributor

phoepsilonix commented Sep 15, 2024

@kzys

Hi.
I'm also a bit confused, not knowing what impact numlock actually has. My laptop might be starting to malfunction.😂
The differences are about as follows. Eisu_toglle probably refers to the alphanumeric toggle.(Eisu=英数(えいすう)=英語の文字、数字=alphabet and numeric.)

lock Eisu_toggle (0x42)
lock Caps_Lock (0x42)

xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Eisu_toggle (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Alt_L (0xcc),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        ISO_Level5_Shift (0xcb)
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c)

@phoepsilonix
Copy link
Contributor

phoepsilonix commented Sep 15, 2024

It seems that the on/off state of Num Lock is the key point of the issue.

I use Num_Lock enabled at startup. I always keep Num_Lock on because I have a numeric keypad. Some keyboards don't have a numeric keypad, and Num_Lock might affect the main keyboard layout. I was wondering if this could be the cause of the issue. So I tested what happens when Num_Lock is turned off.
This is a behavior test of ibus-mozc with IBUS_MOD2_MASK added to kExtraModMask.

  1. When Num_Lock is off, the IME becomes active and Japanese input becomes possible.
    It is possible to toggle the IME on and off.
  2. When Num_Lock is on, it seems impossible to toggle the IME on and off.

In other words, the on/off state of Num_Lock is affecting the behavior of the full-width/half-width key and the hiragana key. This issue does not occur with ibus-mozc without adding IBUS_MOD2_MASK to kExtraModMask.

@kzys
Copy link
Contributor Author

kzys commented Sep 16, 2024

@phoepsilonix Thanks! That makes more sense. Updated the mask.

Comment on lines 71 to 72
constexpr uint kExtraModMask =
IBUS_MOD3_MASK | IBUS_MOD4_MASK | IBUS_MOD5_MASK;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line 72 should have 4 spaces for the indentation.

  constexpr uint kExtraModMask =
      IBUS_MOD3_MASK | IBUS_MOD4_MASK | IBUS_MOD5_MASK;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that :(

Fixed in the last revision.

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 google#853.
@hiroyuki-komatsu hiroyuki-komatsu merged commit b52f304 into google:master Sep 17, 2024
1 check passed
@hiroyuki-komatsu
Copy link
Collaborator

We have merged your PR.
Thank you for your contribution!

hiroyuki-komatsu added a commit that referenced this pull request Oct 10, 2024
2.30.5595 → 2.30.5618

Conversion
* Updated zip code entries (#1063).
* Updated word entries (#1068, #1069)

Bug fix
* Linux: Enabled switching to the DIRECT mode from the menu (#1061)
* Linux: Enabled switching modes with Super+Space in Wayland (#853, #1059)
* macOS: Fixed the limitation of mouse clicking on the renderer on macOS 15 (120bd93)
* Windows: Fixed the setting of Omaha updater for the GoogleJapaneseInput build (#1072)

Build
* Android: Switched the Bazel rules from WORKSPACE to Bzlmod (#1002)
* Android: Updated the Docker build environment
* Linux: Update the build environment: Ubuntu 22.04 → 24.04 (#924)
* macOS / Windows: Updated the Qt version: 6.7.2 → 6.7.3 (#1065)
* Windows: Supported Bazel build (#948)
* Windows: Updated the Wix version: 4.0.5 → 5.0.2 (#1070)

Code
* Performed code refactoring

PiperOrigin-RevId: 684295272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants