Skip to content

Conversation

heiher
Copy link
Contributor

@heiher heiher commented May 10, 2025

Pull request

Issue tracker

Fixes rime/ibus-rime#171

Feature

Recent version of GNOME inspect how input methods handle the Caps Lock key. If the key event is consumed by the input method, the desktop environment no longer toggles the Caps Lock state, which can lead to unexpected behavior.

This patch allows the Caps Lock key event to pass through the input method when good_old_caps_lock is enabled, restoring the expected toggle behavior.

Unit test

  • Done

Manual test

  • Done

Code Review

  1. Unit and manual test pass
  2. GitHub Action CI pass
  3. At least one contributor reviews and votes
  4. Can be merged clean without conflicts
  5. PR will be merged by rebase upstream base

Additional Info

Recent version of GNOME inspect how input methods handle the Caps Lock
key. If the key event is consumed by the input method, the desktop
environment no longer toggles the Caps Lock state, which can lead to
unexpected behavior.

This patch allows the Caps Lock key event to pass through the input
method when `good_old_caps_lock` is enabled, restoring the expected
toggle behavior.

Fixes rime/ibus-rime#171
@heiher
Copy link
Contributor Author

heiher commented May 13, 2025

Filtering out Caps Lock key events in an input method can prevent GUI applications from detecting changes in the Caps Lock state. For example, in the following example, the Caps Lock warning in a GTK3 Entry widget no longer functions as expected.

/*
 * gcc -o gtk3-entry gtk3-entry.c `pkg-config --cflags --libs gtk+-3.0`
 */

#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *entry;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    entry = gtk_entry_new ();
    gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
    gtk_container_add (GTK_CONTAINER (window), entry);
    gtk_widget_show_all (window);

    gtk_main ();

    return 0;
}

Works well (Caps lock warning is shown) without ibus-rime:

good

Doesn't work properly (Caps lock warning is not shown) with ibus-rime:

bad

@heiher
Copy link
Contributor Author

heiher commented May 14, 2025

RFR @lotem Thanks

Copy link
Member

@lotem lotem left a comment

Choose a reason for hiding this comment

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

LGTM

@lotem
Copy link
Member

lotem commented May 14, 2025

Maybe we should always return kRejected for Caps Lock to pass through the IME.
The same applies to other modifier keys for mode switching, like Shift.

I cannot remember the specific reason why these events are reported as such, maybe because they conceptually are "processed by the IME" as hotkeys.

@lotem
Copy link
Member

lotem commented May 14, 2025

@fxliang @LEOYoon-Tsaw

This change can affect other platforms in unexpected ways. Please help verify.

The code comments in ascii_composer specifically mentioned Windows; and macOS defined system level features of the Caps Lock key. Personally I almost never use Caps Lock so I'm not experienced.

@fxliang
Copy link
Contributor

fxliang commented May 14, 2025

I don't know how good old caps lock works, and how to test this.

@heiher
Copy link
Contributor Author

heiher commented May 16, 2025

I don't know how good old caps lock works, and how to test this.

IIRC, the good_old_caps_lock behavior is:

good_old_caps_lock: true

  • Caps Lock works as usual, it toggles uppercase letters.
  • Rime does not intercept it for switching input modes.

good_old_caps_lock: false

  • Caps Lock is repurposed by Rime to toggle input method states (switch between English/Chinese).
  • It no longer changes letter case.

@heiher
Copy link
Contributor Author

heiher commented May 16, 2025

Maybe we should always return kRejected for Caps Lock to pass through the IME.

When good_old_caps_lock is set to false, pressing Caps Lock no longer toggles letter case. If the Caps Lock event is passed through to the application. For above GTK entry case, it may show the "Caps Lock is on" indicator, but still fails to produce uppercase letters when typing. That doesn't seem quite right either.

@fxliang
Copy link
Contributor

fxliang commented May 20, 2025

I don't know how good old caps lock works, and how to test this.

IIRC, the good_old_caps_lock behavior is:

good_old_caps_lock: true

  • Caps Lock works as usual, it toggles uppercase letters.
  • Rime does not intercept it for switching input modes.

good_old_caps_lock: false

  • Caps Lock is repurposed by Rime to toggle input method states (switch between English/Chinese).
  • It no longer changes letter case.

with ci output

good_old_caps_lock: true
capslock switch ascii_mode and capslock state( in rime and capslock led )

good_old_caps_lock: false
capslock switch ascii_mode but not capslock state( when capslock led on/off normally ). caps state work normally with other ime

@lotem
Copy link
Member

lotem commented May 21, 2025

保守修改,應該能行,發現問題再說吧。

@lotem lotem merged commit 2c24811 into rime:master May 21, 2025
10 checks passed
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.

中文输入模式大写锁定后输入的字母是小写
3 participants