Remove duration settings and use constants (#513)

This commit is contained in:
Corentin Noël 2019-07-21 10:55:23 +02:00 committed by Rico Tzschichholz
parent da85223ff8
commit 50694796d4
7 changed files with 80 additions and 59 deletions

View File

@ -184,26 +184,33 @@
</key>
<key type="i" name="open-duration">
<default>350</default>
<summary>Duration of the open animation</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
<key type="i" name="snap-duration">
<default>250</default>
<summary>Duration of the snap animation as used by maximize/unmaximize</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
<key type="i" name="close-duration">
<default>195</default>
<summary>Duration of the close animation</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
<key type="i" name="minimize-duration">
<default>200</default>
<summary>Duration of the minimize animation</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
<key type="i" name="workspace-switch-duration">
<default>300</default>
<summary>Duration of the workspace switch animation</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
<key type="i" name="menu-duration">
<default>150</default>
<summary>Duration of the menu mapping animation</summary>
<description>DEPRECATED: This key is deprecated and ignored.</description>
</key>
</schema>

35
lib/Constants.vala Normal file
View File

@ -0,0 +1,35 @@
//
// Copyright 2019 elementary, Inc. (https://elementary.io)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
namespace Gala
{
[CCode (has_type_id = false)]
public enum AnimationDuration {
// Duration of the open animation
OPEN = 350,
// Duration of the close animation
CLOSE = 195,
// Duration of the minimize animation
MINIMIZE = 200,
// Duration of the menu mapping animation
MENU_MAP = 150,
// Duration of the snap animation as used by maximize/unmaximize
SNAP = 250,
// Duration of the workspace switch animation
WORKSPACE_SWITCH = 300,
}
}

View File

@ -113,6 +113,11 @@ namespace Gala
*/
public abstract Meta.BackgroundGroup background_group { 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.

View File

@ -1,5 +1,6 @@
gala_lib_sources = files(
'ActivatableComponent.vala',
'Constants.vala',
'Plugin.vala',
'Utils.vala',
'WindowIcon.vala',

View File

@ -127,32 +127,6 @@ namespace Gala
}
}
public class AnimationSettings : Granite.Services.Settings
{
public bool enable_animations { get; set; }
public int open_duration { get; set; }
public int snap_duration { get; set; }
public int close_duration { get; set; }
public int minimize_duration { get; set; }
public int workspace_switch_duration { get; set; }
public int menu_duration { get; set; }
static AnimationSettings? instance = null;
private AnimationSettings ()
{
base (Config.SCHEMA + ".animations");
}
public static unowned AnimationSettings get_default ()
{
if (instance == null)
instance = new AnimationSettings ();
return instance;
}
}
public class BackgroundSettings : Granite.Services.Settings
{
public string picture_options { get; set; }

View File

@ -246,8 +246,7 @@ namespace Gala
workspace_clone.restore_easing_state ();
}
workspaces.set_easing_duration (animate ?
AnimationSettings.get_default ().workspace_switch_duration : 0);
workspaces.set_easing_duration (animate ? AnimationDuration.WORKSPACE_SWITCH : 0);
workspaces.x = -active_x;
reposition_icon_groups (animate);

View File

@ -55,6 +55,11 @@ namespace Gala
*/
public Meta.BackgroundGroup background_group { get; protected set; }
/**
* {@inheritDoc}
*/
public bool enable_animations { get; protected set; }
Meta.PluginInfo info;
WindowSwitcher? winswitcher = null;
@ -81,6 +86,8 @@ namespace Gala
Gee.HashSet<Meta.WindowActor> unminimizing = new Gee.HashSet<Meta.WindowActor> ();
GLib.HashTable<Meta.Window, int> ws_assoc = new GLib.HashTable<Meta.Window, int> (direct_hash, direct_equal);
GLib.Settings animations_settings;
public WindowManagerGala ()
{
info = Meta.PluginInfo () {name = "Gala", version = Config.VERSION, author = "Gala Developers",
@ -94,6 +101,12 @@ namespace Gala
Prefs.override_preference_schema ("enable-animations", Config.SCHEMA + ".animations");
}
construct {
animations_settings = new GLib.Settings (Config.SCHEMA + ".animations");
animations_settings.bind ("enable-animations", this, "enable-animations", GLib.SettingsBindFlags.GET);
enable_animations = animations_settings.get_boolean ("enable-animations");
}
public override void start ()
{
Util.later_add (LaterType.BEFORE_REDRAW, show_stage);
@ -482,8 +495,6 @@ namespace Gala
return;
}
bool enable_animations = AnimationSettings.get_default ().enable_animations;
var bottom_actor = bottom_window.get_compositor_private () as Meta.WindowActor;
if (enable_animations) {
animate_bottom_window_scale (bottom_actor);
@ -877,15 +888,14 @@ namespace Gala
unowned Meta.WindowActor window_actor = window.get_compositor_private () as Meta.WindowActor;
window_group.set_child_below_sibling (tile_preview, window_actor);
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var duration = animation_settings.snap_duration / 2U;
var duration = AnimationDuration.SNAP / 2U;
var rect = window.get_frame_rect ();
tile_preview.set_position (rect.x, rect.y);
tile_preview.set_size (rect.width, rect.height);
tile_preview.show ();
if (animation_settings.enable_animations) {
if (enable_animations) {
tile_preview.save_easing_state ();
tile_preview.set_easing_mode (Clutter.AnimationMode.EASE_IN_OUT_QUAD);
tile_preview.set_easing_duration (duration);
@ -999,10 +1009,9 @@ namespace Gala
public override void minimize (WindowActor actor)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var duration = animation_settings.minimize_duration;
const int duration = AnimationDuration.MINIMIZE;
if (!animation_settings.enable_animations
if (!enable_animations
|| duration == 0
|| actor.get_meta_window ().window_type != WindowType.NORMAL) {
minimize_completed (actor);
@ -1071,10 +1080,9 @@ namespace Gala
void maximize (WindowActor actor, int ex, int ey, int ew, int eh)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var duration = animation_settings.snap_duration;
const int duration = AnimationDuration.SNAP;
if (!animation_settings.enable_animations
if (!enable_animations
|| duration == 0) {
return;
}
@ -1164,9 +1172,7 @@ namespace Gala
public override void unminimize (WindowActor actor)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
if (!animation_settings.enable_animations) {
if (!enable_animations) {
actor.show ();
unminimize_completed (actor);
return;
@ -1179,7 +1185,7 @@ namespace Gala
switch (window.window_type) {
case WindowType.NORMAL:
var duration = animation_settings.minimize_duration;
var duration = AnimationDuration.MINIMIZE;
if (duration == 0) {
unminimize_completed (actor);
return;
@ -1214,10 +1220,8 @@ namespace Gala
public override void map (WindowActor actor)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var window = actor.get_meta_window ();
if (!animation_settings.enable_animations) {
if (!enable_animations) {
actor.show ();
map_completed (actor);
@ -1233,7 +1237,7 @@ namespace Gala
switch (window.window_type) {
case WindowType.NORMAL:
var duration = animation_settings.open_duration;
var duration = AnimationDuration.MINIMIZE;
if (duration == 0) {
map_completed (actor);
return;
@ -1271,7 +1275,7 @@ namespace Gala
case WindowType.MENU:
case WindowType.DROPDOWN_MENU:
case WindowType.POPUP_MENU:
var duration = animation_settings.menu_duration;
var duration = AnimationDuration.MENU_MAP;
if (duration == 0) {
map_completed (actor);
return;
@ -1339,12 +1343,11 @@ namespace Gala
public override void destroy (WindowActor actor)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var window = actor.get_meta_window ();
ws_assoc.remove (window);
if (!animation_settings.enable_animations) {
if (!enable_animations) {
destroy_completed (actor);
// only NORMAL windows have icons
@ -1358,7 +1361,7 @@ namespace Gala
switch (window.window_type) {
case WindowType.NORMAL:
var duration = animation_settings.close_duration;
const int duration = AnimationDuration.CLOSE;
if (duration == 0) {
destroy_completed (actor);
return;
@ -1409,7 +1412,7 @@ namespace Gala
case WindowType.MENU:
case WindowType.DROPDOWN_MENU:
case WindowType.POPUP_MENU:
var duration = animation_settings.menu_duration;
var duration = AnimationDuration.MENU_MAP;
if (duration == 0) {
destroy_completed (actor);
return;
@ -1438,10 +1441,8 @@ namespace Gala
void unmaximize (Meta.WindowActor actor, int ex, int ey, int ew, int eh)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var duration = animation_settings.snap_duration;
if (!animation_settings.enable_animations
const int duration = AnimationDuration.SNAP;
if (!enable_animations
|| duration == 0) {
return;
}
@ -1560,10 +1561,9 @@ namespace Gala
public override void switch_workspace (int from, int to, MotionDirection direction)
{
unowned AnimationSettings animation_settings = AnimationSettings.get_default ();
var animation_duration = animation_settings.workspace_switch_duration;
const int animation_duration = AnimationDuration.WORKSPACE_SWITCH;
if (!animation_settings.enable_animations
if (!enable_animations
|| animation_duration == 0
|| (direction != MotionDirection.LEFT && direction != MotionDirection.RIGHT)) {
switch_workspace_completed ();