The Road to Fcitx 5: 2. With multiple focus and multiple display in mind.

I’d like to clarify one thing about this series of articles first. All features described in this series are already implemented, because I do not fell comfortable about writing about vaporware. The purpose of this series is to share some interesting experience during the development that might be useful to other people, so it may describe user invisible changes and uninteresting technical details.

Focus is an important concept to input method. In old Fcitx 4 world, fcitx 4 assume that you may only have one focused input context. And this is gonna changed in Fcitx 5.

There used to be an interesting feature request about using Fcitx on different X11 screen (In old days when xrand or xinerama does not exists). But the problem is you can not do that because it is not possible to open multiple connection or use different screen. The window of GUI must be created separated for different display.

And now things may change in Fcitx 5. Because we will end up with two display server at the same time, so why not support multiple X server too 😛 ?

In Fcitx 5, every input context will have a property about its display. And every display has a new concept called focus group. In Fcitx 5, there will be at most one input context in the same focus group.

Also, one important thing about multiple display support is that, the GUI also need to handle multiple display. As I already stated in previous post, the wayland im protocol will NOT work with X11 client. X11 client must keep using XIM/IM module. Thus X11 window is even necessary for display Input method window under Wayland for Xwayland client. The display server information in input context will also help UI to decide how to display UI for the application in different Display.

Also, Fcitx 5 will use more input context specific state because the many API is now forced to pass a relevant input context. So, although unfocus will still trigger reset (IMHO that’s a reasonable thing to do), the under-hood states are separated instead of shared.

One interesting technical detail about DBus based client is that, we need to put DBus client in to the right focus group. In order to do that, the im module will now send a X client message to a special Fcitx X window to indicate the actual focus group of display server that it wants to join. The message contains a UUID generated by Fcitx. And client will send this UUID back to the fcitx window. If fcitx recognize this UUID, it will put the input context in the corresponding focus group. In this way, we avoid matching DISPLAY env var because it not always reliable. For example, DISPLAY=:0 and DISPLAY=:0.0 may not have visible difference to the client, but if we match it based on $DISPLAY, it is hard to say if these two display are the same display. But by sending the client message to current connected X window, we will always send message to the right X server.

See you next time 🙂 .

P. S.

Also, if you find my work helpful to you, feel free to buy me a beer. The donation link can be found at https://www.csslayer.info/wordpress/donation/ .

Posted in fcitx development | Tagged , , | Leave a comment

The Road to Fcitx 5: 1. libxcb replaces libX11

This is the first post of “Road to Fcitx 5”. I planned to talk about more the changes in Fcitx 5, and comments are welcome.

Right now, I’m using Fcitx 5 from day to day. As you can see from our jenkins service, there are more and more packages get ported to fcitx 5. Our ABI and API is not stable yet, so be sure to recompile all packages before you try out a new version.

One of an early plan about Fcitx 5 is I’d like to get rid of libX11 and replace it with xcb. libX11 is somehow more or less in a maintenance only mode. And it is complex, full of hack (especially for the input method part) to keep old API work.

The road to xcb is not easy for Fcitx. So far there is only one implementation for the XIM Server, which is called IMDkit, bundled within every input method server on Linux. To be honest, I have never read through the IMDkit code but just doing small adaption based on the old implementation back to Fcitx 3.6.

XCB is in a much more clearer state, without the key event hackish inside the LibX11 implementation. But there is no xcb only implementation for input method server/client. That’s bascially one of the reason why Qt5/SDL2 does not have xim support. So I decided to write my own library.

https://github.com/wengxt/xcb-imdkit

And here it is. It’s a pure C library that make use of C11 features to dispatch the protocol serialization. Generating XIM protocol from libX11 based source code is also a funny experience. I even discovered some spelling error in the source that sit there from about 22 years ago. Anyway, it’s a tiny library, support both server and client. It should also be easy to use if you want to write pure Xcb application with input method support. You can also check the examples in the test/ directory of the source code.

Also, if you find my work helpful to you, feel free to buy me a beer. The donation link can be found at https://www.csslayer.info/wordpress/donation/ .

See you next time 🙂 .

Posted in fcitx development | Tagged , , , | Leave a comment

How to use fcitx on Ubuntu 17.10

Since ubuntu moves to GNOME 3, there’s some difference if you want to use fcitx. It’s not hard to do, but need some manual tweak on user configurations.

Here is the instruction about how to use fcitx on a fresh installed ubuntu 17.10 system. Personally I just choose English as system language for this instruction, but it should make no difference.

So first of all, you will need to install fcitx and the input method you want anyway.

sudo apt-get install fcitx fcitx-mozc

Under GNOME the old im-config seems not working because GNOME only supports ibus and they don’t want any other input method related system to use it. We’ll need to set the environment variable manually because of that.

I used to recommend people use ~/.xprofile. but since this file is X only, I’d suggest to use .pam_environment file to set the variable.

On a freshly installed ubuntu 17.10, you will not have ~/.pam_environment file. So you can use

gedit ~/.pam_environment

to edit and create this file with following content.

XMODIFIERS DEFAULT=@im=fcitx
GTK_IM_MODULE DEFAULT=fcitx
QT_IM_MODULE DEFAULT=fcitx

Then, you’ll also need to add an autostart entry to start fcitx. Search “Startup applications Preferences” and add an new entry for fcitx.

