Merge lp:~feng-kylin/unity/ExtendLockscreenTheme into lp:unity

Proposed by handsome_feng
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4073
Proposed branch: lp:~feng-kylin/unity/ExtendLockscreenTheme
Merge into: lp:unity
Diff against target: 2249 lines (+1260/-233)
34 files modified
UnityCore/GnomeSessionManager.cpp (+40/-0)
UnityCore/GnomeSessionManager.h (+2/-0)
UnityCore/GnomeSessionManagerImpl.h (+3/-0)
UnityCore/SessionManager.h (+2/-0)
com.canonical.Unity.gschema.xml (+9/-0)
lockscreen/CMakeLists.txt (+4/-0)
lockscreen/KylinLockScreenShield.cpp (+99/-0)
lockscreen/KylinLockScreenShield.h (+54/-0)
lockscreen/KylinUserPromptView.cpp (+402/-0)
lockscreen/KylinUserPromptView.h (+84/-0)
lockscreen/LockScreenAbstractPromptView.h (+79/-0)
lockscreen/LockScreenBaseShield.cpp (+173/-0)
lockscreen/LockScreenBaseShield.h (+36/-27)
lockscreen/LockScreenController.cpp (+4/-2)
lockscreen/LockScreenController.h (+5/-5)
lockscreen/LockScreenPromptFactory.cpp (+42/-0)
lockscreen/LockScreenPromptFactory.h (+42/-0)
lockscreen/LockScreenShield.cpp (+4/-132)
lockscreen/LockScreenShield.h (+5/-24)
lockscreen/LockScreenShieldFactory.cpp (+15/-7)
lockscreen/LockScreenShieldFactory.h (+17/-16)
lockscreen/UserPromptView.cpp (+1/-1)
lockscreen/UserPromptView.h (+2/-1)
resources/login.svg (+8/-0)
resources/switch_user.svg (+13/-0)
shutdown/StandaloneSession.cpp (+2/-0)
tests/test_gnome_session_manager.cpp (+32/-0)
tests/test_lockscreen_controller.cpp (+10/-9)
tests/test_mock_session_manager.h (+3/-0)
tests/test_unity_settings.cpp (+10/-0)
unity-shared/TextInput.cpp (+35/-8)
unity-shared/TextInput.h (+9/-1)
unity-shared/UnitySettings.cpp (+7/-0)
unity-shared/UnitySettings.h (+7/-0)
To merge this branch: bzr merge lp:~feng-kylin/unity/ExtendLockscreenTheme
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+277084@code.launchpad.net

Commit message

Extend the lockscreen theme for kylin.

Description of the change

Extend the lockscreen theme.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

As a first thing (i'm going into details soon), I think you should properly re-base your changes with trunk because this branch is reverting many changes happened upstream.

Looking at what changed, I think you should probably uncommit your last revision (4040, which is the one causing troubles), and push here again.

So:
bzr shelve --all -m tmp
bzr uncommit
bzr revert
bzr push --overwrite lp:~feng-kylin/unity/ExtendLockscreenTheme
bzr unshelve

If you need to revert 4038, use:
bzr merge -r 4038..4037 .

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ah, also revert the changes applied at po files at revision 4022

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks nice and works well, there are some improvements to do, though.

See the inline comments I wrote.

Let's try to share the most of the code we can, and to make things to be more customizable.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

I would prefer to call LockScreenAbstractShield as LockScreenBaseShield and moving the implementation in a cpp file.

I can do this kind of work, so I can double-check that both implementations keep the things together.
Let me know if it's fine if I provide a branch that you can merge with this.

Revision history for this message
handsome_feng (feng-kylin) wrote :

> I would prefer to call LockScreenAbstractShield as LockScreenBaseShield and
> moving the implementation in a cpp file.
>
> I can do this kind of work, so I can double-check that both implementations
> keep the things together.
> Let me know if it's fine if I provide a branch that you can merge with this.

Sure, It's fine.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

So, I've done some cleanup to this, adding the LockScreenBaseShield class, you can merge with lp:~3v1n0/unity/kylin-lockscreen-cleanup

See the merge proposal at lp:~3v1n0/unity/kylin-lockscreen-cleanup/+merge/279546 for the diff.

Revision history for this message
handsome_feng (feng-kylin) wrote :

> So, I've done some cleanup to this, adding the LockScreenBaseShield class, you
> can merge with lp:~3v1n0/unity/kylin-lockscreen-cleanup
>
> See the merge proposal at lp:~3v1n0/unity/kylin-lockscreen-
> cleanup/+merge/279546 for the diff.

I have merged your branch, it works well. thank you!
and I modified some copyright notices in some file(not sure whether it's right,
If there is anything wrong, please point it out :) ).

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, I can say it looks good now...

Thanks a lot!

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

This branch doesn't build anymore now when merged to trunk:

/«BUILDDIR»/unity-7.4.0+16.04.20160114/lockscreen/KylinUserPromptView.cpp: In member function 'void unity::lockscreen::KylinUserPromptView::AddPrompt(const string&, bool, const PromiseAuthCodePtr&)':
/«BUILDDIR»/unity-7.4.0+16.04.20160114/lockscreen/KylinUserPromptView.cpp:299:15: error: 'class unity::TextInput' has no member named 'show_caps_lock'
   text_input->show_caps_lock = true;

Can you please fix this by replacing "show_caps_lock" with "show_lock_warnings" ?

Thanks

Revision history for this message
handsome_feng (feng-kylin) wrote :

> This branch doesn't build anymore now when merged to trunk:
>
> /«BUILDDIR»/unity-7.4.0+16.04.20160114/lockscreen/KylinUserPromptView.cpp: In
> member function 'void unity::lockscreen::KylinUserPromptView::AddPrompt(const
> string&, bool, const PromiseAuthCodePtr&)':
> /«BUILDDIR»/unity-7.4.0+16.04.20160114/lockscreen/KylinUserPromptView.cpp:299:
> 15: error: 'class unity::TextInput' has no member named 'show_caps_lock'
> text_input->show_caps_lock = true;
>
> Can you please fix this by replacing "show_caps_lock" with
> "show_lock_warnings" ?
>
> Thanks

