kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.18k stars 971 forks source link

kitten for IME input #469

Closed kovidgoyal closed 6 years ago

kovidgoyal commented 6 years ago

IME does not work with kitty thanks to limitations of GLFW (https://github.com/glfw/glfw/issues/41). Rather than trying to write code to interface with the IME platforms of every OS (not to mention the dozens of different IME systems in linux/windows), it might be nicer to create a kitten that implements a standard cross-platform IME interface optimized for usage with the keyboard.

Can use the data from the librime project, see https://github.com/rime/plum

Has a couple of pinyin datasets and also nice symbol definitions for entering commonly used unicode symbols. People can contribute other datasets as needed.

The other alternative is to interface with ibus via it's dbus interface, see for example: https://fossies.org/linux/SDL2/src/core/linux/SDL_ibus.c https://github.com/qt/qtbase/tree/5.11/src/plugins/platforminputcontexts/ibus

This is what most toolkits do on linux, as evidenced by the links above.

derrickcope commented 6 years ago

That doesn't help if you need multilingual input. Any timeline on a solution for this.?

kovidgoyal commented 6 years ago

Sure it does, it works with any language or combination of languages. As for a timeline, it will be done when it is done, if you want it to come faster, feel free to contribute.

derrickcope commented 6 years ago

I don't believe it will work for Chinese since there are several hundred characters that would need to be input in a normal document. Perhaps I am misunderstanding your proposal for a work around though. Also, my use case may be special since I write in the terminal with nvim and then convert to PDF. I wish I could contribute but I don't think my programming skill are there yet. Thanks for the extremely helpful reply though. Looks like a nice project, I will check back later.

imyxh commented 6 years ago

@derrickcope: I don't believe it will work for Chinese since there are several hundred characters that would need to be input in a normal document.

Isn't that the whole plan? LibreIME has a pinyin dataset that can be used to map pinyin to characters. Although I must say that the solution on GLFW's side seems to be awfully simple, unless I'm misunderstanding something.

kovidgoyal commented 6 years ago

The problem with GLFW's solution is that it does not actually work. It causes crashes/hangs and depends on the proper functioning of whatever IME system happens to be installed by the OS, which especially on linux is a total crapshoot.

imyxh commented 6 years ago

Alright, then. I actually think providing the option to use the OS's IME system isn't necessarily a bad idea; many people like me already have IBus or something set up to their liking, and it would prevent the need for a separate keyboard shortcut. But if that would require code for integration with each IME then I suppose it's not worth it. Perhaps kitty can provide its own IME overriding the normal system shortcut, like how ctrl+alt+u doesn't use the OS unicode input. It's also probably worth noting that GLFW has set proper IME support for the 3.4 milestone, though they have been pushing it forward since 3.2....

kovidgoyal commented 6 years ago

On Sun, Jun 03, 2018 at 10:13:26PM -0700, Ian Huang wrote:

Perhaps kitty can provide its own IME overriding the normal system shortcut, like how ctrl+alt+u doesn't use the OS unicode input.

That is precisely what this issue is about.

Akaricchi commented 6 years ago

Why is GLFW even used? SDL2 has had integration with the system IME for years.

kovidgoyal commented 6 years ago

I looked into this and it looks like on Linux, ibus has become the de-facto standard IME system. So it makes sense to add support for it to GLFW. I have done that in the ibus branch. Note that this required fairly major surgery on GLFW (essentially rewriting its event loop to integrate dbus into it), so it is possible that some things might be broken. Please test.

Also, currently while the IME system is working on matches, kitty will not display the typed text in the terminal, that is on my TODO list. Other than that everything works in my (rudimentary) testing. The IME popup widow shows up underthe cursor and you can press the numbers to choose matches or press esc to cancel IME. Tested under X11 (should work in wayland as well, but have not tested it, as I have no idea what the status of ibus under wayand is).

In order to test it, build the ibus branch and (with ibus running) start kitty as

GTK_IM_MODULE=ibus kitty --debug-keyboard

You should see debug output about conencting to the IBUS daemon and iME input via ibus should work.

kovidgoyal commented 6 years ago

And I also implemented display of the typed text while the IME is in progress.

Menchen commented 6 years ago

Will fcitx be supported in kitty ? (not working for me, using ibus branch and GTK_IM_MODULE=fcitx python . --debug-keyboard) I prefer fcitx because it have better compatibility and performance.

kovidgoyal commented 6 years ago

No, I'm afraid I dont have the time/interest to support multiple IME systems. You are welcome to write a fcitx backed for glfw based on my ibus one, it should be easy now that I have done the hard work.

derrickcope commented 6 years ago

hope someone will write a patch for fcitx. I think it is more stable than ibus, at least for Chinese.

derrickcope commented 6 years ago

hope someone will write a patch for fcitx. I think it is more stable than ibus, at least for Chinese.

char commented 6 years ago

ibus-hangul broken - Cannot use space or backspace when in hangul mode.

kovidgoyal commented 6 years ago

Just a heads up: for the next kitty release 0.12.1 I am going to turn off IME by default. You need to set the environment variable:

GLFW_IM_MODULE=ibus

to re-enable it. This is because there have been lots of bug reports about ibus causing keyboard latency/dropped keys. Given that one of kitty's primary goals is reducing input latency, I have decided to turn IME off by default. Apologies for any inconvenience.

MaskRay commented 5 years ago

Just to provide some motivation for better IME support. I tried migrating from another terminal emulator and just noticed this issue - I cannot type Chinese with fcitx in a kitty window.

chux0519 commented 4 years ago

Just to provide some motivation for better IME support. I tried migrating from another terminal emulator and just noticed this issue - I cannot type Chinese with fcitx in a kitty window.\

Me too, I found that kitty's response is faster than others(sakura / alacritty).

nicewarmcoffee commented 3 years ago

Unfortunately, ibus does not work with sway yet. =(

qwIvan commented 3 years ago

Just to provide some motivation for better IME support. I tried migrating from another terminal emulator and just noticed this issue - I cannot type Chinese with fcitx in a kitty window.

GLFW_IM_MODULE=ibus works for me with fcitx5.

qwIvan commented 3 years ago

Just to provide some motivation for better IME support. I tried migrating from another terminal emulator and just noticed this issue - I cannot type Chinese with fcitx in a kitty window.

GLFW_IM_MODULE=ibus works for me with fcitx5.

'GLFW_IM_MODULE=fcitx` works for me with fcitx5 too, thanks!

But running in GLFW_IM_MODULE=fcitx instead of ibus doesn't works for me.

alan-w-255 commented 3 years ago

Just to provide some motivation for better IME support. I tried migrating from another terminal emulator and just noticed this issue - I cannot type Chinese with fcitx in a kitty window.

GLFW_IM_MODULE=ibus works for me with fcitx5.

'GLFW_IM_MODULE=fcitx` works for me with fcitx5 too, thanks!

But running in GLFW_IM_MODULE=fcitx instead of ibus doesn't works for me.

Sorry about that. It doesn't work for me neither. I did not check the env carefully.

wengxt commented 3 years ago

But running in GLFW_IM_MODULE=fcitx instead of ibus doesn't works for me.

GLFW_IM_MODULE=ibus + Fcitx 5 would work. Fcitx5 is able to simulate ibus api.

Adnios commented 3 years ago

GLFW_IM_MODULE=ibus kitty works for me. image

nicewarmcoffee commented 3 years ago

But running in GLFW_IM_MODULE=fcitx instead of ibus doesn't works for me.

GLFW_IM_MODULE=ibus + Fcitx 5 would work. Fcitx5 is able to simulate ibus api.

just tested with: fcitx 5.0.8 sway 1.6.1 kitty 0.21.2 no xwayland

export IMSETTINGS_MODULE=fcitx5 export INPUT_METHOD=fcitx5 export GTK_IM_MODULE=fcitx5 export QT_IM_MODULE=fcitx5 export GLFW_IM_MODULE=ibus export XMODIFIERS=@im=fcitx5 export GDK_BACKEND=wayland

Does not work with kitty =(

kovidgoyal commented 3 years ago

fcitx does not support the wayland text input method. kitty uses that, not dbus, on wayland. If you want to use dbus run kitty with linux_display_server x11

ManInTheSuit commented 2 years ago

I apologize for necroing this thread, but how to enable IME support? When run as in this screenshot: https://user-images.githubusercontent.com/41060790/110936258-91747580-836b-11eb-9dcd-88ca502ea875.png, it works, but putting export GLFW_IM_MODULE=ibus in .bashrc doesn't work. Am I missing something?

Menchen commented 2 years ago

@ManInTheSuit You need to pass the environment variable to kitty, exporting it in .bashrc only export it on interactive shell. What you need to do is export it in your DE or the program that launch kitty, another option is run kitty as GLFW_IM_MODULE=ibus kitty. See more info in https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

ManInTheSuit commented 2 years ago

@ManInTheSuit You need to pass the environment variable to kitty, exporting it in .bashrc only export it on interactive shell. What you need to do is export it in your DE or the program that launch kitty, another option is run kitty as GLFW_IM_MODULE=ibus kitty. See more info in https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

Seeing env GLFW_IM_MODULE=ibus works for child processes, is there any way to set it for all kitty processes? Launching kitty with GLFW_IM_MODULE=ibus kitty doesn't work for some reason in Budgie (the shortcuts application)...

ManInTheSuit commented 2 years ago

Ok solved, I launch kitty like this now: sh -c "GLFW_IM_MODULE=ibus kitty"

char commented 2 years ago

When you want to set an environment variable for a command, you can use env instead of sh à la env GLFW_IM_MODULE=ibus kitty

ManInTheSuit commented 2 years ago

When you want to set an environment variable for a command, you can use env instead of sh à la env GLFW_IM_MODULE=ibus kitty

Thanks, that works!

LeisureLinux commented 2 years ago

I did not find a way to pass the GLFW_IM_MODULE to gsetting default x-terminal-emulator .

tried to run

sudo update-alternatives --config x-terminal-emulator

and make it a shell script as: env GLFW_IM_MODULE=ibus kitty but this is not working when called from the default terminal when I press Ctr-Alt-T.

ManInTheSuit commented 2 years ago

I did not find a way to pass the GLFW_IM_MODULE to gsetting default x-terminal-emulator .

tried to run

sudo update-alternatives --config x-terminal-emulator

and make it a shell script as: env GLFW_IM_MODULE=ibus kitty but this is not working when called from the default terminal when I press Ctr-Alt-T.

I also have alias kitty='GLFW_IM_MODULE=ibus command kitty' in my .bashrc, for calling kitty within any other terminal.

Also, on the off chance that you are having troubles with gnome-terminal, I got my kitty to run system-wide with answer from Doron Behar here: https://askubuntu.com/questions/111592/how-do-i-set-the-default-gnome-terminal

ctrlcctrlv commented 2 years ago

I started bug #5033 to hopefully expand env to cover this case. That would prevent users from needing aliases, .desktop file hacks, etc.

ctrlcctrlv commented 2 years ago

Well, #5033 was closed, but I have a new workaround for the issues I explained above.

If you use KDE, run kmenuedit and edit Kitty like this:

image

I verified that even if you add Kitty's icon to your desktop, the change is preserved:

image

If you have an important .desktop file for Kitty already that is not a mere link to /home/fred/.local/share/applications/kitty.desktop (perhaps it's a link to the old system-wide kitty.desktop), that needs to be removed or recreated.

ctrlcctrlv commented 2 years ago

Related: Ubuntu bug №1970928.

tin-pham commented 2 years ago

Well, #5033 was closed, but I have a new workaround for the issues I explained above.

If you use KDE, run kmenuedit and edit Kitty like this:

image

I verified that even if you add Kitty's icon to your desktop, the change is preserved:

image

If you have an important .desktop file for Kitty already that is not a mere link to /home/fred/.local/share/applications/kitty.desktop (perhaps it's a link to the old system-wide kitty.desktop), that needs to be removed or recreated.

Well this worked when i click to icon or launch kitty from terminal, if i open it with shortcut Super+T, it didn't

wizardyhnr commented 2 years ago

You can edit kitty.desktop to instruct kitty to launch with GLFW_IM_MODULE=ibus.

Below are installation instuctions from kitty's website. https://sw.kovidgoyal.net/kitty/binary/

After that, edit ~/.local/share/applications/kitty.desktop to add env variable in Exec line. It looks like following after that: [Desktop Entry]
Version=1.0 Type=Application Name=kitty GenericName=Terminal emulator Comment=Fast, feature-rich, GPU based terminal TryExec=/location/of/kitty Exec=env GLFW_IM_MODULE=ibus /location/of/kitty Icon=/location/of/kitty/icon Categories=System;TerminalEmulator;

Done.

BTW, you can also customize icon in this way.

marsevilspirit commented 1 month ago

You can add the Fcitx5 configuration in /etc/environment:

GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx
INPUT_METHOD=fcitx
GLFW_IM_MODULE=ibus

This way, you will be able to type in Chinese every time you start kitty.