如何在 linux 上的 fltk 程序 运行 中启用 fcitx 输入法?

How to enable fcitx input method in an fltk program running on linux?

我试图在 linux 上的 fltk 程序 运行 中输入一些汉字,但失败了。我用的是fcitx,中文输入法是fcitx-googlepinyin

以下代码将生成一个包含单个输入框的 window。

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>

int main(int argc, char **argv) {
    Fl::scheme("GTK+");

    Fl::background(35, 35, 35);
    Fl::background2(90, 90, 90);
    Fl::foreground(240, 240, 240);

    Fl_Window *window = new Fl_Window(640, 480);

    Fl_Input *input = new Fl_Input(20, 20, 200, 20);

    window->end();
    window->show(argc, argv);

    return Fl::run();
}

当我点击输入框时,在fltk程序中按ctrl + space无法切换到我的中文输入法。但在其他 GUI 程序,如 Firefox 或 Atom 中,中文输入法运行良好。

我设置了一些变量如下:

export XIM="fcitx"
export XIM_PROGRAM="fcitx"
export XMODIFIERS="@im=fcitx"
export GTK_IM_MODULE="fcitx"
export QT_IM_MODULE="fcitx"

如何在fltk程序中启用fcitx输入法?

研究了X输入法后发现这是fltk >= 1.3.4的bug(fltk-1.3.3有正确的实现)

src/Fl_x.cxx的第673行,正确的代码应该是XSetLocaleModifiers("");而不是XSetLocaleModifiers("@im=");。第1329行也有同样的问题。

只需更正这两行代码并重新编译库,输入法将再次正常工作。

我也在fltk的网站上发了一个bug report,详细的可以去看看