Re: Catching typed characters using the key press handler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



More info, the same code works fine on Linux Mint.

Regards,
  Miroslav

On 9/19/2012 11:24 AM, Miroslav Rajcic wrote:
I am having a problem similar to the one described in the following posts:
https://mail.gnome.org/archives/gtk-list/2009-September/msg00066.html
https://mail.gnome.org/archives/gtk-list/2009-September/msg00067.html

Basically key press event handler passes individual key presses which may not be suitable
to be interpreted as UTF-8 characters.

I've tried to implement solution described in the posts (using GtkIMContext), but it doesn't seem to work correctly.
Sample code is a combination of those two posts:

#include <gtk/gtk.h>
static GtkIMContext *im_context;

static void gtk_entry_commit_cb (GtkIMContext *context, const gchar  *str, gpointer data) {
    printf("TEXT = %s\n", str); fflush(stdout);
}

gboolean key_press_handler(GtkWidget *widget,  GdkEventKey *event, gpointer  data)  {
    if(gtk_im_context_filter_keypress(im_context, event))
        return TRUE;
    return FALSE;
}

int main(int argc, char *argv[]) {
    GtkWidget *the_window;
    gtk_init (&argc, &argv);
    the_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (the_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect (the_window, "key-press-event", G_CALLBACK (key_press_handler), NULL);
    g_signal_connect (the_window, "key-release-event", G_CALLBACK (key_press_handler), NULL);
    im_context = gtk_im_context_simple_new ();
    g_signal_connect (im_context, "commit", G_CALLBACK (gtk_entry_commit_cb), NULL);
    gtk_widget_show_all(the_window);
    gtk_main();
    return 0;
}


My problem is following: when I press single key "č" on Croatian keyboard (AKA "LATIN SMALL LETTER C WITH CARON"),
in the commit callback I get "Ä" letter instead (AKA "LATIN CAPITAL LETTER A WITH DIAERESIS").

Do I need to additionally post-process this string to get the correct UTF-8 string ?

Regards,
  Miroslav

PS. My test PC is using Windows 7 with GTK 2.24.10 (32-bit).
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux