Skip to content

Commit f53af32

Browse files
committed
Handle waiting for window actors in WindowCloneContainer
1 parent 26a5c81 commit f53af32

File tree

4 files changed

+41
-61
lines changed

4 files changed

+41
-61
lines changed

src/Widgets/MultitaskingView/MonitorClone.vala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ public class Gala.MonitorClone : ActorTarget {
8484
}
8585

8686
private void window_left (int window_monitor, Meta.Window window) {
87-
if (window_monitor != monitor)
87+
if (window_monitor != monitor) {
8888
return;
89+
}
8990

9091
window_container.remove_window (window);
9192
}
9293

9394
private void window_entered (int window_monitor, Meta.Window window) {
94-
if (window_monitor != monitor || window.window_type != Meta.WindowType.NORMAL)
95+
if (window_monitor != monitor) {
9596
return;
97+
}
9698

9799
window_container.add_window (window);
98100
}

src/Widgets/MultitaskingView/WindowClone.vala

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
6767
}
6868

6969
private DragDropAction? drag_action = null;
70-
private Clutter.Clone? clone = null;
7170
private ShadowEffect? shadow_effect = null;
7271

7372
private Clutter.Actor prev_parent = null;
7473
private int prev_index = -1;
7574
private ulong check_confirm_dialog_cb = 0;
7675
private bool in_slot_animation = false;
7776

78-
private Clutter.Actor clone_container;
77+
private Clutter.Clone clone;
7978
private Gala.CloseButton close_button;
8079
private ActiveShape active_shape;
8180
private Clutter.Actor window_icon;
8281
private Tooltip window_title;
8382

8483
private GestureController gesture_controller;
8584

