diff options
| author | Ugo Riboni <ugo.riboni@canonical.com> | 2012-08-31 07:40:08 -0400 |
|---|---|---|
| committer | Tarmac <> | 2012-08-31 07:40:08 -0400 |
| commit | ec134eff401b69f80e0e80793d43bac28e01bcc0 (patch) | |
| tree | 7e606f2a4ac10f1d376cefe6d2cbb03fc2bc0e7c /plugins/unityshell | |
| parent | a3621b6d3721db484f4eecb32eac5aa222e3943a (diff) | |
| parent | 004a9cad6b4670e6ba7b8fdc471bbcf99758c847 (diff) | |
Progressively adjust the speed of the minimize animation. First time it is used is slower, then speeds up the more it is used.. Fixes: https://bugs.launchpad.net/bugs/1017510. Approved by Sam Spilsbury.
(bzr r2647)
Diffstat (limited to 'plugins/unityshell')
| -rw-r--r-- | plugins/unityshell/src/WindowMinimizeSpeedController.cpp | 108 | ||||
| -rw-r--r-- | plugins/unityshell/src/WindowMinimizeSpeedController.h | 57 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.cpp | 44 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.h | 8 |
4 files changed, 216 insertions, 1 deletions
diff --git a/plugins/unityshell/src/WindowMinimizeSpeedController.cpp b/plugins/unityshell/src/WindowMinimizeSpeedController.cpp new file mode 100644 index 000000000..66f28d8fc --- /dev/null +++ b/plugins/unityshell/src/WindowMinimizeSpeedController.cpp @@ -0,0 +1,108 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* Compiz unity plugin + * unity.h + * + * Copyright (c) 2010-11 Canonical Ltd. + * + * 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. + * + * Your own copyright notice would go above. You are free to choose whatever + * licence you want, just take note that some compiz code is GPL and you will + * not be able to re-use it if you want to use a different licence. + */ + +#include <gio/gio.h> +#include <NuxCore/Logger.h> + +#include "WindowMinimizeSpeedController.h" + +namespace +{ + +nux::logging::Logger logger ("unity.WindowMinimizeSpeedController"); + +namespace local +{ +const std::string UNITY_SCHEMA = "com.canonical.Unity"; +} +} + +WindowMinimizeSpeedController::WindowMinimizeSpeedController() + : _settings(g_settings_new(local::UNITY_SCHEMA.c_str())) + , _minimize_count(g_settings_get_int(_settings, "minimize-count")) + , _minimize_speed_threshold(g_settings_get_int(_settings, "minimize-speed-threshold")) + , _minimize_slow_duration(g_settings_get_int(_settings, "minimize-slow-duration")) + , _minimize_fast_duration(g_settings_get_int(_settings, "minimize-fast-duration")) +{ + _minimize_count_changed.Connect(_settings, "changed::minimize-count", + [&] (GSettings*, gchar* name) { + _minimize_count = g_settings_get_int(_settings, name); + SetDuration(); + }); + _minimize_speed_threshold_changed.Connect(_settings, "changed::minimize-speed-threshold", + [&] (GSettings*, gchar* name) { + _minimize_speed_threshold = g_settings_get_int(_settings, name); + SetDuration(); + }); + _minimize_fast_duration_changed.Connect(_settings, "changed::minimize-fast-duration", + [&] (GSettings*, gchar* name) { + _minimize_fast_duration = g_settings_get_int(_settings, name); + SetDuration(); + }); + _minimize_slow_duration_changed.Connect(_settings, "changed::minimize-slow-duration", + [&] (GSettings*, gchar* name) { + _minimize_slow_duration = g_settings_get_int(_settings, name); + SetDuration(); + }); +} + +void WindowMinimizeSpeedController::UpdateCount() +{ + if (_minimize_count < _minimize_speed_threshold) { + _minimize_count += 1; + g_settings_set_int(_settings, "minimize-count", _minimize_count); + } +} + +int WindowMinimizeSpeedController::getDuration() +{ + return mDuration; +} + +void WindowMinimizeSpeedController::SetDuration() +{ + /* Perform some sanity checks on the configuration values */ + if (_minimize_fast_duration > _minimize_slow_duration) + { + LOG_WARN(logger) << "Configuration mismatch: minimize-fast-duration (" + << _minimize_fast_duration + << ") is longer than minimize-slow-duration (" + << _minimize_slow_duration << "). Not changing speed."; + return; + } + + if (_minimize_count < 0) + _minimize_count = 0; + if (_minimize_count > _minimize_speed_threshold) + _minimize_count = _minimize_speed_threshold; + + /* Adjust the speed so that it gets linearly closer to maximum speed as we + approach the threshold */ + int speed_range = _minimize_slow_duration - _minimize_fast_duration; + float position = (_minimize_speed_threshold <= 0) ? 1.0 : + static_cast<float>(_minimize_count) / _minimize_speed_threshold; + int duration = _minimize_slow_duration - std::ceil(position * speed_range); + + if (duration != mDuration) { + mDuration = duration; + DurationChanged.emit(); + } +} diff --git a/plugins/unityshell/src/WindowMinimizeSpeedController.h b/plugins/unityshell/src/WindowMinimizeSpeedController.h new file mode 100644 index 000000000..49bcbad14 --- /dev/null +++ b/plugins/unityshell/src/WindowMinimizeSpeedController.h @@ -0,0 +1,57 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* Compiz unity plugin + * unity.h + * + * Copyright (c) 2010-11 Canonical Ltd. + * + * 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. + * + * Your own copyright notice would go above. You are free to choose whatever + * licence you want, just take note that some compiz code is GPL and you will + * not be able to re-use it if you want to use a different licence. + */ + +#ifndef WINDOWMINIMIZESPEEDCONTROLLER_H +#define WINDOWMINIMIZESPEEDCONTROLLER_H + +#include <core/core.h> +#include <UnityCore/GLibWrapper.h> +#include <UnityCore/GLibSignal.h> +#include <sigc++/sigc++.h> + +typedef struct _GSettings GSettings; + +using namespace unity; + +class WindowMinimizeSpeedController +{ +public: + WindowMinimizeSpeedController(); + void UpdateCount(); + int getDuration(); + sigc::signal<void> DurationChanged; + +private: + void SetDuration(); + + glib::Object<GSettings> _settings; + int _minimize_count; + int _minimize_speed_threshold; + int _minimize_slow_duration; + int _minimize_fast_duration; + glib::Signal<void, GSettings*, gchar* > _minimize_count_changed; + glib::Signal<void, GSettings*, gchar* > _minimize_speed_threshold_changed; + glib::Signal<void, GSettings*, gchar* > _minimize_slow_duration_changed; + glib::Signal<void, GSettings*, gchar* > _minimize_fast_duration_changed; + int mDuration; +}; + +#endif // WINDOWMINIMIZESPEEDCONTROLLER_H diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index ed44691bc..f016f2adc 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -128,6 +128,7 @@ UnityScreen::UnityScreen(CompScreen* screen) , panel_texture_has_changed_(true) , paint_panel_(false) , scale_just_activated_(false) + , minimize_speed_controller(new WindowMinimizeSpeedController()) { Timer timer; #ifndef USE_GLES @@ -384,6 +385,10 @@ UnityScreen::UnityScreen(CompScreen* screen) } panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged)); + + minimize_speed_controller->DurationChanged.connect( + sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged) + ); } UnityScreen::~UnityScreen() @@ -2540,6 +2545,40 @@ bool UnityWindow::glDraw(const GLMatrix& matrix, } void +UnityScreen::OnMinimizeDurationChanged () +{ + /* Update the compiz plugin setting with the new computed speed so that it + * will be used in the following minimizations */ + CompPlugin *p = CompPlugin::find("animation"); + if (p) + { + CompOption::Vector &opts = p->vTable->getOptions(); + + for (CompOption &o : opts) + { + if (o.name () == std::string ("minimize_durations")) + { + /* minimize_durations is a list value, but minimize applies only to + * normal windows, so there's always one value */ + CompOption::Value& value = o.value(); + CompOption::Value::Vector& list = value.list(); + CompOption::Value::Vector::iterator i = list.begin(); + if (i != list.end()) { + i->set(minimize_speed_controller->getDuration()); + } + value.set(list); + screen->setOptionForPlugin(p->vTable->name().c_str(), + o.name().c_str(), value); + break; + } + } + } + else { + LOG_WARN(logger) << "Animation plugin not found. Can't set minimize speed."; + } +} + +void UnityWindow::minimize () { if (!window->managed ()) @@ -2655,6 +2694,11 @@ void UnityWindow::windowNotify(CompWindowNotify n) case CompWindowNotifyBeforeDestroy: being_destroyed.emit(); break; + case CompWindowNotifyMinimize: + /* Updating the count in dconf will trigger a "changed" signal to which + * the method setting the new animation speed is attached */ + UnityScreen::get(screen)->minimize_speed_controller->UpdateCount(); + break; default: break; } diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index afc9b8da2..d9d20edb7 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -65,6 +65,8 @@ #include "HudController.h" #include "ThumbnailGenerator.h" +#include "WindowMinimizeSpeedController.h" + namespace unity { @@ -189,6 +191,8 @@ public: void SetUpAndShowSwitcher(switcher::ShowMode show_mode = switcher::ShowMode::CURRENT_VIEWPORT); + void OnMinimizeDurationChanged(); + switcher::Controller::Ptr switcher_controller(); launcher::Controller::Ptr launcher_controller(); @@ -242,7 +246,7 @@ private: void OnPanelStyleChanged(); void InitGesturesSupport(); - + nux::animation::TickSource tick_source_; nux::animation::AnimationController animation_controller_; @@ -339,6 +343,8 @@ private: UBusManager ubus_manager_; glib::SourceManager sources_; unity::ThumbnailGenerator thumb_generator; + + WindowMinimizeSpeedController* minimize_speed_controller; friend class UnityWindow; }; |
