Skip to content

Commit 7cb0c80

Browse files
committed
Introduce WindowActorFetcher
1 parent e6e6a4c commit 7cb0c80

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

src/Widgets/WindowClone.vala

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public class Gala.WindowClone : Clutter.Actor {
8080
}
8181
}
8282

83+
private WindowActorFetcher? window_actor_fetcher = null;
8384
private DragDropAction? drag_action = null;
8485
private Clutter.Clone? clone = null;
8586
private ShadowEffect? shadow_effect = null;
@@ -143,7 +144,12 @@ public class Gala.WindowClone : Clutter.Actor {
143144

144145
reallocate ();
145146

146-
load_clone ();
147+
if (window.get_compositor_private () != null) {
148+
load_clone ();
149+
} else {
150+
window_actor_fetcher = new WindowActorFetcher (window);
151+
window_actor_fetcher.window_actor_ready.connect (load_clone);
152+
}
147153

148154
window.notify["title"].connect (() => window_title.set_text (window.get_title () ?? ""));
149155
window_title.set_text (window.get_title () ?? "");
@@ -176,24 +182,14 @@ public class Gala.WindowClone : Clutter.Actor {
176182
}
177183

178184
/**
179-
* Waits for the texture of a new Meta.WindowActor to be available
180-
* and makes a close of it. If it was already was assigned a slot
185+
* Makes a clone of the window. If the window was already was assigned a slot
181186
* at this point it will animate to it. Otherwise it will just place
182187
* itself at the location of the original window. Also adds the shadow
183188
* effect and makes sure the shadow is updated on size changes.
184189
*/
185-
private void load_clone () {
186-
var actor = (Meta.WindowActor) window.get_compositor_private ();
187-
if (actor == null) {
188-
Idle.add (() => {
189-
if (window.get_compositor_private () != null) {
190-
load_clone ();
191-
}
192-
return Source.REMOVE;
193-
});
194-
195-
return;
196-
}
190+
private void load_clone () requires (window.get_compositor_private () != null) {
191+
window_actor_fetcher = null;
192+
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();
197193

198194
if (overview_mode) {
199195
actor.hide ();

src/WindowActorFetcher.vala

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
/*
7+
* Sends a signal when a window texture is ready.
8+
* Useful when you need to use window actor when the window was created.
9+
*/
10+
public class Gala.WindowActorFetcher : GLib.Object {
11+
public signal void window_actor_ready ();
12+
13+
public Meta.Window window { get; construct; }
14+
15+
public WindowActorFetcher (Meta.Window window) {
16+
Object (window: window);
17+
}
18+
19+
construct {
20+
start_check.begin ();
21+
}
22+
23+
private async void start_check () {
24+
Idle.add (() => {
25+
unowned var window_actor = (Meta.WindowActor) window.get_compositor_private ();
26+
27+
if (window_actor != null) {
28+
window_actor_ready ();
29+
30+
return Source.REMOVE;
31+
}
32+
33+
return Source.CONTINUE;
34+
});
35+
}
36+
}

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ gala_bin_sources = files(
1414
'ScreenSaverManager.vala',
1515
'ScreenshotManager.vala',
1616
'SessionManager.vala',
17+
'WindowActorFetcher.vala',
1718
'WindowAttentionTracker.vala',
1819
'WindowGrabTracker.vala',
1920
'WindowListener.vala',

0 commit comments

Comments
 (0)