From 7ca26eee17f4ce1f75c8d04c2ab689dc7e3d9a97 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Thu, 19 Dec 2024 14:58:32 +0100 Subject: [PATCH] InternalUtils: Introduce wait_for_window_actor utility --- src/InternalUtils.vala | 20 ++++++++++++++++++++ src/Widgets/WindowClone.vala | 16 ++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/InternalUtils.vala b/src/InternalUtils.vala index cd5cc5717..4eb330150 100644 --- a/src/InternalUtils.vala +++ b/src/InternalUtils.vala @@ -348,5 +348,25 @@ namespace Gala { return actor_box; } + + public delegate void WindowActorReadyCallback (Meta.WindowActor window_actor); + + public static void wait_for_window_actor (Meta.Window window, owned WindowActorReadyCallback callback) { + unowned var window_actor = (Meta.WindowActor) window.get_compositor_private (); + if (window_actor != null) { + callback (window_actor); + return; + } + + Idle.add (() => { + window_actor = (Meta.WindowActor) window.get_compositor_private (); + + if (window_actor != null) { + callback (window_actor); + } + + return Source.REMOVE; + }); + } } } diff --git a/src/Widgets/WindowClone.vala b/src/Widgets/WindowClone.vala index 989b280c4..32754c40f 100644 --- a/src/Widgets/WindowClone.vala +++ b/src/Widgets/WindowClone.vala @@ -143,7 +143,7 @@ public class Gala.WindowClone : Clutter.Actor { reallocate (); - load_clone (); + InternalUtils.wait_for_window_actor (window, load_clone); window.notify["title"].connect (() => window_title.set_text (window.get_title () ?? "")); window_title.set_text (window.get_title () ?? ""); @@ -182,19 +182,7 @@ public class Gala.WindowClone : Clutter.Actor { * itself at the location of the original window. Also adds the shadow * effect and makes sure the shadow is updated on size changes. */ - private void load_clone () { - var actor = (Meta.WindowActor) window.get_compositor_private (); - if (actor == null) { - Idle.add (() => { - if (window.get_compositor_private () != null) { - load_clone (); - } - return Source.REMOVE; - }); - - return; - } - + private void load_clone (Meta.WindowActor actor) { if (overview_mode) { actor.hide (); }