Skip to content

IME and the MacOS Character Viewer #3342

@HolgerGottChristensen

Description

@HolgerGottChristensen

I have an application based on winit 0.29.7.
On MacOS you can open the character viewer using the fn/🌐 key.
Screenshot 2023-12-30 at 18 07 14

This seem to be the preferred way of inserting symbols and emojis into text fields in an application.
When I double click one of the characters (which inserts it into other applications), no events are sent from winit.

Screen.Recording.2023-12-30.at.18.16.45.mov

I have experimented more with winit, and it seems that it has to do with the IME implementation.
When I enable IME it still does not send events, but when IME has started, for example by typing the ¨ character, I can then insert emojis by double clicking on the character viewer.

Screen.Recording.2023-12-30.at.18.20.11.mov

When I end the IME for example by typing e, the events of the character viewer stops being sent again.

I looked into the MacOS implementation of winit.
The events from MacOS are sent through the insertText:replacementRange: event handler in the file src/platform_impl/macos/view.rs file.

I have tried debugging the issue, and inserting a dbg in the method:
Screenshot 2023-12-30 at 18 29 56

When clicking the character viewer, the following is printed, when IME is not started:

TRACE [winit::platform_impl::platform::view] Triggered `insertText:replacementRange:`
[src/platform_impl/macos/view.rs:398] &string = "😀"
TRACE [winit::platform_impl::platform::view] Triggered `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `hasMarkedText`
[src/platform_impl/macos/view.rs:398] unsafe { self.hasMarkedText() } = false
[src/platform_impl/macos/view.rs:398] self.is_ime_enabled() = false
[src/platform_impl/macos/view.rs:398] !is_control = true
TRACE [winit::platform_impl::platform::view] Triggered `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `insertText:replacementRange:`

When IME is started(by pressing ¨), it prints the following:

TRACE [winit::platform_impl::platform::view] Triggered `insertText:replacementRange:`
[src/platform_impl/macos/view.rs:396] &string = "😀"
TRACE [winit::platform_impl::platform::view] Triggered `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `hasMarkedText`
[src/platform_impl/macos/view.rs:396] unsafe { self.hasMarkedText() } = true
[src/platform_impl/macos/view.rs:396] self.is_ime_enabled() = true
[src/platform_impl/macos/view.rs:396] !is_control = true
TRACE [winit::platform_impl::platform::view] Triggered `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `hasMarkedText`
TRACE [winit::platform_impl::platform::view] Completed `insertText:replacementRange:`

and sends the events:

WindowEvent { window_id: WindowId(WindowId(5735737648)), event: Ime(Preedit("", None)) }
WindowEvent { window_id: WindowId(WindowId(5735737648)), event: Ime(Commit("😀")) }

If anything is missing I will try my best to provide it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B - bugDang, that shouldn't have happenedDS - appkitAffects the AppKit/macOS backend

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions