diff options
| author | handsome_feng <445865575@qq.com> | 2015-09-30 16:44:23 +0800 |
|---|---|---|
| committer | handsome_feng <445865575@qq.com> | 2015-09-30 16:44:23 +0800 |
| commit | b7839144d4a4078a7e0a16aa46d8b2be3fcadaf4 (patch) | |
| tree | ad94ae13d478036fb1b3798efd99eecefe4fed10 | |
| parent | 5c041f59bc7692ba847fa6381eec35c404fc2d37 (diff) | |
Successfully make it an option
(bzr r4016.2.3)
| -rw-r--r-- | lockscreen/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lockscreen/KylinLockScreenShield.cpp | 262 | ||||
| -rw-r--r-- | lockscreen/KylinLockScreenShield.h | 77 | ||||
| -rw-r--r-- | lockscreen/KylinUserPromptView.cpp | 1 | ||||
| -rw-r--r-- | lockscreen/LockScreenAbstractPromptView.h | 85 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.cpp | 6 | ||||
| -rw-r--r-- | lockscreen/LockScreenController.h | 2 | ||||
| -rw-r--r-- | lockscreen/LockScreenShieldFactory.cpp | 6 | ||||
| -rw-r--r-- | lockscreen/UserPromptView.cpp | 2 | ||||
| -rw-r--r-- | lockscreen/UserPromptView.h | 4 |
10 files changed, 439 insertions, 7 deletions
diff --git a/lockscreen/CMakeLists.txt b/lockscreen/CMakeLists.txt index f07de0578..3ccd322aa 100644 --- a/lockscreen/CMakeLists.txt +++ b/lockscreen/CMakeLists.txt @@ -20,6 +20,7 @@ set (LOCKSCREEN_SOURCES BackgroundSettings.cpp CofView.cpp KylinUserPromptView.cpp + KylinLockScreenShield.cpp LockScreenController.cpp LockScreenSettings.cpp LockScreenShield.cpp diff --git a/lockscreen/KylinLockScreenShield.cpp b/lockscreen/KylinLockScreenShield.cpp new file mode 100644 index 000000000..7442f33c0 --- /dev/null +++ b/lockscreen/KylinLockScreenShield.cpp @@ -0,0 +1,262 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2013 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: Andrea Azzarone <andrea.azzarone@canonical.com> +*/ + +#include "KylinLockScreenShield.h" + +#include <Nux/VLayout.h> +#include <Nux/HLayout.h> +#include <Nux/PaintLayer.h> + +#include "BackgroundSettings.h" +#include "CofView.h" +#include "LockScreenPanel.h" +#include "LockScreenSettings.h" +//#include "UserPromptView.h" +#include "KylinUserPromptView.h" +#include "unity-shared/UScreen.h" +#include "unity-shared/UnitySettings.h" +#include "unity-shared/WindowManager.h" + +namespace unity +{ +namespace lockscreen +{ +namespace +{ +const unsigned MAX_GRAB_WAIT = 100; +} + +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) + , bg_settings_(std::make_shared<BackgroundSettings>()) + , panel_view_(nullptr) + , cof_view_(nullptr) +{ + 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 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); + }); +} + +void KylinShield::UpdateScale() +{ + scale = unity::Settings::Instance().em(monitor)->DPIScale(); +} + +void KylinShield::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 KylinShield::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, &KylinShield::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; + })); + } + } +} + +bool KylinShield::HasGrab() const +{ + auto& wc = nux::GetWindowCompositor(); + return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this); +} + +void KylinShield::ShowPrimaryView() +{ + if (primary_layout_) + { + if (prompt_view_) + { + prompt_view_->scale = scale(); + prompt_layout_->AddView(prompt_view_.GetPointer()); + } + + GrabScreen(false); + SetLayout(primary_layout_.GetPointer()); + return; + } + + GrabScreen(true); + nux::Layout* main_layout = new nux::VLayout(); + primary_layout_ = main_layout; + SetLayout(primary_layout_.GetPointer()); + + prompt_layout_ = new nux::HLayout(); + prompt_layout_->SetLeftAndRightPadding(9 * Settings::GRID_SIZE.CP(scale)); + + if (prompt_view_) + { + prompt_view_->scale = scale(); + prompt_layout_->AddView(prompt_view_.GetPointer()); + } + + // 10 is just a random number to center the prompt view. + main_layout->AddSpace(0, 10); + main_layout->AddLayout(prompt_layout_.GetPointer()); + 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) + { + grab_key.emit(modifiers, keysym); + + if (accelerators_) + { + if (etype == nux::EVENT_KEY_DOWN) + { + if (accelerators_->HandleKeyPress(keysym, modifiers)) + return panel_view_; + } + else if (etype == nux::EVENT_KEY_UP) + { + if (accelerators_->HandleKeyRelease(keysym, modifiers)) + return panel_view_; + } + } + + if (prompt_view_) + { + auto* focus_view = prompt_view_->focus_view(); + + if (focus_view && focus_view->GetInputEventSensitivity()) + return focus_view; + } + } + + return nullptr; +} + +bool KylinShield::AcceptKeyNavFocus() +{ + return false; +} + +nux::Area* KylinShield::FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type) +{ + nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type); + + if (!area && primary) + return this; + + return area; +} + +bool KylinShield::IsIndicatorOpen() const +{ + return panel_view_ ? panel_view_->active() : false; +} + +void KylinShield::ActivatePanel() +{ + if (panel_view_) + panel_view_->ActivatePanel(); +} + +} +} diff --git a/lockscreen/KylinLockScreenShield.h b/lockscreen/KylinLockScreenShield.h new file mode 100644 index 000000000..941c41806 --- /dev/null +++ b/lockscreen/KylinLockScreenShield.h @@ -0,0 +1,77 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2013 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: Andrea Azzarone <andrea.azzarone@canonical.com> +*/ + +#ifndef UNITY_KYLIN_LOCKSCREEN_SHIELD_H +#define UNITY_KYLIN_LOCKSCREEN_SHIELD_H + +#include <UnityCore/ConnectionManager.h> +#include <UnityCore/GLibSource.h> +#include "LockScreenAbstractShield.h" + +namespace unity +{ +namespace lockscreen +{ + +class BackgroundSettings; +class UserAuthenticator; +class AbstractUserPromptView; +class Panel; +class CofView; + +class KylinShield : public AbstractShield +{ +public: + KylinShield(session::Manager::Ptr const&, + Accelerators::Ptr const&, + nux::ObjectPtr<AbstractUserPromptView> const&, + int monitor, bool is_primary); + + bool HasGrab() const override; + bool IsIndicatorOpen() const override; + void ActivatePanel() override; + +protected: + bool AcceptKeyNavFocus() override; + nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override; + nux::Area* FindAreaUnderMouse(nux::Point const&, nux::NuxEventType) override; + +private: + void UpdateBackgroundTexture(); + void GrabScreen(bool cancel_on_failure); + void ShowPrimaryView(); + void ShowSecondaryView(); + void UpdateScale(); + + 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_; + connection::Wrapper panel_active_conn_; + connection::Wrapper regrab_conn_; + glib::Source::UniquePtr regrab_timeout_; + Panel* panel_view_; + CofView* cof_view_; +}; + +} +} + +#endif diff --git a/lockscreen/KylinUserPromptView.cpp b/lockscreen/KylinUserPromptView.cpp index 11c876f29..a1d9008c7 100644 --- a/lockscreen/KylinUserPromptView.cpp +++ b/lockscreen/KylinUserPromptView.cpp @@ -178,7 +178,6 @@ KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_ma void KylinUserPromptView::ResetLayout() { - std::cout << "Kylin user prompt view !!" << std::endl; focus_queue_.clear(); SetLayout(new nux::HLayout()); diff --git a/lockscreen/LockScreenAbstractPromptView.h b/lockscreen/LockScreenAbstractPromptView.h new file mode 100644 index 000000000..58051803d --- /dev/null +++ b/lockscreen/LockScreenAbstractPromptView.h @@ -0,0 +1,85 @@ +// -*- 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_USER_PROMPT_H +#define UNITY_LOCKSCREEN_ABSTRACT_USER_PROMPT_H + +#include <memory> +#include <deque> + +#include <Nux/Nux.h> +#include <Nux/View.h> +#include <Nux/VLayout.h> +#include <UnityCore/SessionManager.h> + +#include "UserAuthenticatorPam.h" +#include "unity-shared/IMTextEntry.h" + +namespace nux +{ +class VLayout; +} +namespace unity +{ + +class StaticCairoText; +class TextInput; + +namespace lockscreen +{ + +class AbstractUserPromptView : public nux::View +{ +public: + AbstractUserPromptView(session::Manager::Ptr const& session_manager) + : nux::View(NUX_TRACKER_LOCATION) + , session_manager_(session_manager) + {} + + nux::Property<double> scale; + + virtual nux::View* focus_view() { return this; } + +// virtual void AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise) = 0; +// virtual void AddMessage(std::string const& message, nux::Color const& color) = 0; + virtual void AuthenticationCb(bool authenticated) = 0; + virtual void Draw(nux::GraphicsEngine& graphics_engine, bool /* force_draw */) = 0; + virtual void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) {} + virtual void ResetLayout() = 0; + virtual void UpdateSize() = 0; +// virtual void EnsureBGLayer() = 0; + + virtual bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character) = 0; + +protected: + session::Manager::Ptr session_manager_; + UserAuthenticatorPam user_authenticator_; + std::shared_ptr<nux::AbstractPaintLayer> bg_layer_; + StaticCairoText* username_; + nux::VLayout* msg_layout_; + nux::VLayout* prompt_layout_; + std::deque<TextInput*> focus_queue_; + + nux::Geometry cached_focused_geo_; +}; + +} // lockscreen +} // unity + +#endif // UNITY_LOCKSCREEN_ABSTRACT_USER_PROMPT_H diff --git a/lockscreen/LockScreenController.cpp b/lockscreen/LockScreenController.cpp index fb5d78fc2..572c7a8fb 100644 --- a/lockscreen/LockScreenController.cpp +++ b/lockscreen/LockScreenController.cpp @@ -225,8 +225,10 @@ void Controller::EnsureShields(std::vector<nux::Geometry> const& monitors) if (!prompt_view) { -// prompt_view = test_mode_ ? nullptr : new UserPromptView(session_manager_); - prompt_view = test_mode_ ? nullptr : new KylinUserPromptView(session_manager_); + if (strcmp(getenv("XDG_CURRENT_DESKTOP"), "KYLIN")) + prompt_view = test_mode_ ? nullptr : new UserPromptView(session_manager_); + else + prompt_view = test_mode_ ? nullptr : new KylinUserPromptView(session_manager_); prompt_view_ = prompt_view.GetPointer(); // new KylinUserPromptView(session_manager_); } diff --git a/lockscreen/LockScreenController.h b/lockscreen/LockScreenController.h index fd5328d36..4887744be 100644 --- a/lockscreen/LockScreenController.h +++ b/lockscreen/LockScreenController.h @@ -29,7 +29,7 @@ #include "ScreenSaverDBusManager.h" #include "ShutdownNotifier.h" #include "SuspendNotifier.h" -//#include "UserPromptView.h" +#include "UserPromptView.h" #include "unity-shared/BackgroundEffectHelper.h" #include "unity-shared/UpstartWrapper.h" diff --git a/lockscreen/LockScreenShieldFactory.cpp b/lockscreen/LockScreenShieldFactory.cpp index 0cd31ef8e..72bf11beb 100644 --- a/lockscreen/LockScreenShieldFactory.cpp +++ b/lockscreen/LockScreenShieldFactory.cpp @@ -21,6 +21,7 @@ #include "LockScreenShield.h" //#include "UserPromptView.h" #include "LockScreenAbstractPromptView.h" +#include "KylinLockScreenShield.h" namespace unity { @@ -34,7 +35,10 @@ nux::ObjectPtr<AbstractShield> ShieldFactory::CreateShield(session::Manager::Ptr nux::ObjectPtr<AbstractUserPromptView> const& prompt_view, int monitor, bool is_primary) { - return nux::ObjectPtr<Shield>(new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary)); + if (!strcmp(getenv("XDG_CURRENT_DESKTOP"),"KYLIN")) + return nux::ObjectPtr<KylinShield>(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)); } } diff --git a/lockscreen/UserPromptView.cpp b/lockscreen/UserPromptView.cpp index 064c899d9..32794dfb8 100644 --- a/lockscreen/UserPromptView.cpp +++ b/lockscreen/UserPromptView.cpp @@ -100,7 +100,7 @@ std::string SanitizeMessage(std::string const& message) } UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager) - : nux::View(NUX_TRACKER_LOCATION) + : AbstractUserPromptView(session_manager) , scale(1.0) , session_manager_(session_manager) , username_(nullptr) diff --git a/lockscreen/UserPromptView.h b/lockscreen/UserPromptView.h index f3cad1cb2..15741030b 100644 --- a/lockscreen/UserPromptView.h +++ b/lockscreen/UserPromptView.h @@ -30,6 +30,8 @@ #include "UserAuthenticatorPam.h" #include "unity-shared/IMTextEntry.h" +#include "LockScreenAbstractPromptView.h" + namespace nux { class VLayout; @@ -44,7 +46,7 @@ class TextInput; namespace lockscreen { -class UserPromptView : public nux::View +class UserPromptView : public AbstractUserPromptView { public: UserPromptView(session::Manager::Ptr const& session_manager); |
