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

basic IME supporting #1474

Closed
wants to merge 105 commits into from
Closed

Conversation

KentaTheBugMaker
Copy link

@KentaTheBugMaker KentaTheBugMaker commented Oct 16, 2022

General

This PR fix #979,#1544.
iced ime support was broken due to winit 0.27 update .
This PR add event to fit new winit IME event model and introduce new event support for text_input.

how to test

download app from my repo https://github.com/t18b219k/iced_text_input_sample/

Phase 1 : Can we input CJK characters?

tested on

  • windows MS-IME
  • windows Google IME
  • linux ibus x11
  • linux ibus wayland(gnome/kde)
  • linux fcitx x11
  • linux fcitx wayland(gnome/kde/sway/hyprland)
  • macos IME

Phase 2 : Candidate position is near the TextInput?

You maybe failed to reproduce due to IME version.
candidate positon on X11 require LibX11 1.8.2 or above.

Wayland requirement.

  • input_method_popups_v2

tested on

  • windows MS-IME
  • windows Google IME
  • Linux IBus X11(on Manjaro 22.0)
  • Linux IBus gnome wayland
  • Linux Fcitx5 X11(on Manjaro 22.0)
  • Linux Fcitx5 gnome wayland
  • Linux Fcitx5 kde wayland( can't move to the position )
  • Linux Fcitx5 sway(supported on sway-im AUR package.)
  • Linux Fcitx5 hyprland
  • macos IME(setting candidate window position delay. maybe macos issue?)

Phase 3 draw underline and cursor

behavior

2022-12-05.23-27-59.mp4

test

not required.
We render underline and cursor correctly if winit correctly report it.

  • windows
  • macos google japanese IME(not report boldlining),
  • macos pinyin
  • IBus X11 (no boldlining)
  • IBus gnome Wayland(pinyin,mozc,and anthy incorrect report)
  • Fcitx5 X11 (no boldlining)
  • Fcitx5 gnome Wayland (mozc and anthy incorrect event report)
  • Fcitx5 sway
  • Fcitx5 hyprland
  • Fcitx5 kde Wayland

tasks

  • enable winit IME support
  • translate winit IME event to iced event
  • text_input editing support
  • tell IME to put candidate window
  • underline

@KentaTheBugMaker KentaTheBugMaker marked this pull request as draft October 16, 2022 21:14
@KentaTheBugMaker
Copy link
Author

I don't have apple devices please test someone .

@KentaTheBugMaker
Copy link
Author

we should move IME window to correct position to provide native look and feel
where we should implement this logic.

@Cupnfish
Copy link
Contributor

Tested and does not work correctly on m1 macOS 13.0 Beta.

@KentaTheBugMaker
Copy link
Author

if alacritty works well this should work as well.
please test alacritty works well.

@someoneinjd
Copy link

On my mac the candidate box is showing but it's in the wrong place (macOS Monterey 12.6, MacBook Pro (16-inch, 2019))
截屏2022-10-18 14 20 09
In alacritty it works well. (alacritty 0.11.0)
截屏2022-10-18 14 26 31

@KentaTheBugMaker KentaTheBugMaker marked this pull request as ready for review October 20, 2022 04:44
@KentaTheBugMaker
Copy link
Author

now candidate window placed near TextInput .
this positioning is not best but much better than nothing,

@KentaTheBugMaker
Copy link
Author

@Cupnfish @someoneinjd please test candidate window position is correct.

@someoneinjd
Copy link

Thanks for your hard work. It works in most cases. But when I use the input method for the first time since the application started, the position is wrong, and after that the position is correct.
截屏2022-10-20 20 34 49
截屏2022-10-20 20 35 02
Alacritty also has this problem, so it might be a winit problem?
截屏2022-10-20 20 35 45
截屏2022-10-20 20 35 56

@someoneinjd
Copy link

I also tested on my surface pro 6 (Arch Linux + Linux 6.0.1 + wayland 1.21.0 + fcitx5 5.0.19 + sway 1.7). And it doesn't have this problem.
20221020_20h59m10s_grim
20221020_21h00m42s_grim

@Cupnfish
Copy link
Contributor

Thanks for your hard work. It works in most cases. But when I use the input method for the first time since the application started, the position is wrong, and after that the position is correct. 截屏2022-10-20 20 34 49 截屏2022-10-20 20 35 02 Alacritty also has this problem, so it might be a winit problem? 截屏2022-10-20 20 35 45 截屏2022-10-20 20 35 56

This is also the case on my laptop. Not only that, switching to another app and then switching back triggers the bug again.

@KentaTheBugMaker
Copy link
Author

Maybe we need to notify IMEEnabled Event from IME to TextInput .
I will try to fix this problem today .

@KentaTheBugMaker
Copy link
Author

@Cupnfish @someoneinjd please test condidate window is correct position even first time.

@someoneinjd
Copy link

someoneinjd commented Oct 21, 2022

I tried but the same error again.
截屏2022-10-21 09 22 14
I added some log code to see whether the position was set.

diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index f372b2ba..2ba8d06d 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -758,6 +758,7 @@ where
                 (text_bounds.x + position.0) as i32,
                 (text_bounds.y) as i32 + size as i32,
             );
+            println!("[IME Enabled] Set IME {:?}", position);
             ime.set_ime_position(position.0, position.1);
         }
         Event::Keyboard(keyboard::Event::IMEPreedit(text)) => {
@@ -802,6 +803,7 @@ where
                 (text_bounds.x + position.0) as i32,
                 (text_bounds.y) as i32 + size as i32,
             );
+            println!("[IME Preedit] Set IME {:?}", position);
             ime.set_ime_position(position.0, position.1);
 
             shell.publish(message);

And here is the output (I typed "你" first and then "好")

    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/todos`
2022-10-21 09:22:06.499 todos[25370:2729210] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit
[IME Enabled] Set IME (55, 205)
[IME Preedit] Set IME (55, 205)
[IME Preedit] Set IME (55, 205)
[IME Preedit] Set IME (77, 205)
[IME Preedit] Set IME (77, 205)
[IME Preedit] Set IME (77, 205)

It seems that the position was calculated correctly but set_ime_position didn't work.

@KentaTheBugMaker
Copy link
Author

KentaTheBugMaker commented Oct 21, 2022

if we set IME position when we receive click event maybe we can achieve correct positioning.

@someoneinjd
Copy link

2022-12-25.14.59.41.mov

works fine!
AFAIK, displaying the candidate window requires the wayland server to support input_method_popups v2, which is not supported by Sway. #7266 tries to add support for it. So you can build sway from this source or just install the aur package sway-im.
What's more, hyprland also supports input_method_popups v2, you can use it to test.

@KentaTheBugMaker
Copy link
Author

thanks for testing

@hecrj hecrj modified the milestones: 0.7.0, 0.8.0 Jan 14, 2023
@hecrj hecrj modified the milestones: 0.8.0, 0.9.0 Feb 18, 2023
@hecrj hecrj modified the milestones: 0.9.0, 1.0.0 Apr 11, 2023
@KentaTheBugMaker
Copy link
Author

due to very large change made in advanced text so I rebased .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IME input method on iced application (fcitix on linux)
8 participants