After that, you’ll already be able to get Fcitx working. But I still recommend you to install this extension for better experience under GNOME. https://extensions.gnome.org/extension/261/kimpanel/. It also provides extra functionality on correctly setting keyboard layout under GNOME with fcitx. Otherwise any keyboard layout group change outside mutter will be reset to mutter’s internal value. (See https://bugzilla.gnome.org/show_bug.cgi?id=756543#c18 for more information)

Unfortunately, it’s hard to install gnome shell extension from browser in a default installation.

To use firefox you may follow the instruction on the website and install firefox extension. (I have no idea why Ubuntu doesn’t include this package and use firefox as default browser, probably this issue is worth a bug report.) You’ll also need to install

sudo apt-get install chrome-gnome-shell

Or you can use gnome’s browser

sudo apt-get install epiphany-browser

To install extension from browser. That are many other way to install gnome shell extensions so I’m not gonna to cover it all.

P. S.

My system does not gives me Wayland session for some reason, so I can’t test the GNOME wayland on Ubuntu 17.10. But just to let you know, as described in my last post, you may use fcitx on GNOME’s wayland session. Though, to get the input method window displayed at right location you currently will need to use fcitx’s master branch and use kimpanel extension.

Posted in fcitx development | Tagged , | Leave a comment

Gaps between Wayland and Fcitx (or all Input methods).

Though some people have no problem (or, only few problems) about using fcitx (to be more specifically version 4) with wayland, but the truth is there are still lots of problems left to be addressed.

The truth is, wayland is not yet ready for input method.

  1. Generic input method protocol is not widely adopted.
    In the old good X11 world, there is a protocol call XIM. No matter how bad it is, it widely used and adopted by nearly all applications. But as for wayland’s protocol “text-input”, the current situation is:
    – Gtk3 doesn’t support it.
    – Qt5 support a not-upstreamed version 2.
    – EFL / weston support the official version in wayland-protocols.
    – SDL2 doesn’t support it.
    – Weston’s reference client side implementation has critical bug.
    What does this mean? This means even you’re using wayland + (GNOME/KDE) for now, you’re still using the old im module via DBus.
  2. The generic input method protocol is bad.
    It is weird that in wayland world, key repetition is a task of client. But the problem is, it even becomes a work for input method. Fcitx 5 for now is the only implementation handles key-repetition correctly. But I don’t even care about this because I don’t even have a real application to test this feature. (You need a patched version for weston-editor to play with it).Also, the wayland input context will be destroyed once it get unfocused, which makes it unable for input method server to track different window and keep different input state for different window (e.g. different window + different im will need this feature) .
  3. The window positioning issue.
    In Wayland world, there’s no way for a non-compositor window to place the window by abstract coordinates (x, y). Also there is no way for a non-compositor window to know about its own location. But for input method, you need to display a window at the position of cursor. The “input-method” protocol in wayland allows you to assign a surface as “input panel”, and the compositor will move it for you.
    This means: when you’re using im module via dbus or typing in a Xwayland window with XIM, it can’t make use of this feature. But you may say, under plasma wayland, or gnome-shell I didn’t see any problem.This is because:
    – GNOME shell is the compositor, it can do hacky things to move the input method window around and make use of compositor feature. Currently gnome-shell’s ibus extension and https://github.com/wengxt/kimpanel-for-gnome-shell/ (you can use it with fcitx) use this method.
    – For Plasma, the plasma shell window occupies the whole screen, which makes kimpanel able to locate its window freely with absolute coordinates.Except these two specific environment (no, weston will not work), input method server will not be able to move the input method window freely.
  4. Keyboard layout management
    This is somewhat less important for now, because of the issue listed above. Input method server (fcitx or ibus) are trying to managing keyboard layout, but there’s no common interface to do this.

Due to the issues above, I do not recommend to use wayland if you need input method. You can try it today, but you may find it working or not working. Also, these issues also largely extinguished my passion about working on wayland. Since for now there are still a lot of works going on with fcitx 5 and libime, my focus are mostly on them instead of making fcitx working on wayland.

But no need to give up too soon, as for the solution, It seems that KWin wants to run input method inside compositor process and this may solve a large portion of problem listed above, because: 1. kwin is compositor, it knows everything about a window, 2. kwin on wayland will control keyboard layout, 3. no “input-method” protocol is needed. Fcitx 5 also contains work to make fcitx run as a library more easily.

Right now my work replacing fcitx 4’s pinyin and table with libime is  near completion. Let’s see how it goes from here.

Posted in fcitx development | Tagged , , , | 3 Comments

最近的一个 Linux Intel 驱动问题和 Workaround

老实说一般我都不愿意写这种文章。因为这种文章基本上都是很有时效性的。但毕竟这个问题已经困扰了我好几个月,所以还是打算记录一下方便同样遇到问题的人。

具体表现是,开机正常,使用正常,但是如果放久了就会黑屏再也起不来。这时还能 ssh 进去,但是从 ssh 重启很大可能会等待很久。上游的 bug report 我也不好分辨到底是哪个,就随便列出几个我觉得相关的。

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

那么最后我的解决方案是什么呢……总之也是在某个 report 里面看到有人提到的方法。

在 /etc/modprobe.d/90-i915.conf 里面写上

options i915 enable_guc_loading=1 enable_guc_submission=1 disable_power_well=0

总之我加上这个参数之后好久都没有出过问题了。

顺带一提我正在使用的内核版本是 4.13.0 但是这个问题至少困扰我了好久好久大概从 4.9 之后升级了 BIOS 开始……

Posted in Linux | Tagged , , , | Leave a comment