diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-11-22 13:20:12 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-11-22 13:21:31 +0000 |
commit | 8cef6c7ec67aec88b339ca647e784afbabf190f8 (patch) | |
tree | 3ef9f72c57ea5a3caaf1e10ac2f119919a0aa6c6 | |
parent | 48c29ef3f8214b21833a88adf02c1e1998f27b68 (diff) |
Related: fdo#41169 fix GTK non-Latin keyboard layout with Latin shortcuts
See also rhbz#958300
Change-Id: I5c3cf9652adb7b1c9ec53a32ed39f231a09ae1d7
-rw-r--r-- | vcl/unx/gtk/window/gtksalframe.cxx | 67 |
1 files changed, 45 insertions, 22 deletions
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx index 5651dcfcebb6..de96dbdc3bb2 100644 --- a/vcl/unx/gtk/window/gtksalframe.cxx +++ b/vcl/unx/gtk/window/gtksalframe.cxx @@ -335,6 +335,14 @@ static sal_uInt16 GetKeyCode( guint keyval ) return nCode; } +static guint GetKeyValFor(GdkKeymap* pKeyMap, guint16 hardware_keycode, guint8 group) +{ + guint updated_keyval = 0; + gdk_keymap_translate_keyboard_state(pKeyMap, hardware_keycode, + (GdkModifierType)0, group, &updated_keyval, NULL, NULL, NULL); + return updated_keyval; +} + // F10 means either KEY_F10 or KEY_MENU, which has to be decided // in the independent part. struct KeyAlternate @@ -385,7 +393,7 @@ struct DamageTracker : public basebmp::IBitmapDeviceDamageTracker void GtkSalFrame::doKeyCallback( guint state, guint keyval, guint16 hardware_keycode, - guint8 /*group*/, + guint8 group, guint32 time, sal_Unicode aOrigCode, bool bDown, @@ -417,33 +425,48 @@ void GtkSalFrame::doKeyCallback( guint state, } #endif - /* #i42122# translate all keys with Ctrl and/or Alt to group 0 - * else shortcuts (e.g. Ctrl-o) will not work but be inserted by - * the application - */ - /* #i52338# do this for all keys that the independent part has no key code for - */ + /* + * #i42122# translate all keys with Ctrl and/or Alt to group 0 else + * shortcuts (e.g. Ctrl-o) will not work but be inserted by the + * application + * + * #i52338# do this for all keys that the independent part has no key code + * for + * + * fdo#41169 rather than use group 0, detect if there is a group which can + * be used to input Latin text and use that if possible + */ aEvent.mnCode = GetKeyCode( keyval ); if( aEvent.mnCode == 0 ) { - // check other mapping - gint eff_group, level; - GdkModifierType consumed; - guint updated_keyval = 0; - // use gdk_keymap_get_default instead of NULL; - // workaround a crahs fixed in gtk 2.4 - if( gdk_keymap_translate_keyboard_state( gdk_keymap_get_default(), - hardware_keycode, - (GdkModifierType)0, - 0, - &updated_keyval, - &eff_group, - &level, - &consumed ) ) + gint best_group = SAL_MAX_INT32; + + // Try and find Latin layout + GdkKeymap* keymap = gdk_keymap_get_default(); + GdkKeymapKey *keys; + gint n_keys; + if (gdk_keymap_get_entries_for_keyval(keymap, GDK_A, &keys, &n_keys)) { - aEvent.mnCode = GetKeyCode( updated_keyval ); + // Find the lowest group that supports Latin layout + for (gint i = 0; i < n_keys; ++i) + { + if (keys[i].level != 0 && keys[i].level != 1) + continue; + best_group = std::min(best_group, keys[i].group); + if (best_group == 0) + break; + } + g_free(keys); } + + //Unavailable, go with original group then I suppose + if (best_group == SAL_MAX_INT32) + best_group = group; + + guint updated_keyval = GetKeyValFor(keymap, hardware_keycode, best_group); + aEvent.mnCode = GetKeyCode(updated_keyval); } + aEvent.mnCode |= GetKeyModCode( state ); if( bDown ) |