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

WindowClone: Allocate window icon in allocate virtual #2158

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Changes from 3 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
115 changes: 22 additions & 93 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ public class Gala.WindowClone : Clutter.Actor {
}

private void reallocate () {
var window_frame_rect = window.get_frame_rect ();

close_button = new Gala.CloseButton (monitor_scale_factor) {
opacity = 0
};
Expand All @@ -169,7 +167,6 @@ public class Gala.WindowClone : Clutter.Actor {
window_icon = new WindowIcon (window, WINDOW_ICON_SIZE, (int)Math.round (monitor_scale_factor));
window_icon.opacity = 0;
window_icon.set_pivot_point (0.5f, 0.5f);
set_window_icon_position (window_frame_rect.width, window_frame_rect.height, monitor_scale_factor);

add_child (close_button);
add_child (window_icon);
Expand Down Expand Up @@ -276,16 +273,9 @@ public class Gala.WindowClone : Clutter.Actor {

unowned var display = window.get_display ();
var monitor_geom = display.get_monitor_geometry (window.get_monitor ());
var initial_scale = monitor_scale_factor;
var target_scale = display.get_monitor_scale (window.get_monitor ());
var offset_x = monitor_geom.x;
var offset_y = monitor_geom.y;

var initial_width = width;
var initial_height = height;

var target_x = outer_rect.x - offset_x;
var target_y = outer_rect.y - offset_y;
var target_x = outer_rect.x - monitor_geom.x;
var target_y = outer_rect.y - monitor_geom.y;

active = false;
update_hover_widgets (true);
Expand All @@ -297,35 +287,8 @@ public class Gala.WindowClone : Clutter.Actor {
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 255, (uint8) 0).start (with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255u, 0u).start (with_gesture, () => {
update_hover_widgets (false);
});

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, outer_rect.height, percentage);
var scale = GestureTracker.animation_value (initial_scale, target_scale, percentage);

set_window_icon_position (width, height, scale, false);
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
if (cancel_action) {
return;
}

toggle_shadow (false);

window_icon.save_easing_state ();
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
window_icon.set_easing_duration (AnimationsSettings.get_animation_duration (MultitaskingView.ANIMATION_DURATION));
set_window_icon_position (outer_rect.width, outer_rect.height, target_scale);
window_icon.restore_easing_state ();
};

if (gesture_tracker == null || !with_gesture || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, false, 0);
} else {
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
});
}

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

var scale = display.get_monitor_scale (display.get_monitor_index_for_rect (rect));

update_hover_widgets (true);
set_window_icon_position (initial_width, initial_height, scale);

new GesturePropertyTransition (this, gesture_tracker, "x", intial_x, (float) rect.x).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "y", intial_y, (float) rect.y).start (with_gesture);
Expand All @@ -360,36 +320,8 @@ public class Gala.WindowClone : Clutter.Actor {
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 0, (uint8) 255).start (with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0u, 255u).start (with_gesture, () => {
update_hover_widgets (false);
});

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var width = GestureTracker.animation_value (initial_width, rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, rect.height, percentage);

set_window_icon_position (width, height, scale, false);
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
if (cancel_action) {
return;
}

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

window_icon.save_easing_state ();
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
window_icon.set_easing_duration (duration);
set_window_icon_position (rect.width, rect.height, scale);
window_icon.restore_easing_state ();

toggle_shadow (true);
};

if (gesture_tracker == null || !with_gesture || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, false, 0);
} else {
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
});
}

public override void allocate (Clutter.ActorBox box) {
Expand Down Expand Up @@ -448,6 +380,13 @@ public class Gala.WindowClone : Clutter.Actor {

var window_title_alloc = InternalUtils.actor_box_from_rect (window_title_x, window_title_y, window_title_width, window_title_height);
window_title.allocate (window_title_alloc);

var window_icon_size = InternalUtils.scale_to_int (WINDOW_ICON_SIZE, monitor_scale);
var window_icon_x = (box.get_width () - window_icon_size) / 2;
var window_icon_y = box.get_height () - (window_icon_size * 0.75f);

var window_icon_alloc = InternalUtils.actor_box_from_rect (window_icon_x, window_icon_y, window_icon_size, window_icon_size);
window_icon.allocate (window_icon_alloc);
leolost2605 marked this conversation as resolved.
Show resolved Hide resolved
}

#if HAS_MUTTER45
Expand Down Expand Up @@ -563,6 +502,9 @@ public class Gala.WindowClone : Clutter.Actor {
* position we just freed is immediately filled by the WindowCloneContainer.
*/
private Clutter.Actor drag_begin (float click_x, float click_y) {
var last_window_icon_x = window_icon.x;
var last_window_icon_y = window_icon.y;

float abs_x, abs_y;
float prev_parent_x, prev_parent_y;

Expand Down Expand Up @@ -594,6 +536,9 @@ public class Gala.WindowClone : Clutter.Actor {

set_position (abs_x + prev_parent_x, abs_y + prev_parent_y);

// Set the last position so that it animates from there and not 0, 0
window_icon.set_position (last_window_icon_x, last_window_icon_y);

window_icon.save_easing_state ();
window_icon.set_easing_duration (duration);
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_IN_OUT_CUBIC);
Expand Down Expand Up @@ -742,7 +687,7 @@ public class Gala.WindowClone : Clutter.Actor {
*/
private void drag_canceled () {
get_parent ().remove_child (this);
prev_parent.insert_child_at_index (this, prev_index);
prev_parent.add_child (this); // Add above so that it is above while it animates back to its place

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

Expand All @@ -756,28 +701,12 @@ public class Gala.WindowClone : Clutter.Actor {

request_reposition ();

window_icon.save_easing_state ();
window_icon.set_easing_duration (duration);
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);

set_window_icon_position (slot.width, slot.height, monitor_scale_factor);
window_icon.restore_easing_state ();

display.set_cursor (Meta.Cursor.DEFAULT);
}

private void set_window_icon_position (float window_width, float window_height, float scale_factor, bool aligned = true) {
var size = InternalUtils.scale_to_int (WINDOW_ICON_SIZE, scale_factor);
var x = (window_width - size) / 2;
var y = window_height - (size * 0.75f);

if (aligned) {
x = (int) Math.round (x);
y = (int) Math.round (y);
}

window_icon.set_size (size, size);
window_icon.set_position (x, y);
Timeout.add (duration, () => {
prev_parent.set_child_at_index (this, prev_index); // Set the correct index so that correct stacking order is kept
return Source.REMOVE;
});
leolost2605 marked this conversation as resolved.
Show resolved Hide resolved
}

private static bool is_close_button_on_left () {
Expand Down
Loading