diff options
| author | handsome_feng <445865575@qq.com> | 2015-12-05 15:03:25 +0800 |
|---|---|---|
| committer | handsome_feng <445865575@qq.com> | 2015-12-05 15:03:25 +0800 |
| commit | acd143655f1a8c77bbfa1ad995fe196caad45739 (patch) | |
| tree | 20b24c4cef04658cacc7f0d949017f2ef9dd31f4 /lockscreen | |
| parent | 9995e7f3389a2cf5cf8c9317db1da4a52011f229 (diff) | |
| parent | dc8cbcb65a3918d4fc7933d84016de6fa5433a3e (diff) | |
merge ~3v1n0/unity/kylin-lockscreen-cleanup
(bzr r4016.2.30)
Diffstat (limited to 'lockscreen')
| -rw-r--r-- | lockscreen/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | lockscreen/KylinLockScreenShield.cpp | 62 | ||||
| -rw-r--r-- | lockscreen/KylinLockScreenShield.h | 14 | ||||
| -rw-r--r-- | lockscreen/LockScreenAbstractShield.h | 146 | ||||
| -rw-r--r-- | lockscreen/LockScreenBaseShield.cpp | 173 | ||||
| -rw-r--r-- | lockscreen/LockScreenBaseShield.h | 88 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.cpp | 10 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.h | 6 | ||||
| -rw-r--r-- | lockscreen/LockScreenPromptFactory.cpp | 42 | ||||
| -rw-r--r-- | lockscreen/LockScreenPromptFactory.h | 42 | ||||
| -rw-r--r-- | lockscreen/LockScreenShield.cpp | 59 | ||||
| -rw-r--r-- | lockscreen/LockScreenShield.h | 14 | ||||
| -rw-r--r-- | lockscreen/LockScreenShieldFactory.cpp | 19 | ||||
| -rw-r--r-- | lockscreen/LockScreenShieldFactory.h | 31 |
14 files changed, 388 insertions, 320 deletions
diff --git a/lockscreen/CMakeLists.txt b/lockscreen/CMakeLists.txt index 3ccd322aa..86d3f492e 100644 --- a/lockscreen/CMakeLists.txt +++ b/lockscreen/CMakeLists.txt @@ -22,10 +22,12 @@ set (LOCKSCREEN_SOURCES KylinUserPromptView.cpp KylinLockScreenShield.cpp LockScreenController.cpp + LockScreenBaseShield.cpp LockScreenSettings.cpp LockScreenShield.cpp LockScreenShieldFactory.cpp LockScreenPanel.cpp + LockScreenPromptFactory.cpp LockScreenAcceleratorController.cpp LockScreenAccelerators.cpp ScreenSaverDBusManager.cpp diff --git a/lockscreen/KylinLockScreenShield.cpp b/lockscreen/KylinLockScreenShield.cpp index 5b1246889..5adf08263 100644 --- a/lockscreen/KylinLockScreenShield.cpp +++ b/lockscreen/KylinLockScreenShield.cpp @@ -21,12 +21,10 @@ #include <Nux/VLayout.h> #include <Nux/HLayout.h> -#include <Nux/PaintLayer.h> #include "CofView.h" #include "LockScreenSettings.h" #include "LockScreenAbstractPromptView.h" -#include "unity-shared/UnitySettings.h" namespace unity { @@ -37,47 +35,10 @@ KylinShield::KylinShield(session::Manager::Ptr const& session_manager, Accelerators::Ptr const& accelerators, nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, int monitor_num, bool is_primary) - : AbstractShield(session_manager, nullptr, accelerators, prompt_view, monitor_num, is_primary) - , cof_view_(nullptr) + : BaseShield(session_manager, nullptr, accelerators, prompt_view, monitor_num, is_primary) { - UpdateScale(); is_primary ? ShowPrimaryView() : ShowSecondaryView(); - EnableInputWindow(true); - - unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &KylinShield::UpdateScale)); - geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();}); - - monitor.changed.connect([this] (int) { - UpdateScale(); - UpdateBackgroundTexture(); - }); - - primary.changed.connect([this] (bool is_primary) { - regrab_conn_->disconnect(); - is_primary ? ShowPrimaryView() : ShowSecondaryView(); - QueueRelayout(); - QueueDraw(); - }); - - scale.changed.connect([this] (double scale) { - if (prompt_view_ && primary()) - prompt_view_->scale = scale; - - if (cof_view_) - cof_view_->scale = scale; - - if (prompt_layout_) - prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale)); - - background_layer_.reset(); - UpdateBackgroundTexture(); - }); - - mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) { - auto const& abs_geo = GetAbsoluteGeometry(); - grab_motion.emit(abs_geo.x + x, abs_geo.y + y); - }); } void KylinShield::ShowPrimaryView() @@ -114,27 +75,6 @@ void KylinShield::ShowPrimaryView() main_layout->AddSpace(0, 10); } -void KylinShield::ShowSecondaryView() -{ - if (prompt_layout_) - prompt_layout_->RemoveChildObject(prompt_view_.GetPointer()); - - if (cof_layout_) - { - SetLayout(cof_layout_.GetPointer()); - return; - } - - nux::Layout* main_layout = new nux::VLayout(); - cof_layout_ = main_layout; - SetLayout(cof_layout_.GetPointer()); - - // The circle of friends - cof_view_ = new CofView(); - cof_view_->scale = scale(); - main_layout->AddView(cof_view_); -} - nux::Area* KylinShield::FindKeyFocusArea(unsigned etype, unsigned long keysym, unsigned long modifiers) { if (primary) diff --git a/lockscreen/KylinLockScreenShield.h b/lockscreen/KylinLockScreenShield.h index f75ec3894..cdabaf5db 100644 --- a/lockscreen/KylinLockScreenShield.h +++ b/lockscreen/KylinLockScreenShield.h @@ -22,18 +22,16 @@ #include <UnityCore/ConnectionManager.h> #include <UnityCore/GLibSource.h> -#include "LockScreenAbstractShield.h" +#include "LockScreenBaseShield.h" namespace unity { namespace lockscreen { -class UserAuthenticator; class AbstractUserPromptView; -class CofView; -class KylinShield : public AbstractShield +class KylinShield : public BaseShield { public: KylinShield(session::Manager::Ptr const&, @@ -45,13 +43,7 @@ protected: nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override; private: - void ShowPrimaryView(); - void ShowSecondaryView(); - - nux::ObjectPtr<nux::Layout> primary_layout_; - nux::ObjectPtr<nux::Layout> prompt_layout_; - nux::ObjectPtr<nux::Layout> cof_layout_; - CofView* cof_view_; + void ShowPrimaryView() override; }; } diff --git a/lockscreen/LockScreenAbstractShield.h b/lockscreen/LockScreenAbstractShield.h deleted file mode 100644 index 386e68586..000000000 --- a/lockscreen/LockScreenAbstractShield.h +++ /dev/null @@ -1,146 +0,0 @@ -// -*- 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 <UnityCore/Indicators.h> - -#include "BackgroundSettings.h" -#include "unity-shared/MockableBaseWindow.h" -#include "unity-shared/UnitySettings.h" -#include "unity-shared/UScreen.h" -#include "unity-shared/WindowManager.h" -#include "LockScreenAccelerators.h" - -namespace unity -{ -namespace lockscreen -{ -namespace -{ -const unsigned MAX_GRAB_WAIT = 100; -} - -class AbstractUserPromptView; - -class AbstractShield : public MockableBaseWindow -{ -public: - AbstractShield(session::Manager::Ptr const& session, - indicator::Indicators::Ptr const& indicators, - Accelerators::Ptr const& accelerators, - nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, - int monitor_num, bool is_primary) - : MockableBaseWindow("Unity Lockscreen") - , primary(is_primary) - , monitor(monitor_num) - , scale(1.0) - , session_manager_(session) - , indicators_(indicators) - , accelerators_(accelerators) - , prompt_view_(prompt_view) - , bg_settings_(std::make_shared<BackgroundSettings>()) - {} - - nux::Property<bool> primary; - nux::Property<int> monitor; - nux::Property<double> scale; - - using MockableBaseWindow::RemoveLayout; - virtual bool HasGrab() const - { - auto& wc = nux::GetWindowCompositor(); - return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this); - } - virtual bool IsIndicatorOpen() const { return false; } - virtual void ActivatePanel() {} - - sigc::signal<void> grabbed; - sigc::signal<void> grab_failed; - sigc::signal<void, int, int> grab_motion; - sigc::signal<void, unsigned long, unsigned long> grab_key; - -protected: - virtual bool AcceptKeyNavFocus() { return false; } - virtual nux::Area* FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type) - { - nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type); - - if (!area && primary) - return this; - - return area; - } - virtual void GrabScreen(bool cancel_on_failure) - { - auto& wc = nux::GetWindowCompositor(); - - if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this)) - { - regrab_conn_->disconnect(); - regrab_timeout_.reset(); - grabbed.emit(); - } - else - { - auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &AbstractShield::GrabScreen), false); - regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb); - - if (cancel_on_failure) - { - regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] { - grab_failed.emit(); - return false; - })); - } - } - } - virtual void UpdateBackgroundTexture() - { - auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor); - - if (!background_layer_ || monitor_geo != background_layer_->GetGeometry()) - { - auto background_texture = bg_settings_->GetBackgroundTexture(monitor); - background_layer_.reset(new nux::TextureLayer(background_texture->GetDeviceTexture(), nux::TexCoordXForm(), nux::color::White, true)); - SetBackgroundLayer(background_layer_.get()); - } - } - virtual void UpdateScale() - { - scale = Settings::Instance().em(monitor)->DPIScale(); - } - - session::Manager::Ptr session_manager_; - indicator::Indicators::Ptr indicators_; - Accelerators::Ptr accelerators_; - nux::ObjectPtr<AbstractUserPromptView> prompt_view_; - std::shared_ptr<BackgroundSettings> bg_settings_; - std::unique_ptr<nux::AbstractPaintLayer> background_layer_; - connection::Wrapper regrab_conn_; - glib::Source::UniquePtr regrab_timeout_; -}; - -} // lockscreen -} // unity - -#endif // UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H diff --git a/lockscreen/LockScreenBaseShield.cpp b/lockscreen/LockScreenBaseShield.cpp new file mode 100644 index 000000000..0d65550c3 --- /dev/null +++ b/lockscreen/LockScreenBaseShield.cpp @@ -0,0 +1,173 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2015 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> + */ + +#include "LockScreenBaseShield.h" + +#include "BackgroundSettings.h" +#include "CofView.h" +#include "LockScreenAbstractPromptView.h" +#include "LockScreenSettings.h" +#include "unity-shared/MockableBaseWindow.h" +#include "unity-shared/UnitySettings.h" +#include "unity-shared/UScreen.h" +#include "unity-shared/WindowManager.h" + +namespace unity +{ +namespace lockscreen +{ +namespace +{ +const unsigned MAX_GRAB_WAIT = 100; +} + +BaseShield::BaseShield(session::Manager::Ptr const& session, + indicator::Indicators::Ptr const& indicators, + Accelerators::Ptr const& accelerators, + nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, + int monitor_num, bool is_primary) + : MockableBaseWindow("Unity Lockscreen") + , primary(is_primary) + , monitor(monitor_num) + , scale(1.0) + , session_manager_(session) + , indicators_(indicators) + , accelerators_(accelerators) + , prompt_view_(prompt_view) + , bg_settings_(std::make_shared<BackgroundSettings>()) + , cof_view_(nullptr) +{ + UpdateScale(); + + unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &BaseShield::UpdateScale)); + geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();}); + + monitor.changed.connect([this] (int monitor) { + UpdateScale(); + UpdateBackgroundTexture(); + }); + + primary.changed.connect([this] (bool is_primary) { + regrab_conn_->disconnect(); + is_primary ? ShowPrimaryView() : ShowSecondaryView(); + QueueRelayout(); + QueueDraw(); + }); + + scale.changed.connect([this] (double scale) { + if (prompt_view_ && primary()) + prompt_view_->scale = scale; + + if (cof_view_) + cof_view_->scale = scale; + + if (prompt_layout_) + prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale)); + + background_layer_.reset(); + UpdateBackgroundTexture(); + }); + + mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) { + auto const& abs_geo = GetAbsoluteGeometry(); + grab_motion.emit(abs_geo.x + x, abs_geo.y + y); + }); +} + +bool BaseShield::HasGrab() const +{ + auto& wc = nux::GetWindowCompositor(); + return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this); +} + +nux::Area* BaseShield::FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type) +{ + nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type); + + if (!area && primary) + return this; + + return area; +} + +void BaseShield::GrabScreen(bool cancel_on_failure) +{ + auto& wc = nux::GetWindowCompositor(); + + if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this)) + { + regrab_conn_->disconnect(); + regrab_timeout_.reset(); + grabbed.emit(); + } + else + { + auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &BaseShield::GrabScreen), false); + regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb); + + if (cancel_on_failure) + { + regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] { + grab_failed.emit(); + return false; + })); + } + } +} + +void BaseShield::UpdateBackgroundTexture() +{ + auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor); + + if (!background_layer_ || monitor_geo != background_layer_->GetGeometry()) + { + auto background_texture = bg_settings_->GetBackgroundTexture(monitor); + background_layer_.reset(new nux::TextureLayer(background_texture->GetDeviceTexture(), nux::TexCoordXForm(), nux::color::White, true)); + SetBackgroundLayer(background_layer_.get()); + } +} + +void BaseShield::UpdateScale() +{ + scale = unity::Settings::Instance().em(monitor)->DPIScale(); +} + +void BaseShield::ShowSecondaryView() +{ + if (prompt_layout_) + prompt_layout_->RemoveChildObject(prompt_view_.GetPointer()); + + if (cof_layout_) + { + SetLayout(cof_layout_.GetPointer()); + return; + } + + nux::Layout* main_layout = new nux::VLayout(); + cof_layout_ = main_layout; + SetLayout(cof_layout_.GetPointer()); + + // The circle of friends + cof_view_ = new CofView(); + cof_view_->scale = scale(); + main_layout->AddView(cof_view_); +} + +} // lockscreen +} // unity diff --git a/lockscreen/LockScreenBaseShield.h b/lockscreen/LockScreenBaseShield.h new file mode 100644 index 000000000..7a2192144 --- /dev/null +++ b/lockscreen/LockScreenBaseShield.h @@ -0,0 +1,88 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2014-2015 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_BASE_SHIELD_H +#define UNITY_LOCKSCREEN_BASE_SHIELD_H + +#include <NuxCore/Property.h> +#include <UnityCore/SessionManager.h> +#include <UnityCore/Indicators.h> +#include <UnityCore/GLibSource.h> +#include "unity-shared/MockableBaseWindow.h" + +#include "LockScreenAccelerators.h" + +namespace unity +{ +namespace lockscreen +{ +class BackgroundSettings; +class AbstractUserPromptView; +class CofView; + +class BaseShield : public MockableBaseWindow +{ +public: + BaseShield(session::Manager::Ptr const&, indicator::Indicators::Ptr const&, + Accelerators::Ptr const&, nux::ObjectPtr<AbstractUserPromptView> const&, + int monitor_num, bool is_primary); + + nux::Property<bool> primary; + nux::Property<int> monitor; + nux::Property<double> scale; + + bool HasGrab() const; + virtual bool IsIndicatorOpen() const { return false; } + virtual void ActivatePanel() {} + using MockableBaseWindow::RemoveLayout; + + sigc::signal<void> grabbed; + sigc::signal<void> grab_failed; + sigc::signal<void, int, int> grab_motion; + sigc::signal<void, unsigned long, unsigned long> grab_key; + +protected: + virtual bool AcceptKeyNavFocus() { return false; } + virtual void ShowPrimaryView() = 0; + virtual void ShowSecondaryView(); + + nux::Area* FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type) override; + + void GrabScreen(bool cancel_on_failure); + void UpdateBackgroundTexture(); + void UpdateScale(); + + session::Manager::Ptr session_manager_; + indicator::Indicators::Ptr indicators_; + Accelerators::Ptr accelerators_; + nux::ObjectPtr<AbstractUserPromptView> prompt_view_; + std::shared_ptr<BackgroundSettings> bg_settings_; + std::unique_ptr<nux::AbstractPaintLayer> background_layer_; + nux::ObjectPtr<nux::Layout> primary_layout_; + nux::ObjectPtr<nux::Layout> prompt_layout_; + nux::ObjectPtr<nux::Layout> cof_layout_; + CofView* cof_view_; + connection::Wrapper regrab_conn_; + glib::Source::UniquePtr regrab_timeout_; +}; + +} // lockscreen +} // unity + +#endif // UNITY_LOCKSCREEN_BASE_SHIELD_H diff --git a/lockscreen/LockScreenController.cpp b/lockscreen/LockScreenController.cpp index f6dda343d..3bd91a0b3 100644 --- a/lockscreen/LockScreenController.cpp +++ b/lockscreen/LockScreenController.cpp @@ -23,13 +23,12 @@ #include <UnityCore/GLibDBusProxy.h> #include <NuxCore/Logger.h> -#include "KylinUserPromptView.h" +#include "LockScreenAbstractPromptView.h" +#include "LockScreenPromptFactory.h" #include "LockScreenShield.h" #include "LockScreenSettings.h" -#include "UserPromptView.h" #include "unity-shared/AnimationUtils.h" #include "unity-shared/UScreen.h" -#include "unity-shared/UnitySettings.h" #include "unity-shared/WindowManager.h" namespace unity @@ -227,10 +226,7 @@ void Controller::EnsureShields(std::vector<nux::Geometry> const& monitors) if (!prompt_view) { - if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN) - prompt_view = test_mode_ ? nullptr : new KylinUserPromptView(session_manager_); - else - prompt_view = test_mode_ ? nullptr : new UserPromptView(session_manager_); + prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_); prompt_view_ = prompt_view.GetPointer(); } diff --git a/lockscreen/LockScreenController.h b/lockscreen/LockScreenController.h index f0550e89e..839028369 100644 --- a/lockscreen/LockScreenController.h +++ b/lockscreen/LockScreenController.h @@ -24,7 +24,7 @@ #include <UnityCore/ConnectionManager.h> #include <UnityCore/GLibSource.h> -#include "LockScreenAbstractPromptView.h" +#include "LockScreenBaseShield.h" #include "LockScreenShieldFactory.h" #include "LockScreenAcceleratorController.h" #include "ScreenSaverDBusManager.h" @@ -77,8 +77,8 @@ private: void OnScreenSaverActivationRequest(bool activate); void OnPrimaryShieldMotion(int x, int y); - std::vector<nux::ObjectPtr<AbstractShield>> shields_; - nux::ObjectWeakPtr<AbstractShield> primary_shield_; + std::vector<nux::ObjectPtr<BaseShield>> shields_; + nux::ObjectWeakPtr<BaseShield> primary_shield_; nux::ObjectWeakPtr<AbstractUserPromptView> prompt_view_; nux::ObjectPtr<nux::BaseWindow> blank_window_; diff --git a/lockscreen/LockScreenPromptFactory.cpp b/lockscreen/LockScreenPromptFactory.cpp new file mode 100644 index 000000000..02e39eb24 --- /dev/null +++ b/lockscreen/LockScreenPromptFactory.cpp @@ -0,0 +1,42 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2015 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> +*/ + +#include "LockScreenPromptFactory.h" +#include "KylinUserPromptView.h" +#include "UserPromptView.h" +#include "unity-shared/UnitySettings.h" + +namespace unity +{ +namespace lockscreen +{ +nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm) +{ + nux::ObjectPtr<AbstractUserPromptView> prompt; + + if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN) + prompt = new KylinUserPromptView(sm); + else + prompt = new UserPromptView(sm); + + return prompt; +} + +} +} diff --git a/lockscreen/LockScreenPromptFactory.h b/lockscreen/LockScreenPromptFactory.h new file mode 100644 index 000000000..af21e1982 --- /dev/null +++ b/lockscreen/LockScreenPromptFactory.h @@ -0,0 +1,42 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2015 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_PROMPT_FACTORY +#define UNITY_LOCKSCREEN_PROMPT_FACTORY + +#include <NuxCore/NuxCore.h> +#include <UnityCore/SessionManager.h> + +namespace unity +{ +class MockableBaseWindow; + +namespace lockscreen +{ +class AbstractUserPromptView; + +struct PromptFactory +{ + static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&); +}; + +} +} + +#endif // UNITY_LOCKSCREEN_PROMPT_FACTORY diff --git a/lockscreen/LockScreenShield.cpp b/lockscreen/LockScreenShield.cpp index ff31e3e7f..264cf7132 100644 --- a/lockscreen/LockScreenShield.cpp +++ b/lockscreen/LockScreenShield.cpp @@ -21,13 +21,10 @@ #include <Nux/VLayout.h> #include <Nux/HLayout.h> -#include <Nux/PaintLayer.h> -#include "CofView.h" #include "LockScreenPanel.h" #include "LockScreenSettings.h" #include "LockScreenAbstractPromptView.h" -#include "unity-shared/UnitySettings.h" namespace unity { @@ -39,52 +36,19 @@ Shield::Shield(session::Manager::Ptr const& session_manager, Accelerators::Ptr const& accelerators, nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, int monitor_num, bool is_primary) - : AbstractShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary) + : BaseShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary) , panel_view_(nullptr) - , cof_view_(nullptr) { - UpdateScale(); is_primary ? ShowPrimaryView() : ShowSecondaryView(); - EnableInputWindow(true); - unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &Shield::UpdateScale)); - geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();}); - monitor.changed.connect([this] (int monitor) { - UpdateScale(); - if (panel_view_) panel_view_->monitor = monitor; - - UpdateBackgroundTexture(); }); primary.changed.connect([this] (bool is_primary) { - regrab_conn_->disconnect(); - is_primary ? ShowPrimaryView() : ShowSecondaryView(); if (panel_view_) panel_view_->SetInputEventSensitivity(is_primary); - QueueRelayout(); - QueueDraw(); - }); - - scale.changed.connect([this] (double scale) { - if (prompt_view_ && primary()) - prompt_view_->scale = scale; - - if (cof_view_) - cof_view_->scale = scale; - - if (prompt_layout_) - prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale)); - - background_layer_.reset(); - UpdateBackgroundTexture(); - }); - - mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) { - auto const& abs_geo = GetAbsoluteGeometry(); - grab_motion.emit(abs_geo.x + x, abs_geo.y + y); }); } @@ -125,27 +89,6 @@ void Shield::ShowPrimaryView() main_layout->AddSpace(0, 10); } -void Shield::ShowSecondaryView() -{ - if (prompt_layout_) - prompt_layout_->RemoveChildObject(prompt_view_.GetPointer()); - - if (cof_layout_) - { - SetLayout(cof_layout_.GetPointer()); - return; - } - - nux::Layout* main_layout = new nux::VLayout(); - cof_layout_ = main_layout; - SetLayout(cof_layout_.GetPointer()); - - // The circle of friends - cof_view_ = new CofView(); - cof_view_->scale = scale(); - main_layout->AddView(cof_view_); -} - Panel* Shield::CreatePanel() { if (!indicators_ || !session_manager_) diff --git a/lockscreen/LockScreenShield.h b/lockscreen/LockScreenShield.h index 7cc99bcee..053e0102f 100644 --- a/lockscreen/LockScreenShield.h +++ b/lockscreen/LockScreenShield.h @@ -21,20 +21,17 @@ #define UNITY_LOCKSCREEN_SHIELD_H #include <UnityCore/ConnectionManager.h> -#include <UnityCore/GLibSource.h> -#include "LockScreenAbstractShield.h" +#include "LockScreenBaseShield.h" namespace unity { namespace lockscreen { -class UserAuthenticator; class AbstractUserPromptView; class Panel; -class CofView; -class Shield : public AbstractShield +class Shield : public BaseShield { public: Shield(session::Manager::Ptr const&, @@ -50,16 +47,11 @@ protected: nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override; private: - void ShowPrimaryView(); - void ShowSecondaryView(); + void ShowPrimaryView() override; Panel* CreatePanel(); - nux::ObjectPtr<nux::Layout> primary_layout_; - nux::ObjectPtr<nux::Layout> prompt_layout_; - nux::ObjectPtr<nux::Layout> cof_layout_; connection::Wrapper panel_active_conn_; Panel* panel_view_; - CofView* cof_view_; }; } diff --git a/lockscreen/LockScreenShieldFactory.cpp b/lockscreen/LockScreenShieldFactory.cpp index 74bc77c9b..4f8d51ade 100644 --- a/lockscreen/LockScreenShieldFactory.cpp +++ b/lockscreen/LockScreenShieldFactory.cpp @@ -19,7 +19,6 @@ #include "LockScreenShieldFactory.h" #include "LockScreenShield.h" -#include "LockScreenAbstractPromptView.h" #include "KylinLockScreenShield.h" #include "unity-shared/UnitySettings.h" @@ -28,16 +27,20 @@ namespace unity namespace lockscreen { -nux::ObjectPtr<AbstractShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager, - indicator::Indicators::Ptr const& indicators, - Accelerators::Ptr const& accelerators, - nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, - int monitor, bool is_primary) +nux::ObjectPtr<BaseShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager, + indicator::Indicators::Ptr const& indicators, + Accelerators::Ptr const& accelerators, + nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, + int monitor, bool is_primary) { + nux::ObjectPtr<BaseShield> shield; + if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN) - return nux::ObjectPtr<KylinShield>(new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary)); + shield = new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary); else - return nux::ObjectPtr<Shield>(new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary)); + shield = new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary); + + return shield; } } diff --git a/lockscreen/LockScreenShieldFactory.h b/lockscreen/LockScreenShieldFactory.h index b841e1288..1e66b754d 100644 --- a/lockscreen/LockScreenShieldFactory.h +++ b/lockscreen/LockScreenShieldFactory.h @@ -20,18 +20,19 @@ #ifndef UNITY_LOCKSCREEN_SHIELD_FACTORY #define UNITY_LOCKSCREEN_SHIELD_FACTORY -#include <Nux/Nux.h> -#include "LockScreenAbstractShield.h" +#include <NuxCore/NuxCore.h> +#include <UnityCore/SessionManager.h> +#include <UnityCore/Indicators.h> +#include "LockScreenAccelerators.h" namespace unity { - class MockableBaseWindow; namespace lockscreen { - class AbstractUserPromptView; +class BaseShield; struct ShieldFactoryInterface { @@ -39,23 +40,23 @@ struct ShieldFactoryInterface virtual ~ShieldFactoryInterface() = default; - virtual nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&, - indicator::Indicators::Ptr const&, - Accelerators::Ptr const&, - nux::ObjectPtr<AbstractUserPromptView> const&, - int monitor, bool is_primary) = 0; + virtual nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&, + indicator::Indicators::Ptr const&, + Accelerators::Ptr const&, + nux::ObjectPtr<AbstractUserPromptView> const&, + int monitor, bool is_primary) = 0; }; struct ShieldFactory : ShieldFactoryInterface { - nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&, - indicator::Indicators::Ptr const&, - Accelerators::Ptr const&, - nux::ObjectPtr<AbstractUserPromptView> const&, - int monitor, bool is_primary) override; + nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&, + indicator::Indicators::Ptr const&, + Accelerators::Ptr const&, + nux::ObjectPtr<AbstractUserPromptView> const&, + int monitor, bool is_primary) override; }; } } -#endif +#endif // UNITY_LOCKSCREEN_SHIELD_FACTORY |
