From 7ace62501f0a0457b7c26ebc203169b6c06f7da8 Mon Sep 17 00:00:00 2001 From: Leonhard Date: Sat, 15 Feb 2025 16:52:43 +0100 Subject: [PATCH 1/2] HideTracker: Disconnect timeouts on unmanaging (#2272) --- src/ShellClients/HideTracker.vala | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ShellClients/HideTracker.vala b/src/ShellClients/HideTracker.vala index 8d79ae2db..7969bfae7 100644 --- a/src/ShellClients/HideTracker.vala +++ b/src/ShellClients/HideTracker.vala @@ -37,17 +37,15 @@ public class Gala.HideTracker : Object { Object (display: display, panel: panel); } - ~HideTracker () { - if (hide_timeout_id != 0) { - Source.remove (hide_timeout_id); - } - - if (update_timeout_id != 0) { - Source.remove (update_timeout_id); - } - } - construct { + panel.window.unmanaging.connect_after (() => { + // The timeouts hold refs on us so we stay connected to signal handlers that might + // access the panel which was already freed. To prevent that make sure we reset + // the timeouts so that we get freed immediately + reset_hide_timeout (); + reset_update_timeout (); + }); + // Can't be local otherwise we get a memory leak :( // See https://gitlab.gnome.org/GNOME/vala/-/issues/1548 current_focus_window = display.focus_window; @@ -152,6 +150,13 @@ public class Gala.HideTracker : Object { }); } + private void reset_update_timeout () { + if (update_timeout_id != 0) { + Source.remove (update_timeout_id); + update_timeout_id = 0; + } + } + public void update_overlap () { overlap = false; focus_overlap = false; From ef6292a939dde9e2e6f548e9ca62b97affa92dfa Mon Sep 17 00:00:00 2001 From: Leonhard Date: Sat, 15 Feb 2025 17:03:31 +0100 Subject: [PATCH 2/2] WorkspaceManager: Queue an idle to add a window (#2271) --- src/ShellClients/NotificationsClient.vala | 1 + src/WorkspaceManager.vala | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ShellClients/NotificationsClient.vala b/src/ShellClients/NotificationsClient.vala index 795f56ecf..173d16446 100644 --- a/src/ShellClients/NotificationsClient.vala +++ b/src/ShellClients/NotificationsClient.vala @@ -20,6 +20,7 @@ public class Gala.NotificationsClient : Object { client.window_created.connect ((window) => { window.set_data (NOTIFICATION_DATA_KEY, true); window.make_above (); + window.stick (); #if HAS_MUTTER46 client.wayland_client.make_dock (window); #endif diff --git a/src/WorkspaceManager.vala b/src/WorkspaceManager.vala index ce9070787..98ba05999 100644 --- a/src/WorkspaceManager.vala +++ b/src/WorkspaceManager.vala @@ -85,7 +85,7 @@ public class Gala.WorkspaceManager : Object { return; } - workspace.window_added.connect (window_added); + workspace.window_added.connect (queue_window_added); workspace.window_removed.connect (window_removed); } @@ -124,9 +124,15 @@ public class Gala.WorkspaceManager : Object { } } - private void window_added (Meta.Workspace? workspace, Meta.Window window) { + private void queue_window_added (Meta.Workspace? workspace, Meta.Window window) { + // We get this call very early so we have to queue an idle for ShellClients + // that might not have checked the window/got a protocol call yet + Idle.add (() => window_added (workspace, window)); + } + + private bool window_added (Meta.Workspace? workspace, Meta.Window window) { if (workspace == null || !Meta.Prefs.get_dynamic_workspaces () || window.on_all_workspaces) { - return; + return Source.REMOVE; } unowned Meta.WorkspaceManager manager = workspace.get_display ().get_workspace_manager (); @@ -139,6 +145,8 @@ public class Gala.WorkspaceManager : Object { ) { append_workspace (); } + + return Source.REMOVE; } private void window_removed (Meta.Workspace? workspace, Meta.Window window) { @@ -185,7 +193,7 @@ public class Gala.WorkspaceManager : Object { private void window_entered_monitor (Meta.Display display, int monitor, Meta.Window window) { if (InternalUtils.workspaces_only_on_primary () && monitor == display.get_primary_monitor ()) { - window_added (window.get_workspace (), window); + queue_window_added (window.get_workspace (), window); } } @@ -243,7 +251,7 @@ public class Gala.WorkspaceManager : Object { return; } - workspace.window_added.disconnect (window_added); + workspace.window_added.disconnect (queue_window_added); workspace.window_removed.disconnect (window_removed); workspaces_marked_removed.add (workspace);