vcl/unx/gtk3/gtkinst.cxx |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

New commits:
commit 8f08c9ac2805488ab60e32cc641d72aac1cbf3ce
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Nov 18 13:02:52 2024 +0100
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Thu Nov 28 21:56:37 2024 +0100

    tdf#163792 gtk3: Don't always focus combobox when its popup closes
    
    Since
    
        commit 405cf00e4818886b0d3053d03cfb2e3f3a5e8eb8
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Tue May 28 11:50:12 2024 +0200
    
            related tdf#160971 gtk3 a11y: Keep new combobox value
    
    , closing an (editable) combobox like the font size one
    in the Writer formatting toolbar resulted in the combobox's entry
    having focus, while the focus was set to the document before that
    commit.
    
    Make this work as expected (again), by making grabbing the
    focus conditional in 2 places:
    
    1) In GtkInstanceComboBox::signal_popup_toggled,
    only set the focus to the GtkEntry of the custom
    combobox implementation if the child focus is already
    inside of the combobox. As I understand it, the intended
    logic is "move focus from the combo box's button to its entry",
    not "unconditionally grab the focus".
    This also matches what the gtk4 implementation does. Sync the
    comment from the gtk4 implementation, which explicitly
    mentions the case of the font combobox in the toolbar (which
    behaves the same as the font size one in that regard) where
    focus should not be grabbed.
    
    2) In GtkComboBox::menu_toggled, only explicitly set focus to
    the toggle button if the combo box is located inside of a popup.
    This is the same condition used to grab all keyboard events.
    
    The code to do both was introduced in
    
        commit 131c1c7da8c567636ca55751e49d24cb6d6c9b9e
        Date:   Sun Nov 21 19:53:47 2021 +0000
    
            Related: tdf#145786 cooperate between our own grabs
    
    whose commit message only explicitly mentions grabs
    for popups. The scenarios described in the commit message
    still work as expected with GDK_BACKEND=x11.
    
    With this in place, focus now moves to the document
    as expected when clicking on a combobox entry in the popup
    for the font size combobox in Writer's formatting toolbar,
    while clicking an entry in any of the comboboxes in e.g.
    Writer's "Format" -> "Character" dialog's "Font" tab still
    results in the entry of the combobox getting focus.
    
    Change-Id: Ib07b034f8327dab19a2264ae3ed8e20ea918dd89
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176713
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit 4e770803c63417791cf2e38e27ec85127056b7a5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176730
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index d8844aacc65b..1f1ea5d3ac15 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -21330,8 +21330,10 @@ private:
                 GdkSurface* pParentSurface = pParent ? 
widget_get_surface(pParent) : nullptr;
                 void* pParentIsPopover = pParentSurface ? 
g_object_get_data(G_OBJECT(pParentSurface), "g-lo-InstancePopup") : nullptr;
                 if (pParentIsPopover)
+                {
                     do_grab(m_pToggleButton);
-                gtk_widget_grab_focus(m_pToggleButton);
+                    gtk_widget_grab_focus(m_pToggleButton);
+                }
             }
         }
         else
@@ -21377,11 +21379,18 @@ private:
         ComboBox::signal_popup_toggled();
         if (!m_bPopupActive && m_pEntry)
         {
-            disable_notify_events();
-            //restore focus to the GtkEntry when the popup is gone, which
-            //is what the vcl case does, to ease the transition a little
-            gtk_widget_grab_focus(m_pEntry);
-            enable_notify_events();
+            if (has_child_focus())
+            {
+                // restore focus to the GtkEntry when the popup is gone, which
+                // is what the vcl case does, to ease the transition a little,
+                // but don't do it if the focus was moved out of togglebutton
+                // by something else already (e.g. font combobox in toolbar
+                // on a "direct pick" from the menu which moves focus into
+                // the main document
+                disable_notify_events();
+                gtk_widget_grab_focus(m_pEntry);
+                enable_notify_events();
+            }
 
             // tdf#160971: For some reason, the tree view in the no longer 
visible
             // popup still incorrectly assumes it has focus in addition to the 
now

Reply via email to