Satty icon indicating copy to clipboard operation
Satty copied to clipboard

Non-Latin alphabet support

Open ystyle opened this issue 2 years ago • 29 comments
trafficstars

Unable to activate fcitx5 input method

ystyle avatar Oct 18 '23 10:10 ystyle

thank you for this. Can you provide more information in what this is and what is useful for?

if you are a developer: do you have resources that demonstrate it?

gabm avatar Oct 18 '23 10:10 gabm

Add multiple input methods to fcitx5, use ctrl + space to switch input methods when annotating, but the input method does not respond. I have never learned rust. Neovide solved this problem in x11 not long ago.

ystyle avatar Oct 19 '23 02:10 ystyle

If you can't put a GtkEntry there, you'll need to interact using GtkIMContext yourself.

Update: for why this is useful: An input method is used to input complex scripts like Chinese, Japanese or the like.

Satty doesn't even support paste, which means the usual workaround for lacking IM support doesn't work either. ydotool emulates a keyboard and thus can't type Chinese either. wtype should work, but it has other problems.

lilydjwg avatar Nov 23 '23 11:11 lilydjwg

i really didn't get what you wanted to do as the interface is mainly pointer based - but you do mean the text box input, right?

gabm avatar Nov 23 '23 12:11 gabm

Yes. That's the only place where the user can input text, I suppose?

Basically, you need to create a GtkIMContext, call gtk_im_context_focus_in when the user is going to input text, and call gtk_im_context_set_cursor_location when the text cursor moves, listen to commit signal to get the inputted text and insert it to your text buffer. You also need to handle those preedit-{start,changed,end} signals and use gtk_im_context_get_preedit_string to get the preedit string, show it in your UI.

I'll make a screen record to show how text is inputted with fcitx5 in a normal GTK application.

lilydjwg avatar Nov 23 '23 12:11 lilydjwg

This is how an input method is in use. The purple window is from the input method, and the application window is gtk4-demo-application.

https://github.com/gabm/Satty/assets/440661/163a0caa-4db2-494b-aa10-c4a548b2fbee

You need to tell the input method that the user is going to input text, where the cursor is, and retrieve and draw both preedit and committed text on your UI.

Although only the text tool needs this, it's an important annotation tool for screenshots, so I really hope it works for us.

lilydjwg avatar Nov 23 '23 12:11 lilydjwg

I made progress on this. Would you be able to build from source and test?

gabm avatar Nov 27 '23 15:11 gabm

I made progress on this. Would you be able to build from source and test?

I can try, but it will have to be tomorrow (it's night here now)

ystyle avatar Nov 27 '23 15:11 ystyle

I'll let you know when i pushed it.. still some refactoring needed

gabm avatar Nov 27 '23 15:11 gabm

I can test too.

lilydjwg avatar Nov 28 '23 02:11 lilydjwg

Hi both, thank you for volunteering. I pushed a branch multi-input that uses the IMMulticontext as seen in https://github.com/flxzt/rnote/blob/main/crates/rnote-ui/src/canvas/mod.rs#L473. There is currently no "pre-edit" text handling because I don't know how to draw that currently...

Can you let me know if that works and maybe create a screen recording?

gabm avatar Dec 06 '23 10:12 gabm

No, it doesn't work. No text input (in the wayland protocol) is created. It seems that you created an IMMulticontext but never used it? I don't quite understand what that #[relm4::component] macro is doing though.

lilydjwg avatar Dec 06 '23 13:12 lilydjwg

sorry to hear that.. how can i test this myself?

gabm avatar Dec 06 '23 13:12 gabm

Try to install fcitx5? You need to add and activate one input method (one for any language will do).

lilydjwg avatar Dec 06 '23 13:12 lilydjwg

Hello, I've submitted a PR for this issue. Please take a look. Thanks. @gabm #52

Clareses avatar Feb 22 '24 12:02 Clareses

Hello, I've submitted a PR for this issue. Please take a look. Thanks. @gabm #52

I tried your PR, and setting GTK_IM_MODULE=fcitx under x11 and wayland works, but it does not support the text-input protocol for wayland. I encountered an issue where the input method dialog under wayland always appears at the top-left corner of one screen and does not follow the input position. Under Wayfire and Sway, it always appears on the left screen, while under Hyprland, it always appears on the right screen.

screenshot resized

xiaohuirong avatar Feb 22 '24 15:02 xiaohuirong

In Wayland, using --gtk-version=4 to enable the GTK4 input method module support in Chromium also has a similar position offset issue. https://issues.chromium.org/issues/40929728

xiaohuirong avatar Feb 22 '24 15:02 xiaohuirong

I have another idea for this issue: overlay a transparent-background GtkTextView on where text is to be inputted. This can solve the input method issue as well as copy & paste and shortcut keys etc. Unfortunately I didn't figure out how to use relm4.

lilydjwg avatar Feb 22 '24 16:02 lilydjwg

Yes with GTK_IM_MODULE=fcitx it works to some extent for me too. Besides the popup window placement issue, the preedit string is also not displayed.

lilydjwg avatar Feb 23 '24 03:02 lilydjwg

The first version got released as part of https://github.com/gabm/Satty/releases/tag/v0.10.0. Since there are still open issues, I will re-open this.

gabm avatar Feb 23 '24 12:02 gabm

could the non-Latin community check wether the opengl based text rendering in #55 works for you?

gabm avatar Feb 26 '24 19:02 gabm

No. It doesn't work with either text input or gtk module. Since nothing not on the keyboard can be inputted, I have no idea how non-latin text will render.

lilydjwg avatar Feb 27 '24 03:02 lilydjwg

I tried merging opengl branch into the multiinput branch and entered non-Latin alphabet characters. OpenGL seems to be working fine. 2024-02-27-12-02-54

Clareses avatar Feb 27 '24 04:02 Clareses

Oops, I didn't merge the multiinput branch. It has a lot of conflicts to merge.

lilydjwg avatar Feb 27 '24 04:02 lilydjwg

oops, I assumed the opengl branch did have those patches already - sorry.

Just to clarify: the main branch includes the multi-input patches and its released as v0.10.0. OpenGL will - once released - of course include all previous patches/features.

@lilydjwg thanks for your feedback, @Clareses thanks for merging and testing it - nice to see it works!

gabm avatar Feb 27 '24 04:02 gabm

Currently with satty 0.12.0, I have to set GTK_IM_MODULE=fcitx5 to make it works with fcitx5, however fcitx5 seems to deprecate GTK_IM_MODULE

rtgiskard avatar May 07 '24 06:05 rtgiskard

with satty 0.13.0, can't input chinese by fcitx5 in Hyprland (a wayland-based desktop environment), and I set GTK_IM_MODULE=fcitx5, but still can't works.

GyaneshW avatar Jul 18 '24 13:07 GyaneshW

@Clareses is there something you could do?

gabm avatar Jul 18 '24 13:07 gabm

Could this related to some breaking change in Hyprland? It dropped wlroots as dependency and replaced it with https://github.com/hyprwm/aquamarine, after version 0.42

wenjinnn avatar Oct 15 '24 02:10 wenjinnn