Skip to content

Cocoa: simplify input method handling, stoping using TIS to swich IME#7

Open
ghostflyby wants to merge 16 commits into
clear-code:im-supportfrom
ghostflyby:im-cocoa-simple
Open

Cocoa: simplify input method handling, stoping using TIS to swich IME#7
ghostflyby wants to merge 16 commits into
clear-code:im-supportfrom
ghostflyby:im-cocoa-simple

Conversation

@ghostflyby

Copy link
Copy Markdown

As mentioned in glfw#2130 (comment).

Cocoa is different from other platforms, as it can’t simply disable IME without disabling char inputs completely. But we can manually interprets keyEvents as chars to imitate the behavior of other platforms.

Using TIS to switch IME is definitely a bad idea as one shall have multiple IMEs.

daipom and others added 16 commits January 14, 2025 12:06
This fix is based on shibukawa's fix:
  glfw#658
  shibukawa@d36a164

Some minor coding style changes are made, but not yet follow glfw's one,
and some comments doesn't follow recent changes. So further work is
needed.

Co-authored-by: Yoshiki Shibukawa <yoshiki@shibu.jp>
Co-authored-by: Takuro Ashie <ashie@clear-code.com>
This commit re-organizes 9d9af13.

* Use dynamic load for Imm32.
* Generalize platform-specific features to _GLFWplatform.
* Add caret-position info to preedit-callback.
* Add cursorWidth to preeditCursor and related APIs.
* Handle UTF16 data correctly.
* Handle GCS_RESULTSTR so that committed texts are processed correctly.
* Handle WM_IME_ENDCOMPOSITION to clear preedit.
* Handle WM_IME_SETCONTEXT.
    * https://learn.microsoft.com/en-us/windows/win32/intl/wm-ime-setcontext#remarks
* Refactor code shapes and variable names.

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
This fix is based on shibukawa's fix:
  glfw#658
  shibukawa@d36a164

Co-authored-by: Yoshiki Shibukawa <yoshiki@shibu.jp>
Co-authored-by: Takuro Ashie <ashie@clear-code.com>
This commit re-organizes 31b12b7.

* Use dynamic load for TIS functions and stop using Carbon.
* Generalize platform-specific features to _GLFWplatform.
* Add caret-position info to preedit-callback.
* Handle UTF16 data correctly.
* Implement `firstRectForCharacterRange:actualRange:` to display preedit candidate window correctly.
* Suppress _glfwInputKey during preediting.
* Ensure preedit cleared after committed.
* Fix wrong length of markedRange.
* Improve IME status APIs.
* Refactor code shapes and variable names.

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
Co-authored-by: xfangfang <2553041586@qq.com>
This fix is based on shibukawa's fix:
  glfw#658

The differences is the following.

* Remove `X_HAVE_UTF8_STRING` branching since the current logic doesn't use it
* Replace `XNDestroyCallback` for `XNPreeditAttributes` in `XCreateIC`

Co-authored-by: Yoshiki Shibukawa <yoshiki@shibu.jp>
Co-authored-by: Takuro Ashie <ashie@clear-code.com>
This commit re-organizes 6e7f939.

* Load missing XIM related function symbols.
* Generalize platform-specific features to _GLFWplatform.
* Change the defalut input style to over-the-spot style.
* Rename `decodeUTF8()` to `_glfwDecodeUTF8()` to make it as internal API.
    * It will be also needed to implment input method for Wayland.
* Refactor code shapes and variable names.

About over-the-spot style and on-the-spot style on X11:

* In over-the-spot mode, almost all APIs are disabled since applications only
  need to specify the preedit candidate window position by `glfwSetPreeditCursorPos()`.
* We can change the style by enabling `GLFW_X11_ONTHESPOT` init hint, but it
  has the following problems.
    * Status APIs don't work because status callbacks don't work.
      (at least in my ibus environment).
    * Can't specify the candidate window position.

Known problems:

* Some keys (arrow, Enter, BackSpace, ...) are passed to applications during preediting.
    * This will be fixed in PR glfw#1972 : glfw#1972

Co-authored-by: Takuro Ashie <ashie@clear-code.com>
They are wayland protocols to support input methods:
https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/text-input/text-input-unstable-v3.xml
https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/text-input/text-input-unstable-v1.xml

text_input_unstable_v3 is widely supported by major desktop environment
on GNU/Linux such as GNOME or KDE.

text_input_unstable_v1 isn't so popular but Weston which is the
reference Wayland implementation supports only it and doesn't support
text_input_unstable_v3 so that we also implement it.
Co-authored-by: Takuro Ashie <ashie@clear-code.com>
new

- Daijiro Fukuda
- Ryo Ichinose (from glfw#658)
- Yasutaka Kumei (from glfw#658)
- xfangfang

already in the list

- Takuro Ashie
- Yoshiki Shibukawa
You can use this feature when you need to manage the drawing of
the preedit candidates on the application side.
Load it dynamically instead.
@ghostflyby

Copy link
Copy Markdown
Author

录屏2025-06-07 15 21 18

ABC Chinese Pinyin
IME true ASCII Chinese
IME false ASCII ASCII

@ashie ashie self-requested a review June 9, 2025 00:08
@ashie

ashie commented Jun 10, 2025

Copy link
Copy Markdown
Member

Thanks for your patch 👍
I'm planning to merge this with a new API mentioned in glfw#2130 (comment), then add corresponding implementation for Windows & GNU/Linux.

@ghostflyby

Copy link
Copy Markdown
Author

Now the old implementation is causing issues witnessed on latest Minecraft.

  1. IME is forced to be enabled by switching to locale first input when focusing textfields, previous IME not remembered.
  2. The switch popup shows itself when switching between two modes, which is quite annoying.

This is now not a feature provider or a refactor for code quality, but a bug fix.

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.

5 participants