Done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/GnomeSessionManager.cpp'
--- UnityCore/GnomeSessionManager.cpp 2015-09-10 15:37:07 +0000
+++ UnityCore/GnomeSessionManager.cpp 2016-01-15 01:41:44 +0000
@@ -155,6 +155,13 @@
155 });155 });
156 }156 }
157157
158 {
159 dm_seat_proxy_ = std::make_shared<glib::DBusProxy>("org.freedesktop.Accounts",
160 ("/org/freedesktop/Accounts/User" + std::to_string(getuid())).c_str(),
161 "org.freedesktop.Accounts.User",
162 G_BUS_TYPE_SYSTEM);
163 }
164
158 CallLogindMethod("CanHibernate", nullptr, [this] (GVariant* variant, glib::Error const& err) {165 CallLogindMethod("CanHibernate", nullptr, [this] (GVariant* variant, glib::Error const& err) {
159 if (err)166 if (err)
160 {167 {
@@ -429,6 +436,22 @@
429 });436 });
430}437}
431438
439void GnomeManager::Impl::CallDisplayManagerSeatMethod(std::string const& method, GVariant* parameters)
440{
441 const char* xdg_seat_path = test_mode_ ? "/org/freedesktop/DisplayManager/Seat0" : g_getenv("XDG_SEAT_PATH");
442
443 auto proxy = std::make_shared<glib::DBusProxy>(test_mode_ ? testing::DBUS_NAME : "org.freedesktop.DisplayManager",
444 glib::gchar_to_string(xdg_seat_path),
445 "org.freedesktop.DisplayManager.Seat",
446 test_mode_ ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM);
447 proxy->CallBegin(method, parameters, [this, proxy] (GVariant*, glib::Error const& e) {
448 if (e)
449 {
450 LOG_ERROR(logger) << "DisplayManager Seat call failed: " << e.Message();
451 }
452 });
453}
454
432void GnomeManager::Impl::LockScreen(bool prompt)455void GnomeManager::Impl::LockScreen(bool prompt)
433{456{
434 EnsureCancelPendingAction();457 EnsureCancelPendingAction();
@@ -490,6 +513,13 @@
490 return inhibitors.GetBool();513 return inhibitors.GetBool();
491}514}
492515
516void GnomeManager::Impl::UserIconFile(std::function<void(std::string const&)> const& callback)
517{
518 dm_seat_proxy_->GetProperty("IconFile", [this, callback] (GVariant *value) {
519 callback(glib::Variant(value).GetString());
520 });
521}
522
493bool GnomeManager::Impl::IsUserInGroup(std::string const& user_name, std::string const& group_name)523bool GnomeManager::Impl::IsUserInGroup(std::string const& user_name, std::string const& group_name)
494{524{
495 auto group = getgrnam(group_name.c_str());525 auto group = getgrnam(group_name.c_str());
@@ -535,6 +565,11 @@
535 return glib::gchar_to_string(g_get_host_name());565 return glib::gchar_to_string(g_get_host_name());
536}566}
537567
568void GnomeManager::UserIconFile(std::function<void(std::string const&)> const& callback) const
569{
570 impl_->UserIconFile(callback);
571}
572
538void GnomeManager::ScreenSaverActivate()573void GnomeManager::ScreenSaverActivate()
539{574{
540 screensaver_requested.emit(true);575 screensaver_requested.emit(true);
@@ -665,6 +700,11 @@
665 });700 });
666}701}
667702
703void GnomeManager::SwitchToGreeter()
704{
705 impl_->CallDisplayManagerSeatMethod("SwitchToGreeter");
706}
707
668bool GnomeManager::CanLock() const708bool GnomeManager::CanLock() const
669{709{
670 if (is_locked())710 if (is_locked())
671711
=== modified file 'UnityCore/GnomeSessionManager.h'
--- UnityCore/GnomeSessionManager.h 2014-05-16 04:24:05 +0000
+++ UnityCore/GnomeSessionManager.h 2016-01-15 01:41:44 +0000
@@ -36,6 +36,7 @@
36 std::string RealName() const;36 std::string RealName() const;
37 std::string UserName() const;37 std::string UserName() const;
38 std::string HostName() const;38 std::string HostName() const;
39 void UserIconFile(std::function<void(std::string const&)> const&) const;
3940
40 void ScreenSaverActivate();41 void ScreenSaverActivate();
41 void ScreenSaverDeactivate();42 void ScreenSaverDeactivate();
@@ -46,6 +47,7 @@
46 void Shutdown();47 void Shutdown();
47 void Suspend();48 void Suspend();
48 void Hibernate();49 void Hibernate();
50 void SwitchToGreeter();
4951
50 bool CanLock() const;52 bool CanLock() const;
51 bool CanShutdown() const;53 bool CanShutdown() const;
5254
=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
--- UnityCore/GnomeSessionManagerImpl.h 2015-01-24 00:56:37 +0000
+++ UnityCore/GnomeSessionManagerImpl.h 2016-01-15 01:41:44 +0000
@@ -54,6 +54,7 @@
54 bool HasInhibitors();54 bool HasInhibitors();
55 void EnsureCancelPendingAction();55 void EnsureCancelPendingAction();
56 void LockScreen(bool prompt);56 void LockScreen(bool prompt);
57 void UserIconFile(std::function<void(std::string const&)> const& callback);
5758
58 GVariant* OnShellMethodCall(std::string const& method, GVariant* parameters);59 GVariant* OnShellMethodCall(std::string const& method, GVariant* parameters);
59 void CallGnomeSessionMethod(std::string const& method, GVariant* parameters = nullptr,60 void CallGnomeSessionMethod(std::string const& method, GVariant* parameters = nullptr,
@@ -61,6 +62,7 @@
61 void CallUPowerMethod(std::string const& method, glib::DBusProxy::ReplyCallback const& cb = nullptr);62 void CallUPowerMethod(std::string const& method, glib::DBusProxy::ReplyCallback const& cb = nullptr);
62 void CallLogindMethod(std::string const& method, GVariant* parameters = nullptr, glib::DBusProxy::CallFinishedCallback const& cb = nullptr);63 void CallLogindMethod(std::string const& method, GVariant* parameters = nullptr, glib::DBusProxy::CallFinishedCallback const& cb = nullptr);
63 void CallConsoleKitMethod(std::string const& method, GVariant* parameters = nullptr);64 void CallConsoleKitMethod(std::string const& method, GVariant* parameters = nullptr);
65 void CallDisplayManagerSeatMethod(std::string const& method, GVariant* parameters = nullptr);
64 bool InteractiveMode();66 bool InteractiveMode();
65 void UpdateHaveOtherOpenSessions();67 void UpdateHaveOtherOpenSessions();
6668
@@ -78,6 +80,7 @@
78 glib::DBusProxy::Ptr login_proxy_;80 glib::DBusProxy::Ptr login_proxy_;
79 glib::DBusProxy::Ptr presence_proxy_;81 glib::DBusProxy::Ptr presence_proxy_;
80 glib::DBusProxy::Ptr dm_proxy_;82 glib::DBusProxy::Ptr dm_proxy_;
83 glib::DBusProxy::Ptr dm_seat_proxy_;
8184
82 int open_sessions_;85 int open_sessions_;
83};86};
8487
=== modified file 'UnityCore/SessionManager.h'
--- UnityCore/SessionManager.h 2014-05-16 04:24:05 +0000
+++ UnityCore/SessionManager.h 2016-01-15 01:41:44 +0000
@@ -44,6 +44,7 @@
44 virtual std::string RealName() const = 0;44 virtual std::string RealName() const = 0;
45 virtual std::string UserName() const = 0;45 virtual std::string UserName() const = 0;
46 virtual std::string HostName() const = 0;46 virtual std::string HostName() const = 0;
47 virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0;
4748
48 virtual void ScreenSaverActivate() = 0;49 virtual void ScreenSaverActivate() = 0;
49 virtual void ScreenSaverDeactivate() = 0;50 virtual void ScreenSaverDeactivate() = 0;
@@ -54,6 +55,7 @@
54 virtual void Shutdown() = 0;55 virtual void Shutdown() = 0;
55 virtual void Suspend() = 0;56 virtual void Suspend() = 0;
56 virtual void Hibernate() = 0;57 virtual void Hibernate() = 0;
58 virtual void SwitchToGreeter() = 0;
5759
58 virtual bool CanLock() const = 0;60 virtual bool CanLock() const = 0;
59 virtual bool CanShutdown() const = 0;61 virtual bool CanShutdown() const = 0;
6062
=== modified file 'com.canonical.Unity.gschema.xml'
--- com.canonical.Unity.gschema.xml 2015-09-17 16:44:26 +0000
+++ com.canonical.Unity.gschema.xml 2016-01-15 01:41:44 +0000
@@ -9,6 +9,10 @@
9 <value nick="Not Expanded" value="0" />9 <value nick="Not Expanded" value="0" />
10 <value nick="Expanded" value="1" />10 <value nick="Expanded" value="1" />
11 </enum>11 </enum>
12 <enum id="desktop-type-enum">
13 <value nick="Ubuntu" value="0" />
14 <value nick="UbuntuKylin" value="1" />
15 </enum>
1216
13 <schema path="/com/canonical/unity/" id="com.canonical.Unity" gettext-domain="unity">17 <schema path="/com/canonical/unity/" id="com.canonical.Unity" gettext-domain="unity">
14 <key enum="form-factor-enum" name="form-factor">18 <key enum="form-factor-enum" name="form-factor">
@@ -21,6 +25,11 @@
21 <summary>Whether the home screen should be expanded.</summary>25 <summary>Whether the home screen should be expanded.</summary>
22 <description>Whether the home screen should be expanded.</description>26 <description>Whether the home screen should be expanded.</description>
23 </key>27 </key>
28 <key enum="desktop-type-enum" name="desktop-type">
29 <default>"Ubuntu"</default>
30 <summary>The current desktop name.</summary>
31 <description>The current desktop name.</description>
32 </key>
24 <key type="i" name="minimize-count">33 <key type="i" name="minimize-count">
25 <default>0</default>34 <default>0</default>
26 <summary>Number of times a normal window has been minimized.</summary>35 <summary>Number of times a normal window has been minimized.</summary>
2736
=== modified file 'lockscreen/CMakeLists.txt'
--- lockscreen/CMakeLists.txt 2015-07-31 12:16:54 +0000
+++ lockscreen/CMakeLists.txt 2016-01-15 01:41:44 +0000
@@ -19,11 +19,15 @@
19set (LOCKSCREEN_SOURCES19set (LOCKSCREEN_SOURCES
20 BackgroundSettings.cpp20 BackgroundSettings.cpp
21 CofView.cpp21 CofView.cpp
22 KylinUserPromptView.cpp
23 KylinLockScreenShield.cpp
22 LockScreenController.cpp24 LockScreenController.cpp
25 LockScreenBaseShield.cpp
23 LockScreenSettings.cpp26 LockScreenSettings.cpp
24 LockScreenShield.cpp27 LockScreenShield.cpp
25 LockScreenShieldFactory.cpp28 LockScreenShieldFactory.cpp
26 LockScreenPanel.cpp29 LockScreenPanel.cpp
30 LockScreenPromptFactory.cpp
27 LockScreenAcceleratorController.cpp31 LockScreenAcceleratorController.cpp
28 LockScreenAccelerators.cpp32 LockScreenAccelerators.cpp
29 ScreenSaverDBusManager.cpp33 ScreenSaverDBusManager.cpp
3034
=== added file 'lockscreen/KylinLockScreenShield.cpp'
--- lockscreen/KylinLockScreenShield.cpp 1970-01-01 00:00:00 +0000
+++ lockscreen/KylinLockScreenShield.cpp 2016-01-15 01:41:44 +0000
@@ -0,0 +1,99 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4* 2015, National University of Defense Technology(NUDT) & Kylin Ltd
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 3 as
8* published by the Free Software Foundation.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
19* handsome_feng <jianfengli@ubuntukylin.com>
20*/
21
22#include "KylinLockScreenShield.h"
23
24#include <Nux/VLayout.h>
25#include <Nux/HLayout.h>
26
27#include "CofView.h"
28#include "LockScreenSettings.h"
29#include "LockScreenAbstractPromptView.h"
30
31namespace unity
32{
33namespace lockscreen
34{
35
36KylinShield::KylinShield(session::Manager::Ptr const& session_manager,
37 Accelerators::Ptr const& accelerators,
38 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
39 int monitor_num, bool is_primary)
40 : BaseShield(session_manager, nullptr, accelerators, prompt_view, monitor_num, is_primary)
41{
42 is_primary ? ShowPrimaryView() : ShowSecondaryView();
43 EnableInputWindow(true);
44}
45
46void KylinShield::ShowPrimaryView()
47{
48 if (primary_layout_)
49 {
50 if (prompt_view_)
51 {
52 prompt_view_->scale = scale();
53 prompt_layout_->AddView(prompt_view_.GetPointer());
54 }
55
56 GrabScreen(false);
57 SetLayout(primary_layout_.GetPointer());
58 return;
59 }
60
61 GrabScreen(true);
62 nux::Layout* main_layout = new nux::VLayout();
63 primary_layout_ = main_layout;
64 SetLayout(primary_layout_.GetPointer());
65
66 prompt_layout_ = new nux::HLayout();
67
68 if (prompt_view_)
69 {
70 prompt_view_->scale = scale();
71 prompt_layout_->AddView(prompt_view_.GetPointer());
72 }
73
74 // 10 is just a random number to center the prompt view.
75 main_layout->AddSpace(0, 10);
76 main_layout->AddLayout(prompt_layout_.GetPointer(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
77 main_layout->AddSpace(0, 10);
78}
79
80nux::Area* KylinShield::FindKeyFocusArea(unsigned etype, unsigned long keysym, unsigned long modifiers)
81{
82 if (primary)
83 {
84 grab_key.emit(modifiers, keysym);
85
86 if (prompt_view_)
87 {
88 auto* focus_view = prompt_view_->focus_view();
89
90 if (focus_view && focus_view->GetInputEventSensitivity())
91 return focus_view;
92 }
93 }
94
95 return nullptr;
96}
97
98}
99}
0100
=== added file 'lockscreen/KylinLockScreenShield.h'
--- lockscreen/KylinLockScreenShield.h 1970-01-01 00:00:00 +0000
+++ lockscreen/KylinLockScreenShield.h 2016-01-15 01:41:44 +0000
@@ -0,0 +1,54 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4* 2015, National University of Defense Technology(NUDT) & Kylin Ltd
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 3 as
8* published by the Free Software Foundation.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
19* handsome_feng <jianfengli@ubuntukylin.com>
20*/
21
22#ifndef UNITY_KYLIN_LOCKSCREEN_SHIELD_H
23#define UNITY_KYLIN_LOCKSCREEN_SHIELD_H
24
25#include <UnityCore/ConnectionManager.h>
26#include <UnityCore/GLibSource.h>
27#include "LockScreenBaseShield.h"
28
29namespace unity
30{
31namespace lockscreen
32{
33
34class AbstractUserPromptView;
35
36class KylinShield : public BaseShield
37{
38public:
39 KylinShield(session::Manager::Ptr const&,
40 Accelerators::Ptr const&,
41 nux::ObjectPtr<AbstractUserPromptView> const&,
42 int monitor, bool is_primary);
43
44protected:
45 nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override;
46
47private:
48 void ShowPrimaryView() override;
49};
50
51}
52}
53
54#endif
055
=== added file 'lockscreen/KylinUserPromptView.cpp'
--- lockscreen/KylinUserPromptView.cpp 1970-01-01 00:00:00 +0000
+++ lockscreen/KylinUserPromptView.cpp 2016-01-15 01:41:44 +0000
@@ -0,0 +1,402 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4* 2015, National University of Defense Technology(NUDT) & Kylin Ltd
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 3 as
8* published by the Free Software Foundation.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
19* handsome_feng <jianfengli@ubuntukylin.com>
20*/
21
22#include "KylinUserPromptView.h"
23
24#include "config.h"
25#include <gtk/gtk.h>
26#include <glib/gi18n-lib.h>
27
28#include <boost/algorithm/string/trim.hpp>
29#include <Nux/VLayout.h>
30#include <Nux/HLayout.h>
31#include <NuxCore/Logger.h>
32#include "Variant.h"
33
34#include "LockScreenSettings.h"
35#include "unity-shared/CairoTexture.h"
36#include "unity-shared/TextInput.h"
37#include "unity-shared/StaticCairoText.h"
38#include "unity-shared/RawPixel.h"
39#include "unity-shared/IconTexture.h"
40#include "unity-shared/TextureCache.h"
41
42namespace unity
43{
44namespace lockscreen
45{
46namespace
47{
48const RawPixel AVATAR_SIZE = 128_em;
49const RawPixel ACTIVATOR_ICON_SIZE = 34_em;
50const RawPixel LAYOUT_MARGIN = 20_em;
51const RawPixel MSG_LAYOUT_MARGIN = 15_em;
52const RawPixel MSG_LAYOUT_PADDING = 33_em;
53const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
54const RawPixel SWITCH_ICON_SIZE = 34_em;
55const RawPixel TEXT_INPUT_HEIGHT = 36_em;
56const RawPixel TEXT_INPUT_WIDTH = 320_em;
57const int PROMPT_FONT_SIZE = 14;
58
59const std::string ACTIVATOR_ICON = "login.svg";
60
61std::string SanitizeMessage(std::string const& message)
62{
63 std::string msg = boost::algorithm::trim_copy(message);
64
65 if (msg.empty())
66 return msg;
67
68 if (msg[msg.size()-1] == ':')
69 msg = msg.substr(0, msg.size()-1);
70
71 if (msg == "Password")
72 return _("Password");
73
74 if (msg == "login")
75 return _("Username");
76
77 return msg;
78}
79
80}
81
82KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_manager)
83 : AbstractUserPromptView(session_manager)
84 , scale(1.0)
85 , session_manager_(session_manager)
86 , username_(nullptr)
87 , msg_layout_(nullptr)
88 , prompt_layout_(nullptr)
89 , avatar_layout_(nullptr)
90 , switch_icon_(nullptr)
91 , avatar_(nullptr)
92 , avatar_icon_file("")
93{
94 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
95 AddPrompt(message, true, promise);
96 });
97
98 user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
99 AddPrompt(message, false, promise);
100 });
101
102 user_authenticator_.message_requested.connect([this](std::string const& message){
103 AddMessage(message, nux::color::White);
104 });
105
106 user_authenticator_.error_requested.connect([this](std::string const& message){
107 AddMessage(message, nux::color::Red);
108 });
109
110 user_authenticator_.clear_prompts.connect([this](){
111 ResetLayout();
112 });
113
114 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize)));
115
116 session_manager_->UserIconFile([this] (std::string const& value) {
117 avatar_icon_file = value;
118 AddAvatar(value, AVATAR_SIZE.CP(scale));
119 });
120
121 UpdateSize();
122 ResetLayout();
123
124 user_authenticator_.AuthenticateStart(session_manager_->UserName(),
125 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));
126}
127
128void KylinUserPromptView::ResetLayout()
129{
130 focus_queue_.clear();
131
132 SetLayout(new nux::HLayout());
133
134 static_cast<nux::HLayout*>(GetLayout())->SetHorizontalInternalMargin(LAYOUT_MARGIN.CP(scale));
135
136 if (g_getenv("XDG_SEAT_PATH"))
137 {
138 nux::Layout* switch_layout = new nux::HLayout();
139
140 TextureCache& cache = TextureCache::GetDefault();
141 switch_icon_ = new IconTexture(cache.FindTexture("switch_user.svg", SWITCH_ICON_SIZE.CP(scale), SWITCH_ICON_SIZE.CP(scale)));
142 switch_layout->AddView(switch_icon_);
143 switch_icon_->mouse_click.connect([this](int x, int y, unsigned long button_flags, unsigned long key_flags) {
144 session_manager_->SwitchToGreeter();
145 });
146 switch_layout->SetMaximumSize(SWITCH_ICON_SIZE.CP(scale), SWITCH_ICON_SIZE.CP(scale));
147 GetLayout()->AddLayout(switch_layout);
148 }
149
150 avatar_layout_ = new nux::VLayout();
151 if (!avatar_icon_file().empty())
152 AddAvatar(avatar_icon_file(), AVATAR_SIZE.CP(scale));
153 GetLayout()->AddLayout(avatar_layout_);
154
155 nux::Layout* prompt_layout = new nux::VLayout();
156
157 auto const& real_name = session_manager_->RealName();
158 auto const& name = (real_name.empty() ? session_manager_->UserName() : real_name);
159
160 username_ = new unity::StaticCairoText(name);
161 username_->SetScale(scale);
162 username_->SetFont("Ubuntu "+std::to_string(PROMPT_FONT_SIZE));
163 prompt_layout->AddView(username_);
164
165 msg_layout_ = new nux::VLayout();
166 msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale));
167 msg_layout_->SetTopAndBottomPadding(MSG_LAYOUT_PADDING.CP(scale), 0);
168 prompt_layout->AddLayout(msg_layout_);
169
170 prompt_layout_ = new nux::VLayout();
171 prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale));
172 prompt_layout->AddLayout(prompt_layout_);
173
174 GetLayout()->AddLayout(prompt_layout);
175 QueueRelayout();
176 QueueDraw();
177}
178
179void KylinUserPromptView::UpdateSize()
180{
181 auto width = 13 * Settings::GRID_SIZE.CP(scale);
182 auto height = 3 * Settings::GRID_SIZE.CP(scale);
183
184 SetMinimumWidth(width);
185 SetMaximumWidth(width);
186 SetMinimumHeight(height);
187
188 if (username_)
189 username_->SetScale(scale);
190
191 if (msg_layout_)
192 {
193 msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale));
194
195 for (auto* area : msg_layout_->GetChildren())
196 {
197 area->SetMaximumWidth(TEXT_INPUT_WIDTH);
198 static_cast<StaticCairoText*>(area)->SetScale(scale);
199 }
200 }
201
202 if (prompt_layout_)
203 {
204 prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale));
205
206 for (auto* area : prompt_layout_->GetChildren())
207 {
208 auto* text_input = static_cast<TextInput*>(area);
209 text_input->SetMinimumHeight(TEXT_INPUT_HEIGHT.CP(scale));
210 text_input->SetMaximumHeight(TEXT_INPUT_HEIGHT.CP(scale));
211 text_input->SetMinimumWidth(TEXT_INPUT_WIDTH.CP(scale));
212 text_input->SetMaximumWidth(TEXT_INPUT_WIDTH.CP(scale));
213 text_input->scale = scale();
214 }
215 }
216
217 ComputeContentSize();
218 QueueRelayout();
219 QueueDraw();
220}
221
222bool KylinUserPromptView::InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character)
223{
224 if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ESCAPE))
225 {
226 if (!focus_queue_.empty())
227 focus_queue_.front()->text_entry()->SetText("");
228
229 return true;
230 }
231
232 return false;
233}
234
235void KylinUserPromptView::AuthenticationCb(bool authenticated)
236{
237 ResetLayout();
238
239 if (authenticated)
240 {
241 session_manager_->unlock_requested.emit();
242 }
243 else
244 {
245 AddMessage(_("Invalid password, please try again"), nux::color::Red);
246
247 user_authenticator_.AuthenticateStart(session_manager_->UserName(),
248 sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb));
249 }
250}
251
252void KylinUserPromptView::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw)
253{
254 nux::Geometry const& geo = GetGeometry();
255
256 graphics_engine.PushClippingRectangle(geo);
257 nux::GetPainter().PaintBackground(graphics_engine, geo);
258
259 graphics_engine.PopClippingRectangle();
260}
261
262void KylinUserPromptView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw)
263{
264 nux::Geometry const& geo = GetGeometry();
265 graphics_engine.PushClippingRectangle(geo);
266
267 if (GetLayout())
268 GetLayout()->ProcessDraw(graphics_engine, force_draw);
269
270 graphics_engine.PopClippingRectangle();
271}
272
273nux::View* KylinUserPromptView::focus_view()
274{
275 if (focus_queue_.empty())
276 return nullptr;
277
278 for (auto* view : focus_queue_)
279 if (view->text_entry()->HasKeyboardFocus())
280 return view;
281
282 return focus_queue_.front()->text_entry();
283}
284
285void KylinUserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise)
286{
287 auto* text_input = new unity::TextInput();
288 auto* text_entry = text_input->text_entry();
289
290 text_input->scale = scale();
291 text_input->activator_icon = ACTIVATOR_ICON;
292 text_input->activator_icon_size = ACTIVATOR_ICON_SIZE;
293 text_input->background_color = nux::Color(1.0f, 1.0f, 1.0f, 0.8f);
294 text_input->border_color = nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
295 text_input->border_radius = 0;
296 text_input->hint_color = nux::Color(0.0f, 0.0f, 0.0f, 0.5f);
297 text_input->input_hint = SanitizeMessage(message);
298 text_input->hint_font_size = PROMPT_FONT_SIZE;
299 text_input->show_lock_warnings = true;
300 text_input->show_activator = true;
301 text_entry->SetPasswordMode(!visible);
302 text_entry->SetPasswordChar("•");
303 text_entry->SetToggleCursorVisibilityOnKeyFocus(true);
304 text_entry->clipboard_enabled = false;
305 text_entry->SetTextColor(nux::color::Black);
306
307 text_input->SetMinimumHeight(TEXT_INPUT_HEIGHT.CP(scale));
308 text_input->SetMaximumHeight(TEXT_INPUT_HEIGHT.CP(scale));
309 text_input->SetMinimumWidth(TEXT_INPUT_WIDTH.CP(scale));
310 text_input->SetMaximumWidth(TEXT_INPUT_WIDTH.CP(scale));
311 prompt_layout_->AddView(text_input, 1);
312 focus_queue_.push_back(text_input);
313
314 // Don't remove it, it helps with a11y.
315 if (focus_queue_.size() == 1)
316 nux::GetWindowCompositor().SetKeyFocusArea(text_entry);
317
318 text_entry->activated.connect([this, text_input, promise](){
319 auto* text_entry = text_input->text_entry();
320
321 if (!text_entry->GetInputEventSensitivity())
322 return;
323
324 if (focus_queue_.size() == 1)
325 {
326 text_input->SetSpinnerVisible(true);
327 text_input->SetSpinnerState(STATE_SEARCHING);
328 }
329
330 focus_queue_.pop_front();
331 cached_focused_geo_ = text_entry->GetGeometry();
332 text_entry->SetInputEventSensitivity(false);
333 QueueRelayout();
334 QueueDraw();
335
336 std::string const& password = text_entry->GetText();
337 if (promise)
338 promise->set_value(password);
339 });
340
341 GetLayout()->ComputeContentPosition(0, 0);
342 ComputeContentSize();
343 QueueRelayout();
344 QueueDraw();
345}
346
347void KylinUserPromptView::AddMessage(std::string const& message, nux::Color const& color)
348{
349 auto* view = new unity::StaticCairoText("");
350 view->SetScale(scale);
351 view->SetFont(Settings::Instance().font_name());
352 view->SetTextColor(color);
353 view->SetText(message);
354 view->SetMaximumWidth(TEXT_INPUT_WIDTH.CP(scale));
355 msg_layout_->AddView(view);
356
357 GetLayout()->ComputeContentPosition(0, 0);
358 ComputeContentSize();
359 QueueRelayout();
360 QueueDraw();
361}
362
363void KylinUserPromptView::AddAvatar(std::string const& icon_file, int icon_size)
364{
365 avatar_ = new IconTexture(LoadUserIcon(icon_file, icon_size));
366 avatar_->SetMinimumWidth(icon_size);
367 avatar_->SetMaximumWidth(icon_size);
368 avatar_layout_->AddView(avatar_);
369
370 GetLayout()->ComputeContentPosition(0, 0);
371 ComputeContentSize();
372 QueueRelayout();
373 QueueDraw();
374}
375
376nux::ObjectPtr<nux::BaseTexture> KylinUserPromptView::LoadUserIcon(std::string const& icon_file, int icon_size)
377{
378 glib::Error error;
379 glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_size(icon_file.c_str(), icon_size, icon_size, &error));
380 if (!pixbuf)
381 {
382 auto* theme = gtk_icon_theme_get_default();
383 GtkIconLookupFlags flags = GTK_ICON_LOOKUP_FORCE_SIZE;
384 pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default-kylin", icon_size, flags, &error);
385 if (!pixbuf)
386 pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default", icon_size, flags, &error);
387 }
388 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
389 cairo_t* cr = cg.GetInternalContext();
390
391 gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
392 cairo_paint_with_alpha(cr, 1.0);
393 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
394 cairo_rectangle(cr, 0, 0, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
395 cairo_set_line_width(cr, 3);
396 cairo_stroke(cr);
397
398 return texture_ptr_from_cairo_graphics(cg);
399}
400
401}
402}
0403
=== added file 'lockscreen/KylinUserPromptView.h'
--- lockscreen/KylinUserPromptView.h 1970-01-01 00:00:00 +0000
+++ lockscreen/KylinUserPromptView.h 2016-01-15 01:41:44 +0000
@@ -0,0 +1,84 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4* 2015, National University of Defense Technology(NUDT) & Kylin Ltd
5*
6* This program is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 3 as
8* published by the Free Software Foundation.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17*
18* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
19* handsome_feng <jianfengli@ubuntukylin.com>
20*/
21
22#ifndef UNITY_KYLIN_USER_PROMPT_BOX
23#define UNITY_KYLIN_USER_PROMPT_BOX
24
25#include "LockScreenAbstractPromptView.h"
26
27namespace nux
28{
29class VLayout;
30class HLayout;
31}
32
33namespace unity
34{
35
36class StaticCairoText;
37class TextInput;
38class IconTexture;
39class RawPixel;
40
41namespace lockscreen
42{
43
44class KylinUserPromptView : public AbstractUserPromptView
45{
46public:
47 KylinUserPromptView(session::Manager::Ptr const& session_manager);
48
49 nux::Property<double> scale;
50
51 nux::View* focus_view();
52
53 void AddAvatar(std::string const& avatar_icon, int avatar_size);
54 void AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const&);
55 void AddMessage(std::string const& message, nux::Color const& color);
56 void AuthenticationCb(bool authenticated);
57
58protected:
59 void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw);
60 void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw);
61 void ResetLayout();
62 void UpdateSize();
63 bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
64 nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size);
65
66private:
67 session::Manager::Ptr session_manager_;
68 UserAuthenticatorPam user_authenticator_;
69 StaticCairoText* username_;
70 nux::VLayout* msg_layout_;
71 nux::VLayout* prompt_layout_;
72 nux::VLayout* avatar_layout_;
73 std::deque<TextInput*> focus_queue_;
74 IconTexture* switch_icon_;
75 IconTexture* avatar_;
76 nux::Property<std::string> avatar_icon_file;
77
78 nux::Geometry cached_focused_geo_;
79};
80
81}
82}
83
84#endif
085
=== added file 'lockscreen/LockScreenAbstractPromptView.h'
--- lockscreen/LockScreenAbstractPromptView.h 1970-01-01 00:00:00 +0000
+++ lockscreen/LockScreenAbstractPromptView.h 2016-01-15 01:41:44 +0000
@@ -0,0 +1,79 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2015 Canonical Ltd
4 * 2015, National University of Defense Technology(NUDT) & Kylin Ltd
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authored by: handsome_feng <jianfengli@ubuntukylin.com>
19 */
20
21#ifndef UNITY_LOCKSCREEN_ABSTRACT_USER_PROMPT_H
22#define UNITY_LOCKSCREEN_ABSTRACT_USER_PROMPT_H
23
24#include <memory>
25#include <deque>
26
27#include <Nux/Nux.h>
28#include <Nux/View.h>
29#include <Nux/VLayout.h>
30#include <UnityCore/SessionManager.h>
31
32#include "UserAuthenticatorPam.h"
33#include "unity-shared/IMTextEntry.h"
34
35namespace nux
36{
37class VLayout;
38}
39namespace unity
40{
41
42class StaticCairoText;
43class TextInput;
44
45namespace lockscreen
46{
47
48class AbstractUserPromptView : public nux::View
49{
50public:
51 AbstractUserPromptView(session::Manager::Ptr const& session_manager)
52 : nux::View(NUX_TRACKER_LOCATION)
53 , session_manager_(session_manager)
54 {}
55
56 nux::Property<double> scale;
57
58 virtual nux::View* focus_view() = 0;
59
60 virtual void AuthenticationCb(bool authenticated) = 0;
61 virtual void ResetLayout() = 0;
62 virtual void UpdateSize() = 0;
63
64protected:
65 session::Manager::Ptr session_manager_;
66 UserAuthenticatorPam user_authenticator_;
67 std::shared_ptr<nux::AbstractPaintLayer> bg_layer_;
68 StaticCairoText* username_;
69 nux::VLayout* msg_layout_;
70 nux::VLayout* prompt_layout_;
71 std::deque<TextInput*> focus_queue_;
72
73 nux::Geometry cached_focused_geo_;
74};
75
76} // lockscreen
77} // unity
78
79#endif // UNITY_LOCKSCREEN_ABSTRACT_USER_PROMPT_H
080
=== added file 'lockscreen/LockScreenBaseShield.cpp'
--- lockscreen/LockScreenBaseShield.cpp 1970-01-01 00:00:00 +0000
+++ lockscreen/LockScreenBaseShield.cpp 2016-01-15 01:41:44 +0000
@@ -0,0 +1,173 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2015 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18 */
19
20#include "LockScreenBaseShield.h"
21
22#include "BackgroundSettings.h"
23#include "CofView.h"
24#include "LockScreenAbstractPromptView.h"
25#include "LockScreenSettings.h"
26#include "unity-shared/MockableBaseWindow.h"
27#include "unity-shared/UnitySettings.h"
28#include "unity-shared/UScreen.h"
29#include "unity-shared/WindowManager.h"
30
31namespace unity
32{
33namespace lockscreen
34{
35namespace
36{
37const unsigned MAX_GRAB_WAIT = 100;
38}
39
40BaseShield::BaseShield(session::Manager::Ptr const& session,
41 indicator::Indicators::Ptr const& indicators,
42 Accelerators::Ptr const& accelerators,
43 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
44 int monitor_num, bool is_primary)
45 : MockableBaseWindow("Unity Lockscreen")
46 , primary(is_primary)
47 , monitor(monitor_num)
48 , scale(1.0)
49 , session_manager_(session)
50 , indicators_(indicators)
51 , accelerators_(accelerators)
52 , prompt_view_(prompt_view)
53 , bg_settings_(std::make_shared<BackgroundSettings>())
54 , cof_view_(nullptr)
55{
56 UpdateScale();
57
58 unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &BaseShield::UpdateScale));
59 geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();});
60
61 monitor.changed.connect([this] (int monitor) {
62 UpdateScale();
63 UpdateBackgroundTexture();
64 });
65
66 primary.changed.connect([this] (bool is_primary) {
67 regrab_conn_->disconnect();
68 is_primary ? ShowPrimaryView() : ShowSecondaryView();
69 QueueRelayout();
70 QueueDraw();
71 });
72
73 scale.changed.connect([this] (double scale) {
74 if (prompt_view_ && primary())
75 prompt_view_->scale = scale;
76
77 if (cof_view_)
78 cof_view_->scale = scale;
79
80 if (prompt_layout_)
81 prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale));
82
83 background_layer_.reset();
84 UpdateBackgroundTexture();
85 });
86
87 mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) {
88 auto const& abs_geo = GetAbsoluteGeometry();
89 grab_motion.emit(abs_geo.x + x, abs_geo.y + y);
90 });
91}
92
93bool BaseShield::HasGrab() const
94{
95 auto& wc = nux::GetWindowCompositor();
96 return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this);
97}
98
99nux::Area* BaseShield::FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type)
100{
101 nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type);
102
103 if (!area && primary)
104 return this;
105
106 return area;
107}
108
109void BaseShield::GrabScreen(bool cancel_on_failure)
110{
111 auto& wc = nux::GetWindowCompositor();
112
113 if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this))
114 {
115 regrab_conn_->disconnect();
116 regrab_timeout_.reset();
117 grabbed.emit();
118 }
119 else
120 {
121 auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &BaseShield::GrabScreen), false);
122 regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb);
123
124 if (cancel_on_failure)
125 {
126 regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] {
127 grab_failed.emit();
128 return false;
129 }));
130 }
131 }
132}
133
134void BaseShield::UpdateBackgroundTexture()
135{
136 auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
137
138 if (!background_layer_ || monitor_geo != background_layer_->GetGeometry())
139 {
140 auto background_texture = bg_settings_->GetBackgroundTexture(monitor);
141 background_layer_.reset(new nux::TextureLayer(background_texture->GetDeviceTexture(), nux::TexCoordXForm(), nux::color::White, true));
142 SetBackgroundLayer(background_layer_.get());
143 }
144}
145
146void BaseShield::UpdateScale()
147{
148 scale = unity::Settings::Instance().em(monitor)->DPIScale();
149}
150
151void BaseShield::ShowSecondaryView()
152{
153 if (prompt_layout_)
154 prompt_layout_->RemoveChildObject(prompt_view_.GetPointer());
155
156 if (cof_layout_)
157 {
158 SetLayout(cof_layout_.GetPointer());
159 return;
160 }
161
162 nux::Layout* main_layout = new nux::VLayout();
163 cof_layout_ = main_layout;
164 SetLayout(cof_layout_.GetPointer());
165
166 // The circle of friends
167 cof_view_ = new CofView();
168 cof_view_->scale = scale();
169 main_layout->AddView(cof_view_);
170}
171
172} // lockscreen
173} // unity
0174
=== renamed file 'lockscreen/LockScreenAbstractShield.h' => 'lockscreen/LockScreenBaseShield.h'
--- lockscreen/LockScreenAbstractShield.h 2014-09-19 18:02:37 +0000
+++ lockscreen/LockScreenBaseShield.h 2016-01-15 01:41:44 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2014 Canonical Ltd3 * Copyright (C) 2014-2015 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as6 * it under the terms of the GNU General Public License version 3 as
@@ -17,49 +17,40 @@
17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>17 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18 */18 */
1919
20#ifndef UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H20#ifndef UNITY_LOCKSCREEN_BASE_SHIELD_H
21#define UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H21#define UNITY_LOCKSCREEN_BASE_SHIELD_H
2222
23#include <NuxCore/Property.h>23#include <NuxCore/Property.h>
24#include <UnityCore/SessionManager.h>24#include <UnityCore/SessionManager.h>
25#include <UnityCore/Indicators.h>25#include <UnityCore/Indicators.h>
2626#include <UnityCore/GLibSource.h>
27#include "unity-shared/MockableBaseWindow.h"27#include "unity-shared/MockableBaseWindow.h"
28
28#include "LockScreenAccelerators.h"29#include "LockScreenAccelerators.h"
2930
30namespace unity31namespace unity
31{32{
32namespace lockscreen33namespace lockscreen
33{34{
3435class BackgroundSettings;
35class UserPromptView;36class AbstractUserPromptView;
3637class CofView;
37class AbstractShield : public MockableBaseWindow38
39class BaseShield : public MockableBaseWindow
38{40{
39public:41public:
40 AbstractShield(session::Manager::Ptr const& session,42 BaseShield(session::Manager::Ptr const&, indicator::Indicators::Ptr const&,
41 indicator::Indicators::Ptr const& indicators,43 Accelerators::Ptr const&, nux::ObjectPtr<AbstractUserPromptView> const&,
42 Accelerators::Ptr const& accelerators,44 int monitor_num, bool is_primary);
43 nux::ObjectPtr<UserPromptView> const& prompt_view,
44 int monitor_num, bool is_primary)
45 : MockableBaseWindow("Unity Lockscreen")
46 , primary(is_primary)
47 , monitor(monitor_num)
48 , scale(1.0)
49 , session_manager_(session)
50 , indicators_(indicators)
51 , accelerators_(accelerators)
52 , prompt_view_(prompt_view)
53 {}
5445
55 nux::Property<bool> primary;46 nux::Property<bool> primary;
56 nux::Property<int> monitor;47 nux::Property<int> monitor;
57 nux::Property<double> scale;48 nux::Property<double> scale;
5849
50 bool HasGrab() const;
51 virtual bool IsIndicatorOpen() const { return false; }
52 virtual void ActivatePanel() {}
59 using MockableBaseWindow::RemoveLayout;53 using MockableBaseWindow::RemoveLayout;
60 virtual bool HasGrab() const = 0;
61 virtual bool IsIndicatorOpen() const = 0;
62 virtual void ActivatePanel() = 0;
6354
64 sigc::signal<void> grabbed;55 sigc::signal<void> grabbed;
65 sigc::signal<void> grab_failed;56 sigc::signal<void> grab_failed;
@@ -67,13 +58,31 @@
67 sigc::signal<void, unsigned long, unsigned long> grab_key;58 sigc::signal<void, unsigned long, unsigned long> grab_key;
6859
69protected:60protected:
61 virtual bool AcceptKeyNavFocus() { return false; }
62 virtual void ShowPrimaryView() = 0;
63 virtual void ShowSecondaryView();
64
65 nux::Area* FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type) override;
66
67 void GrabScreen(bool cancel_on_failure);
68 void UpdateBackgroundTexture();
69 void UpdateScale();
70
70 session::Manager::Ptr session_manager_;71 session::Manager::Ptr session_manager_;
71 indicator::Indicators::Ptr indicators_;72 indicator::Indicators::Ptr indicators_;
72 Accelerators::Ptr accelerators_;73 Accelerators::Ptr accelerators_;
73 nux::ObjectPtr<UserPromptView> prompt_view_;74 nux::ObjectPtr<AbstractUserPromptView> prompt_view_;
75 std::shared_ptr<BackgroundSettings> bg_settings_;
76 std::unique_ptr<nux::AbstractPaintLayer> background_layer_;
77 nux::ObjectPtr<nux::Layout> primary_layout_;
78 nux::ObjectPtr<nux::Layout> prompt_layout_;
79 nux::ObjectPtr<nux::Layout> cof_layout_;
80 CofView* cof_view_;
81 connection::Wrapper regrab_conn_;
82 glib::Source::UniquePtr regrab_timeout_;
74};83};
7584
76} // lockscreen85} // lockscreen
77} // unity86} // unity
7887
79#endif // UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H88#endif // UNITY_LOCKSCREEN_BASE_SHIELD_H
8089
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2015-03-24 19:25:26 +0000
+++ lockscreen/LockScreenController.cpp 2016-01-15 01:41:44 +0000
@@ -23,6 +23,8 @@
23#include <UnityCore/GLibDBusProxy.h>23#include <UnityCore/GLibDBusProxy.h>
24#include <NuxCore/Logger.h>24#include <NuxCore/Logger.h>
2525
26#include "LockScreenAbstractPromptView.h"
27#include "LockScreenPromptFactory.h"
26#include "LockScreenShield.h"28#include "LockScreenShield.h"
27#include "LockScreenSettings.h"29#include "LockScreenSettings.h"
28#include "unity-shared/AnimationUtils.h"30#include "unity-shared/AnimationUtils.h"
@@ -218,13 +220,13 @@
218 int primary = UScreen::GetDefault()->GetMonitorWithMouse();220 int primary = UScreen::GetDefault()->GetMonitorWithMouse();
219221
220 // Keep a reference of the old prompt_view222 // Keep a reference of the old prompt_view
221 nux::ObjectPtr<UserPromptView> prompt_view(prompt_view_.GetPointer());223 nux::ObjectPtr<AbstractUserPromptView> prompt_view(prompt_view_.GetPointer());
222224
223 shields_.resize(num_monitors);225 shields_.resize(num_monitors);
224226
225 if (!prompt_view)227 if (!prompt_view)
226 {228 {
227 prompt_view = test_mode_ ? nullptr : new UserPromptView(session_manager_);229 prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_);
228 prompt_view_ = prompt_view.GetPointer();230 prompt_view_ = prompt_view.GetPointer();
229 }231 }
230232
231233
=== modified file 'lockscreen/LockScreenController.h'
--- lockscreen/LockScreenController.h 2014-10-21 15:31:27 +0000
+++ lockscreen/LockScreenController.h 2016-01-15 01:41:44 +0000
@@ -24,12 +24,12 @@
24#include <UnityCore/ConnectionManager.h>24#include <UnityCore/ConnectionManager.h>
25#include <UnityCore/GLibSource.h>25#include <UnityCore/GLibSource.h>
2626
27#include "LockScreenBaseShield.h"
27#include "LockScreenShieldFactory.h"28#include "LockScreenShieldFactory.h"
28#include "LockScreenAcceleratorController.h"29#include "LockScreenAcceleratorController.h"
29#include "ScreenSaverDBusManager.h"30#include "ScreenSaverDBusManager.h"
30#include "ShutdownNotifier.h"31#include "ShutdownNotifier.h"
31#include "SuspendNotifier.h"32#include "SuspendNotifier.h"
32#include "UserPromptView.h"
33#include "unity-shared/BackgroundEffectHelper.h"33#include "unity-shared/BackgroundEffectHelper.h"
34#include "unity-shared/UpstartWrapper.h"34#include "unity-shared/UpstartWrapper.h"
3535
@@ -38,7 +38,7 @@
38namespace lockscreen38namespace lockscreen
39{39{
4040
41class UserPromptView;41class AbstractUserPromptView;
4242
43class Controller : public sigc::trackable43class Controller : public sigc::trackable
44{44{
@@ -77,9 +77,9 @@
77 void OnScreenSaverActivationRequest(bool activate);77 void OnScreenSaverActivationRequest(bool activate);
78 void OnPrimaryShieldMotion(int x, int y);78 void OnPrimaryShieldMotion(int x, int y);
7979
80 std::vector<nux::ObjectPtr<AbstractShield>> shields_;80 std::vector<nux::ObjectPtr<BaseShield>> shields_;
81 nux::ObjectWeakPtr<AbstractShield> primary_shield_;81 nux::ObjectWeakPtr<BaseShield> primary_shield_;
82 nux::ObjectWeakPtr<UserPromptView> prompt_view_;82 nux::ObjectWeakPtr<AbstractUserPromptView> prompt_view_;
83 nux::ObjectPtr<nux::BaseWindow> blank_window_;83 nux::ObjectPtr<nux::BaseWindow> blank_window_;
8484
85 DBusManager::Ptr dbus_manager_;85 DBusManager::Ptr dbus_manager_;
8686
=== added file 'lockscreen/LockScreenPromptFactory.cpp'
--- lockscreen/LockScreenPromptFactory.cpp 1970-01-01 00:00:00 +0000
+++ lockscreen/LockScreenPromptFactory.cpp 2016-01-15 01:41:44 +0000
@@ -0,0 +1,42 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as
7* published by the Free Software Foundation.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*
17* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18*/
19
20#include "LockScreenPromptFactory.h"
21#include "KylinUserPromptView.h"
22#include "UserPromptView.h"
23#include "unity-shared/UnitySettings.h"
24
25namespace unity
26{
27namespace lockscreen
28{
29nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm)
30{
31 nux::ObjectPtr<AbstractUserPromptView> prompt;
32
33 if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
34 prompt = new KylinUserPromptView(sm);
35 else
36 prompt = new UserPromptView(sm);
37
38 return prompt;
39}
40
41}
42}
043
=== added file 'lockscreen/LockScreenPromptFactory.h'
--- lockscreen/LockScreenPromptFactory.h 1970-01-01 00:00:00 +0000
+++ lockscreen/LockScreenPromptFactory.h 2016-01-15 01:41:44 +0000
@@ -0,0 +1,42 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2015 Canonical Ltd
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as
7* published by the Free Software Foundation.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*
17* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18*/
19
20#ifndef UNITY_LOCKSCREEN_PROMPT_FACTORY
21#define UNITY_LOCKSCREEN_PROMPT_FACTORY
22
23#include <NuxCore/NuxCore.h>
24#include <UnityCore/SessionManager.h>
25
26namespace unity
27{
28class MockableBaseWindow;
29
30namespace lockscreen
31{
32class AbstractUserPromptView;
33
34struct PromptFactory
35{
36 static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&);
37};
38
39}
40}
41
42#endif // UNITY_LOCKSCREEN_PROMPT_FACTORY
043
=== modified file 'lockscreen/LockScreenShield.cpp'
--- lockscreen/LockScreenShield.cpp 2014-09-19 20:44:05 +0000
+++ lockscreen/LockScreenShield.cpp 2016-01-15 01:41:44 +0000
@@ -21,127 +21,35 @@
2121
22#include <Nux/VLayout.h>22#include <Nux/VLayout.h>
23#include <Nux/HLayout.h>23#include <Nux/HLayout.h>
24#include <Nux/PaintLayer.h>
2524
26#include "BackgroundSettings.h"
27#include "CofView.h"
28#include "LockScreenPanel.h"25#include "LockScreenPanel.h"
29#include "LockScreenSettings.h"26#include "LockScreenSettings.h"
30#include "UserPromptView.h"27#include "LockScreenAbstractPromptView.h"
31#include "unity-shared/UScreen.h"
32#include "unity-shared/UnitySettings.h"
33#include "unity-shared/WindowManager.h"
3428
35namespace unity29namespace unity
36{30{
37namespace lockscreen31namespace lockscreen
38{32{
39namespace
40{
41const unsigned MAX_GRAB_WAIT = 100;
42}
4333
44Shield::Shield(session::Manager::Ptr const& session_manager,34Shield::Shield(session::Manager::Ptr const& session_manager,
45 indicator::Indicators::Ptr const& indicators,35 indicator::Indicators::Ptr const& indicators,
46 Accelerators::Ptr const& accelerators,36 Accelerators::Ptr const& accelerators,
47 nux::ObjectPtr<UserPromptView> const& prompt_view,37 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
48 int monitor_num, bool is_primary)38 int monitor_num, bool is_primary)
49 : AbstractShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary)39 : BaseShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary)
50 , bg_settings_(std::make_shared<BackgroundSettings>())
51 , panel_view_(nullptr)40 , panel_view_(nullptr)
52 , cof_view_(nullptr)
53{41{
54 UpdateScale();
55 is_primary ? ShowPrimaryView() : ShowSecondaryView();42 is_primary ? ShowPrimaryView() : ShowSecondaryView();
56
57 EnableInputWindow(true);43 EnableInputWindow(true);
5844
59 unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &Shield::UpdateScale));
60 geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();});
61
62 monitor.changed.connect([this] (int monitor) {45 monitor.changed.connect([this] (int monitor) {
63 UpdateScale();
64
65 if (panel_view_)46 if (panel_view_)
66 panel_view_->monitor = monitor;47 panel_view_->monitor = monitor;
67
68 UpdateBackgroundTexture();
69 });48 });
7049
71 primary.changed.connect([this] (bool is_primary) {50 primary.changed.connect([this] (bool is_primary) {
72 regrab_conn_->disconnect();
73 is_primary ? ShowPrimaryView() : ShowSecondaryView();
74 if (panel_view_) panel_view_->SetInputEventSensitivity(is_primary);51 if (panel_view_) panel_view_->SetInputEventSensitivity(is_primary);
75 QueueRelayout();52 });
76 QueueDraw();
77 });
78
79 scale.changed.connect([this] (double scale) {
80 if (prompt_view_ && primary())
81 prompt_view_->scale = scale;
82
83 if (cof_view_)
84 cof_view_->scale = scale;
85
86 if (prompt_layout_)
87 prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale));
88
89 background_layer_.reset();
90 UpdateBackgroundTexture();
91 });
92
93 mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) {
94 auto const& abs_geo = GetAbsoluteGeometry();
95 grab_motion.emit(abs_geo.x + x, abs_geo.y + y);
96 });
97}
98
99void Shield::UpdateScale()
100{
101 scale = unity::Settings::Instance().em(monitor)->DPIScale();
102}
103
104void Shield::UpdateBackgroundTexture()
105{
106 auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
107
108 if (!background_layer_ || monitor_geo != background_layer_->GetGeometry())
109 {
110 auto background_texture = bg_settings_->GetBackgroundTexture(monitor);
111 background_layer_.reset(new nux::TextureLayer(background_texture->GetDeviceTexture(), nux::TexCoordXForm(), nux::color::White, true));
112 SetBackgroundLayer(background_layer_.get());
113 }
114}
115
116void Shield::GrabScreen(bool cancel_on_failure)
117{
118 auto& wc = nux::GetWindowCompositor();
119
120 if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this))
121 {
122 regrab_conn_->disconnect();
123 regrab_timeout_.reset();
124 grabbed.emit();
125 }
126 else
127 {
128 auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &Shield::GrabScreen), false);
129 regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb);
130
131 if (cancel_on_failure)
132 {
133 regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] {
134 grab_failed.emit();
135 return false;
136 }));
137 }
138 }
139}
140
141bool Shield::HasGrab() const
142{
143 auto& wc = nux::GetWindowCompositor();
144 return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this);
145}53}
14654
147void Shield::ShowPrimaryView()55void Shield::ShowPrimaryView()
@@ -181,27 +89,6 @@
181 main_layout->AddSpace(0, 10);89 main_layout->AddSpace(0, 10);
182}90}
18391
184void Shield::ShowSecondaryView()
185{
186 if (prompt_layout_)
187 prompt_layout_->RemoveChildObject(prompt_view_.GetPointer());
188
189 if (cof_layout_)
190 {
191 SetLayout(cof_layout_.GetPointer());
192 return;
193 }
194
195 nux::Layout* main_layout = new nux::VLayout();
196 cof_layout_ = main_layout;
197 SetLayout(cof_layout_.GetPointer());
198
199 // The circle of friends
200 cof_view_ = new CofView();
201 cof_view_->scale = scale();
202 main_layout->AddView(cof_view_);
203}
204
205Panel* Shield::CreatePanel()92Panel* Shield::CreatePanel()
206{93{
207 if (!indicators_ || !session_manager_)94 if (!indicators_ || !session_manager_)
@@ -259,21 +146,6 @@
259 return nullptr;146 return nullptr;
260}147}
261148
262bool Shield::AcceptKeyNavFocus()
263{
264 return false;
265}
266
267nux::Area* Shield::FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type)
268{
269 nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type);
270
271 if (!area && primary)
272 return this;
273
274 return area;
275}
276
277bool Shield::IsIndicatorOpen() const149bool Shield::IsIndicatorOpen() const
278{150{
279 return panel_view_ ? panel_view_->active() : false;151 return panel_view_ ? panel_view_->active() : false;
280152
=== modified file 'lockscreen/LockScreenShield.h'
--- lockscreen/LockScreenShield.h 2014-09-19 18:02:37 +0000
+++ lockscreen/LockScreenShield.h 2016-01-15 01:41:44 +0000
@@ -21,56 +21,37 @@
21#define UNITY_LOCKSCREEN_SHIELD_H21#define UNITY_LOCKSCREEN_SHIELD_H
2222
23#include <UnityCore/ConnectionManager.h>23#include <UnityCore/ConnectionManager.h>
24#include <UnityCore/GLibSource.h>24#include "LockScreenBaseShield.h"
25#include "LockScreenAbstractShield.h"
2625
27namespace unity26namespace unity
28{27{
29namespace lockscreen28namespace lockscreen
30{29{
3130
32class BackgroundSettings;31class AbstractUserPromptView;
33class UserAuthenticator;
34class UserPromptView;
35class Panel;32class Panel;
36class CofView;
3733
38class Shield : public AbstractShield34class Shield : public BaseShield
39{35{
40public:36public:
41 Shield(session::Manager::Ptr const&,37 Shield(session::Manager::Ptr const&,
42 indicator::Indicators::Ptr const&,38 indicator::Indicators::Ptr const&,
43 Accelerators::Ptr const&,39 Accelerators::Ptr const&,
44 nux::ObjectPtr<UserPromptView> const&,40 nux::ObjectPtr<AbstractUserPromptView> const&,
45 int monitor, bool is_primary);41 int monitor, bool is_primary);
4642
47 bool HasGrab() const override;
48 bool IsIndicatorOpen() const override;43 bool IsIndicatorOpen() const override;
49 void ActivatePanel() override;44 void ActivatePanel() override;
5045
51protected:46protected:
52 bool AcceptKeyNavFocus() override;
53 nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override;47 nux::Area* FindKeyFocusArea(unsigned int, unsigned long, unsigned long) override;
54 nux::Area* FindAreaUnderMouse(nux::Point const&, nux::NuxEventType) override;
5548
56private:49private:
57 void UpdateBackgroundTexture();50 void ShowPrimaryView() override;
58 void GrabScreen(bool cancel_on_failure);
59 void ShowPrimaryView();
60 void ShowSecondaryView();
61 void UpdateScale();
62 Panel* CreatePanel();51 Panel* CreatePanel();
6352
64 std::shared_ptr<BackgroundSettings> bg_settings_;
65 std::unique_ptr<nux::AbstractPaintLayer> background_layer_;
66 nux::ObjectPtr<nux::Layout> primary_layout_;
67 nux::ObjectPtr<nux::Layout> prompt_layout_;
68 nux::ObjectPtr<nux::Layout> cof_layout_;
69 connection::Wrapper panel_active_conn_;53 connection::Wrapper panel_active_conn_;
70 connection::Wrapper regrab_conn_;
71 glib::Source::UniquePtr regrab_timeout_;
72 Panel* panel_view_;54 Panel* panel_view_;
73 CofView* cof_view_;
74};55};
7556
76}57}
7758
=== modified file 'lockscreen/LockScreenShieldFactory.cpp'
--- lockscreen/LockScreenShieldFactory.cpp 2014-07-11 17:45:39 +0000
+++ lockscreen/LockScreenShieldFactory.cpp 2016-01-15 01:41:44 +0000
@@ -19,20 +19,28 @@
1919
20#include "LockScreenShieldFactory.h"20#include "LockScreenShieldFactory.h"
21#include "LockScreenShield.h"21#include "LockScreenShield.h"
22#include "UserPromptView.h"22#include "KylinLockScreenShield.h"
23#include "unity-shared/UnitySettings.h"
2324
24namespace unity25namespace unity
25{26{
26namespace lockscreen27namespace lockscreen
27{28{
2829
29nux::ObjectPtr<AbstractShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager,30nux::ObjectPtr<BaseShield> ShieldFactory::CreateShield(session::Manager::Ptr const& session_manager,
30 indicator::Indicators::Ptr const& indicators,31 indicator::Indicators::Ptr const& indicators,
31 Accelerators::Ptr const& accelerators,32 Accelerators::Ptr const& accelerators,
32 nux::ObjectPtr<UserPromptView> const& prompt_view,33 nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
33 int monitor, bool is_primary)34 int monitor, bool is_primary)
34{35{
35 return nux::ObjectPtr<Shield>(new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary));36 nux::ObjectPtr<BaseShield> shield;
37
38 if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
39 shield = new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary);
40 else
41 shield = new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary);
42
43 return shield;
36}44}
3745
38}46}
3947
=== modified file 'lockscreen/LockScreenShieldFactory.h'
--- lockscreen/LockScreenShieldFactory.h 2014-07-11 17:45:39 +0000
+++ lockscreen/LockScreenShieldFactory.h 2016-01-15 01:41:44 +0000
@@ -20,18 +20,19 @@
20#ifndef UNITY_LOCKSCREEN_SHIELD_FACTORY20#ifndef UNITY_LOCKSCREEN_SHIELD_FACTORY
21#define UNITY_LOCKSCREEN_SHIELD_FACTORY21#define UNITY_LOCKSCREEN_SHIELD_FACTORY
2222
23#include <Nux/Nux.h>23#include <NuxCore/NuxCore.h>
24#include "LockScreenAbstractShield.h"24#include <UnityCore/SessionManager.h>
25#include <UnityCore/Indicators.h>
26#include "LockScreenAccelerators.h"
2527
26namespace unity28namespace unity
27{29{
28
29class MockableBaseWindow;30class MockableBaseWindow;
3031
31namespace lockscreen32namespace lockscreen
32{33{
3334class AbstractUserPromptView;
34class UserPromptView;35class BaseShield;
3536
36struct ShieldFactoryInterface37struct ShieldFactoryInterface
37{38{
@@ -39,23 +40,23 @@
3940
40 virtual ~ShieldFactoryInterface() = default;41 virtual ~ShieldFactoryInterface() = default;
4142
42 virtual nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&,43 virtual nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
43 indicator::Indicators::Ptr const&,44 indicator::Indicators::Ptr const&,
44 Accelerators::Ptr const&,45 Accelerators::Ptr const&,
45 nux::ObjectPtr<UserPromptView> const&,46 nux::ObjectPtr<AbstractUserPromptView> const&,
46 int monitor, bool is_primary) = 0;47 int monitor, bool is_primary) = 0;
47};48};
4849
49struct ShieldFactory : ShieldFactoryInterface50struct ShieldFactory : ShieldFactoryInterface
50{51{
51 nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&,52 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
52 indicator::Indicators::Ptr const&,53 indicator::Indicators::Ptr const&,
53 Accelerators::Ptr const&,54 Accelerators::Ptr const&,
54 nux::ObjectPtr<UserPromptView> const&,55 nux::ObjectPtr<AbstractUserPromptView> const&,
55 int monitor, bool is_primary) override;56 int monitor, bool is_primary) override;
56};57};
5758
58}59}
59}60}
6061
61#endif62#endif // UNITY_LOCKSCREEN_SHIELD_FACTORY
6263
=== modified file 'lockscreen/UserPromptView.cpp'
--- lockscreen/UserPromptView.cpp 2015-11-06 13:50:59 +0000
+++ lockscreen/UserPromptView.cpp 2016-01-15 01:41:44 +0000
@@ -100,7 +100,7 @@
100}100}
101101
102UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)102UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)
103 : nux::View(NUX_TRACKER_LOCATION)103 : AbstractUserPromptView(session_manager)
104 , scale(1.0)104 , scale(1.0)
105 , session_manager_(session_manager)105 , session_manager_(session_manager)
106 , username_(nullptr)106 , username_(nullptr)
107107
=== modified file 'lockscreen/UserPromptView.h'
--- lockscreen/UserPromptView.h 2014-07-28 16:58:13 +0000
+++ lockscreen/UserPromptView.h 2016-01-15 01:41:44 +0000
@@ -27,6 +27,7 @@
27#include <Nux/View.h>27#include <Nux/View.h>
28#include <UnityCore/SessionManager.h>28#include <UnityCore/SessionManager.h>
2929
30#include "LockScreenAbstractPromptView.h"
30#include "UserAuthenticatorPam.h"31#include "UserAuthenticatorPam.h"
31#include "unity-shared/IMTextEntry.h"32#include "unity-shared/IMTextEntry.h"
3233
@@ -44,7 +45,7 @@
44namespace lockscreen45namespace lockscreen
45{46{
4647
47class UserPromptView : public nux::View48class UserPromptView : public AbstractUserPromptView
48{49{
49public:50public:
50 UserPromptView(session::Manager::Ptr const& session_manager);51 UserPromptView(session::Manager::Ptr const& session_manager);
5152
=== added file 'resources/login.svg'
--- resources/login.svg 1970-01-01 00:00:00 +0000
+++ resources/login.svg 2016-01-15 01:41:44 +0000
@@ -0,0 +1,8 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 viewBox="0 0 34 34" enable-background="new 0 0 34 34" xml:space="preserve">
6<rect x="0" display="none" fill="#CABADA" width="34" height="34"/>
7<polygon fill="#1A2A7C" points="7,16 21.6,16 16,10 20,10 26.9,17.5 20,25 16,25 21.5,19 7,19 "/>
8</svg>
09
=== added file 'resources/switch_user.svg'
--- resources/switch_user.svg 1970-01-01 00:00:00 +0000
+++ resources/switch_user.svg 2016-01-15 01:41:44 +0000
@@ -0,0 +1,13 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 viewBox="0 0 34 34" enable-background="new 0 0 34 34" xml:space="preserve">
6<rect x="0" display="none" fill="#CABADA" width="34" height="34"/>
7<polygon display="none" fill="#1A2A7C" points="7,16 21.6,16 16,10 20,10 26.9,17.5 20,25 16,25 21.5,19 7,19 "/>
8<g>
9 <path fill="#FFFFFF" d="M17,1c8.8,0,16,7.2,16,16s-7.2,16-16,16S1,25.8,1,17S8.1,1,17,1 M17,0C7.6,0,0,7.6,0,17s7.6,17,17,17
10 s17-7.6,17-17S26.3,0,17,0L17,0z"/>
11</g>
12<polygon fill="#FFFFFF" points="13.9,9.6 19.2,9.6 14.9,14.8 27.6,14.8 27.6,20.1 14.8,20.1 19.1,25.4 13.9,25.4 6.4,17.5 "/>
13</svg>
014
=== modified file 'shutdown/StandaloneSession.cpp'
--- shutdown/StandaloneSession.cpp 2014-05-16 04:24:05 +0000
+++ shutdown/StandaloneSession.cpp 2016-01-15 01:41:44 +0000
@@ -39,6 +39,7 @@
39 std::string RealName() const { return "Marco Trevisan"; }39 std::string RealName() const { return "Marco Trevisan"; }
40 std::string UserName() const { return "marco"; }40 std::string UserName() const { return "marco"; }
41 std::string HostName() const { return "tricky"; }41 std::string HostName() const { return "tricky"; }
42 void UserIconFile(std::function<void(std::string const&)> const&) const { std::cout << "UserIconFile" << std::endl; }
4243
43 void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }44 void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }
44 void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }45 void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }
@@ -49,6 +50,7 @@
49 void Shutdown() { std::cout << "Shutdown" << std::endl; }50 void Shutdown() { std::cout << "Shutdown" << std::endl; }
50 void Suspend() { std::cout << "Suspend" << std::endl; }51 void Suspend() { std::cout << "Suspend" << std::endl; }
51 void Hibernate() { std::cout << "Hibernate" << std::endl; }52 void Hibernate() { std::cout << "Hibernate" << std::endl; }
53 void SwitchToGreeter() { std::cout << "SwitchToGreeter" << std::endl; }
5254
53 void CancelAction() { std::cout << "CancelAction" << std::endl; }55 void CancelAction() { std::cout << "CancelAction" << std::endl; }
5456
5557
=== modified file 'tests/test_gnome_session_manager.cpp'
--- tests/test_gnome_session_manager.cpp 2015-09-30 21:02:08 +0000
+++ tests/test_gnome_session_manager.cpp 2016-01-15 01:41:44 +0000
@@ -42,6 +42,7 @@
42const std::string CONSOLE_KIT_PATH = "/org/freedesktop/ConsoleKit/Manager";42const std::string CONSOLE_KIT_PATH = "/org/freedesktop/ConsoleKit/Manager";
43const std::string SESSION_MANAGER_PATH = "/org/gnome/SessionManager";43const std::string SESSION_MANAGER_PATH = "/org/gnome/SessionManager";
44const std::string SESSION_MANAGER_PRESENCE_PATH = "/org/gnome/SessionManager/Presence";44const std::string SESSION_MANAGER_PRESENCE_PATH = "/org/gnome/SessionManager/Presence";
45const std::string DISPLAY_MANAGER_SEAT_PATH = "/org/freedesktop/DisplayManager/Seat0";
4546
46const std::string SESSION_OPTIONS = "com.canonical.indicator.session";47const std::string SESSION_OPTIONS = "com.canonical.indicator.session";
47const std::string SUPPRESS_DIALOGS_KEY = "suppress-logout-restart-shutdown";48const std::string SUPPRESS_DIALOGS_KEY = "suppress-logout-restart-shutdown";
@@ -137,6 +138,13 @@
137</node>138</node>
138)";139)";
139140
141const std::string DISPLAY_MANAGER_SEAT =
142R"(<node>
143 <interface name="org.freedesktop.DisplayManager.Seat">
144 <method name="SwitchToGreeter"/>
145 </interface>
146</node>
147)";
140}148}
141149
142struct MockGnomeSessionManager : session::GnomeManager {150struct MockGnomeSessionManager : session::GnomeManager {
@@ -208,6 +216,9 @@
208 return nullptr;216 return nullptr;
209 });217 });
210218
219 display_manager_seat_ = std::make_shared<DBusServer>();
220 display_manager_seat_->AddObjects(introspection::DISPLAY_MANAGER_SEAT, DISPLAY_MANAGER_SEAT_PATH);
221
211 manager = std::make_shared<MockGnomeSessionManager>();222 manager = std::make_shared<MockGnomeSessionManager>();
212 shell_proxy_ = std::make_shared<DBusProxy>(TEST_SERVER_NAME, SHELL_OBJECT_PATH, SHELL_INTERFACE);223 shell_proxy_ = std::make_shared<DBusProxy>(TEST_SERVER_NAME, SHELL_OBJECT_PATH, SHELL_INTERFACE);
213224
@@ -228,6 +239,7 @@
228 Utils::WaitUntilMSec([] { return logind_->IsConnected(); });239 Utils::WaitUntilMSec([] { return logind_->IsConnected(); });
229 Utils::WaitUntilMSec([] { return console_kit_->IsConnected(); });240 Utils::WaitUntilMSec([] { return console_kit_->IsConnected(); });
230 Utils::WaitUntilMSec([] { return session_manager_->IsConnected(); });241 Utils::WaitUntilMSec([] { return session_manager_->IsConnected(); });
242 Utils::WaitUntilMSec([] { return display_manager_seat_->IsConnected(); });
231 Utils::WaitUntilMSec([] { return shell_proxy_->IsConnected();});243 Utils::WaitUntilMSec([] { return shell_proxy_->IsConnected();});
232 ASSERT_TRUE(shell_proxy_->IsConnected());244 ASSERT_TRUE(shell_proxy_->IsConnected());
233 EnableInteractiveShutdown(true);245 EnableInteractiveShutdown(true);
@@ -277,6 +289,7 @@
277 logind_.reset();289 logind_.reset();
278 console_kit_.reset();290 console_kit_.reset();
279 session_manager_.reset();291 session_manager_.reset();
292 display_manager_seat_.reset();
280 }293 }
281294
282 bool SettingsAvailable()295 bool SettingsAvailable()
@@ -342,6 +355,7 @@
342 static DBusServer::Ptr console_kit_;355 static DBusServer::Ptr console_kit_;
343 static DBusServer::Ptr logind_;356 static DBusServer::Ptr logind_;
344 static DBusServer::Ptr session_manager_;357 static DBusServer::Ptr session_manager_;
358 static DBusServer::Ptr display_manager_seat_;
345 static DBusProxy::Ptr shell_proxy_;359 static DBusProxy::Ptr shell_proxy_;
346};360};
347361
@@ -350,6 +364,7 @@
350DBusServer::Ptr TestGnomeSessionManager::console_kit_;364DBusServer::Ptr TestGnomeSessionManager::console_kit_;
351DBusServer::Ptr TestGnomeSessionManager::logind_;365DBusServer::Ptr TestGnomeSessionManager::logind_;
352DBusServer::Ptr TestGnomeSessionManager::session_manager_;366DBusServer::Ptr TestGnomeSessionManager::session_manager_;
367DBusServer::Ptr TestGnomeSessionManager::display_manager_seat_;
353DBusProxy::Ptr TestGnomeSessionManager::shell_proxy_;368DBusProxy::Ptr TestGnomeSessionManager::shell_proxy_;
354bool TestGnomeSessionManager::can_shutdown_;369bool TestGnomeSessionManager::can_shutdown_;
355bool TestGnomeSessionManager::can_suspend_;370bool TestGnomeSessionManager::can_suspend_;
@@ -390,6 +405,23 @@
390 EXPECT_EQ(manager->HostName(), g_get_host_name());405 EXPECT_EQ(manager->HostName(), g_get_host_name());
391}406}
392407
408TEST_F(TestGnomeSessionManager, SwitchToGreeter)
409{
410 bool switch_called = false;
411
412 display_manager_seat_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant*) {
413 if (method == "SwitchToGreeter")
414 switch_called = true;
415
416 return static_cast<GVariant*>(nullptr);
417 });
418
419 manager->SwitchToGreeter();
420
421 Utils::WaitUntilMSec(switch_called);
422 EXPECT_TRUE(switch_called);
423}
424
393TEST_F(TestGnomeSessionManager, ScreenSaverActivate)425TEST_F(TestGnomeSessionManager, ScreenSaverActivate)
394{426{
395 bool signal_emitted = false;427 bool signal_emitted = false;
396428
=== modified file 'tests/test_lockscreen_controller.cpp'
--- tests/test_lockscreen_controller.cpp 2014-09-19 18:02:37 +0000
+++ tests/test_lockscreen_controller.cpp 2016-01-15 01:41:44 +0000
@@ -20,7 +20,7 @@
20#include <gmock/gmock.h>20#include <gmock/gmock.h>
21using namespace testing;21using namespace testing;
2222
23#include "lockscreen/UserPromptView.h"23#include "lockscreen/LockScreenAbstractPromptView.h"
24#include "lockscreen/LockScreenController.h"24#include "lockscreen/LockScreenController.h"
2525
26#include <Nux/NuxTimerTickSource.h>26#include <Nux/NuxTimerTickSource.h>
@@ -51,26 +51,27 @@
51}51}
5252
5353
54struct MockShield : AbstractShield54struct MockShield : BaseShield
55{55{
56 MockShield()56 MockShield()
57 : AbstractShield(nullptr, nullptr, nullptr, nux::ObjectPtr<UserPromptView>(), 0, false)57 : BaseShield(nullptr, nullptr, nullptr, nux::ObjectPtr<AbstractUserPromptView>(), 0, false)
58 {}58 {}
5959
60 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());60 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());
61 MOCK_METHOD0(ActivatePanel, void());61 MOCK_METHOD0(ActivatePanel, void());
62 MOCK_CONST_METHOD0(HasGrab, bool());62 MOCK_CONST_METHOD0(HasGrab, bool());
63 MOCK_METHOD0(ShowPrimaryView, void());
63};64};
6465
65struct ShieldFactoryMock : ShieldFactoryInterface66struct ShieldFactoryMock : ShieldFactoryInterface
66{67{
67 nux::ObjectPtr<AbstractShield> CreateShield(session::Manager::Ptr const&,68 nux::ObjectPtr<BaseShield> CreateShield(session::Manager::Ptr const&,
68 indicator::Indicators::Ptr const&,69 indicator::Indicators::Ptr const&,
69 Accelerators::Ptr const&,70 Accelerators::Ptr const&,
70 nux::ObjectPtr<UserPromptView> const&,71 nux::ObjectPtr<AbstractUserPromptView> const&,
71 int, bool) override72 int, bool) override
72 {73 {
73 return nux::ObjectPtr<AbstractShield>(new MockShield());74 return nux::ObjectPtr<BaseShield>(new MockShield());
74 }75 }
75};76};
7677
7778
=== modified file 'tests/test_mock_session_manager.h'
--- tests/test_mock_session_manager.h 2014-05-16 04:24:05 +0000
+++ tests/test_mock_session_manager.h 2016-01-15 01:41:44 +0000
@@ -28,10 +28,12 @@
28struct MockManager : Manager28struct MockManager : Manager
29{29{
30 typedef std::shared_ptr<MockManager> Ptr;30 typedef std::shared_ptr<MockManager> Ptr;
31 typedef std::function<void(std::string const&)> ReplyCallback;
3132
32 MOCK_CONST_METHOD0(RealName, std::string());33 MOCK_CONST_METHOD0(RealName, std::string());
33 MOCK_CONST_METHOD0(UserName, std::string());34 MOCK_CONST_METHOD0(UserName, std::string());
34 MOCK_CONST_METHOD0(HostName, std::string());35 MOCK_CONST_METHOD0(HostName, std::string());
36 MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback const&));
3537
36 MOCK_METHOD0(ScreenSaverActivate, void());38 MOCK_METHOD0(ScreenSaverActivate, void());
37 MOCK_METHOD0(ScreenSaverDeactivate, void());39 MOCK_METHOD0(ScreenSaverDeactivate, void());
@@ -43,6 +45,7 @@
43 MOCK_METHOD0(Suspend, void());45 MOCK_METHOD0(Suspend, void());
44 MOCK_METHOD0(Hibernate, void());46 MOCK_METHOD0(Hibernate, void());
45 MOCK_METHOD0(CancelAction, void());47 MOCK_METHOD0(CancelAction, void());
48 MOCK_METHOD0(SwitchToGreeter, void());
4649
47 MOCK_CONST_METHOD0(CanLock, bool());50 MOCK_CONST_METHOD0(CanLock, bool());
48 MOCK_CONST_METHOD0(CanShutdown, bool());51 MOCK_CONST_METHOD0(CanShutdown, bool());
4952
=== modified file 'tests/test_unity_settings.cpp'
--- tests/test_unity_settings.cpp 2014-03-21 19:45:29 +0000
+++ tests/test_unity_settings.cpp 2016-01-15 01:41:44 +0000
@@ -53,12 +53,14 @@
53 , sig_receiver(unity_settings)53 , sig_receiver(unity_settings)
54 {54 {
55 g_settings_set_enum(gsettings, "form-factor", static_cast<int>(unity::FormFactor::DESKTOP));55 g_settings_set_enum(gsettings, "form-factor", static_cast<int>(unity::FormFactor::DESKTOP));
56 g_settings_set_enum(gsettings, "desktop-type", static_cast<int>(unity::DesktopType::UBUNTU));
56 }57 }
5758
58 ~TestUnitySettings()59 ~TestUnitySettings()
59 {60 {
60 sig_receiver.notify_callbacks();61 sig_receiver.notify_callbacks();
61 g_settings_reset(gsettings, "form-factor");62 g_settings_reset(gsettings, "form-factor");
63 g_settings_reset(gsettings, "desktop-type");
62 }64 }
63};65};
6466
@@ -78,6 +80,14 @@
78 EXPECT_EQ(unity_settings->form_factor(), unity::FormFactor::NETBOOK);80 EXPECT_EQ(unity_settings->form_factor(), unity::FormFactor::NETBOOK);
79}81}
8082
83TEST_F(TestUnitySettings, GetDesktopType)
84{
85 ASSERT_NE(unity_settings->desktop_type(), unity::DesktopType::UBUNTUKYLIN);
86
87 g_settings_set_enum(gsettings, "desktop-type", static_cast<int>(unity::DesktopType::UBUNTUKYLIN));
88 EXPECT_EQ(unity_settings->desktop_type(), unity::DesktopType::UBUNTUKYLIN);
89}
90
81TEST_F(TestUnitySettings, FormFactorChangedSignal_Extern)91TEST_F(TestUnitySettings, FormFactorChangedSignal_Extern)
82{92{
83 EXPECT_CALL(sig_receiver, FormFactorChanged(unity::FormFactor::NETBOOK));93 EXPECT_CALL(sig_receiver, FormFactorChanged(unity::FormFactor::NETBOOK));
8494
=== modified file 'unity-shared/TextInput.cpp'
--- unity-shared/TextInput.cpp 2015-12-16 09:03:56 +0000
+++ unity-shared/TextInput.cpp 2016-01-15 01:41:44 +0000
@@ -54,6 +54,7 @@
54const RawPixel TOOLTIP_OFFSET = 10_em;54const RawPixel TOOLTIP_OFFSET = 10_em;
55const RawPixel DEFAULT_ICON_SIZE = 22_em;55const RawPixel DEFAULT_ICON_SIZE = 22_em;
5656
57std::string ACTIVATOR_ICON = "arrow_right.png";
57std::string WARNING_ICON = "dialog-warning-symbolic";58std::string WARNING_ICON = "dialog-warning-symbolic";
58// Fonts59// Fonts
59const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";60const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";
@@ -88,9 +89,15 @@
8889
89TextInput::TextInput(NUX_FILE_LINE_DECL)90TextInput::TextInput(NUX_FILE_LINE_DECL)
90 : View(NUX_FILE_LINE_PARAM)91 : View(NUX_FILE_LINE_PARAM)
92 , activator_icon(ACTIVATOR_ICON)
93 , activator_icon_size(DEFAULT_ICON_SIZE)
94 , background_color(nux::Color(0.0f, 0.0f, 0.0f, 0.35f))
95 , border_color(nux::Color(1.0f, 1.0f, 1.0f, 0.7f))
96 , border_radius(BORDER_RADIUS)
91 , input_hint("")97 , input_hint("")
92 , hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)98 , hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)
93 , hint_font_size(HINT_LABEL_FONT_SIZE)99 , hint_font_size(HINT_LABEL_FONT_SIZE)
100 , hint_color(nux::Color(1.0f, 1.0f, 1.0f, 0.5f))
94 , show_activator(false)101 , show_activator(false)
95 , show_lock_warnings(false)102 , show_lock_warnings(false)
96 , scale(1.0)103 , scale(1.0)
@@ -109,7 +116,9 @@
109 hint_layout_->SetLeftAndRightPadding(HINT_PADDING.CP(scale), HINT_PADDING.CP(scale));116 hint_layout_->SetLeftAndRightPadding(HINT_PADDING.CP(scale), HINT_PADDING.CP(scale));
110117
111 hint_ = new StaticCairoText("");118 hint_ = new StaticCairoText("");
112 hint_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 0.5f));119 hint_->SetTextColor(hint_color);
120 hint_color.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateHintColor)));
121
113 hint_->SetScale(scale);122 hint_->SetScale(scale);
114 hint_layout_->AddView(hint_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);123 hint_layout_->AddView(hint_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
115 hint_font_name.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateHintFont)));124 hint_font_name.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateHintFont)));
@@ -146,10 +155,18 @@
146 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));155 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));
147156
148 // Activator157 // Activator
149 activator_ = new IconTexture(LoadActivatorIcon(DEFAULT_ICON_SIZE.CP(scale)));158 activator_ = new IconTexture(LoadActivatorIcon(activator_icon(), activator_icon_size().CP(scale)));
150 activator_->SetVisible(show_activator());159 activator_->SetVisible(show_activator());
151 layout_->AddView(activator_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);160 layout_->AddView(activator_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
152161
162 activator_icon.changed.connect([this] (std::string icon) {
163 activator_->SetTexture(LoadActivatorIcon(icon, activator_icon_size().CP(scale)));
164 });
165
166 activator_icon_size.changed.connect([this] (RawPixel icon_size) {
167 activator_->SetTexture(LoadActivatorIcon(activator_icon(), icon_size.CP(scale)));
168 });
169
153 show_activator.changed.connect([this] (bool value) {170 show_activator.changed.connect([this] (bool value) {
154 activator_->SetVisible(value);171 activator_->SetVisible(value);
155 });172 });
@@ -185,6 +202,11 @@
185 warning_->mouse_leave.connect([this] (int x, int y, int button, int key_flags) {202 warning_->mouse_leave.connect([this] (int x, int y, int button, int key_flags) {
186 tooltip_timeout_ ? tooltip_timeout_.reset() : QueueDraw();203 tooltip_timeout_ ? tooltip_timeout_.reset() : QueueDraw();
187 });204 });
205
206 //background
207 background_color.changed.connect([this] (nux::Color color) { UpdateBackground(true); });
208 border_color.changed.connect([this] (nux::Color color) { UpdateBackground(true); });
209 border_radius.changed.connect([this] (int radius) { UpdateBackground(true); });
188}210}
189211
190void TextInput::UpdateSize()212void TextInput::UpdateSize()
@@ -208,7 +230,7 @@
208 hint_->SetMaximumHeight(pango_entry_->GetMinimumHeight());230 hint_->SetMaximumHeight(pango_entry_->GetMinimumHeight());
209231
210 spinner_->scale = scale;232 spinner_->scale = scale;
211 activator_->SetTexture(LoadActivatorIcon(DEFAULT_ICON_SIZE.CP(scale)));233 activator_->SetTexture(LoadActivatorIcon(activator_icon(), activator_icon_size().CP(scale)));
212 warning_->SetTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));234 warning_->SetTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));
213 warning_tooltip_.Release();235 warning_tooltip_.Release();
214236
@@ -254,10 +276,15 @@
254 hint_->SetFont((hint_font_name() + " " + std::to_string(hint_font_size())).c_str());276 hint_->SetFont((hint_font_name() + " " + std::to_string(hint_font_size())).c_str());
255}277}
256278
257nux::ObjectPtr<nux::BaseTexture> TextInput::LoadActivatorIcon(int icon_size)279void TextInput::UpdateHintColor()
280{
281 hint_->SetTextColor(hint_color);
282}
283
284nux::ObjectPtr<nux::BaseTexture> TextInput::LoadActivatorIcon(std::string const& icon_file, int icon_size)
258{285{
259 TextureCache& cache = TextureCache::GetDefault();286 TextureCache& cache = TextureCache::GetDefault();
260 return cache.FindTexture("arrow_right.png", icon_size, icon_size);287 return cache.FindTexture(icon_file, icon_size, icon_size);
261}288}
262289
263nux::ObjectPtr<nux::BaseTexture> TextInput::LoadWarningIcon(int icon_size)290nux::ObjectPtr<nux::BaseTexture> TextInput::LoadWarningIcon(int icon_size)
@@ -459,15 +486,15 @@
459 cairo_graphics.DrawRoundedRectangle(cr,486 cairo_graphics.DrawRoundedRectangle(cr,
460 1.0f,487 1.0f,
461 0.5, 0.5,488 0.5, 0.5,
462 BORDER_RADIUS,489 border_radius(),
463 (last_width_/scale) - 1, (last_height_/scale) - 1,490 (last_width_/scale) - 1, (last_height_/scale) - 1,
464 false);491 false);
465492
466 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);493 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
467 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.35f);494 cairo_set_source_rgba(cr, background_color().red, background_color().green, background_color().blue, background_color().alpha);
468 cairo_fill_preserve(cr);495 cairo_fill_preserve(cr);
469 cairo_set_line_width(cr, 1);496 cairo_set_line_width(cr, 1);
470 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.7f);497 cairo_set_source_rgba(cr, border_color().red, border_color().green, border_color().blue, border_color().alpha);
471 cairo_stroke(cr);498 cairo_stroke(cr);
472499
473 auto texture2D = texture_ptr_from_cairo_graphics(cairo_graphics);500 auto texture2D = texture_ptr_from_cairo_graphics(cairo_graphics);
474501
=== modified file 'unity-shared/TextInput.h'
--- unity-shared/TextInput.h 2015-11-06 11:40:31 +0000
+++ unity-shared/TextInput.h 2016-01-15 01:41:44 +0000
@@ -26,6 +26,7 @@
2626
27#include "Introspectable.h"27#include "Introspectable.h"
28#include "IMTextEntry.h"28#include "IMTextEntry.h"
29#include "RawPixel.h"
29#include "SearchBarSpinner.h"30#include "SearchBarSpinner.h"
3031
31namespace nux32namespace nux
@@ -57,10 +58,16 @@
5758
58 IMTextEntry* text_entry() const;59 IMTextEntry* text_entry() const;
5960
61 nux::Property<std::string> activator_icon;
62 nux::Property<RawPixel> activator_icon_size;
63 nux::Property<nux::Color> background_color;
64 nux::Property<nux::Color> border_color;
65 nux::Property<int> border_radius;
60 nux::RWProperty<std::string> input_string;66 nux::RWProperty<std::string> input_string;
61 nux::Property<std::string> input_hint;67 nux::Property<std::string> input_hint;
62 nux::Property<std::string> hint_font_name;68 nux::Property<std::string> hint_font_name;
63 nux::Property<int> hint_font_size;69 nux::Property<int> hint_font_size;
70 nux::Property<nux::Color> hint_color;
64 nux::ROProperty<bool> im_active;71 nux::ROProperty<bool> im_active;
65 nux::ROProperty<bool> im_preedit;72 nux::ROProperty<bool> im_preedit;
66 nux::Property<bool> show_activator;73 nux::Property<bool> show_activator;
@@ -70,6 +77,7 @@
70private:77private:
71 void OnFontChanged();78 void OnFontChanged();
72 void UpdateHintFont();79 void UpdateHintFont();
80 void UpdateHintColor();
73 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);81 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
74 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);82 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
75 void UpdateBackground(bool force);83 void UpdateBackground(bool force);
@@ -84,7 +92,7 @@
84 void CheckLocks();92 void CheckLocks();
85 void OnLockStateChanged(bool);93 void OnLockStateChanged(bool);
8694
87 nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(int icon_size);95 nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(std::string const& icon_file, int icon_size);
88 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);96 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
89 void LoadWarningTooltip();97 void LoadWarningTooltip();
9098
9199
=== modified file 'unity-shared/UnitySettings.cpp'
--- unity-shared/UnitySettings.cpp 2015-05-22 13:20:22 +0000
+++ unity-shared/UnitySettings.cpp 2016-01-15 01:41:44 +0000
@@ -38,6 +38,7 @@
38const std::string SETTINGS_NAME = "com.canonical.Unity";38const std::string SETTINGS_NAME = "com.canonical.Unity";
39const std::string FORM_FACTOR = "form-factor";39const std::string FORM_FACTOR = "form-factor";
40const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";40const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";
41const std::string DESKTOP_TYPE = "desktop-type";
4142
42const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";43const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";
43const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";44const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";
@@ -94,6 +95,7 @@
94 parent_->form_factor.SetSetterFunction(sigc::mem_fun(this, &Impl::SetFormFactor));95 parent_->form_factor.SetSetterFunction(sigc::mem_fun(this, &Impl::SetFormFactor));
95 parent_->double_click_activate.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDoubleClickActivate));96 parent_->double_click_activate.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDoubleClickActivate));
96 parent_->remote_content.SetGetterFunction(sigc::mem_fun(this, &Impl::GetRemoteContentEnabled));97 parent_->remote_content.SetGetterFunction(sigc::mem_fun(this, &Impl::GetRemoteContentEnabled));
98 parent_->desktop_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDesktopType));
9799
98 for (unsigned i = 0; i < monitors::MAX; ++i)100 for (unsigned i = 0; i < monitors::MAX; ++i)
99 em_converters_.emplace_back(std::make_shared<EMConverter>());101 em_converters_.emplace_back(std::make_shared<EMConverter>());
@@ -218,6 +220,11 @@
218 return cached_double_click_activate_;220 return cached_double_click_activate_;
219 }221 }
220222
223 DesktopType GetDesktopType() const
224 {
225 return static_cast<DesktopType>(g_settings_get_enum(usettings_, DESKTOP_TYPE.c_str()));
226 }
227
221 int GetFontSize() const228 int GetFontSize() const
222 {229 {
223 gint font_size;230 gint font_size;
224231
=== modified file 'unity-shared/UnitySettings.h'
--- unity-shared/UnitySettings.h 2015-05-22 13:20:22 +0000
+++ unity-shared/UnitySettings.h 2016-01-15 01:41:44 +0000
@@ -35,6 +35,12 @@
35 TV35 TV
36};36};
3737
38enum class DesktopType
39{
40 UBUNTU,
41 UBUNTUKYLIN
42};
43
38class Settings44class Settings
39{45{
40public:46public:
@@ -51,6 +57,7 @@
5157
52 nux::RWProperty<FormFactor> form_factor;58 nux::RWProperty<FormFactor> form_factor;
53 nux::Property<bool> is_standalone;59 nux::Property<bool> is_standalone;
60 nux::ROProperty<DesktopType> desktop_type;
54 nux::ROProperty<bool> double_click_activate;61 nux::ROProperty<bool> double_click_activate;
55 nux::Property<unsigned> lim_movement_thresold;62 nux::Property<unsigned> lim_movement_thresold;
56 nux::Property<unsigned> lim_double_click_wait;63 nux::Property<unsigned> lim_double_click_wait;