Linux Adventures: Chinese Input Using Fcitx in KDE

A Story In 87 Browser Tabs

I recently moved laptops, which means I have a fresh Linux install that needs configuring. __(Remember to back up first!)__ As with a real-life move (which I am also in the middle of, in addition to the shutdown), it’s a chance to start new. To leave behind old, bad habits and obsessions, to grow and flourish in new directions in a vast digital territory.

Or so I tell myself.

I grew up using Ubuntu from Ubuntu 8 “Hardy Heron” through 18 “Bionic Beaver”, and only a few years ago switched over to Kubuntu. By no means a radical shift in the Linux community. And I’ve never attempted to run Arch, because I’m not really a purist with a burning need to display my “e-peen” to the world. If you want to see the awesome desktops of competitive geekery, check out r/unixporn.

Visuals are nice, but secondary, as I do need a few things to remain the same across installs, functionality-wise. One of those is Chinese-Zh Pinyin input, and (secondarily) unicode.

So that I can type things like: 學而時習之不亦樂乎 and or . (If you see boxes there, set the page Character encoding to UTF-8.) Frustratingly, KDE does nothave easy integration with either ibus or fcitx out-of-the-box like Gnome does. The actual process to get pinyin input in KDE is not that difficult, but _figuring out_ that process took me almost four hours all together.

I’m not sure I am confident enough to call this a “guide,” but I want to have a record of the things I tried that eventually worked, even if just for my future self.

Libraries Installed

I can’t guarantee these alone will satisfy all system requirements across distros. I installed nearly everything with ‘fcitx-*’ from the repos. And it depends on which versions of GTK and Qt apps your system has running.

Installing `fcitx`, `fcitx-config`, and `fcitx-googlepinyin` will also grab a lot of the other dependencies, it may not be necessary to install each file listed below manually. If you are in need of backports for a GTK2 app or Qt3, the Kubuntu/backports PPA] is a good place to pull from.

fcitx fcitx-config fcitx-googlepinyin fcitx-config-gtk2
fcitx-frontend-qt4 fcitx-frontend-qt5 fcitx-modules
language-pack-zh-hans qtcongif-qt4

Solution

At first, with fcitx running, I could input Pinyin into Chrome, Firefox, and Thunderbird, but not into Kate, Kterm, LibreOffice, or Haroopad.

The solution to Fcitx not triggering when in Kate or other apps was to run `qtconfig-qt4` from the terminal, and in the drop-down menu under “Input Method” select Fcitx instead of ibus or Xim.

As with other IM changes, log out and log back in and voilá! Fcitx should now trigger when the hotkeys are pressed anywhere there is a cursor.

Sources
+ [Arch Linux Fcitx Guide](https://wiki.archlinux.org/index.php/fcitx)
+ [Fcitx FAQ](https://fcitx-im.org/wiki/FAQ#All_Qt_Apps_have_problem.3F) (Found the solution above for ‘Not running in Qt apps’ here)
+ [Manjaro Forums](https://forum.manjaro.org/t/fcitx-chinese-input-not-working-in-kde/55561) (One of many such visited)
+ [KDE Reddit](https://reddit.com/r/kde) (Perform a search for ‘pinyin’ or ‘fcitx’)

Solution 2

Manjaro forums are full of issues like this, many suggesting to make an ~/.xprofile or ~/.profile file with the following lines:

export XMODIFIERS="@im=fcitx"
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export DefaultIMModule=fcitx

Maybe this solution works for some, but I did not have either of those files, and adding them did not seem to make a difference, nor did their deletion now that Fcitx is working.

I also installed and tried using ibus for a bit, just to see if it enjoyed OOTB-usability as many of the forum suggestions claimed. Spoiler: it did not. I had the same issues running ibus as I had with Fcitx, where it would trigger in browsers, but not in any other text-application.

NOTE: With the recent (2022-09) swith to fcitx5, I found I had to change my ~/.profile config:

export XMODIFIERS="@im=fcitx5" 
export GTK_IM_MODULE=fcitx5
export QT_IM_MODULE=fcitx5 
export DefaultIMModule=fcitx5

Conclusion

With a bit of time, hopefully someone else’s, it is quite possible to input Chinese characters in KDE desktop apps. With the vast number of CJK-users out there, I am somewhat surprised that the process is as complicated as it is, and that CJK support has not been built in to the KDE project as of yet. This likely reflects the geographic distribution of KDE developers, however, not because “it isn’t important.”

I would like to try and make the process more streamlined, trying various methods on a fresh install of Kubuntu to see which is the most efficient. If I do, I will update this post (or just link to the new study). If I can make an efficient enough script, maybe it could get included in an actual distro release. Then I could add: “Linux developer” to my LinkedIn, right above “Accomplished Technical Writer & Life Guru.”