Skip to content

Commit 301d33d

Browse files
committed
WindowClone: Allocate window icon in allocate virtual
1 parent 903bc3f commit 301d33d

File tree

4 files changed

+28
-97
lines changed

4 files changed

+28
-97
lines changed

lib/App.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public class Gala.App : GLib.Object {
158158
return windows.data;
159159
}
160160

161-
public GLib.SList<pid_t?> get_pids () {
162-
var results = new GLib.SList<pid_t?> ();
161+
public GLib.SList<int?> get_pids () {
162+
var results = new GLib.SList<int?> ();
163163
foreach (unowned var window in windows) {
164164
var pid = window.get_pid ();
165165
if (pid < 1) {

src/Widgets/WindowClone.vala

Lines changed: 24 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ public class Gala.WindowClone : Clutter.Actor {
159159
}
160160

161161
private void reallocate () {
162-
var window_frame_rect = window.get_frame_rect ();
163-
164162
close_button = new Gala.CloseButton (monitor_scale_factor) {
165163
opacity = 0
166164
};
@@ -169,7 +167,6 @@ public class Gala.WindowClone : Clutter.Actor {
169167
window_icon = new WindowIcon (window, WINDOW_ICON_SIZE, (int)Math.round (monitor_scale_factor));
170168
window_icon.opacity = 0;
171169
window_icon.set_pivot_point (0.5f, 0.5f);
172-
set_window_icon_position (window_frame_rect.width, window_frame_rect.height, monitor_scale_factor);
173170

174171
add_child (close_button);
175172
add_child (window_icon);
@@ -276,16 +273,9 @@ public class Gala.WindowClone : Clutter.Actor {
276273

277274
unowned var display = window.get_display ();
278275
var monitor_geom = display.get_monitor_geometry (window.get_monitor ());
279-
var initial_scale = monitor_scale_factor;
280-
var target_scale = display.get_monitor_scale (window.get_monitor ());
281-
var offset_x = monitor_geom.x;
282-
var offset_y = monitor_geom.y;
283-
284-
var initial_width = width;
285-
var initial_height = height;
286276

287-
var target_x = outer_rect.x - offset_x;
288-
var target_y = outer_rect.y - offset_y;
277+
var target_x = outer_rect.x - monitor_geom.x;
278+
var target_y = outer_rect.y - monitor_geom.y;
289279

290280
active = false;
291281
update_hover_widgets (true);
@@ -297,35 +287,8 @@ public class Gala.WindowClone : Clutter.Actor {
297287
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 255, (uint8) 0).start (with_gesture);
298288
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255u, 0u).start (with_gesture, () => {
299289
update_hover_widgets (false);
300-
});
301-
302-
GestureTracker.OnUpdate on_animation_update = (percentage) => {
303-
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage);
304-
var height = GestureTracker.animation_value (initial_height, outer_rect.height, percentage);
305-
var scale = GestureTracker.animation_value (initial_scale, target_scale, percentage);
306-
307-
set_window_icon_position (width, height, scale, false);
308-
};
309-
310-
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
311-
if (cancel_action) {
312-
return;
313-
}
314-
315290
toggle_shadow (false);
316-
317-
window_icon.save_easing_state ();
318-
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
319-
window_icon.set_easing_duration (AnimationsSettings.get_animation_duration (MultitaskingView.ANIMATION_DURATION));
320-
set_window_icon_position (outer_rect.width, outer_rect.height, target_scale);
321-
window_icon.restore_easing_state ();
322-
};
323-
324-
if (gesture_tracker == null || !with_gesture || !AnimationsSettings.get_enable_animations ()) {
325-
on_animation_end (1, false, 0);
326-
} else {
327-
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
328-
}
291+
});
329292
}
330293

331294
/**
@@ -348,10 +311,7 @@ public class Gala.WindowClone : Clutter.Actor {
348311
float intial_x = from_window_position ? outer_rect.x - monitor_geom.x : x;
349312
float intial_y = from_window_position ? outer_rect.y - monitor_geom.y : y;
350313

351-
var scale = display.get_monitor_scale (display.get_monitor_index_for_rect (rect));
352-
353314
update_hover_widgets (true);
354-
set_window_icon_position (initial_width, initial_height, scale);
355315

356316
new GesturePropertyTransition (this, gesture_tracker, "x", intial_x, (float) rect.x).start (with_gesture);
357317
new GesturePropertyTransition (this, gesture_tracker, "y", intial_y, (float) rect.y).start (with_gesture);
@@ -360,44 +320,18 @@ public class Gala.WindowClone : Clutter.Actor {
360320
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 0, (uint8) 255).start (with_gesture);
361321
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0u, 255u).start (with_gesture, () => {
362322
update_hover_widgets (false);
363-
});
364-
365-
GestureTracker.OnUpdate on_animation_update = (percentage) => {
366-
var width = GestureTracker.animation_value (initial_width, rect.width, percentage);
367-
var height = GestureTracker.animation_value (initial_height, rect.height, percentage);
368-
369-
set_window_icon_position (width, height, scale, false);
370-
};
371-
372-
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
373-
if (cancel_action) {
374-
return;
375-
}
376-
377-
var duration = AnimationsSettings.get_animation_duration (MultitaskingView.ANIMATION_DURATION);
378-
379-
window_icon.save_easing_state ();
380-
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
381-
window_icon.set_easing_duration (duration);
382-
set_window_icon_position (rect.width, rect.height, scale);
383-
window_icon.restore_easing_state ();
384-
385323
toggle_shadow (true);
386-
};
387-
388-
if (gesture_tracker == null || !with_gesture || !AnimationsSettings.get_enable_animations ()) {
389-
on_animation_end (1, false, 0);
390-
} else {
391-
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
392-
}
324+
});
393325
}
394326

395327
public override void allocate (Clutter.ActorBox box) {
396328
base.allocate (box);
397329

398330
if (clone == null || (drag_action != null && drag_action.dragging)) {
331+
warning ("RETURN");
399332
return;
400333
}
334+
warning ("ALLOCATE");
401335

402336
var input_rect = window.get_buffer_rect ();
403337
var outer_rect = window.get_frame_rect ();
@@ -448,6 +382,13 @@ public class Gala.WindowClone : Clutter.Actor {
448382

449383
var window_title_alloc = InternalUtils.actor_box_from_rect (window_title_x, window_title_y, window_title_width, window_title_height);
450384
window_title.allocate (window_title_alloc);
385+
386+
var window_icon_size = InternalUtils.scale_to_int (WINDOW_ICON_SIZE, monitor_scale);
387+
var window_icon_x = (box.get_width () - window_icon_size) / 2;
388+
var window_icon_y = box.get_height () - (window_icon_size * 0.75f);
389+
390+
var window_icon_alloc = InternalUtils.actor_box_from_rect (window_icon_x, window_icon_y, window_icon_size, window_icon_size);
391+
window_icon.allocate (window_icon_alloc);
451392
}
452393

453394
#if HAS_MUTTER45
@@ -563,6 +504,9 @@ public class Gala.WindowClone : Clutter.Actor {
563504
* position we just freed is immediately filled by the WindowCloneContainer.
564505
*/
565506
private Clutter.Actor drag_begin (float click_x, float click_y) {
507+
var last_window_icon_x = window_icon.x;
508+
var last_window_icon_y = window_icon.y;
509+
566510
float abs_x, abs_y;
567511
float prev_parent_x, prev_parent_y;
568512

@@ -594,6 +538,9 @@ public class Gala.WindowClone : Clutter.Actor {
594538

595539
set_position (abs_x + prev_parent_x, abs_y + prev_parent_y);
596540

541+
// Set the last position so that it animates from there and not 0, 0
542+
window_icon.set_position (last_window_icon_x, last_window_icon_y);
543+
597544
window_icon.save_easing_state ();
598545
window_icon.set_easing_duration (duration);
599546
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_IN_OUT_CUBIC);
@@ -742,7 +689,7 @@ public class Gala.WindowClone : Clutter.Actor {
742689
*/
743690
private void drag_canceled () {
744691
get_parent ().remove_child (this);
745-
prev_parent.insert_child_at_index (this, prev_index);
692+
prev_parent.add_child (this); // Add above so that it is above while it animates back to its place
746693

747694
var duration = AnimationsSettings.get_animation_duration (MultitaskingView.ANIMATION_DURATION);
748695

@@ -756,28 +703,12 @@ public class Gala.WindowClone : Clutter.Actor {
756703

757704
request_reposition ();
758705

759-
window_icon.save_easing_state ();
760-
window_icon.set_easing_duration (duration);
761-
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
762-
763-
set_window_icon_position (slot.width, slot.height, monitor_scale_factor);
764-
window_icon.restore_easing_state ();
765-
766706
display.set_cursor (Meta.Cursor.DEFAULT);
767-
}
768-
769-
private void set_window_icon_position (float window_width, float window_height, float scale_factor, bool aligned = true) {
770-
var size = InternalUtils.scale_to_int (WINDOW_ICON_SIZE, scale_factor);
771-
var x = (window_width - size) / 2;
772-
var y = window_height - (size * 0.75f);
773707

774-
if (aligned) {
775-
x = (int) Math.round (x);
776-
y = (int) Math.round (y);
777-
}
778-
779-
window_icon.set_size (size, size);
780-
window_icon.set_position (x, y);
708+
Timeout.add (duration, () => {
709+
prev_parent.set_child_at_index (this, prev_index); // Set the correct index so that correct stacking order is kept
710+
return Source.REMOVE;
711+
});
781712
}
782713

783714
private static bool is_close_button_on_left () {

src/WindowTracker.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Gala.WindowTracker : GLib.Object {
5252
return get_app_from_id (id);
5353
}
5454

55-
private static unowned Gala.App? get_app_from_pid (pid_t pid) {
55+
private static unowned Gala.App? get_app_from_pid (int pid) {
5656
var running_apps = Gala.AppSystem.get_default ().get_running_apps ();
5757
foreach (unowned Gala.App app in running_apps) {
5858
var app_pids = app.get_pids ();

vapi/libmutter.vapi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ namespace Meta {
11171117
public Meta.MaximizeFlags get_maximized ();
11181118
public int get_monitor ();
11191119
public unowned string? get_mutter_hints ();
1120-
public pid_t get_pid ();
1120+
public int get_pid ();
11211121
public unowned string get_role ();
11221122
public unowned string? get_sandboxed_app_id ();
11231123
public uint get_stable_sequence ();

0 commit comments

Comments
 (0)