Blame marco_0004-workspace-Don-t-try-to-use-per-workspace-MRU-lists-a-1.22.patch

raveit65 bba250f
From 8f9435ab776dc7c26a0ecc68be2755c4058d30d3 Mon Sep 17 00:00:00 2001
raveit65 bba250f
From: rcaridade145 <rcaridade145@gmail.com>
raveit65 bba250f
Date: Tue, 3 Mar 2020 20:51:17 +0000
raveit65 bba250f
Subject: [PATCH 4/4] workspace: Don't try to use per-workspace MRU lists as a
raveit65 bba250f
 hint for focusing
raveit65 bba250f
raveit65 bba250f
A prior commit switched from focusing the topmost window as the default
raveit65 bba250f
window to focusing the MRU window. This was done in alignment with the
raveit65 bba250f
introduction of per-workspace MRU lists to avoid problems where the window
raveit65 bba250f
stack was inadvertently changed when focusing windows during window switches.
raveit65 bba250f
raveit65 bba250f
Now that focusing windows don't have as big an impact on the stacking order,
raveit65 bba250f
we can revert back to focusing the top window, which is less confusing to the
raveit65 bba250f
user.
raveit65 bba250f
raveit65 bba250f
For now, leave per-workspace MRU lists, as they're a pretty good approximation
raveit65 bba250f
of a global MRU list, and it works well enough.
raveit65 bba250f
raveit65 bba250f
https://bugzilla.gnome.org/show_bug.cgi?id=620744
raveit65 bba250f
raveit65 bba250f
Based on commit https://gitlab.gnome.org/GNOME/metacity/-/commit/f628d8f8901f46fa9e00707ae9d7ccfd1e85f427
raveit65 bba250f
---
raveit65 bba250f
 doc/how-to-get-focus-right.txt |  2 +-
raveit65 bba250f
 src/core/workspace.c           | 42 +++++-----------------------------
raveit65 bba250f
 src/core/workspace.h           | 11 +++++++++
raveit65 bba250f
 3 files changed, 18 insertions(+), 37 deletions(-)
raveit65 bba250f
raveit65 bba250f
diff --git a/doc/how-to-get-focus-right.txt b/doc/how-to-get-focus-right.txt
raveit65 bba250f
index 45c0f378..b9ccee6d 100644
raveit65 bba250f
--- a/doc/how-to-get-focus-right.txt
raveit65 bba250f
+++ b/doc/how-to-get-focus-right.txt
raveit65 bba250f
@@ -7,7 +7,7 @@ end of the discussion for how these special cases are handled.)  The
raveit65 bba250f
 basics are easy:
raveit65 bba250f
 
raveit65 bba250f
 Focus method  Behavior
raveit65 bba250f
-    click     When a user clicks on a window, focus it
raveit65 bba250f
+    click     Focus the window on top
raveit65 bba250f
    sloppy     When an EnterNotify is received, focus the window
raveit65 bba250f
     mouse     Same as sloppy, but also defocus when mouse enters DESKTOP
raveit65 bba250f
               window
raveit65 bba250f
diff --git a/src/core/workspace.c b/src/core/workspace.c
raveit65 bba250f
index dffb1ebf..b83491e3 100644
raveit65 bba250f
--- a/src/core/workspace.c
raveit65 bba250f
+++ b/src/core/workspace.c
raveit65 bba250f
@@ -33,7 +33,7 @@
raveit65 bba250f
 
raveit65 bba250f
 void meta_workspace_queue_calc_showing   (MetaWorkspace *workspace);
raveit65 bba250f
 static void set_active_space_hint        (MetaScreen *screen);
