X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4040fe6eafef8a6162f00d782a288ef78be1ff02..0a0fc5b527437ddb5d41057d60506bfb22ea2bd3:/src/gtk1/window.cpp diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index f192a7ef11..5792525800 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -486,10 +486,21 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU static long map_to_unmodified_wx_keysym( GdkEventKey *event ) { + // VZ: it seems that GDK_KEY_RELEASE event doesn't set event->string + // but only event->keyval which is quite useless to us, so remember + // the last character from GDK_KEY_PRESS and resue it as last resort + // + // NB: should be MT-neutral as always called from main thread only + static struct + { + KeySym keysym; + long keycode; + } s_lastKeyPress = { 0, 0 }; + KeySym keysym = event->keyval; long key_code; - switch (keysym) + switch ( keysym ) { case GDK_Shift_L: case GDK_Shift_R: key_code = WXK_SHIFT; break; @@ -581,16 +592,43 @@ static long map_to_unmodified_wx_keysym( GdkEventKey *event ) case GDK_F11: key_code = WXK_F11; break; case GDK_F12: key_code = WXK_F12; break; default: - if ( (keysym & 0xFF) == keysym ) + { + // do we have the translation? + if ( event->length == 1 ) { - guint upper = gdk_keyval_to_upper( (guint)keysym ); - key_code = upper ? upper : keysym; + keysym = (KeySym)event->string[0]; } - else + else if ( (keysym & 0xFF) != keysym ) + { + // non ASCII key, what to do? + + if ( event->type == GDK_KEY_RELEASE ) + { + // reuse the one from the last keypress if any + if ( keysym == s_lastKeyPress.keysym ) + { + key_code = s_lastKeyPress.keycode; + + // skip "return 0" + break; + } + } + + // ignore this one, we don't know it + return 0; + } + //else: ASCII key, ok + + guint upper = gdk_keyval_to_upper( (guint)keysym ); + key_code = upper ? upper : keysym; + + if ( event->type == GDK_KEY_PRESS ) { - // unknown key code - key_code = 0; + // remember it to be reused below later + s_lastKeyPress.keysym = keysym; + s_lastKeyPress.keycode = key_code; } + } } return key_code; @@ -683,19 +721,14 @@ static long map_to_wx_keysym( GdkEventKey *event ) case GDK_F11: key_code = WXK_F11; break; case GDK_F12: key_code = WXK_F12; break; default: - { if (event->length == 1) { - if (event->length == 1) - { - key_code = (unsigned char)*event->string; - } - else if ((keysym & 0xFF) == keysym) - { - key_code = (guint)keysym; - } + key_code = (unsigned char)*event->string; + } + else if ((keysym & 0xFF) == keysym) + { + key_code = (guint)keysym; } - } } return key_code;