[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - vcl/unx

Caolán McNamara caolanm at redhat.com
Mon Nov 25 13:38:42 PST 2013


 vcl/unx/gtk/window/gtksalframe.cxx |   67 ++++++++++++++++++++++++-------------
 1 file changed, 45 insertions(+), 22 deletions(-)

New commits:
commit d77483f0ab1a7f97ec41adfac66d98696adeef70
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Nov 22 13:20:12 2013 +0000

    Related: fdo#41169 fix GTK non-Latin keyboard layout with Latin shortcuts
    
    See also rhbz#958300
    
    Change-Id: I5c3cf9652adb7b1c9ec53a32ed39f231a09ae1d7
    (cherry picked from commit 8cef6c7ec67aec88b339ca647e784afbabf190f8)
    Reviewed-on: https://gerrit.libreoffice.org/6759
    Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>
    Tested-by: Khaled Hosny <khaledhosny at eglug.org>

diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx
index fef8407..7db5649 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -323,6 +323,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
@@ -373,7 +381,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,
@@ -405,33 +413,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 )


More information about the Libreoffice-commits mailing list