[mutter/wip/exalm/focused-appearance: 37/37] window: Make default focus window on each workspace appear focused




commit 811d853a5da8d0327d795d83b48d2bc208428dbd
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sat Oct 12 23:55:26 2019 +0500

    window: Make default focus window on each workspace appear focused
    
    Makes workspace transitions in gnome-shell look more seamless, since
    both outgoing and incoming workspace have focused windows.
    
    This is only done for click focus mode, since it's not known which
    window would be focused for the other modes.

 src/core/window-private.h |  2 ++
 src/core/window.c         | 20 ++++++++++++++++++--
 src/core/workspace.c      | 31 +++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index d1730c9880..7e9274d6b8 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -717,6 +717,8 @@ void        meta_window_get_session_geometry (MetaWindow  *window,
 
 void        meta_window_update_unfocused_button_grabs (MetaWindow *window);
 
+void        meta_window_appears_focused_changed (MetaWindow *window);
+
 void     meta_window_set_focused_internal (MetaWindow *window,
                                            gboolean    focused);
 
diff --git a/src/core/window.c b/src/core/window.c
index d99db949f8..8f3ddcc81c 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -251,6 +251,10 @@ prefs_changed_callback (MetaPreference pref,
       meta_window_recalc_features (window);
       meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
     }
+  else if (pref == META_PREF_FOCUS_MODE)
+    {
+      meta_window_appears_focused_changed (window);
+    }
 }
 
 static void
@@ -4911,6 +4915,9 @@ set_workspace_state (MetaWindow    *window,
         }
     }
 
+  if (!window->constructing)
+    meta_window_appears_focused_changed (window);
+
   /* queue a move_resize since changing workspaces may change
    * the relevant struts
    */
@@ -5210,7 +5217,7 @@ meta_window_change_workspace_by_index (MetaWindow *window,
     meta_window_change_workspace (window, workspace);
 }
 
-static void
+void
 meta_window_appears_focused_changed (MetaWindow *window)
 {
   set_net_wm_state (window);
@@ -7312,7 +7319,16 @@ meta_window_get_frame (MetaWindow *window)
 gboolean
 meta_window_appears_focused (MetaWindow *window)
 {
-  return window->has_focus || (window->attached_focus_window != NULL);
+  MetaWorkspaceManager *workspace_manager;
+  MetaWorkspace *workspace;
+
+  workspace_manager = window->display->workspace_manager;
+  workspace = meta_window_get_workspace (window);
+
+  if (workspace && workspace != workspace_manager->active_workspace)
+    return window == meta_workspace_get_default_focus_window (workspace);
+  else
+    return window->has_focus || window->attached_focus_window;
 }
 
 gboolean
diff --git a/src/core/workspace.c b/src/core/workspace.c
index 83795cab91..347dc89903 100644
--- a/src/core/workspace.c
+++ b/src/core/workspace.c
@@ -365,15 +365,37 @@ meta_workspace_remove (MetaWorkspace *workspace)
    */
 }
 
+static void
+update_workspace_default_focus (MetaWorkspace *workspace,
+                                MetaWindow    *not_this_one)
+{
+  g_autoptr (GSList) windows = NULL;
+  GSList *l;
+
+  windows = meta_display_list_windows (workspace->display, META_LIST_DEFAULT);
+  for (l = windows; l; l = l->next)
+    {
+      MetaWindow *window = META_WINDOW (l->data);
+
+      if (meta_window_located_on_workspace (window, workspace) &&
+          window != not_this_one)
+        meta_window_appears_focused_changed (window);
+    }
+}
+
 void
 meta_workspace_add_window (MetaWorkspace *workspace,
                            MetaWindow    *window)
 {
+  MetaWorkspaceManager *workspace_manager;
+
   g_return_if_fail (g_list_find (workspace->mru_list, window) == NULL);
 
   COGL_TRACE_BEGIN_SCOPED (MetaWorkspaceAddWindow,
                            "Workspace (add window)");
 
+  workspace_manager = workspace->display->workspace_manager;
+
   workspace->mru_list = g_list_prepend (workspace->mru_list, window);
 
   workspace->windows = g_list_prepend (workspace->windows, window);
@@ -386,6 +408,9 @@ meta_workspace_add_window (MetaWorkspace *workspace,
       meta_workspace_invalidate_work_area (workspace);
     }
 
+  if (workspace != workspace_manager->active_workspace)
+    update_workspace_default_focus (workspace, window);
+
   g_signal_emit (workspace, signals[WINDOW_ADDED], 0, window);
   g_object_notify_by_pspec (G_OBJECT (workspace), obj_props[PROP_N_WINDOWS]);
 }
@@ -394,6 +419,8 @@ void
 meta_workspace_remove_window (MetaWorkspace *workspace,
                               MetaWindow    *window)
 {
+  MetaWorkspaceManager *workspace_manager = workspace->display->workspace_manager;
+
   COGL_TRACE_BEGIN_SCOPED (MetaWorkspaceRemoveWindow,
                            "Workspace (remove window)");
 
@@ -410,6 +437,9 @@ meta_workspace_remove_window (MetaWorkspace *workspace,
       meta_workspace_invalidate_work_area (workspace);
     }
 
+  if (workspace != workspace_manager->active_workspace)
+    update_workspace_default_focus (workspace, window);
+
   g_signal_emit (workspace, signals[WINDOW_REMOVED], 0, window);
   g_object_notify (G_OBJECT (workspace), "n-windows");
 }
@@ -658,6 +688,7 @@ meta_workspace_activate_with_focus (MetaWorkspace *workspace,
   if (focus_this)
     {
       meta_window_activate (focus_this, timestamp);
+      update_workspace_default_focus (workspace, focus_this);
     }
   else if (move_window)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]