iced icon indicating copy to clipboard operation
iced copied to clipboard

basic IME supporting

Open KentaTheBugMaker opened this issue 2 years ago • 37 comments

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.

https://user-images.githubusercontent.com/48007646/196058439-1359af31-1c13-44d6-8016-100db22f6c64.mp4

Phase 1 tested on (Can we input CJK characters?)

  • [x] windows MS-IME
  • [x] windows Google IME
  • [x] linux ibus x11
  • [x] linux ibus wayland
  • [x] linux fcitx x11
  • [x] linux fcitx wayland
  • [ ] macos 11 IME
  • [x] macos 12 IME
  • [x] macos 13 IME

https://user-images.githubusercontent.com/48007646/196908017-45ea5b4b-c224-4c02-a6ca-fa89fd31f5c1.mp4

Phase 2 tested on(Candidate position is near the TextInput?)

X11 winit candidate window issue https://github.com/rust-windowing/winit/issues/2522

  • [x] windows MS-IME
  • [x] windows Google IME
  • [x] Linux ibus X11(winit issue)
  • [x] Linux ibux wayland
  • [x] Linux fcitx X11(winit issue)
  • [x] Linux fcitx wayland
  • [ ] macos 11 IME
  • [ ] macos 12 IME
  • [ ] macos 13 IME

tasks

  • [x] enable winit IME support
  • [x] translate winit IME event to iced event
  • [x] text_input editing support
  • [x] tell IME to put candidate window

KentaTheBugMaker avatar Oct 16 '22 21:10 KentaTheBugMaker

I don't have apple devices please test someone .

KentaTheBugMaker avatar Oct 16 '22 23:10 KentaTheBugMaker

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

KentaTheBugMaker avatar Oct 17 '22 02:10 KentaTheBugMaker

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

Cupnfish avatar Oct 17 '22 17:10 Cupnfish

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

KentaTheBugMaker avatar Oct 17 '22 23:10 KentaTheBugMaker

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

someoneinjd avatar Oct 18 '22 06:10 someoneinjd

we need to tell IME candidate window position to winit but I can't find good way.

KentaTheBugMaker avatar Oct 18 '22 07:10 KentaTheBugMaker

@hecrj I want to move IME candidate window to correct position but I can't find the way to send window Action from widget. I think we need to extend Widget interface like clipboard implementation. Is there any opinion to this problem.

KentaTheBugMaker avatar Oct 18 '22 23:10 KentaTheBugMaker

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

KentaTheBugMaker avatar Oct 20 '22 04:10 KentaTheBugMaker

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

KentaTheBugMaker avatar Oct 20 '22 09:10 KentaTheBugMaker

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 avatar Oct 20 '22 12:10 someoneinjd

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

someoneinjd avatar Oct 20 '22 13:10 someoneinjd

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.

Cupnfish avatar Oct 20 '22 14:10 Cupnfish

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

KentaTheBugMaker avatar Oct 20 '22 20:10 KentaTheBugMaker

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

KentaTheBugMaker avatar Oct 20 '22 22:10 KentaTheBugMaker

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.

someoneinjd avatar Oct 21 '22 01:10 someoneinjd

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

KentaTheBugMaker avatar Oct 21 '22 02:10 KentaTheBugMaker

@someoneinjd @Cupnfish please test if it works. set_ime_position when TextInput clicked. If this doesn't work we need to talk with alacritty team.

KentaTheBugMaker avatar Oct 21 '22 12:10 KentaTheBugMaker

@someoneinjd @Cupnfish please test if it works. set_ime_position when TextInput clicked. If this doesn't work we need to talk with alacritty team.

It still comes up with that problem.

Cupnfish avatar Oct 21 '22 14:10 Cupnfish

Unfortunately the problem still exists 截屏2022-10-22 07 44 51

someoneinjd avatar Oct 21 '22 23:10 someoneinjd

shall we release this PR or not? if you fixed this problem please open PR to my repo.

KentaTheBugMaker avatar Oct 21 '22 23:10 KentaTheBugMaker

I find that set_ime_position in IMEEnabled doesn't work, maybe we need to set the candidate box position before receiving this event. But this may not be easy to achieve, because when I use the Chinese input method to start todos and type, IMEEnabled is the first event received by the update function. Maybe we can force the user to click the input box before they can type.

someoneinjd avatar Oct 22 '22 05:10 someoneinjd

image

Unfocus text_input then type korean, preedit character(expect) inserted in text_input. It can delete manually but isn't deleted automatically.

Used font: NanumGothic.ttf OS: Windows 10

zmtq05 avatar Oct 24 '22 12:10 zmtq05

IME handling is very platform dependent issue so feel free to PR to my repo .

KentaTheBugMaker avatar Oct 25 '22 11:10 KentaTheBugMaker

@hecrj This PR is very platform issue but no one tried to improving this PR. I think it better to basic support than nothing. So i want to left task for community to improve support.

KentaTheBugMaker avatar Oct 25 '22 11:10 KentaTheBugMaker

I want to help, but I don't know where to start. Can I get a hint?

zmtq05 avatar Oct 26 '22 04:10 zmtq05

@zmtq05 here is my repo https://github.com/t18b219k/iced it seems to me connecting to IME is ok . so I want to you to dive to native/src/widget/text_input.rs update function. before you making PR please run CI to build test binary. if you can please install CJK font for easy test.

KentaTheBugMaker avatar Oct 26 '22 11:10 KentaTheBugMaker

I resolve my issue by does nothing when receive preedit event and unfocused. but japanese and chinese candidate window still appear when unfocused then input. EDIT: egui(+ eframe) is same.

sorry for bad english.

zmtq05 avatar Oct 27 '22 00:10 zmtq05

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

Related X11 bug

https://bugs.freedesktop.org/show_bug.cgi?id=1580

Riey avatar Oct 29 '22 00:10 Riey

underlining when using IME. Bold line means this section text is converting.

https://user-images.githubusercontent.com/48007646/198844635-dd08f4e4-47b4-4ec2-8a3f-d580096cc5f4.mp4

KentaTheBugMaker avatar Oct 29 '22 17:10 KentaTheBugMaker

@zmtq05 Thank you for good idea. My implementation is buggy when we use IME and open many TextInputs. Your idea implemented in my latest patch. https://github.com/t18b219k/iced/commit/fbc9c595c994831e4c18030b4d9d09a2bea3a516

KentaTheBugMaker avatar Oct 29 '22 17:10 KentaTheBugMaker

underline position is weird. image

zmtq05 avatar Oct 30 '22 09:10 zmtq05

image Cursor must be located after the character. image

zmtq05 avatar Oct 31 '22 10:10 zmtq05