[maemo-developers] [maemo-developers] And some more notes about successfully using input methods
From: Aaron Levinson alevinsn at aracnet.comDate: Wed Jan 4 23:06:21 EET 2006
- Previous message: [maemo-developers] using the Select button to turn text input on and off
- Next message: [maemo-developers] Info on FIASCO components/hackers' guide to the N770
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here are some notes regarding using input methods that are fairly non-obvious and caused me a good deal of frustration: 1. In order to use the Hildon input method, only the "commit" event is of interest. The Hildon input method doesn't appear to use the preedit_changed event. The handwriting input method, however, appears to use the preedit_changed event (in addition to the commit event), but a good place to start is with the commit event (especially since the handwriting input method is not provided in the scratchbox environment, and it may be inconvenient to debug on the device, although debugging on the device is certainly possible). 2. You probably want to set the "use-show-hide" property on the input method after creating it using gtk_im_multicontext_new(). 3. You should wait till your widget realizes before calling gtk_im_context_set_client_window(). You can do this either by connecting to the "realize" event on the widget or overriding the "realize" function in the GtkWidgetClass for your widget's class. osso-xterm uses the latter approach (as does my VNC viewer port). You'll want to call gtk_im_context_set_client_window() again, when your widget is unrealized, passing in 0 for the second input. 4. After calling gtk_im_context_set_client_window(), make sure to setup signal handlers for the focus-in-event and focus-out-event events on your widget (technically, you can do this earlier, but you don't need it setup before this point). You can use the same function for the callback for both events and distinguish between focus-in and focus-out in the function. When you get a focus-in in the callback, call gtk_im_context_focus_in(). When you get a focus-out, call gtk_im_context_focus_out(). If you don't do this, the virtual keyboard won't display and instead you'll see an obscure error from the window manager on the command-line (as I discovered and had no idea how to fix). This is also less than obvious from the GTK documentation as well, although it may be something that is specific to the Hildon input method, because it uses a window. 5. In the signal handler that you setup for the input method commit event, the gchar * string input is in UTF-8 format. Here's some code that you could use to deal with this UTF-8 string: gunichar uChar = 0; guint keyval = 0; gchar *text2 = text; // the string is in UTF-8 format--iterate through the characters while (*text2) { uChar = g_utf8_get_char(text2); keyval = gdk_unicode_to_keyval(uChar); // // do something with the character here // text2 = g_utf8_next_char(text2); } Well, at least it was reasonable for me to use the following code, since I need to send a key press and release as single entities to the VNC server. Hope this helps to illuminate some of the mysteries of using GTK input methods. Aaron
- Previous message: [maemo-developers] using the Select button to turn text input on and off
- Next message: [maemo-developers] Info on FIASCO components/hackers' guide to the N770
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]