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 AnimationsSettings #2105

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
25 changes: 25 additions & 0 deletions lib/AnimationsSettings.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

namespace AnimationsSettings {
private GLib.Settings? animations_settings;
private bool enable_animations = true;

/**
* Whether animations should be displayed.
*/
public bool get_enable_animations () {
if (animations_settings == null) {
animations_settings = new GLib.Settings ("io.elementary.desktop.wm.animations");
animations_settings.changed["enable-animations"].connect (() => {
enable_animations = animations_settings.get_boolean ("enable-animations");
});

enable_animations = animations_settings.get_boolean ("enable-animations");
}

return enable_animations;
}
}
5 changes: 0 additions & 5 deletions lib/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ namespace Gala {
*/
public abstract Gala.ActivatableComponent workspace_view { get; protected set; }

/**
* Whether animations should be displayed.
*/
public abstract bool enable_animations { get; protected set; }

/**
* Enters the modal mode, which means that all events are directed to the stage instead
* of the windows. This is the only way to receive keyboard events besides shortcut listeners.
Expand Down
1 change: 1 addition & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
gala_lib_sources = files(
'ActivatableComponent.vala',
'AnimationsSettings.vala',
'App.vala',
'AppCache.vala',
'AppSystem.vala',
Expand Down
14 changes: 7 additions & 7 deletions plugins/pip/PopupWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
opacity = 0;

save_easing_state ();
set_easing_duration (wm.enable_animations ? 200 : 0);
set_easing_duration (AnimationsSettings.get_enable_animations () ? 200 : 0);
opacity = 255;
restore_easing_state ();
}

public override void hide () {
opacity = 255;

var duration = wm.enable_animations ? 200 : 0;
var duration = AnimationsSettings.get_enable_animations () ? 200 : 0;
save_easing_state ();
set_easing_duration (duration);
opacity = 0;
Expand All @@ -173,7 +173,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
#else
public override bool enter_event (Clutter.CrossingEvent event) {
#endif
var duration = wm.enable_animations ? 300 : 0;
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;

close_button.save_easing_state ();
close_button.set_easing_duration (duration);
Expand All @@ -193,7 +193,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
#else
public override bool leave_event (Clutter.CrossingEvent event) {
#endif
var duration = wm.enable_animations ? 300 : 0;
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;

close_button.save_easing_state ();
close_button.set_easing_duration (duration);
Expand Down Expand Up @@ -315,7 +315,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
}

private void on_close_click_clicked () {
var duration = wm.enable_animations ? FADE_OUT_TIMEOUT : 0;
var duration = AnimationsSettings.get_enable_animations () ? FADE_OUT_TIMEOUT : 0;

save_easing_state ();
set_easing_duration (duration);
Expand Down Expand Up @@ -449,7 +449,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
var screen_limit_start_y = SCREEN_MARGIN + monitor_y;
var screen_limit_end_y = monitor_height + monitor_y - SCREEN_MARGIN - height;

var duration = wm.enable_animations ? 300 : 0;
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);
Expand All @@ -462,7 +462,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
private bool place_window_off_screen () {
off_screen = false;

var duration = wm.enable_animations ? 300 : 0;
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);
Expand Down
2 changes: 1 addition & 1 deletion src/Background/BackgroundManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
return;
}

if (animate && wm.enable_animations) {
if (animate && AnimationsSettings.get_enable_animations ()) {
var transition = new Clutter.PropertyTransition ("opacity");
transition.set_from_value (255);
transition.set_to_value (0);
Expand Down
18 changes: 9 additions & 9 deletions src/NotificationStack.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Gala.NotificationStack : Object {
update_stack_allocation ();
}

public void show_notification (Meta.WindowActor notification, bool animate)
public void show_notification (Meta.WindowActor notification)
requires (notification != null && !notification.is_destroyed () && !notifications.contains (notification)) {

notification.set_pivot_point (0.5f, 0.5f);
Expand All @@ -62,7 +62,7 @@ public class Gala.NotificationStack : Object {
var window_rect = window.get_frame_rect ();
window.stick ();

if (animate) {
if (AnimationsSettings.get_enable_animations ()) {
// Don't flicker at the beginning of the animation
notification.opacity = 0;
notification.rotation_angle_x = 90;
Expand Down Expand Up @@ -96,7 +96,7 @@ public class Gala.NotificationStack : Object {
* by shifting all current notifications by height
* and then add it to the notifications list.
*/
update_positions (animate, scale, window_rect.height);
update_positions (scale, window_rect.height);

int notification_x_pos = area.x + area.width - window_rect.width;
if (Clutter.get_default_text_direction () == Clutter.TextDirection.RTL) {
Expand All @@ -117,7 +117,7 @@ public class Gala.NotificationStack : Object {
stack_y = area.y;
}

private void update_positions (bool animate, float scale, float add_y = 0.0f) {
private void update_positions (float scale, float add_y = 0.0f) {
var y = stack_y + TOP_OFFSET + add_y + InternalUtils.scale_to_int (ADDITIONAL_MARGIN, scale);
var i = notifications.size;
var delay_step = i > 0 ? 150 / i : 0;
Expand All @@ -131,7 +131,7 @@ public class Gala.NotificationStack : Object {
continue;
}

if (animate) {
if (AnimationsSettings.get_enable_animations ()) {
actor.save_easing_state ();
actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);
actor.set_easing_duration (200);
Expand All @@ -140,7 +140,7 @@ public class Gala.NotificationStack : Object {

move_window (actor, -1, (int)y);

if (animate) {
if (AnimationsSettings.get_enable_animations ()) {
actor.restore_easing_state ();
}

Expand All @@ -160,8 +160,8 @@ public class Gala.NotificationStack : Object {
}
}

public void destroy_notification (Meta.WindowActor notification, bool animate) {
if (animate) {
public void destroy_notification (Meta.WindowActor notification) {
if (AnimationsSettings.get_enable_animations ()) {
notification.save_easing_state ();
notification.set_easing_duration (100);
notification.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
Expand All @@ -178,7 +178,7 @@ public class Gala.NotificationStack : Object {
var scale = display.get_monitor_scale (primary);

notifications.remove (notification);
update_positions (animate, scale);
update_positions (scale);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ShellClients/PanelClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class Gala.PanelClone : Object {

private int get_animation_duration () {
var fullscreen = wm.get_display ().get_monitor_in_fullscreen (panel.window.get_monitor ());
var should_animate = wm.enable_animations && !wm.workspace_view.is_opened () && !fullscreen;
var should_animate = AnimationsSettings.get_enable_animations () && !wm.workspace_view.is_opened () && !fullscreen;
return should_animate ? ANIMATION_DURATION : 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/IconGroup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace Gala {
if (animate) {
icon.save_easing_state ();
icon.set_easing_mode (Clutter.AnimationMode.LINEAR);
icon.set_easing_duration (wm.enable_animations ? 200 : 0);
icon.set_easing_duration (AnimationsSettings.get_enable_animations () ? 200 : 0);
icon.opacity = 0;
icon.restore_easing_state ();

Expand Down
20 changes: 10 additions & 10 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ namespace Gala {
}

public void play_nudge_animation (Meta.MotionDirection direction) {
if (!wm.enable_animations) {
if (!AnimationsSettings.get_enable_animations ()) {
return;
}

Expand Down Expand Up @@ -413,7 +413,7 @@ namespace Gala {
workspaces.restore_easing_state ();

if (!is_nudge_animation) {
if (wm.enable_animations) {
if (AnimationsSettings.get_enable_animations ()) {
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = duration,
remove_on_complete = true
Expand All @@ -440,7 +440,7 @@ namespace Gala {
}
};

if (!wm.enable_animations) {
if (!AnimationsSettings.get_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 @@ -476,14 +476,14 @@ namespace Gala {
}

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

workspaces.save_easing_state ();
workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
workspaces.set_easing_duration ((animate && wm.enable_animations) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
workspaces.set_easing_duration ((animate && AnimationsSettings.get_enable_animations ()) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
workspaces.x = -active_x;
workspaces.restore_easing_state ();

Expand Down Expand Up @@ -668,7 +668,7 @@ namespace Gala {
}

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

Expand Down Expand Up @@ -840,12 +840,12 @@ namespace Gala {

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

if (!with_gesture || !wm.enable_animations) {
if (!with_gesture || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, false, 0);
} else {
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
Expand All @@ -871,12 +871,12 @@ namespace Gala {

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

if (!with_gesture || !wm.enable_animations) {
if (!with_gesture || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, false, 0);
} else {
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/ScreenShield.vala
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ namespace Gala {
grab_key_focus ();
modal_proxy = wm.push_modal (this);

if (wm.enable_animations && animate) {
if (AnimationsSettings.get_enable_animations () && animate) {
animate_and_lock (animation_time);
} else {
_set_active (true);
Expand Down
22 changes: 11 additions & 11 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Gala.WindowClone : Clutter.Actor {
public bool active {
set {
active_shape.save_easing_state ();
active_shape.set_easing_duration (wm.enable_animations ? FADE_ANIMATION_DURATION : 0);
active_shape.set_easing_duration (AnimationsSettings.get_enable_animations () ? FADE_ANIMATION_DURATION : 0);
active_shape.opacity = value ? 255 : 0;
active_shape.restore_easing_state ();
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public class Gala.WindowClone : Clutter.Actor {
return;
}

var duration = (animate && wm.enable_animations) ? MultitaskingView.ANIMATION_DURATION : 0;
var duration = (animate && AnimationsSettings.get_enable_animations ()) ? MultitaskingView.ANIMATION_DURATION : 0;

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
Expand Down Expand Up @@ -351,7 +351,7 @@ public class Gala.WindowClone : Clutter.Actor {
}
};

if (!animate || gesture_tracker == null || !with_gesture || !wm.enable_animations) {
if (!animate || 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 Down Expand Up @@ -400,7 +400,7 @@ public class Gala.WindowClone : Clutter.Actor {
return;
}

var duration = wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0;
var duration = AnimationsSettings.get_enable_animations () ? MultitaskingView.ANIMATION_DURATION : 0;

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
Expand Down Expand Up @@ -432,7 +432,7 @@ public class Gala.WindowClone : Clutter.Actor {
}
};

if (gesture_tracker == null || !with_gesture || !wm.enable_animations) {
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 Down Expand Up @@ -485,7 +485,7 @@ public class Gala.WindowClone : Clutter.Actor {
return Clutter.EVENT_PROPAGATE;
}

var duration = wm.enable_animations ? FADE_ANIMATION_DURATION : 0;
var duration = AnimationsSettings.get_enable_animations () ? FADE_ANIMATION_DURATION : 0;

close_button.save_easing_state ();
close_button.set_easing_mode (Clutter.AnimationMode.LINEAR);
Expand All @@ -507,7 +507,7 @@ public class Gala.WindowClone : Clutter.Actor {
#else
public override bool leave_event (Clutter.CrossingEvent event) {
#endif
var duration = wm.enable_animations ? FADE_ANIMATION_DURATION : 0;
var duration = AnimationsSettings.get_enable_animations () ? FADE_ANIMATION_DURATION : 0;

close_button.save_easing_state ();
close_button.set_easing_mode (Clutter.AnimationMode.LINEAR);
Expand Down Expand Up @@ -551,7 +551,7 @@ public class Gala.WindowClone : Clutter.Actor {
remove_transition ("shadow-opacity");
}

if (wm.enable_animations) {
if (AnimationsSettings.get_enable_animations ()) {
var shadow_transition = new Clutter.PropertyTransition ("shadow-opacity") {
duration = MultitaskingView.ANIMATION_DURATION,
remove_on_complete = true,
Expand Down Expand Up @@ -643,7 +643,7 @@ public class Gala.WindowClone : Clutter.Actor {
active_shape.hide ();

var scale = window_icon.width / clone.width;
var duration = wm.enable_animations ? FADE_ANIMATION_DURATION : 0;
var duration = AnimationsSettings.get_enable_animations () ? FADE_ANIMATION_DURATION : 0;

clone.get_transformed_position (out abs_x, out abs_y);
clone.save_easing_state ();
Expand Down Expand Up @@ -702,7 +702,7 @@ public class Gala.WindowClone : Clutter.Actor {
var scale = hovered ? 0.4 : 1.0;
var opacity = hovered ? 0 : 255;
var duration = hovered && insert_thumb != null ? insert_thumb.delay : 100;
duration = wm.enable_animations ? duration : 0;
duration = AnimationsSettings.get_enable_animations () ? duration : 0;

window_icon.save_easing_state ();

Expand Down Expand Up @@ -810,7 +810,7 @@ public class Gala.WindowClone : Clutter.Actor {
get_parent ().remove_child (this);
prev_parent.insert_child_at_index (this, prev_index);

var duration = wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0;
var duration = AnimationsSettings.get_enable_animations () ? MultitaskingView.ANIMATION_DURATION : 0;

clone.set_pivot_point (0.0f, 0.0f);
clone.save_easing_state ();
Expand Down
Loading