Skip to content

Commit 5069479

Browse files
Corentin Noëlricotz
authored andcommitted
Remove duration settings and use constants (#513)
1 parent da85223 commit 5069479

File tree

7 files changed

+80
-59
lines changed

7 files changed

+80
-59
lines changed

data/org.pantheon.desktop.gala.gschema.xml.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,33 @@
184184
</key>
185185
<key type="i" name="open-duration">
186186
<default>350</default>
187+
<summary>Duration of the open animation</summary>
188+
<description>DEPRECATED: This key is deprecated and ignored.</description>
187189
</key>
188190
<key type="i" name="snap-duration">
189191
<default>250</default>
190192
<summary>Duration of the snap animation as used by maximize/unmaximize</summary>
193+
<description>DEPRECATED: This key is deprecated and ignored.</description>
191194
</key>
192195
<key type="i" name="close-duration">
193196
<default>195</default>
194197
<summary>Duration of the close animation</summary>
198+
<description>DEPRECATED: This key is deprecated and ignored.</description>
195199
</key>
196200
<key type="i" name="minimize-duration">
197201
<default>200</default>
198202
<summary>Duration of the minimize animation</summary>
203+
<description>DEPRECATED: This key is deprecated and ignored.</description>
199204
</key>
200205
<key type="i" name="workspace-switch-duration">
201206
<default>300</default>
202207
<summary>Duration of the workspace switch animation</summary>
208+
<description>DEPRECATED: This key is deprecated and ignored.</description>
203209
</key>
204210
<key type="i" name="menu-duration">
205211
<default>150</default>
206212
<summary>Duration of the menu mapping animation</summary>
213+
<description>DEPRECATED: This key is deprecated and ignored.</description>
207214
</key>
208215
</schema>
209216

lib/Constants.vala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright 2019 elementary, Inc. (https://elementary.io)
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
//
17+
18+
namespace Gala
19+
{
20+
[CCode (has_type_id = false)]
21+
public enum AnimationDuration {
22+
// Duration of the open animation
23+
OPEN = 350,
24+
// Duration of the close animation
25+
CLOSE = 195,
26+
// Duration of the minimize animation
27+
MINIMIZE = 200,
28+
// Duration of the menu mapping animation
29+
MENU_MAP = 150,
30+
// Duration of the snap animation as used by maximize/unmaximize
31+
SNAP = 250,
32+
// Duration of the workspace switch animation
33+
WORKSPACE_SWITCH = 300,
34+
}
35+
}

lib/WindowManager.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ namespace Gala
113113
*/
114114
public abstract Meta.BackgroundGroup background_group { get; protected set; }
115115

116+
/**
117+
* Whether animations should be displayed.
118+
*/
119+
public abstract bool enable_animations { get; protected set; }
120+
116121
/**
117122
* Enters the modal mode, which means that all events are directed to the stage instead
118123
* 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+
'Constants.vala',
34
'Plugin.vala',
45
'Utils.vala',
56
'WindowIcon.vala',

src/Settings.vala

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,6 @@ namespace Gala
127127
}
128128
}
129129

130-
public class AnimationSettings : Granite.Services.Settings
131-
{
132-
public bool enable_animations { get; set; }
133-
public int open_duration { get; set; }
134-
public int snap_duration { get; set; }
135-
public int close_duration { get; set; }
136-
public int minimize_duration { get; set; }
137-
public int workspace_switch_duration { get; set; }
138-
public int menu_duration { get; set; }
139-
140-
static AnimationSettings? instance = null;
141-
142-
private AnimationSettings ()
143-
{
144-
base (Config.SCHEMA + ".animations");
145-
}
146-
147-
public static unowned AnimationSettings get_default ()
148-
{
149-
if (instance == null)
150-
instance = new AnimationSettings ();
151-
152-
return instance;
153-
}
154-
}
155-
156130
public class BackgroundSettings : Granite.Services.Settings
157131
{
158132
public string picture_options { get; set; }

src/Widgets/MultitaskingView.vala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ namespace Gala
246246
workspace_clone.restore_easing_state ();
247247
}
248248

249-
workspaces.set_easing_duration (animate ?
250-
AnimationSettings.get_default ().workspace_switch_duration : 0);
249+
workspaces.set_easing_duration (animate ? AnimationDuration.WORKSPACE_SWITCH : 0);
251250
workspaces.x = -active_x;
252251

253252
reposition_icon_groups (animate);

src/WindowManager.vala

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ namespace Gala
5555
*/
5656
public Meta.BackgroundGroup background_group { get; protected set; }
5757

58+
/**
59+
* {@inheritDoc}
60+
*/
61+
public bool enable_animations { get; protected set; }
62+
5863
Meta.PluginInfo info;
5964

6065
WindowSwitcher? winswitcher = null;
@@ -81,6 +86,8 @@ namespace Gala
8186
Gee.HashSet<Meta.WindowActor> unminimizing = new Gee.HashSet<Meta.WindowActor> ();
8287
GLib.HashTable<Meta.Window, int> ws_assoc = new GLib.HashTable<Meta.Window, int> (direct_hash, direct_equal);
8388

89+
GLib.Settings animations_settings;
90+
8491
public WindowManagerGala ()
8592
{
8693
info = Meta.PluginInfo () {name = "Gala", version = Config.VERSION, author = "Gala Developers",
@@ -94,6 +101,12 @@ namespace Gala
94101
Prefs.override_preference_schema ("enable-animations", Config.SCHEMA + ".animations");
95102
}
96103

104+
construct {
105+
animations_settings = new GLib.Settings (Config.SCHEMA + ".animations");
106+
animations_settings.bind ("enable-animations", this, "enable-animations", GLib.SettingsBindFlags.GET);
107+
enable_animations = animations_settings.get_boolean ("enable-animations");
108+
}
109+
97110
public override void start ()
98111
{
99112
Util.later_add (LaterType.BEFORE_REDRAW, show_stage);
@@ -482,8 +495,6 @@ namespace Gala
482495
return;
483496
}
484497

485-
bool enable_animations = AnimationSettings.get_default ().enable_animations;
486-
487498
var bottom_actor = bottom_window.get_compositor_private () as Meta.WindowActor;
488499
if (enable_animations) {
489500
animate_bottom_window_scale (bottom_actor);
@@ -877,15 +888,14 @@ namespace Gala
877888
unowned Meta.WindowActor window_actor = window.get_compositor_private () as Meta.WindowActor;
878889
window_group.set_child_below_sibling (tile_preview, window_actor);
879890

880-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
881-
var duration = animation_settings.snap_duration / 2U;
891+
var duration = AnimationDuration.SNAP / 2U;
882892

883893
var rect = window.get_frame_rect ();
884894
tile_preview.set_position (rect.x, rect.y);
885895
tile_preview.set_size (rect.width, rect.height);
886896
tile_preview.show ();
887897

888-
if (animation_settings.enable_animations) {
898+
if (enable_animations) {
889899
tile_preview.save_easing_state ();
890900
tile_preview.set_easing_mode (Clutter.AnimationMode.EASE_IN_OUT_QUAD);
891901
tile_preview.set_easing_duration (duration);
@@ -999,10 +1009,9 @@ namespace Gala
9991009

10001010
public override void minimize (WindowActor actor)
10011011
{
1002-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1003-
var duration = animation_settings.minimize_duration;
1012+
const int duration = AnimationDuration.MINIMIZE;
10041013

1005-
if (!animation_settings.enable_animations
1014+
if (!enable_animations
10061015
|| duration == 0
10071016
|| actor.get_meta_window ().window_type != WindowType.NORMAL) {
10081017
minimize_completed (actor);
@@ -1071,10 +1080,9 @@ namespace Gala
10711080

10721081
void maximize (WindowActor actor, int ex, int ey, int ew, int eh)
10731082
{
1074-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1075-
var duration = animation_settings.snap_duration;
1083+
const int duration = AnimationDuration.SNAP;
10761084

1077-
if (!animation_settings.enable_animations
1085+
if (!enable_animations
10781086
|| duration == 0) {
10791087
return;
10801088
}
@@ -1164,9 +1172,7 @@ namespace Gala
11641172

11651173
public override void unminimize (WindowActor actor)
11661174
{
1167-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1168-
1169-
if (!animation_settings.enable_animations) {
1175+
if (!enable_animations) {
11701176
actor.show ();
11711177
unminimize_completed (actor);
11721178
return;
@@ -1179,7 +1185,7 @@ namespace Gala
11791185

11801186
switch (window.window_type) {
11811187
case WindowType.NORMAL:
1182-
var duration = animation_settings.minimize_duration;
1188+
var duration = AnimationDuration.MINIMIZE;
11831189
if (duration == 0) {
11841190
unminimize_completed (actor);
11851191
return;
@@ -1214,10 +1220,8 @@ namespace Gala
12141220

12151221
public override void map (WindowActor actor)
12161222
{
1217-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1218-
12191223
var window = actor.get_meta_window ();
1220-
if (!animation_settings.enable_animations) {
1224+
if (!enable_animations) {
12211225
actor.show ();
12221226
map_completed (actor);
12231227

@@ -1233,7 +1237,7 @@ namespace Gala
12331237

12341238
switch (window.window_type) {
12351239
case WindowType.NORMAL:
1236-
var duration = animation_settings.open_duration;
1240+
var duration = AnimationDuration.MINIMIZE;
12371241
if (duration == 0) {
12381242
map_completed (actor);
12391243
return;
@@ -1271,7 +1275,7 @@ namespace Gala
12711275
case WindowType.MENU:
12721276
case WindowType.DROPDOWN_MENU:
12731277
case WindowType.POPUP_MENU:
1274-
var duration = animation_settings.menu_duration;
1278+
var duration = AnimationDuration.MENU_MAP;
12751279
if (duration == 0) {
12761280
map_completed (actor);
12771281
return;
@@ -1339,12 +1343,11 @@ namespace Gala
13391343

13401344
public override void destroy (WindowActor actor)
13411345
{
1342-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
13431346
var window = actor.get_meta_window ();
13441347

13451348
ws_assoc.remove (window);
13461349

1347-
if (!animation_settings.enable_animations) {
1350+
if (!enable_animations) {
13481351
destroy_completed (actor);
13491352

13501353
// only NORMAL windows have icons
@@ -1358,7 +1361,7 @@ namespace Gala
13581361

13591362
switch (window.window_type) {
13601363
case WindowType.NORMAL:
1361-
var duration = animation_settings.close_duration;
1364+
const int duration = AnimationDuration.CLOSE;
13621365
if (duration == 0) {
13631366
destroy_completed (actor);
13641367
return;
@@ -1409,7 +1412,7 @@ namespace Gala
14091412
case WindowType.MENU:
14101413
case WindowType.DROPDOWN_MENU:
14111414
case WindowType.POPUP_MENU:
1412-
var duration = animation_settings.menu_duration;
1415+
var duration = AnimationDuration.MENU_MAP;
14131416
if (duration == 0) {
14141417
destroy_completed (actor);
14151418
return;
@@ -1438,10 +1441,8 @@ namespace Gala
14381441

14391442
void unmaximize (Meta.WindowActor actor, int ex, int ey, int ew, int eh)
14401443
{
1441-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1442-
var duration = animation_settings.snap_duration;
1443-
1444-
if (!animation_settings.enable_animations
1444+
const int duration = AnimationDuration.SNAP;
1445+
if (!enable_animations
14451446
|| duration == 0) {
14461447
return;
14471448
}
@@ -1560,10 +1561,9 @@ namespace Gala
15601561

15611562
public override void switch_workspace (int from, int to, MotionDirection direction)
15621563
{
1563-
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
1564-
var animation_duration = animation_settings.workspace_switch_duration;
1564+
const int animation_duration = AnimationDuration.WORKSPACE_SWITCH;
15651565

1566-
if (!animation_settings.enable_animations
1566+
if (!enable_animations
15671567
|| animation_duration == 0
15681568
|| (direction != MotionDirection.LEFT && direction != MotionDirection.RIGHT)) {
15691569
switch_workspace_completed ();

0 commit comments

Comments
 (0)