Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce WindowActorFetcher #2176

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class Gala.WindowClone : Clutter.Actor {
}
}

private WindowActorFetcher? window_actor_fetcher = null;
private DragDropAction? drag_action = null;
private Clutter.Clone? clone = null;
private ShadowEffect? shadow_effect = null;
Expand Down Expand Up @@ -143,7 +144,12 @@ public class Gala.WindowClone : Clutter.Actor {

reallocate ();

load_clone ();
if (window.get_compositor_private () != null) {
load_clone ();
} else {
window_actor_fetcher = new WindowActorFetcher (window);
window_actor_fetcher.window_actor_ready.connect (load_clone);
}

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

/**
* Waits for the texture of a new Meta.WindowActor to be available
* and makes a close of it. If it was already was assigned a slot
* Makes a clone of the window. If the window was already was assigned a slot
* at this point it will animate to it. Otherwise it will just place
* 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 () requires (window.get_compositor_private () != null) {
window_actor_fetcher = null;
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();

if (overview_mode) {
actor.hide ();
Expand Down
46 changes: 46 additions & 0 deletions src/WindowActorFetcher.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

/*
* Sends a signal when a window actor is ready.
* Useful when you need to use window actor when the window was created.
*/
public class Gala.WindowActorFetcher : GLib.Object {
public signal void window_actor_ready ();

public Meta.Window window { get; construct; }

private uint idle_id = 0;

public WindowActorFetcher (Meta.Window window) {
Object (window: window);
}

~WindowActorFetcher () {
if (idle_id > 0) {
Source.remove (idle_id);
}
}

construct {
idle_id = Idle.add (() => {
if (window == null) {
idle_id = 0;
return Source.REMOVE;
}

unowned var window_actor = (Meta.WindowActor) window.get_compositor_private ();

if (window_actor != null) {
window_actor_ready ();
idle_id = 0;

return Source.REMOVE;
}

return Source.CONTINUE;
});
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gala_bin_sources = files(
'ScreenSaverManager.vala',
'ScreenshotManager.vala',
'SessionManager.vala',
'WindowActorFetcher.vala',
'WindowAttentionTracker.vala',
'WindowGrabTracker.vala',
'WindowListener.vala',
Expand Down
Loading