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

349 Views Asked by At

I'm trying to input some Chinese characters in my fltk program running on linux but failed. I'm using fcitx, and specifically fcitx-googlepinyin as the Chinese input method.

The following code will produce a single window containing a single input box.

#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();
}

When I click on the input box, I can't switch to my Chinese input method by pressing ctrl + space in the fltk program. But in other GUI programs like Firefox or Atom the Chinese input method works well.

I've set some variables as follows:

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

How to enable fcitx input method in an fltk program?

1

There are 1 best solutions below

0
On BEST ANSWER

After studying X input method, I discover that this is a bug in fltk >= 1.3.4 (fltk-1.3.3 has the correct implementation).

On line 673 of src/Fl_x.cxx, the correct code should be XSetLocaleModifiers(""); instead of XSetLocaleModifiers("@im=");. Line 1329 has the same problem.

Just correct these two lines of code and recompile the library, the input methods will work correctly again.

I've also posted a bug report on the website of fltk, check it for more detail.