Blame SOURCES/0001-workspace-Focus-only-ancestors-that-are-focusable.patch

1a3082
From eca25ab6a12770a2a767458d9b0129d4fde3995c Mon Sep 17 00:00:00 2001
1a3082
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
1a3082
Date: Tue, 13 Nov 2018 08:31:52 +0100
1a3082
Subject: [PATCH 1/2] workspace: Focus only ancestors that are focusable
1a3082
1a3082
When destroying a window that has a parent, we initially try to focus one of
1a3082
its ancestors. However if no ancestor can be focused, then we should instead
1a3082
focus the default focus window instead of trying to request focus for a window
1a3082
that can't get focus anyways.
1a3082
1a3082
Fixes https://gitlab.gnome.org/GNOME/mutter/issues/308
1a3082
(cherry picked from commit eccc791f3b3451216f957e67fec47a73b65ed2b2)
1a3082
---
1a3082
 src/core/workspace.c | 37 +++++++++++++++++++++++++++----------
1a3082
 1 file changed, 27 insertions(+), 10 deletions(-)
1a3082
1a3082
diff --git a/src/core/workspace.c b/src/core/workspace.c
1a3082
index f2b2c2c48..58fcfa78c 100644
1a3082
--- a/src/core/workspace.c
1a3082
+++ b/src/core/workspace.c
1a3082
@@ -85,6 +85,12 @@ typedef struct _MetaWorkspaceLogicalMonitorData
1a3082
   MetaRectangle logical_monitor_work_area;
1a3082
 } MetaWorkspaceLogicalMonitorData;
1a3082
 
1a3082
+typedef struct _MetaWorkspaceFocusableAncestorData
1a3082
+{
1a3082
+  MetaWorkspace *workspace;
1a3082
+  MetaWindow *out_window;
1a3082
+} MetaWorkspaceFocusableAncestorData;
1a3082
+
1a3082
 static MetaWorkspaceLogicalMonitorData *
1a3082
 meta_workspace_get_logical_monitor_data (MetaWorkspace      *workspace,
1a3082
                                          MetaLogicalMonitor *logical_monitor)
1a3082
@@ -1322,13 +1328,20 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
1a3082
 }
1a3082
 
1a3082
 static gboolean
1a3082
-record_ancestor (MetaWindow *window,
1a3082
-                 void       *data)
1a3082
+find_focusable_ancestor (MetaWindow *window,
1a3082
+                         gpointer    user_data)
1a3082
 {
1a3082
-  MetaWindow **result = data;
1a3082
+  MetaWorkspaceFocusableAncestorData *data = user_data;
1a3082
+
1a3082
+  if (!window->unmanaging && meta_window_is_focusable (window) &&
1a3082
+      meta_window_located_on_workspace (window, data->workspace) &&
1a3082
+      meta_window_showing_on_its_workspace (window))
1a3082
+    {
1a3082
+      data->out_window = window;
1a3082
+      return FALSE;
1a3082
+    }
1a3082
 
1a3082
-  *result = window;
1a3082
-  return FALSE; /* quit with the first ancestor we find */
1a3082
+  return TRUE;
1a3082
 }
1a3082
 
1a3082
 /* Focus ancestor of not_this_one if there is one */
1a3082
@@ -1350,11 +1363,15 @@ focus_ancestor_or_top_window (MetaWorkspace *workspace,
1a3082
   if (not_this_one)
1a3082
     {
1a3082
       MetaWindow *ancestor;
1a3082
-      ancestor = NULL;
1a3082
-      meta_window_foreach_ancestor (not_this_one, record_ancestor, &ancestor);
1a3082
-      if (ancestor != NULL &&
1a3082
-          meta_window_located_on_workspace (ancestor, workspace) &&
1a3082
-          meta_window_showing_on_its_workspace (ancestor))
1a3082
+      MetaWorkspaceFocusableAncestorData data;
1a3082
+
1a3082
+      data = (MetaWorkspaceFocusableAncestorData) {
1a3082
+        .workspace = workspace,
1a3082
+      };
1a3082
+      meta_window_foreach_ancestor (not_this_one, find_focusable_ancestor, &data);
1a3082
+      ancestor = data.out_window;
1a3082
+
1a3082
+      if (ancestor)
1a3082
         {
1a3082
           meta_topic (META_DEBUG_FOCUS,
1a3082
                       "Focusing %s, ancestor of %s\n",
1a3082
-- 
1a3082
2.21.0
1a3082