Blame SOURCES/0001-Resolves-tdf-145567-restore-focus-to-the-usual-frame.patch

17f16b
From ea6cfca48017b76bfeb8898e6d9e47b3011a3add Mon Sep 17 00:00:00 2001
17f16b
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
17f16b
Date: Sat, 6 Nov 2021 21:32:21 +0000
17f16b
Subject: [PATCH] Resolves: tdf#145567 restore focus to the usual frame focus
17f16b
 widget
17f16b
17f16b
when tearing down the start center. Don't leave the focus in an
17f16b
arbitrary widget.
17f16b
17f16b
Change-Id: I82c30c94121dc43b2ea1b4fbc66a0a3e79f7e664
17f16b
---
17f16b
 vcl/unx/gtk3/gtk3gtkinst.cxx | 28 ++++++++++++++++++++++++++++
17f16b
 1 file changed, 28 insertions(+)
17f16b
17f16b
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
17f16b
index a5d233e2f95e..0fddb27aaa2d 100644
17f16b
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
17f16b
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
17f16b
@@ -1899,6 +1899,26 @@ GdkDragAction VclToGdk(sal_Int8 dragOperation)
17f16b
     return eRet;
17f16b
 }
17f16b
 
17f16b
+GtkWindow* get_active_window()
17f16b
+{
17f16b
+    GtkWindow* pFocus = nullptr;
17f16b
+
17f16b
+    GList* pList = gtk_window_list_toplevels();
17f16b
+
17f16b
+    for (GList* pEntry = pList; pEntry; pEntry = pEntry->next)
17f16b
+    {
17f16b
+        if (gtk_window_has_toplevel_focus(GTK_WINDOW(pEntry->data)))
17f16b
+        {
17f16b
+            pFocus = GTK_WINDOW(pEntry->data);
17f16b
+            break;
17f16b
+        }
17f16b
+    }
17f16b
+
17f16b
+    g_list_free(pList);
17f16b
+
17f16b
+    return pFocus;
17f16b
+}
17f16b
+
17f16b
 class GtkInstanceWidget : public virtual weld::Widget
17f16b
 {
17f16b
 protected:
17f16b
@@ -16635,6 +16655,14 @@ private:
17f16b
         // rehook handler and let vcl cycle its own way through this widget's
17f16b
         // children
17f16b
         pFrame->AllowCycleFocusOut();
17f16b
+
17f16b
+        // tdf#145567 if the focus is in this hierarchy then, now that we are tearing down,
17f16b
+        // move focus to the usual focus candidate for the frame
17f16b
+        GtkWindow* pFocusWin = get_active_window();
17f16b
+        GtkWidget* pFocus = pFocusWin ? gtk_window_get_focus(pFocusWin) : nullptr;
17f16b
+        bool bHasFocus = pFocus && gtk_widget_is_ancestor(pFocus, pTopLevel);
17f16b
+        if (bHasFocus)
17f16b
+            pFrame->GrabFocus();
17f16b
     }
17f16b
 
17f16b
     static void signalUnmap(GtkWidget*, gpointer user_data)
17f16b
-- 
17f16b
2.33.1
17f16b