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

Multitasking view: Respect animations key #1656

Merged
merged 10 commits into from Apr 17, 2023
31 changes: 15 additions & 16 deletions src/Widgets/IconGroup.vala
Expand Up @@ -231,12 +231,8 @@ namespace Gala {
* the group.
*/
public void add_window (Meta.Window window, bool no_redraw = false, bool temporary = false) {
var new_window = new WindowIconActor (window);

new_window.save_easing_state ();
new_window.set_easing_duration (0);
var new_window = new WindowIconActor (wm, window);
new_window.set_position (32, 32);
new_window.restore_easing_state ();
new_window.temporary = temporary;

icon_container.add_child (new_window);
Expand All @@ -251,25 +247,28 @@ namespace Gala {
* @param animate Whether to fade the icon out before removing it
*/
public void remove_window (Meta.Window window, bool animate = true) {
foreach (var child in icon_container.get_children ()) {
unowned WindowIconActor w = (WindowIconActor) child;
if (w.window == window) {
foreach (unowned var child in icon_container.get_children ()) {
unowned var icon = (WindowIconActor) child;
if (icon.window == window) {
if (animate) {
w.set_easing_mode (Clutter.AnimationMode.LINEAR);
w.set_easing_duration (200);
w.opacity = 0;
icon.save_easing_state ();
icon.set_easing_mode (Clutter.AnimationMode.LINEAR);
icon.set_easing_duration (wm.enable_animations ? 200 : 0);
icon.opacity = 0;
icon.restore_easing_state ();

var transition = w.get_transition ("opacity");
var transition = icon.get_transition ("opacity");
if (transition != null) {
transition.completed.connect (() => {
w.destroy ();
icon.destroy ();
});
} else {
w.destroy ();
icon.destroy ();
}

} else
w.destroy ();
} else {
icon.destroy ();
}

// don't break here! If people spam hover events and we animate
// removal, we can actually multiple instances of the same window icon
Expand Down
8 changes: 5 additions & 3 deletions src/Widgets/IconGroupContainer.vala
Expand Up @@ -25,6 +25,8 @@ namespace Gala {
public const int SPACING = 48;
public const int GROUP_WIDTH = 64;

public WindowManager wm { get; construct; }

public signal void request_reposition (bool animate);

private float _scale_factor = 1.0f;
Expand All @@ -40,8 +42,8 @@ namespace Gala {
}
}

public IconGroupContainer (float scale) {
Object (scale_factor: scale);
public IconGroupContainer (WindowManager wm, float scale) {
Object (wm: wm, scale_factor: scale);

layout_manager = new Clutter.BoxLayout ();
}
Expand All @@ -60,7 +62,7 @@ namespace Gala {

insert_child_at_index (group, index * 2);

var thumb = new WorkspaceInsertThumb (index, scale_factor);
var thumb = new WorkspaceInsertThumb (wm, index, scale_factor);
thumb.notify["expanded"].connect_after (expanded_changed);
insert_child_at_index (thumb, index * 2);

Expand Down
1 change: 0 additions & 1 deletion src/Widgets/MonitorClone.vala
Expand Up @@ -42,7 +42,6 @@ namespace Gala {
reactive = true;

background = new BackgroundManager (display, monitor, false);
background.set_easing_duration (MultitaskingView.ANIMATION_DURATION);

window_container = new WindowCloneContainer (wm, gesture_tracker);
window_container.window_selected.connect ((w) => { window_selected (w); });
Expand Down
91 changes: 52 additions & 39 deletions src/Widgets/MultitaskingView.vala
Expand Up @@ -72,7 +72,7 @@ namespace Gala {
workspaces = new Clutter.Actor ();
workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);

icon_groups = new IconGroupContainer (display.get_monitor_scale (display.get_primary_monitor ()));
icon_groups = new IconGroupContainer (wm, display.get_monitor_scale (display.get_primary_monitor ()));

dock_clones = new Clutter.Actor ();

Expand Down Expand Up @@ -355,39 +355,54 @@ namespace Gala {
workspaces.restore_easing_state ();

if (!is_nudge_animation) {
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = calculated_duration,
remove_on_complete = true
};
active_transition.set_from_value (active_icon_group.backdrop_opacity);
active_transition.set_to_value (cancel_action ? 1.0f : 0.0f);
active_icon_group.add_transition ("backdrop-opacity", active_transition);

var target_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = calculated_duration,
remove_on_complete = true
};
target_transition.set_from_value (target_icon_group.backdrop_opacity);
target_transition.set_to_value (cancel_action ? 0.0f : 1.0f);
target_icon_group.add_transition ("backdrop-opacity", target_transition);
if (wm.enable_animations) {
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = duration,
remove_on_complete = true
};
active_transition.set_from_value (active_icon_group.backdrop_opacity);
active_transition.set_to_value (cancel_action ? 1.0f : 0.0f);
active_icon_group.add_transition ("backdrop-opacity", active_transition);

var target_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = duration,
remove_on_complete = true
};
target_transition.set_from_value (target_icon_group.backdrop_opacity);
target_transition.set_to_value (cancel_action ? 0.0f : 1.0f);
target_icon_group.add_transition ("backdrop-opacity", target_transition);
} else {
active_icon_group.backdrop_opacity = cancel_action ? 1.0f : 0.0f;
target_icon_group.backdrop_opacity = cancel_action ? 0.0f : 1.0f;
}
}


workspaces.get_transition ("x").completed.connect (() => {
var transition = workspaces.get_transition ("x");
if (transition != null) {
transition.completed.connect (() => {
workspace_gesture_tracker.enabled = true;

if (!is_nudge_animation && !cancel_action) {
manager.get_workspace_by_index (target_workspace_index).activate (display.get_current_time ());
update_positions (false);
}
});
} else {
workspace_gesture_tracker.enabled = true;

if (!is_nudge_animation && !cancel_action) {
manager.get_workspace_by_index (target_workspace_index).activate (display.get_current_time ());
update_positions (false);
} else {
// Reset easing parameters either way.
// This stops the animation from causing touch events to "lag" behind.
workspaces.set_easing_duration (0);
}
});
}
};

workspace_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
if (!wm.enable_animations) {
on_animation_end (1, false, 0);
} else {
workspace_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
}

/**
Expand Down Expand Up @@ -415,13 +430,13 @@ namespace Gala {
}

workspace_clone.save_easing_state ();
workspace_clone.set_easing_duration (animate ? 200 : 0);
workspace_clone.set_easing_duration ((animate && wm.enable_animations) ? 200 : 0);
workspace_clone.x = dest_x;
workspace_clone.restore_easing_state ();
}

workspaces.save_easing_state ();
workspaces.set_easing_duration (animate ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
workspaces.set_easing_duration ((animate && wm.enable_animations) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
workspaces.x = -active_x;
workspaces.restore_easing_state ();

Expand Down Expand Up @@ -629,6 +644,11 @@ namespace Gala {
return;
}

// we don't want to handle cancel animation when animation are off
if (is_cancel_animation && !wm.enable_animations) {
return;
}

animating = true;

opened = !opened;
Expand Down Expand Up @@ -769,9 +789,7 @@ namespace Gala {
var clone = new SafeWindowClone (window, true);
dock_clones.add_child (clone);

GestureTracker.OnBegin on_animation_begin = () => {
clone.set_position (initial_x, initial_y);
};
clone.set_position (initial_x, initial_y);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
Expand All @@ -785,16 +803,15 @@ namespace Gala {

clone.save_easing_state ();
clone.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
clone.set_easing_duration (is_cancel_animation ? 0 : ANIMATION_DURATION);
clone.set_easing_duration ((!is_cancel_animation && wm.enable_animations) ? ANIMATION_DURATION : 0);
clone.y = target_y;
clone.restore_easing_state ();
};

if (!with_gesture) {
on_animation_begin (0);
if (!with_gesture || !wm.enable_animations) {
on_animation_end (1, false, 0);
} else {
multitasking_gesture_tracker.connect_handlers ((owned) on_animation_begin, (owned) on_animation_update, (owned) on_animation_end);
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
}
}
Expand All @@ -805,10 +822,6 @@ namespace Gala {
var initial_y = dock.y;
var target_y = dock.source.y;

GestureTracker.OnBegin on_animation_begin = () => {
dock.set_easing_duration (0);
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
dock.y = y;
Expand All @@ -820,16 +833,16 @@ namespace Gala {
}

dock.save_easing_state ();
dock.set_easing_duration (ANIMATION_DURATION);
dock.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
dock.set_easing_duration (wm.enable_animations ? ANIMATION_DURATION : 0);
dock.y = target_y;
dock.restore_easing_state ();
};

if (!with_gesture) {
if (!with_gesture || !wm.enable_animations) {
on_animation_end (1, false, 0);
} else {
multitasking_gesture_tracker.connect_handlers ((owned) on_animation_begin, (owned) on_animation_update, (owned) on_animation_end);
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
}
}
Expand Down