[gnome-shell/gnome-40] shell/window-tracker: Track ::window-added again



commit 1134253a794ab8b1a3a6159e6f8fbbef1db5fd48
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jan 20 20:39:51 2022 +0100

    shell/window-tracker: Track ::window-added again
    
    Switching from ::window-added to ::window-created broke extensions
    that look up a window's app on ::window-added, as that signal is
    emitted before ::window-created and the window is therefore not
    tracked yet.
    
    For the upcoming release we can expect extensions to adjust to the
    change, but for stable branches it is better to unbreak extensions
    by tracking ::window-added again.
    
    This partially reverts commit 5674dee6a4d5539941e8c.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2120>

 src/shell-window-tracker.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
---
diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c
index 7ef94e7591..bc15c2d812 100644
--- a/src/shell-window-tracker.c
+++ b/src/shell-window-tracker.c
@@ -560,6 +560,17 @@ static void
 on_window_created (MetaDisplay *display,
                    MetaWindow  *window,
                    gpointer     user_data)
+{
+  ShellWindowTracker *self = user_data;
+
+  if (!g_hash_table_contains (self->window_to_app, window))
+    track_window (self, window);
+}
+
+static void
+shell_window_tracker_on_window_added (MetaWorkspace   *workspace,
+                                      MetaWindow      *window,
+                                      gpointer         user_data)
 {
   track_window (SHELL_WINDOW_TRACKER (user_data), window);
 }
@@ -602,15 +613,48 @@ 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_connect (workspace, "window-added",
+                        G_CALLBACK (shell_window_tracker_on_window_added), 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);
   g_signal_connect(display, "window-created",
                    G_CALLBACK (on_window_created), self);
+
+  shell_window_tracker_on_n_workspaces_changed (workspace_manager, NULL, self);
 }
 
 static void


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