raveit65 bba250f
-static void focus_ancestor_or_mru_window (MetaWorkspace *workspace,
raveit65 bba250f
+static void focus_ancestor_or_top_window (MetaWorkspace *workspace,
raveit65 bba250f
                                           MetaWindow    *not_this_one,
raveit65 bba250f
                                           guint32        timestamp);
raveit65 bba250f
 static void free_this                    (gpointer candidate,
raveit65 bba250f
@@ -971,7 +971,7 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
raveit65 bba250f
 
raveit65 bba250f
   if (meta_prefs_get_focus_mode () == META_FOCUS_MODE_CLICK ||
raveit65 bba250f
       !workspace->screen->display->mouse_mode)
raveit65 bba250f
-    focus_ancestor_or_mru_window (workspace, not_this_one, timestamp);
raveit65 bba250f
+    focus_ancestor_or_top_window (workspace, not_this_one, timestamp);
raveit65 bba250f
   else
raveit65 bba250f
     {
raveit65 bba250f
       MetaWindow * window;
raveit65 bba250f
@@ -1008,7 +1008,7 @@ meta_workspace_focus_default_window (MetaWorkspace *workspace,
raveit65 bba250f
             }
raveit65 bba250f
         }
raveit65 bba250f
       else if (meta_prefs_get_focus_mode () == META_FOCUS_MODE_SLOPPY)
raveit65 bba250f
-        focus_ancestor_or_mru_window (workspace, not_this_one, timestamp);
raveit65 bba250f
+        focus_ancestor_or_top_window (workspace, not_this_one, timestamp);
raveit65 bba250f
       else if (meta_prefs_get_focus_mode () == META_FOCUS_MODE_MOUSE)
raveit65 bba250f
         {
raveit65 bba250f
           meta_topic (META_DEBUG_FOCUS,
raveit65 bba250f
@@ -1035,13 +1035,11 @@ record_ancestor (MetaWindow *window,
raveit65 bba250f
  * window on active workspace
raveit65 bba250f
  */
raveit65 bba250f
 static void
raveit65 bba250f
-focus_ancestor_or_mru_window (MetaWorkspace *workspace,
raveit65 bba250f
+focus_ancestor_or_top_window (MetaWorkspace *workspace,
raveit65 bba250f
                               MetaWindow    *not_this_one,
raveit65 bba250f
                               guint32        timestamp)
raveit65 bba250f
 {
raveit65 bba250f
   MetaWindow *window = NULL;
raveit65 bba250f
-  MetaWindow *desktop_window = NULL;
raveit65 bba250f
-  GList *tmp;
raveit65 bba250f
 
raveit65 bba250f
   if (not_this_one)
raveit65 bba250f
     meta_topic (META_DEBUG_FOCUS,
raveit65 bba250f
@@ -1072,36 +1070,8 @@ focus_ancestor_or_mru_window (MetaWorkspace *workspace,
raveit65 bba250f
         }
raveit65 bba250f
     }
raveit65 bba250f
 
raveit65 bba250f
-  /* No ancestor, look for the MRU window */
raveit65 bba250f
-  tmp = workspace->mru_list;
raveit65 bba250f
-
raveit65 bba250f
-  while (tmp)
raveit65 bba250f
-    {
raveit65 bba250f
-      MetaWindow* tmp_window;
raveit65 bba250f
-      tmp_window = ((MetaWindow*) tmp->data);
raveit65 bba250f
-      if (tmp_window != not_this_one           &&
raveit65 bba250f
-          meta_window_showing_on_its_workspace (tmp_window) &&
raveit65 bba250f
-          tmp_window->type != META_WINDOW_DOCK &&
raveit65 bba250f
-          tmp_window->type != META_WINDOW_DESKTOP)
raveit65 bba250f
-        {
raveit65 bba250f
-          window = tmp->data;
raveit65 bba250f
-          break;
raveit65 bba250f
-        }
raveit65 bba250f
-      else if (tmp_window != not_this_one      &&
raveit65 bba250f
-               desktop_window == NULL          &&
raveit65 bba250f
-               meta_window_showing_on_its_workspace (tmp_window) &&
raveit65 bba250f
-               tmp_window->type == META_WINDOW_DESKTOP)
raveit65 bba250f
-        {
raveit65 bba250f
-          /* Found the most recently used desktop window */
raveit65 bba250f
-          desktop_window = tmp_window;
raveit65 bba250f
-        }
raveit65 bba250f
-
raveit65 bba250f
-      tmp = tmp->next;
raveit65 bba250f
-    }
raveit65 bba250f
-
raveit65 bba250f
-  /* If no window was found, default to the MRU desktop-window */
raveit65 bba250f
-  if (window == NULL)
raveit65 bba250f
-    window = desktop_window;
raveit65 bba250f
+  window = meta_stack_get_default_focus_window (workspace->screen->stack,
raveit65 bba250f
+                                                workspace, NULL);
raveit65 bba250f
 
raveit65 bba250f
   if (window)
raveit65 bba250f
     {
raveit65 bba250f
diff --git a/src/core/workspace.h b/src/core/workspace.h
raveit65 bba250f
index 7d02861e..b8ea3c97 100644
raveit65 bba250f
--- a/src/core/workspace.h
raveit65 bba250f
+++ b/src/core/workspace.h
raveit65 bba250f
@@ -52,6 +52,17 @@ struct _MetaWorkspace
raveit65 bba250f
   MetaScreen *screen;
raveit65 bba250f
 
raveit65 bba250f
   GList *windows;
raveit65 bba250f
+  
raveit65 bba250f
+  /* The "MRU list", or "most recently used" list, is a list of
raveit65 bba250f
+   * MetaWindows ordered based on the time the the user interacted
raveit65 bba250f
+   * with the window most recently.
raveit65 bba250f
+   *
raveit65 bba250f
+   * For historical reasons, we keep an MRU list per workspace.
raveit65 bba250f
+   * It used to be used to calculate the default focused window,
raveit65 bba250f
+   * but isn't anymore, as the window next in the stacking order
raveit65 bba250f
+  * can sometimes be not the window the user interacted with last,
raveit65 bba250f
+  */
raveit65 bba250f
+
raveit65 bba250f
   GList *mru_list;
raveit65 bba250f
 
raveit65 bba250f
   GList  *list_containing_self;
raveit65 bba250f
-- 
raveit65 bba250f
2.21.1
raveit65 bba250f