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>
This commit is contained in:
Florian Müllner 2021-11-16 20:46:58 +01:00
parent f8e531b52d
commit acee68c5da

View File

@ -557,9 +557,9 @@ track_window (ShellWindowTracker *self,
} }
static void static void
shell_window_tracker_on_window_added (MetaWorkspace *workspace, on_window_created (MetaDisplay *display,
MetaWindow *window, MetaWindow *window,
gpointer user_data) gpointer user_data)
{ {
track_window (SHELL_WINDOW_TRACKER (user_data), window); track_window (SHELL_WINDOW_TRACKER (user_data), window);
} }
@ -588,14 +588,6 @@ disassociate_window (ShellWindowTracker *self,
g_object_unref (app); 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 static void
load_initial_windows (ShellWindowTracker *tracker) 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 static void
init_window_tracking (ShellWindowTracker *self) init_window_tracking (ShellWindowTracker *self)
{ {
MetaDisplay *display = shell_global_get_display (shell_global_get ()); 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_signal_connect (display, "notify::focus-window",
G_CALLBACK (on_focus_window_changed), self); G_CALLBACK (on_focus_window_changed), self);
g_signal_connect(display, "window-created",
shell_window_tracker_on_n_workspaces_changed (workspace_manager, NULL, self); G_CALLBACK (on_window_created), self);
} }
static void static void