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

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