Skip to content

Commit b0a5f8a

Browse files
authored
Introduce AnimationsSettings (#2105)
1 parent 897dd84 commit b0a5f8a

17 files changed

+106
-99
lines changed

lib/AnimationsSettings.vala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
namespace AnimationsSettings {
7+
private GLib.Settings? animations_settings;
8+
private bool enable_animations = true;
9+
10+
/**
11+
* Whether animations should be displayed.
12+
*/
13+
public bool get_enable_animations () {
14+
if (animations_settings == null) {
15+
animations_settings = new GLib.Settings ("io.elementary.desktop.wm.animations");
16+
animations_settings.changed["enable-animations"].connect (() => {
17+
enable_animations = animations_settings.get_boolean ("enable-animations");
18+
});
19+
20+
enable_animations = animations_settings.get_boolean ("enable-animations");
21+
}
22+
23+
return enable_animations;
24+
}
25+
}

lib/WindowManager.vala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,6 @@ namespace Gala {
123123
*/
124124
public abstract Gala.ActivatableComponent workspace_view { get; protected set; }
125125

126-
/**
127-
* Whether animations should be displayed.
128-
*/
129-
public abstract bool enable_animations { get; protected set; }
130-
131126
/**
132127
* Enters the modal mode, which means that all events are directed to the stage instead
133128
* of the windows. This is the only way to receive keyboard events besides shortcut listeners.

lib/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gala_lib_sources = files(
22
'ActivatableComponent.vala',
3+
'AnimationsSettings.vala',
34
'App.vala',
45
'AppCache.vala',
56
'AppSystem.vala',

plugins/pip/PopupWindow.vala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
143143
opacity = 0;
144144

145145
save_easing_state ();
146-
set_easing_duration (wm.enable_animations ? 200 : 0);
146+
set_easing_duration (AnimationsSettings.get_enable_animations () ? 200 : 0);
147147
opacity = 255;
148148
restore_easing_state ();
149149
}
150150

151151
public override void hide () {
152152
opacity = 255;
153153

154-
var duration = wm.enable_animations ? 200 : 0;
154+
var duration = AnimationsSettings.get_enable_animations () ? 200 : 0;
155155
save_easing_state ();
156156
set_easing_duration (duration);
157157
opacity = 0;
@@ -173,7 +173,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
173173
#else
174174
public override bool enter_event (Clutter.CrossingEvent event) {
175175
#endif
176-
var duration = wm.enable_animations ? 300 : 0;
176+
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;
177177

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

198198
close_button.save_easing_state ();
199199
close_button.set_easing_duration (duration);
@@ -315,7 +315,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
315315
}
316316

317317
private void on_close_click_clicked () {
318-
var duration = wm.enable_animations ? FADE_OUT_TIMEOUT : 0;
318+
var duration = AnimationsSettings.get_enable_animations () ? FADE_OUT_TIMEOUT : 0;
319319

320320
save_easing_state ();
321321
set_easing_duration (duration);
@@ -449,7 +449,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor {
449449
var screen_limit_start_y = SCREEN_MARGIN + monitor_y;
450450
var screen_limit_end_y = monitor_height + monitor_y - SCREEN_MARGIN - height;
451451

452-
var duration = wm.enable_animations ? 300 : 0;
452+
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;
453453

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

465-
var duration = wm.enable_animations ? 300 : 0;
465+
var duration = AnimationsSettings.get_enable_animations () ? 300 : 0;
466466

467467
save_easing_state ();
468468
set_easing_mode (Clutter.AnimationMode.EASE_OUT_BACK);

src/Background/BackgroundManager.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Gala.BackgroundManager : Meta.BackgroundGroup, Gala.BackgroundManag
6161
return;
6262
}
6363

64-
if (animate && wm.enable_animations) {
64+
if (animate && AnimationsSettings.get_enable_animations ()) {
6565
var transition = new Clutter.PropertyTransition ("opacity");
6666
transition.set_from_value (255);
6767
transition.set_to_value (0);

src/NotificationStack.vala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Gala.NotificationStack : Object {
4848
update_stack_allocation ();
4949
}
5050

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

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

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

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

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

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

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

143-
if (animate) {
143+
if (AnimationsSettings.get_enable_animations ()) {
144144
actor.restore_easing_state ();
145145
}
146146

@@ -160,8 +160,8 @@ public class Gala.NotificationStack : Object {
160160
}
161161
}
162162

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

180180
notifications.remove (notification);
181-
update_positions (animate, scale);
181+
update_positions (scale);
182182
}
183183

184184
/**

src/ShellClients/PanelClone.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class Gala.PanelClone : Object {
116116

117117
private int get_animation_duration () {
118118
var fullscreen = wm.get_display ().get_monitor_in_fullscreen (panel.window.get_monitor ());
119-
var should_animate = wm.enable_animations && !wm.workspace_view.is_opened () && !fullscreen;
119+
var should_animate = AnimationsSettings.get_enable_animations () && !wm.workspace_view.is_opened () && !fullscreen;
120120
return should_animate ? ANIMATION_DURATION : 0;
121121
}
122122

src/Widgets/IconGroup.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ namespace Gala {
165165
if (animate) {
166166
icon.save_easing_state ();
167167
icon.set_easing_mode (Clutter.AnimationMode.LINEAR);
168-
icon.set_easing_duration (wm.enable_animations ? 200 : 0);
168+
icon.set_easing_duration (AnimationsSettings.get_enable_animations () ? 200 : 0);
169169
icon.opacity = 0;
170170
icon.restore_easing_state ();
171171

src/Widgets/MultitaskingView.vala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ namespace Gala {
263263
}
264264

265265
public void play_nudge_animation (Meta.MotionDirection direction) {
266-
if (!wm.enable_animations) {
266+
if (!AnimationsSettings.get_enable_animations ()) {
267267
return;
268268
}
269269

@@ -413,7 +413,7 @@ namespace Gala {
413413
workspaces.restore_easing_state ();
414414

415415
if (!is_nudge_animation) {
416-
if (wm.enable_animations) {
416+
if (AnimationsSettings.get_enable_animations ()) {
417417
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
418418
duration = duration,
419419
remove_on_complete = true
@@ -440,7 +440,7 @@ namespace Gala {
440440
}
441441
};
442442

443-
if (!wm.enable_animations) {
443+
if (!AnimationsSettings.get_enable_animations ()) {
444444
on_animation_end (1, false, 0);
445445
} else {
446446
workspace_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
@@ -476,14 +476,14 @@ namespace Gala {
476476
}
477477

478478
workspace_clone.save_easing_state ();
479-
workspace_clone.set_easing_duration ((animate && wm.enable_animations) ? 200 : 0);
479+
workspace_clone.set_easing_duration ((animate && AnimationsSettings.get_enable_animations ()) ? 200 : 0);
480480
workspace_clone.x = dest_x;
481481
workspace_clone.restore_easing_state ();
482482
}
483483

484484
workspaces.save_easing_state ();
485485
workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
486-
workspaces.set_easing_duration ((animate && wm.enable_animations) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
486+
workspaces.set_easing_duration ((animate && AnimationsSettings.get_enable_animations ()) ? AnimationDuration.WORKSPACE_SWITCH_MIN : 0);
487487
workspaces.x = -active_x;
488488
workspaces.restore_easing_state ();
489489

@@ -668,7 +668,7 @@ namespace Gala {
668668
}
669669

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

@@ -840,12 +840,12 @@ namespace Gala {
840840

841841
clone.save_easing_state ();
842842
clone.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
843-
clone.set_easing_duration ((!is_cancel_animation && wm.enable_animations) ? ANIMATION_DURATION : 0);
843+
clone.set_easing_duration ((!is_cancel_animation && AnimationsSettings.get_enable_animations ()) ? ANIMATION_DURATION : 0);
844844
clone.y = target_y;
845845
clone.restore_easing_state ();
846846
};
847847

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

872872
dock.save_easing_state ();
873873
dock.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
874-
dock.set_easing_duration (wm.enable_animations ? ANIMATION_DURATION : 0);
874+
dock.set_easing_duration (AnimationsSettings.get_enable_animations () ? ANIMATION_DURATION : 0);
875875
dock.y = target_y;
876876
dock.restore_easing_state ();
877877
};
878878

879-
if (!with_gesture || !wm.enable_animations) {
879+
if (!with_gesture || !AnimationsSettings.get_enable_animations ()) {
880880
on_animation_end (1, false, 0);
881881
} else {
882882
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);

src/Widgets/ScreenShield.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ namespace Gala {
336336
grab_key_focus ();
337337
modal_proxy = wm.push_modal (this);
338338

339-
if (wm.enable_animations && animate) {
339+
if (AnimationsSettings.get_enable_animations () && animate) {
340340
animate_and_lock (animation_time);
341341
} else {
342342
_set_active (true);

0 commit comments

Comments
 (0)