86-
public WindowClone (WindowManager wm, Meta.Window window, float monitor_scale, bool overview_mode = false) {
85+
public WindowClone (WindowManager wm, Meta.Window window, float monitor_scale, bool overview_mode = false)
86+
requires (window.get_compositor_private () != null) {
8787
Object (
8888
wm: wm,
8989
window: window,
@@ -126,23 +126,22 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
126126
add_action (drag_action);
127127
}
128128

129-
active_shape = new ActiveShape ();
130-
active_shape.opacity = 0;
131-
132-
clone_container = new Clutter.Actor () {
133-
pivot_point = { 0.5f, 0.5f }
129+
active_shape = new ActiveShape () {
130+
opacity = 0
134131
};
135132

133+
clone = new Clutter.Clone ((Meta.WindowActor) window.get_compositor_private ());
134+
136135
window_title = new Tooltip ();
137136

138137
add_child (active_shape);
139-
add_child (clone_container);
138+
add_child (clone);
140139
add_child (window_title);
141140

142141
notify["monitor-scale"].connect (reallocate);
143142
reallocate ();
144143

145-
InternalUtils.wait_for_window_actor (window, load_clone);
144+
check_shadow_requirements ();
146145

147146
window.notify["title"].connect (() => window_title.set_text (window.get_title () ?? ""));
148147
window_title.set_text (window.get_title () ?? "");
@@ -178,29 +177,7 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
178177
set_child_below_sibling (window_icon, window_title);
179178
}
180179

181-
/**
182-
* Waits for the texture of a new Meta.WindowActor to be available
183-
* and makes a close of it. If it was already was assigned a slot
184-
* at this point it will animate to it. Otherwise it will just place
185-
* itself at the location of the original window. Also adds the shadow
186-
* effect and makes sure the shadow is updated on size changes.
187-
*/
188-
private void load_clone (Meta.WindowActor actor) {
189-
if (overview_mode) {
190-
actor.hide ();
191-
}
192-
193-
clone = new Clutter.Clone (actor);
194-
clone_container.add_child (clone);
195-
196-
check_shadow_requirements ();
197-
}
198-
199180
private void check_shadow_requirements () {
200-
if (clone == null) {
201-
return;
202-
}
203-
204181
if (window.fullscreen || window.maximized_horizontally && window.maximized_vertically) {
205182
if (shadow_effect == null) {
206183
shadow_effect = new ShadowEffect ("window", monitor_scale);
@@ -279,8 +256,8 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
279256
var target_translation_y = (float) (-CLOSE_TRANSLATION * monitor_scale * progress);
280257
var target_opacity = (uint) (255 * (1 - progress));
281258

282-
clone_container.translation_y = target_translation_y;
283-
clone_container.opacity = target_opacity;
259+
clone.translation_y = target_translation_y;
260+
clone.opacity = target_opacity;
284261

285262
window_icon.translation_y = target_translation_y;
286263
window_icon.opacity = target_opacity;
@@ -303,29 +280,24 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
303280
public override void allocate (Clutter.ActorBox box) {
304281
base.allocate (box);
305282

306-
var input_rect = window.get_buffer_rect ();
307-
var outer_rect = window.get_frame_rect ();
308-
var clone_scale_factor = width / outer_rect.width;
309-
310-
// Compensate for invisible borders of the texture
311-
float clone_x = (input_rect.x - outer_rect.x) * clone_scale_factor;
312-
float clone_y = (input_rect.y - outer_rect.y) * clone_scale_factor;
313-
314-
var clone_container_alloc = InternalUtils.actor_box_from_rect (clone_x, clone_y, input_rect.width * clone_scale_factor, input_rect.height * clone_scale_factor);
315-
clone_container.allocate (clone_container_alloc);
316-
317-
if (clone == null || (drag_action != null && drag_action.dragging)) {
283+
if (drag_action != null && drag_action.dragging) {
318284
return;
319285
}
320286

321-
unowned var display = wm.get_display ();
287+
var input_rect = window.get_buffer_rect ();
288+
var outer_rect = window.get_frame_rect ();
289+
var clone_scale_factor = width / outer_rect.width;
322290

323291
clone.set_scale (clone_scale_factor, clone_scale_factor);
324292

325293
float clone_width, clone_height;
326294
clone.get_preferred_size (null, null, out clone_width, out clone_height);
327295

328-
var clone_alloc = InternalUtils.actor_box_from_rect (0, 0, clone_width, clone_height);
296+
// Compensate for invisible borders of the texture
297+
float clone_x = (input_rect.x - outer_rect.x) * clone_scale_factor;
298+
float clone_y = (input_rect.y - outer_rect.y) * clone_scale_factor;
299+
300+
var clone_alloc = InternalUtils.actor_box_from_rect (clone_x, clone_y, clone_width, clone_height);
329301
clone.allocate (clone_alloc);
330302

331303
Clutter.ActorBox shape_alloc = {
@@ -355,6 +327,7 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
355327
var window_icon_alloc = InternalUtils.actor_box_from_rect (window_icon_x, window_icon_y, window_icon_width, window_icon_height);
356328
window_icon.allocate (window_icon_alloc);
357329

330+
unowned var display = wm.get_display ();
358331
var rect = get_transformed_extents ();
359332
var monitor_index = display.get_monitor_index_for_rect (Mtk.Rectangle.from_graphene_rect (rect, ROUND));
360333
var monitor_scale = display.get_monitor_scale (monitor_index);
@@ -429,9 +402,7 @@ public class Gala.WindowClone : ActorTarget, RootTarget {
429402
drag_action.cancel ();
430403
}
431404

432-
if (clone != null) {
433-
clone.destroy ();
434-
}
405+
clone.destroy ();
435406

436407
if (check_confirm_dialog_cb != 0) {
437408
SignalHandler.disconnect (window.get_display (), check_confirm_dialog_cb);

src/Widgets/MultitaskingView/WindowCloneContainer.vala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,23 @@ public class Gala.WindowCloneContainer : ActorTarget {
3939
* @param window The window for which to create the WindowClone for
4040
*/
4141
public void add_window (Meta.Window window) {
42+
InternalUtils.wait_for_window_actor_visible (window, _add_child);
43+
}
44+
45+
private void _add_child (Meta.WindowActor window_actor) {
46+
unowned var window = window_actor.meta_window;
47+
48+
if (window.window_type != NORMAL) {
49+
return;
50+
}
51+
4252
var windows = new List<Meta.Window> ();
4353
windows.append (window);
4454
foreach (unowned var clone in (GLib.List<weak WindowClone>) get_children ()) {
55+
if (clone.window == window) {
56+
return;
57+
}
58+
4559
windows.append (clone.window);
4660
}
4761

src/Widgets/MultitaskingView/WorkspaceClone.vala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,13 @@ public class Gala.WorkspaceClone : ActorTarget {
202202
* Add a window to the WindowCloneContainer if it belongs to this workspace and this monitor.
203203
*/
204204
private void add_window (Meta.Window window) {
205-
if (window.window_type != NORMAL ||
206-
window.get_workspace () != workspace ||
205+
if (window.get_workspace () != workspace ||
207206
StaticWindowContainer.get_instance (workspace.get_display ()).is_static (window) ||
208207
!window.is_on_primary_monitor ()
209208
) {
210209
return;
211210
}
212211

213-
foreach (var child in (GLib.List<weak WindowClone>) window_container.get_children ()) {
214-
if (child.window == window) {
215-
return;
216-
}
217-
}
218-
219212
window_container.add_window (window);
220213
}
221214

0 commit comments

Comments
 (0)