I'm creating a application using C & gtk+2 with custom text input, pango to draw the characters to GtkDrawingArea, everything works fine until a user tells me that he can't input Chinese characters in my application, he use a fcitx input method.
Currently I'm using simple key_press_event & key_release_event GSignals to implement character input, but I don't think it will work for input methods, I found a GtkIMContext api but not sure how to use it.
So, my question is, how to receive characters from fcitx/ibus input methods in gtk+2?
Finally I found the way myself.
First of all, I have a
GtkWindow *.To support input methods, I have to initialize a
GtkIMContextand set the client window,gtk_im_context_set_client_windowuseGdkWindow *as its second parameter.The last step, set focus to this
im_context.Now the input methods are available! After this, you can listen for signals of
GtkIMContextto handle inputs.In order to receive english characters in
commitsignal's callback, you must listen forkey-press-eventsignal and usegtk_im_context_filter_keypressfunction.Refenerces: