diff options
| -rw-r--r-- | lockscreen/LockScreenAbstractShield.h | 55 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.cpp | 26 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.h | 5 | ||||
| -rw-r--r-- | lockscreen/LockScreenShield.cpp | 5 | ||||
| -rw-r--r-- | lockscreen/LockScreenShield.h | 14 | ||||
| -rw-r--r-- | lockscreen/LockScreenShieldFactory.cpp | 7 | ||||
| -rw-r--r-- | lockscreen/LockScreenShieldFactory.h | 12 | ||||
| -rw-r--r-- | tests/test_lockscreen_controller.cpp | 7 |
8 files changed, 85 insertions, 46 deletions
diff --git a/lockscreen/LockScreenAbstractShield.h b/lockscreen/LockScreenAbstractShield.h new file mode 100644 index 000000000..3521198eb --- /dev/null +++ b/lockscreen/LockScreenAbstractShield.h @@ -0,0 +1,55 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2014 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * 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/>. + * + * Authored by: Marco Trevisan <marco.trevisan@canonical.com> + */ + +#ifndef UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H +#define UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H + +#include <NuxCore/Property.h> +#include <UnityCore/SessionManager.h> + +#include "unity-shared/MockableBaseWindow.h" + +namespace unity +{ +namespace lockscreen +{ + +class AbstractShield : public MockableBaseWindow +{ +public: + AbstractShield(session::Manager::Ptr const& session, int monitor, bool is_primary) + : MockableBaseWindow("Unity Lockscreen") + , primary(is_primary) + , monitor_(monitor) + , session_manager_(session) + {} + + nux::Property<bool> primary; + + sigc::signal<void, int, int> grab_motion; + +protected: + int monitor_; + session::Manager::Ptr session_manager_; +}; + +} // lockscreen +} // unity + +#endif // UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H diff --git a/lockscreen/LockScreenController.cpp b/lockscreen/LockScreenController.cpp index 7aec4282d..d798c1077 100644 --- a/lockscreen/LockScreenController.cpp +++ b/lockscreen/LockScreenController.cpp @@ -19,6 +19,7 @@ #include "LockScreenController.h" +#include "LockScreenShield.h" #include "LockScreenSettings.h" #include "unity-shared/AnimationUtils.h" #include "unity-shared/UScreen.h" @@ -61,8 +62,11 @@ Controller::Controller(session::Manager::Ptr const& session_manager, }); fade_animator_.finished.connect([this]() { - if (fade_animator_.GetCurrentValue() == 0.0f) + if (animation::GetDirection(fade_animator_) == animation::Direction::BACKWARD) + { + motion_connection_->disconnect(); shields_.clear(); + } }); } @@ -77,15 +81,17 @@ void Controller::OnPrimaryShieldMotion(int x, int y) if (!primary_shield_->GetAbsoluteGeometry().IsPointInside(x, y)) { for (auto const& shield : shields_) - if (shield->GetAbsoluteGeometry().IsPointInside(x, y)) - { - primary_shield_->primary = false; - primary_shield_ = shield; - shield->primary = true; - auto move_cb = sigc::mem_fun(this, &Controller::OnPrimaryShieldMotion); - motion_connection_ = shield->grab_motion.connect(move_cb); - break; - } + { + if (!shield->GetAbsoluteGeometry().IsPointInside(x, y)) + continue; + + primary_shield_->primary = false; + primary_shield_ = shield; + shield->primary = true; + auto move_cb = sigc::mem_fun(this, &Controller::OnPrimaryShieldMotion); + motion_connection_ = shield->grab_motion.connect(move_cb); + break; + } } } diff --git a/lockscreen/LockScreenController.h b/lockscreen/LockScreenController.h index d977ab8dd..7ee09bb93 100644 --- a/lockscreen/LockScreenController.h +++ b/lockscreen/LockScreenController.h @@ -23,7 +23,6 @@ #include <NuxCore/Animation.h> #include <UnityCore/ConnectionManager.h> -#include "LockScreenShield.h" #include "LockScreenShieldFactory.h" #include "unity-shared/BackgroundEffectHelper.h" #include "unity-shared/UpstartWrapper.h" @@ -58,8 +57,8 @@ private: void OnUnlockRequested(); void OnPrimaryShieldMotion(int x, int y); - std::vector<nux::ObjectPtr<Shield>> shields_; - nux::ObjectWeakPtr<Shield> primary_shield_; + std::vector<nux::ObjectPtr<AbstractShield>> shields_; + nux::ObjectWeakPtr<AbstractShield> primary_shield_; session::Manager::Ptr session_manager_; UpstartWrapper::Ptr upstart_wrapper_; ShieldFactoryInterface::Ptr shield_factory_; diff --git a/lockscreen/LockScreenShield.cpp b/lockscreen/LockScreenShield.cpp index c2751d8fa..7b3c4aa6a 100644 --- a/lockscreen/LockScreenShield.cpp +++ b/lockscreen/LockScreenShield.cpp @@ -38,10 +38,7 @@ namespace lockscreen { Shield::Shield(session::Manager::Ptr const& session_manager, int monitor, bool is_primary) - : MockableBaseWindow("Unity Lockscreen") - , primary(is_primary) - , monitor_(monitor) - , session_manager_(session_manager) + : AbstractShield(session_manager, monitor, is_primary) , bg_settings_(new BackgroundSettings) , prompt_view_(nullptr) { diff --git a/lockscreen/LockScreenShield.h b/lockscreen/LockScreenShield.h index bdf95c491..c260b3e47 100644 --- a/lockscreen/LockScreenShield.h +++ b/lockscreen/LockScreenShield.h @@ -20,10 +20,7 @@ #ifndef UNITY_LOCKSCREEN_SHIELD_H #define UNITY_LOCKSCREEN_SHIELD_H -#include <NuxCore/Property.h> -#include <UnityCore/SessionManager.h> - -#include "unity-shared/MockableBaseWindow.h" +#include "LockScreenAbstractShield.h" namespace unity { @@ -34,19 +31,15 @@ class BackgroundSettings; class UserAuthenticator; class UserPromptView; -class Shield : public MockableBaseWindow +class Shield : public AbstractShield { public: Shield(session::Manager::Ptr const& session_manager, int monitor, bool is_primary); - nux::Property<bool> primary; - bool AcceptKeyNavFocus() override; nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override; nux::Area* FindAreaUnderMouse(nux::Point const&, nux::NuxEventType) override; - sigc::signal<void, int, int> grab_motion; - private: void UpdateBackgroundTexture(); void ShowPrimaryView(); @@ -57,9 +50,6 @@ private: void OnIndicatorEntryShowMenu(std::string const&, unsigned, int, int, unsigned); void OnIndicatorEntryActivated(std::string const& panel, std::string const& entry, nux::Geometry const& geo); - - int monitor_; - session::Manager::Ptr session_manager_; std::shared_ptr<BackgroundSettings> bg_settings_; std::unique_ptr<nux::AbstractPaintLayer> background_layer_; nux::ObjectPtr<nux::Layout> primary_layout_; diff --git a/lockscreen/LockScreenShieldFactory.cpp b/lockscreen/LockScreenShieldFactory.cpp index 462e81e06..afff43f9c 100644 --- a/lockscreen/LockScreenShieldFactory.cpp +++ b/lockscreen/LockScreenShieldFactory.cpp @@ -25,12 +25,9 @@ namespace unity namespace lockscreen { -nux::ObjectPtr<MockableBaseWindow> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager, - int monitor, - bool is_primary) +nux::ObjectPtr<AbstractShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager, int monitor, bool is_primary) { - nux::ObjectPtr<Shield> shield(new Shield(session_manager, monitor, is_primary)); - return shield; + return nux::ObjectPtr<Shield>(new Shield(session_manager, monitor, is_primary)); } } diff --git a/lockscreen/LockScreenShieldFactory.h b/lockscreen/LockScreenShieldFactory.h index 23dbcae8d..f822d316c 100644 --- a/lockscreen/LockScreenShieldFactory.h +++ b/lockscreen/LockScreenShieldFactory.h @@ -21,7 +21,7 @@ #define UNITY_LOCKSCREEN_SHIELD_FACTORY #include <Nux/Nux.h> -#include <UnityCore/SessionManager.h> +#include "LockScreenAbstractShield.h" namespace unity { @@ -35,18 +35,14 @@ struct ShieldFactoryInterface { typedef std::shared_ptr<ShieldFactoryInterface> Ptr; - virtual ~ShieldFactoryInterface() {}; + virtual ~ShieldFactoryInterface() = default; - virtual nux::ObjectPtr<MockableBaseWindow> CreateShield(session::Manager::Ptr const& session_manager, - int monitor, - bool is_primary) = 0; + virtual nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&, int monitor, bool is_primary) = 0; }; struct ShieldFactory : ShieldFactoryInterface { - nux::ObjectPtr<MockableBaseWindow> CreateShield(session::Manager::Ptr const& session_manager, - int monitor, - bool is_primary) override; + nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&, int monitor, bool is_primary) override; }; } diff --git a/tests/test_lockscreen_controller.cpp b/tests/test_lockscreen_controller.cpp index 5b4bd2aad..d82a7c2c9 100644 --- a/tests/test_lockscreen_controller.cpp +++ b/tests/test_lockscreen_controller.cpp @@ -64,11 +64,10 @@ R"(<node> struct ShieldFactoryMock : ShieldFactoryInterface { - nux::ObjectPtr<MockableBaseWindow> CreateShield (session::Manager::Ptr const&, int, bool) override + nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&, int, bool) override { - nux::ObjectPtr<MockableBaseWindow> shield(new MockableBaseWindow); - return shield; - } + return nux::ObjectPtr<AbstractShield>(new AbstractShield(nullptr, 0, false)); + } }; struct TestLockScreenController : Test |
