gabm / Satty

Satty - Modern Screenshot Annotation. A tool inspired by Swappy and Flameshot.
Mozilla Public License 2.0
388 stars 18 forks source link

Non-Latin alphabet support #2

Open ystyle opened 8 months ago

ystyle commented 8 months ago

Unable to activate fcitx5 input method

gabm commented 8 months ago

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?

ystyle commented 8 months ago

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.

lilydjwg commented 7 months ago

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.

gabm commented 7 months ago

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?

lilydjwg commented 7 months ago

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 commented 7 months ago

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.

gabm commented 7 months ago

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

ystyle commented 7 months ago

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)

gabm commented 7 months ago

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

lilydjwg commented 7 months ago

I can test too.

gabm commented 7 months ago

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?

lilydjwg commented 7 months ago

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.

gabm commented 7 months ago

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

lilydjwg commented 7 months ago

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

Clareses commented 4 months ago

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

xiaohuirong commented 4 months ago

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 commented 4 months ago

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

lilydjwg commented 4 months ago

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 commented 4 months ago

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.

gabm commented 4 months ago

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 commented 4 months ago

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

lilydjwg commented 4 months ago

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.

Clareses commented 4 months ago

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

lilydjwg commented 4 months ago

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

gabm commented 4 months ago

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!

rtgiskard commented 2 months ago

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