[gnome-shell] shell/window-tracker: Track ::window-created



commit acee68c5da8e1bd0216545ff0553674c8a85060e
Author: Florian Müllner <fmuellner gnome org>
Date:   Tue Nov 16 20:46:58 2021 +0100

    shell/window-tracker: Track ::window-created
    
    We currently track windows via MetaWorkspace's ::window-added and
    ::window-removed signals. Those aren't emitted for override-redirect
    windows though, as those aren't actually located on any workspace
    (see https://gitlab.gnome.org/GNOME/mutter/-/blob/gnome-41/src/core/window.c#L1322).
    
    While that shouldn't be an issue as there's no good reason to look up
    the ShellApp of an OR window, extensions can make modifications that
    result in OR windows ending up in places that assume that every window
    has an associated ShellApp.
    
    We can either
     - accept that extensions break stuff (including badly)
     - carefully handle app-less windows everywhere
     - extend tracking to OR windows
    
    Opt for the last option, as that's the most user-friendly and least
    disruptive one.
    
    It's also simpler to track ::window-created and ::unmanaged, as we
    don't have to track workspaces or windows moving between workspaces.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4751
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2029>

 src/shell-window-tracker.c | 54 +++++-----------------------------------------
 1 file changed, 5 insertions(+), 49 deletions(-)
---
diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c
index cc03fb5f6e..11e777d5d6 100644
--- a/src/shell-window-tracker.c
+++ b/src/shell-window-tracker.c
@@ -557,9 +557,9 @@ track_window (ShellWindowTracker *self,
 }
 
 static void
-shell_window_tracker_on_window_added (MetaWorkspace   *workspace,
-                                      MetaWindow      *window,
-                                      gpointer         user_data)
+on_window_created (MetaDisplay *display,
+                   MetaWindow  *window,
+                   gpointer     user_data)
 {
   track_window (SHELL_WINDOW_TRACKER (user_data), window);
 }
@@ -588,14 +588,6 @@ disassociate_window (ShellWindowTracker   *self,
   g_object_unref (app);
 }
 
-static void
-shell_window_tracker_on_window_removed (MetaWorkspace   *workspace,
-                                     MetaWindow      *window,
-                                     gpointer         user_data)
-{
-  disassociate_window (SHELL_WINDOW_TRACKER (user_data), window);
-}
-
 static void
 load_initial_windows (ShellWindowTracker *tracker)
 {
@@ -622,51 +614,15 @@ load_initial_windows (ShellWindowTracker *tracker)
     }
 }
 
-static void
-shell_window_tracker_on_n_workspaces_changed (MetaWorkspaceManager *workspace_manager,
-                                              GParamSpec           *pspec,
-                                              gpointer              user_data)
-{
-  ShellWindowTracker *self = SHELL_WINDOW_TRACKER (user_data);
-  GList *workspaces;
-  GList *l;
-
-  workspaces = meta_workspace_manager_get_workspaces (workspace_manager);
-  for (l = workspaces; l; l = l->next)
-    {
-      MetaWorkspace *workspace = l->data;
-
-      /* This pair of disconnect/connect is idempotent if we were
-       * already connected, while ensuring we get connected for
-       * new workspaces.
-       */
-      g_signal_handlers_disconnect_by_func (workspace,
-                                            shell_window_tracker_on_window_added,
-                                            self);
-      g_signal_handlers_disconnect_by_func (workspace,
-                                            shell_window_tracker_on_window_removed,
-                                            self);
-
-      g_signal_connect (workspace, "window-added",
-                        G_CALLBACK (shell_window_tracker_on_window_added), self);
-      g_signal_connect (workspace, "window-removed",
-                        G_CALLBACK (shell_window_tracker_on_window_removed), self);
-    }
-}
-
 static void
 init_window_tracking (ShellWindowTracker *self)
 {
   MetaDisplay *display = shell_global_get_display (shell_global_get ());
-  MetaWorkspaceManager *workspace_manager =
-    meta_display_get_workspace_manager (display);
 
-  g_signal_connect (workspace_manager, "notify::n-workspaces",
-                    G_CALLBACK (shell_window_tracker_on_n_workspaces_changed), self);
   g_signal_connect (display, "notify::focus-window",
                     G_CALLBACK (on_focus_window_changed), self);
-
-  shell_window_tracker_on_n_workspaces_changed (workspace_manager, NULL, self);
+  g_signal_connect(display, "window-created",
+                   G_CALLBACK (on_window_created), self);
 }
 
 static void


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