Re: GdkEventKey --> utf-8 ?
- From: Joerg Anders <jan informatik tu-chemnitz de>
- To: Tor Lillqvist <tml iki fi>
- Cc: gtk-list gnome org
- Subject: Re: GdkEventKey --> utf-8 ?
- Date: Thu, 10 Sep 2009 14:14:49 +0200 (MESZ)
On Thu, 10 Sep 2009, Tor Lillqvist wrote:
Please post a minimal but complete sample program that
exhibits the in your opinion buggy behaviour.
--------------------------------------------
gboolean key_press_handler(GtkWidget *widget, GdkEventKey *event, gpointer data) {
char utf8string[10];
int ll;
guint32 unichar;
printf("keyval = %d (0x%x)\n", event->keyval, event->keyval);
unichar = gdk_keyval_to_unicode(event->keyval);
printf("unichar = %d (0x%x)\n", unichar, unichar);
ll = g_unichar_to_utf8(unichar, utf8string);
utf8string[ll] = '\0';
printf("utf8 = %s\n", utf8string); fflush(stdout);
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, "key-press-event", G_CALLBACK (key_press_handler), NULL);
gtk_widget_show_all(the_window);
gtk_main();
return 0;
}
-------------------------------------------
The result is:
keyval = 111 (0x6f)
unichar = 111 (0x6f)
utf8 = o
But note: If he uses a GtkEntry widget:
------------------------------------------------------------
static void OnEnter(GtkEntry *entry, gpointer user_data) {
const char *the_text, *cptr;
the_text = gtk_entry_get_text(GTK_ENTRY(entry));
printf("TEXT = %s\n", the_text);
for (cptr = the_text; *cptr; cptr++) {
printf("\t%d(0x%x)\n", *cptr, *cptr);
}
fflush(stdout);
}
int main(int argc, char *argv[]) {
GtkWidget *the_window;
GtkWidget *the_entry;
gtk_init (&argc, &argv);
the_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
the_entry = gtk_entry_new();
g_signal_connect (the_entry, "activate", G_CALLBACK (OnEnter), NULL);
gtk_container_add (GTK_CONTAINER (the_window), the_entry);
gtk_widget_show_all(the_window);
gtk_main();
return 0;
}
------------------------------------------------------------
The result is correct:
TEXT = ö
-61(0xffffffc3)
-74(0xffffffb6)
This shows: The X11 configuration isn't totally wrong.
the question is: What does the GtkEntry widget, what the
gdk_keyval_to_unicode() function is unable to do?
I should mention he uses an
Option "XkbLayout" "es"
in /etc/X11/xorg.conf
I asked him how he inserts the German Umlauts because they are not
present on a Spanish keyboard:
http://en.wikipedia.org/wiki/Keyboard_layout#Spanish_.28Spain.29.2C_aka_Spanish_.28International_sort.29
His answer:
+ The key on the left of ç. (in red - has a blu { ) So:
+ I press and hold Shift, then press that key, unpress and type o.
+ Note: if you want an Ö you must hold shift key pressed until you
+ press o.
+ Look this is the way to do this, and works in all applications. The
+ same for ê, for example.
+
+ For an á I have to press that key (without shift) and then a.
+
Perhaps this includes the solution. Any Spanish users/developers on
this list ?
--
J.Anders, GERMANY, TU Chemnitz, Fakultaet fuer Informatik
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]