summaryrefslogtreecommitdiff
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2013-02-06 18:27:01 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2013-02-06 18:27:01 +0100
commit211af4e49afcfbd7ad62a1f0f7b5bbbd575db048 (patch)
tree8b35c158e91fc60fb871930da4bc798e147ffce6
parent4050069fe60fb6e25d1e43659797c52c7d76d737 (diff)
SwitcherController: add a fade animator to show/hide the switcher window
(bzr r3132.2.2)
-rw-r--r--launcher/SwitcherController.cpp65
-rw-r--r--launcher/SwitcherController.h1
-rw-r--r--launcher/SwitcherControllerImpl.h3
3 files changed, 55 insertions, 14 deletions
diff --git a/launcher/SwitcherController.cpp b/launcher/SwitcherController.cpp
index 844871cb9..555062d51 100644
--- a/launcher/SwitcherController.cpp
+++ b/launcher/SwitcherController.cpp
@@ -40,6 +40,7 @@ const std::string LAZY_TIMEOUT = "lazy-timeout";
const std::string SHOW_TIMEOUT = "show-timeout";
const std::string DETAIL_TIMEOUT = "detail-timeout";
const std::string VIEW_CONSTRUCT_IDLE = "view-construct-idle";
+const unsigned FADE_DURATION = 80;
/**
* Helper comparison functor for sorting application icons.
@@ -196,6 +197,14 @@ void Controller::SetDetailOnTimeout(bool timeout)
detail_on_timeout = timeout;
}
+double Controller::Opacity() const
+{
+ if (!impl_->view_window_)
+ return 0.0f;
+
+ return impl_->view_window_->GetOpacity();
+}
+
std::string
Controller::GetName() const
{
@@ -225,6 +234,7 @@ Controller::Impl::Impl(Controller* obj,
, create_window_(create_window)
, main_layout_(nullptr)
, bg_color_(0, 0, 0, 0.5)
+ , fade_animator_(FADE_DURATION)
{
ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Controller::Impl::OnBackgroundUpdate));
@@ -235,6 +245,16 @@ Controller::Impl::Impl(Controller* obj,
// TODO We need to get actual timing data to suggest this is necessary.
//sources_.AddTimeoutSeconds(construct_timeout_, [&] { ConstructWindow(); return false; }, LAZY_TIMEOUT);
+
+ fade_animator_.updated.connect([this] (double opacity) {
+ if (view_window_)
+ {
+ view_window_->SetOpacity(opacity);
+
+ if (!obj_->visible_ && opacity == 0.0f)
+ HideWindow();
+ }
+ });
}
void Controller::Impl::OnBackgroundUpdate(GVariant* data)
@@ -267,11 +287,12 @@ void Controller::Impl::Show(ShowMode show, SortMode sort, std::vector<AbstractLa
SelectFirstItem();
obj_->visible_ = true;
+ int real_wait = timeout_length - fade_animator_.Duration();
- if (timeout_length > 0)
+ if (real_wait > 0)
{
sources_.AddIdle([&] { ConstructView(); return false; }, VIEW_CONSTRUCT_IDLE);
- sources_.AddTimeout(timeout_length, [&] { ShowView(); return false; }, SHOW_TIMEOUT);
+ sources_.AddTimeout(real_wait, [&] { ShowView(); return false; }, SHOW_TIMEOUT);
}
else
{
@@ -331,11 +352,20 @@ void Controller::Impl::ShowView()
ubus_manager_.SendMessage(UBUS_SWITCHER_START, NULL);
- if (view_window_) {
+ if (view_window_)
+ {
view_window_->ShowWindow(true);
view_window_->PushToFront();
view_window_->SetOpacity(1.0f);
- view_window_->CaptureMouseDownAnyWhereElse(true);
+
+ if (fade_animator_.CurrentState() == nux::animation::Animation::State::Running)
+ {
+ fade_animator_.Reverse();
+ }
+ else
+ {
+ fade_animator_.SetStartValue(0.0f).SetFinishValue(1.0f).Start();
+ }
}
}
@@ -392,30 +422,37 @@ void Controller::Impl::Hide(bool accept_state)
}
ubus_manager_.SendMessage(UBUS_SWITCHER_END, g_variant_new_boolean(!accept_state));
+ ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", false, obj_->monitor_));
sources_.Remove(VIEW_CONSTRUCT_IDLE);
sources_.Remove(SHOW_TIMEOUT);
sources_.Remove(DETAIL_TIMEOUT);
- model_.reset();
obj_->visible_ = false;
- if (view_)
- main_layout_->RemoveChildObject(view_.GetPointer());
-
- if (view_window_)
+ if (fade_animator_.CurrentState() == nux::animation::Animation::State::Running)
+ {
+ fade_animator_.Reverse();
+ }
+ else
{
- view_window_->SetOpacity(0.0f);
- view_window_->ShowWindow(false);
- view_window_->PushToBack();
+ fade_animator_.SetStartValue(1.0f).SetFinishValue(0.0f).Start();
}
+}
- ubus_manager_.SendMessage(UBUS_SWITCHER_SHOWN, g_variant_new("(bi)", false, obj_->monitor_));
+void Controller::Impl::HideWindow()
+{
+ main_layout_->RemoveChildObject(view_.GetPointer());
+ view_window_->SetOpacity(0.0f);
+ view_window_->ShowWindow(false);
+ view_window_->PushToBack();
+ view_window_->EnableInputWindow(false);
+
+ model_.reset();
view_.Release();
}
-
void Controller::Impl::Next()
{
if (!model_)
diff --git a/launcher/SwitcherController.h b/launcher/SwitcherController.h
index 928a5c26f..024f7f4d4 100644
--- a/launcher/SwitcherController.h
+++ b/launcher/SwitcherController.h
@@ -114,6 +114,7 @@ public:
bool IsShowDesktopDisabled() const;
void SetShowDesktopDisabled(bool disabled);
int StartIndex() const;
+ double Opacity() const;
Selection GetCurrentSelection() const;
diff --git a/launcher/SwitcherControllerImpl.h b/launcher/SwitcherControllerImpl.h
index 62fc6d06a..9feedd7ee 100644
--- a/launcher/SwitcherControllerImpl.h
+++ b/launcher/SwitcherControllerImpl.h
@@ -32,6 +32,7 @@
#include <Nux/Nux.h>
#include <Nux/BaseWindow.h>
#include <Nux/WindowCompositor.h>
+#include <NuxCore/Animation.h>
namespace unity
{
@@ -73,6 +74,7 @@ struct Controller::Impl
void ConstructWindow();
void ConstructView();
void ShowView();
+ void HideWindow();
bool OnDetailTimer();
void OnModelSelectionChanged(launcher::AbstractLauncherIcon::Ptr const& icon);
@@ -91,6 +93,7 @@ struct Controller::Impl
nux::ObjectPtr<nux::BaseWindow> view_window_;
nux::HLayout* main_layout_;
nux::Color bg_color_;
+ nux::animation::AnimateValue<double> fade_animator_;
UBusManager ubus_manager_;
glib::SourceManager sources_;