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

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