Get Fcitx Work Along with iBus

I have both i3wm and gnome3 installed on my laptop. As known to all, ibus is a mandatory dependency for gnome3. However, I want to use ibus under gnome3, and in i3wm, I want to use fcitx as my input framework. Then here is the problem, how should I configure the environment variables to avoid conflicts between fcitx and ibus?

Since I start different X sessions through gdm, ~/.xinitrc will not work. Though ~/.xprofile enables me to use fcitx smoothly under i3wm, however, when I use gnome3, it will break ibus, and I will not able to type Chinese characters. Unlike openbox, i3wm does not have dedicated environment file.

So, if I want to get fcitx work along with ibus, I should specify in configuration file, when i3wm is detected as current running X session, the session should apply correct environment variables for fcitx. We can just leave ibus along, it will work well without specifying environment variables.

After searching the google, I found some clues in official i3wm FAQ. Here I will not explain the details, I will only write down the method as a memo.

To achieve my goal, I only need to write following configurations into ~/.profile:

1
2
3
4
5
if [ "$DESKTOP_SESSION" = "i3" ]; then
export XMODIFIERS=@im=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
fi

The function of these configurations is obvious, the X session will apply correct environment variables for fcitx when i3wm is detected as current running X session.

With these configurations, fcitx now works well with ibus.