vcl/inc/unx/gtk/gtkframe.hxx | 1 vcl/unx/gtk3/gtkframe.cxx | 53 +++++++++++++++++++++++++------------------ vcl/unx/gtk3/gtkinst.cxx | 4 ++- 3 files changed, 35 insertions(+), 23 deletions(-)
New commits: commit d40fb8ade1380fc34844e7bda7a6e335807ee5c6 Author: Caolán McNamara <[email protected]> AuthorDate: Wed Dec 17 21:30:20 2025 +0000 Commit: Caolán McNamara <[email protected]> CommitDate: Thu Dec 18 09:25:02 2025 +0100 Resolves: tdf#151849 use convoluted find-latin keygroup for accelerators for native gtk widget keyevent handlers, same as the toplevel widget uses, so Ctrl+יworks like Ctrl+h. None of this is portable to gtk4 I think. Change-Id: Ia4f350c1b726abf8ba98fbb66177f27c0f988a30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195814 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Jenkins diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 5acb24f85a8a..9f3901547635 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -641,6 +641,7 @@ public: static sal_uInt16 GetKeyCode(guint nKeyVal); #if !GTK_CHECK_VERSION(4, 0, 0) static guint GetKeyValFor(GdkKeymap* pKeyMap, guint16 hardware_keycode, guint8 group); + static guint8 GetBestAccelKeyGroup(GdkKeymap* keymap, guint8 group); #endif static sal_uInt16 GetKeyModCode(guint nState); static GdkEvent* makeFakeKeyPress(GtkWidget* pWidget); diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index c16445dc80c8..58d80d5f2cb1 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -330,6 +330,36 @@ guint GtkSalFrame::GetKeyValFor(GdkKeymap* pKeyMap, guint16 hardware_keycode, gu GdkModifierType(0), group, &updated_keyval, nullptr, nullptr, nullptr); return updated_keyval; } + + +guint8 GtkSalFrame::GetBestAccelKeyGroup(GdkKeymap* keymap, guint8 group) +{ + gint best_group = SAL_MAX_INT32; + + // Try and find Latin layout + GdkKeymapKey *keys; + gint n_keys; + if (gdk_keymap_get_entries_for_keyval(keymap, GDK_KEY_A, &keys, &n_keys)) + { + // 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; + + return best_group; +} + #endif namespace { @@ -425,30 +455,9 @@ bool GtkSalFrame::doKeyCallback( guint state, #if !GTK_CHECK_VERSION(4, 0, 0) if( aEvent.mnCode == 0 ) { - 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_KEY_A, &keys, &n_keys)) - { - // 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; - + guint8 best_group = GetBestAccelKeyGroup(keymap, group); guint updated_keyval = GetKeyValFor(keymap, hardware_keycode, best_group); aEvent.mnCode = GetKeyCode(updated_keyval); } diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 44e86f527967..9729e4aacba5 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -2096,7 +2096,9 @@ class GtkInstanceBuilder; #if !GTK_CHECK_VERSION(4, 0, 0) if (nKeyCode == 0) { - guint updated_keyval = GtkSalFrame::GetKeyValFor(gdk_keymap_get_default(), hardware_keycode, group); + GdkKeymap* keymap = gdk_keymap_get_default(); + guint8 best_group = GtkSalFrame::GetBestAccelKeyGroup(keymap, group); + guint updated_keyval = GtkSalFrame::GetKeyValFor(keymap, hardware_keycode, best_group); nKeyCode = GtkSalFrame::GetKeyCode(updated_keyval); } #else
