Merge lp:~azzar1/unity/sh-72 into lp:unity/7.2

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3837
Proposed branch: lp:~azzar1/unity/sh-72
Merge into: lp:unity/7.2
Diff against target: 1030 lines (+242/-469)
25 files modified
UnityCore/GnomeSessionManager.cpp (+8/-2)
UnityCore/SessionManager.h (+1/-0)
lockscreen/CMakeLists.txt (+1/-2)
lockscreen/LockScreenAbstractShield.h (+3/-5)
lockscreen/LockScreenAcceleratorController.h (+1/-1)
lockscreen/LockScreenController.cpp (+26/-9)
lockscreen/LockScreenController.h (+3/-5)
lockscreen/LockScreenPanel.h (+3/-3)
lockscreen/LockScreenShieldFactory.h (+2/-0)
lockscreen/ShutdownNotifier.cpp (+0/-152)
lockscreen/ShutdownNotifier.h (+0/-51)
lockscreen/SuspendInhibitorManager.cpp (+131/-0)
lockscreen/SuspendInhibitorManager.h (+54/-0)
lockscreen/SuspendNotifier.cpp (+0/-153)
lockscreen/SuspendNotifier.h (+0/-51)
lockscreen/UserPromptView.h (+1/-1)
lockscreen/pch/lockscreen_pch.hh (+2/-2)
shutdown/SessionController.h (+1/-1)
shutdown/SessionDBusManager.h (+3/-3)
shutdown/SessionView.h (+1/-1)
tests/test_mock_session_manager.h (+1/-1)
unity-shared/PluginAdapter.cpp (+0/-20)
unity-shared/PluginAdapter.h (+0/-1)
unity-shared/StandaloneWindowManager.h (+0/-2)
unity-shared/WindowManager.h (+0/-3)
To merge this branch: bzr merge lp:~azzar1/unity/sh-72
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+291231@code.launchpad.net

Commit message

Improve the "lock on suspend" logic to always keep in sync the inhibitor with the lockscreen.

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

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-10-21 15:54:37 +0000
+++ UnityCore/GnomeSessionManager.cpp 2016-04-07 11:57:30 +0000
@@ -115,8 +115,14 @@
115 manager_->unlock_requested.emit();115 manager_->unlock_requested.emit();
116 });116 });
117117
118 login_proxy_->ConnectProperty("Active", [this] (GVariant* active) {118 login_proxy_->ConnectProperty("Active", [this] (GVariant* variant) {
119 manager_->screensaver_requested.emit(!glib::Variant(active).GetBool());119 bool active = glib::Variant(variant).GetBool();
120 manager_->screensaver_requested.emit(!active);
121 manager_->is_session_active.changed.emit(active);
122 });
123
124 manager_->is_session_active.SetGetterFunction([this] {
125 return login_proxy_->GetProperty("Active").GetBool();
120 });126 });
121 }127 }
122128
123129
=== modified file 'UnityCore/SessionManager.h'
--- UnityCore/SessionManager.h 2014-07-23 18:56:11 +0000
+++ UnityCore/SessionManager.h 2016-04-07 11:57:30 +0000
@@ -40,6 +40,7 @@
4040
41 nux::ROProperty<bool> have_other_open_sessions;41 nux::ROProperty<bool> have_other_open_sessions;
42 nux::Property<bool> is_locked;42 nux::Property<bool> is_locked;
43 nux::ROProperty<bool> is_session_active;
4344
44 virtual std::string RealName() const = 0;45 virtual std::string RealName() const = 0;
45 virtual std::string UserName() const = 0;46 virtual std::string UserName() const = 0;
4647
=== modified file 'lockscreen/CMakeLists.txt'
--- lockscreen/CMakeLists.txt 2014-12-16 19:27:36 +0000
+++ lockscreen/CMakeLists.txt 2016-04-07 11:57:30 +0000
@@ -27,8 +27,7 @@
27 LockScreenAcceleratorController.cpp27 LockScreenAcceleratorController.cpp
28 LockScreenAccelerators.cpp28 LockScreenAccelerators.cpp
29 ScreenSaverDBusManager.cpp29 ScreenSaverDBusManager.cpp
30 ShutdownNotifier.cpp30 SuspendInhibitorManager.cpp
31 SuspendNotifier.cpp
32 UserAuthenticatorPam.cpp31 UserAuthenticatorPam.cpp
33 UserPromptView.cpp32 UserPromptView.cpp
34 )33 )
3534
=== modified file 'lockscreen/LockScreenAbstractShield.h'
--- lockscreen/LockScreenAbstractShield.h 2014-12-15 19:12:07 +0000
+++ lockscreen/LockScreenAbstractShield.h 2016-04-07 11:57:30 +0000
@@ -21,19 +21,17 @@
21#define UNITY_LOCKSCREEN_ABSTRACT_SHIELD_H21#define UNITY_LOCKSCREEN_ABSTRACT_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"
26
27#include "unity-shared/MockableBaseWindow.h"26#include "unity-shared/MockableBaseWindow.h"
28#include "LockScreenAccelerators.h"27#include "LockScreenAccelerators.h"
28#include "UserPromptView.h"
2929
30namespace unity30namespace unity
31{31{
32namespace lockscreen32namespace lockscreen
33{33{
3434
35class UserPromptView;
36
37class AbstractShield : public MockableBaseWindow35class AbstractShield : public MockableBaseWindow
38{36{
39public:37public:
4038
=== modified file 'lockscreen/LockScreenAcceleratorController.h'
--- lockscreen/LockScreenAcceleratorController.h 2014-07-23 18:56:11 +0000
+++ lockscreen/LockScreenAcceleratorController.h 2016-04-07 11:57:30 +0000
@@ -20,7 +20,7 @@
20#ifndef UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER20#ifndef UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER
21#define UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER21#define UNITY_LOCKSCREEN_ACCELERATOR_CONTROLLER
2222
23#include <UnityCore/SessionManager.h>23#include "UnityCore/SessionManager.h"
24#include "LockScreenAccelerators.h"24#include "LockScreenAccelerators.h"
2525
26namespace unity26namespace unity
2727
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2015-05-15 19:39:03 +0000
+++ lockscreen/LockScreenController.cpp 2016-04-07 11:57:30 +0000
@@ -25,6 +25,7 @@
2525
26#include "LockScreenShield.h"26#include "LockScreenShield.h"
27#include "LockScreenSettings.h"27#include "LockScreenSettings.h"
28#include "UserPromptView.h"
28#include "unity-shared/AnimationUtils.h"29#include "unity-shared/AnimationUtils.h"
29#include "unity-shared/UScreen.h"30#include "unity-shared/UScreen.h"
30#include "unity-shared/WindowManager.h"31#include "unity-shared/WindowManager.h"
@@ -60,7 +61,7 @@
60 , session_manager_(session_manager)61 , session_manager_(session_manager)
61 , upstart_wrapper_(upstart_wrapper)62 , upstart_wrapper_(upstart_wrapper)
62 , shield_factory_(shield_factory)63 , shield_factory_(shield_factory)
63 , suspend_notifier_(std::make_shared<SuspendNotifier>())64 , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>())
64 , fade_animator_(LOCK_FADE_DURATION)65 , fade_animator_(LOCK_FADE_DURATION)
65 , blank_window_animator_(IDLE_FADE_DURATION)66 , blank_window_animator_(IDLE_FADE_DURATION)
66 , test_mode_(test_mode)67 , test_mode_(test_mode)
@@ -79,17 +80,22 @@
79 });80 });
80 hidden_window_connection_->block();81 hidden_window_connection_->block();
8182
82 suspend_notifier_->RegisterInterest([this](){83 suspend_inhibitor_manager_->about_to_suspend.connect([this] () {
83 if (Settings::Instance().lock_on_suspend())84 if (Settings::Instance().lock_on_suspend())
84 session_manager_->PromptLockScreen();85 session_manager_->PromptLockScreen();
85 });86 });
8687
88 Settings::Instance().lock_on_suspend.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));
89 Settings::Instance().use_legacy.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));
90 suspend_inhibitor_manager_->connected.connect(sigc::mem_fun(this, &Controller::SyncInhibitor));
91
87 dbus_manager_->simulate_activity.connect(sigc::mem_fun(this, &Controller::SimulateActivity));92 dbus_manager_->simulate_activity.connect(sigc::mem_fun(this, &Controller::SimulateActivity));
88 session_manager_->screensaver_requested.connect(sigc::mem_fun(this, &Controller::OnScreenSaverActivationRequest));93 session_manager_->screensaver_requested.connect(sigc::mem_fun(this, &Controller::OnScreenSaverActivationRequest));
89 session_manager_->lock_requested.connect(sigc::bind(sigc::mem_fun(this, &Controller::OnLockRequested), false));94 session_manager_->lock_requested.connect(sigc::bind(sigc::mem_fun(this, &Controller::OnLockRequested), false));
90 session_manager_->prompt_lock_requested.connect(sigc::bind(sigc::mem_fun(this, &Controller::OnLockRequested), true));95 session_manager_->prompt_lock_requested.connect(sigc::bind(sigc::mem_fun(this, &Controller::OnLockRequested), true));
91 session_manager_->unlock_requested.connect(sigc::mem_fun(this, &Controller::OnUnlockRequested));96 session_manager_->unlock_requested.connect(sigc::mem_fun(this, &Controller::OnUnlockRequested));
92 session_manager_->presence_status_changed.connect(sigc::mem_fun(this, &Controller::OnPresenceStatusChanged));97 session_manager_->presence_status_changed.connect(sigc::mem_fun(this, &Controller::OnPresenceStatusChanged));
98 session_manager_->is_session_active.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));
9399
94 fade_animator_.updated.connect([this](double value) {100 fade_animator_.updated.connect([this](double value) {
95 std::for_each(shields_.begin(), shields_.end(), [value](nux::ObjectPtr<Shield> const& shield) {101 std::for_each(shields_.begin(), shields_.end(), [value](nux::ObjectPtr<Shield> const& shield) {
@@ -100,6 +106,8 @@
100 });106 });
101107
102 fade_animator_.finished.connect([this] {108 fade_animator_.finished.connect([this] {
109 SyncInhibitor();
110
103 if (animation::GetDirection(fade_animator_) == animation::Direction::BACKWARD)111 if (animation::GetDirection(fade_animator_) == animation::Direction::BACKWARD)
104 {112 {
105 primary_shield_connections_.Clear();113 primary_shield_connections_.Clear();
@@ -147,6 +155,8 @@
147 }));155 }));
148 }156 }
149 });157 });
158
159 SyncInhibitor();
150}160}
151161
152void Controller::ActivatePanel()162void Controller::ActivatePanel()
@@ -444,11 +454,6 @@
444 indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>();454 indicators_ = std::make_shared<indicator::LockScreenDBusIndicators>();
445 upstart_wrapper_->Emit("desktop-lock");455 upstart_wrapper_->Emit("desktop-lock");
446456
447 shutdown_notifier_ = std::make_shared<ShutdownNotifier>();
448 shutdown_notifier_->RegisterInterest([](){
449 WindowManager::Default().UnmapAllNoNuxWindowsSync();
450 });
451
452 accelerator_controller_ = std::make_shared<AcceleratorController>(session_manager_);457 accelerator_controller_ = std::make_shared<AcceleratorController>(session_manager_);
453 auto activate_key = WindowManager::Default().activate_indicators_key();458 auto activate_key = WindowManager::Default().activate_indicators_key();
454 auto accelerator = std::make_shared<Accelerator>(activate_key.second, 0, activate_key.first);459 auto accelerator = std::make_shared<Accelerator>(activate_key.second, 0, activate_key.first);
@@ -487,8 +492,6 @@
487492
488void Controller::OnUnlockRequested()493void Controller::OnUnlockRequested()
489{494{
490 shutdown_notifier_.reset();
491
492 lockscreen_timeout_.reset();495 lockscreen_timeout_.reset();
493 screensaver_post_lock_timeout_.reset();496 screensaver_post_lock_timeout_.reset();
494497
@@ -522,5 +525,19 @@
522 return primary_shield_.IsValid() ? primary_shield_->IsIndicatorOpen() : false;525 return primary_shield_.IsValid() ? primary_shield_->IsIndicatorOpen() : false;
523}526}
524527
528void Controller::SyncInhibitor()
529{
530 bool locked = IsLocked() && primary_shield_.IsValid() && primary_shield_->GetOpacity() == 1.0f;
531 bool inhibit = session_manager_->is_session_active() &&
532 !locked &&
533 Settings::Instance().lock_on_suspend() &&
534 !Settings::Instance().use_legacy();
535
536 if (inhibit)
537 suspend_inhibitor_manager_->Inhibit("Unity needs to lock the screen");
538 else
539 suspend_inhibitor_manager_->Uninhibit();
540}
541
525} // lockscreen542} // lockscreen
526} // unity543} // unity
527544
=== modified file 'lockscreen/LockScreenController.h'
--- lockscreen/LockScreenController.h 2014-12-16 19:27:36 +0000
+++ lockscreen/LockScreenController.h 2016-04-07 11:57:30 +0000
@@ -26,10 +26,8 @@
2626
27#include "LockScreenShieldFactory.h"27#include "LockScreenShieldFactory.h"
28#include "LockScreenAcceleratorController.h"28#include "LockScreenAcceleratorController.h"
29#include "SuspendInhibitorManager.h"
29#include "ScreenSaverDBusManager.h"30#include "ScreenSaverDBusManager.h"
30#include "ShutdownNotifier.h"
31#include "SuspendNotifier.h"
32#include "UserPromptView.h"
33#include "unity-shared/BackgroundEffectHelper.h"31#include "unity-shared/BackgroundEffectHelper.h"
34#include "unity-shared/UpstartWrapper.h"32#include "unity-shared/UpstartWrapper.h"
3533
@@ -70,6 +68,7 @@
70 void ResetPostLockScreenSaver();68 void ResetPostLockScreenSaver();
71 void SetupPrimaryShieldConnections();69 void SetupPrimaryShieldConnections();
72 void ActivatePanel();70 void ActivatePanel();
71 void SyncInhibitor();
7372
74 void OnLockRequested(bool prompt);73 void OnLockRequested(bool prompt);
75 void OnUnlockRequested();74 void OnUnlockRequested();
@@ -88,8 +87,7 @@
88 AcceleratorController::Ptr accelerator_controller_;87 AcceleratorController::Ptr accelerator_controller_;
89 UpstartWrapper::Ptr upstart_wrapper_;88 UpstartWrapper::Ptr upstart_wrapper_;
90 ShieldFactoryInterface::Ptr shield_factory_;89 ShieldFactoryInterface::Ptr shield_factory_;
91 ShutdownNotifier::Ptr shutdown_notifier_;90 SuspendInhibitorManager::Ptr suspend_inhibitor_manager_;
92 SuspendNotifier::Ptr suspend_notifier_;
9391
94 nux::animation::AnimateValue<double> fade_animator_;92 nux::animation::AnimateValue<double> fade_animator_;
95 nux::animation::AnimateValue<double> blank_window_animator_;93 nux::animation::AnimateValue<double> blank_window_animator_;
9694
=== modified file 'lockscreen/LockScreenPanel.h'
--- lockscreen/LockScreenPanel.h 2014-04-30 00:45:17 +0000
+++ lockscreen/LockScreenPanel.h 2016-04-07 11:57:30 +0000
@@ -22,9 +22,9 @@
2222
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include <Nux/View.h>24#include <Nux/View.h>
25#include <UnityCore/Indicators.h>25#include "UnityCore/Indicators.h"
26#include <UnityCore/GLibSource.h>26#include "UnityCore/GLibSource.h"
27#include <UnityCore/SessionManager.h>27#include "UnityCore/SessionManager.h"
2828
29namespace unity29namespace unity
30{30{
3131
=== modified file 'lockscreen/LockScreenShieldFactory.h'
--- lockscreen/LockScreenShieldFactory.h 2014-12-08 21:56:36 +0000
+++ lockscreen/LockScreenShieldFactory.h 2016-04-07 11:57:30 +0000
@@ -22,6 +22,8 @@
2222
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include "LockScreenAbstractShield.h"24#include "LockScreenAbstractShield.h"
25#include "UnityCore/SessionManager.h"
26#include "UnityCore/Indicators.h"
2527
26namespace unity28namespace unity
27{29{
2830
=== removed file 'lockscreen/ShutdownNotifier.cpp'
--- lockscreen/ShutdownNotifier.cpp 2014-12-16 19:27:36 +0000
+++ lockscreen/ShutdownNotifier.cpp 1970-01-01 00:00:00 +0000
@@ -1,152 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include "ShutdownNotifier.h"
20
21#include <NuxCore/Logger.h>
22#include "UnityCore/GLibDBusProxy.h"
23
24namespace unity
25{
26namespace lockscreen
27{
28
29DECLARE_LOGGER(logger, "unity.lockscreen.shutdownnotifier");
30
31//
32// Private Implementation
33//
34
35class ShutdownNotifier::Impl
36{
37public:
38 Impl();
39 ~Impl();
40
41 bool RegisterInterest(ShutdownCallback const& cb);
42 void UnregisterInterest();
43
44 void Inhibit();
45 void Uninhibit();
46 bool IsInhibited() const;
47
48private:
49 std::shared_ptr<glib::DBusProxy> logind_proxy_;
50 ShutdownCallback cb_;
51 gint delay_inhibit_fd_;
52};
53
54ShutdownNotifier::Impl::Impl()
55 : logind_proxy_(std::make_shared<glib::DBusProxy>("org.freedesktop.login1",
56 "/org/freedesktop/login1",
57 "org.freedesktop.login1.Manager",
58 G_BUS_TYPE_SYSTEM))
59 , delay_inhibit_fd_(-1)
60{}
61
62ShutdownNotifier::Impl::~Impl()
63{
64 UnregisterInterest();
65}
66
67bool ShutdownNotifier::Impl::RegisterInterest(ShutdownCallback const& cb)
68{
69 if (!cb or cb_)
70 return false;
71
72 cb_ = cb;
73
74 Inhibit();
75
76 logind_proxy_->Connect("PrepareForShutdown", [this](GVariant* variant) {
77 bool active = glib::Variant(variant).GetBool();
78
79 if (active)
80 {
81 cb_();
82 UnregisterInterest();
83 }
84 });
85
86 return true;
87}
88
89void ShutdownNotifier::Impl::UnregisterInterest()
90{
91 if (!cb_)
92 return;
93
94 Uninhibit();
95
96 logind_proxy_->DisconnectSignal("PrepareForShutdown");
97 cb_ = nullptr;
98}
99
100void ShutdownNotifier::Impl::Inhibit()
101{
102 if (IsInhibited())
103 return;
104
105 GVariant* args = g_variant_new("(ssss)", "shutdown", "Unity Lockscreen", "Screen is locked", "delay");
106
107 logind_proxy_->CallWithUnixFdList("Inhibit", args, [this] (GVariant* variant, glib::Error const& e) {
108 if (e)
109 {
110 LOG_ERROR(logger) << "Failed to inhbit suspend";
111 }
112 delay_inhibit_fd_ = glib::Variant(variant).GetInt32();
113 });
114}
115
116void ShutdownNotifier::Impl::Uninhibit()
117{
118 if (!IsInhibited())
119 return;
120
121 close(delay_inhibit_fd_);
122 delay_inhibit_fd_ = -1;
123}
124
125bool ShutdownNotifier::Impl::IsInhibited() const
126{
127 return delay_inhibit_fd_ != -1;
128}
129
130//
131// End Private Implementation
132//
133
134ShutdownNotifier::ShutdownNotifier()
135 : pimpl_(new(Impl))
136{}
137
138ShutdownNotifier::~ShutdownNotifier()
139{}
140
141bool ShutdownNotifier::RegisterInterest(ShutdownCallback const& cb)
142{
143 return pimpl_->RegisterInterest(cb);
144}
145
146void ShutdownNotifier::UnregisterInterest()
147{
148 pimpl_->UnregisterInterest();
149}
150
151}
152}
1530
=== removed file 'lockscreen/ShutdownNotifier.h'
--- lockscreen/ShutdownNotifier.h 2014-12-16 19:27:36 +0000
+++ lockscreen/ShutdownNotifier.h 1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#ifndef UNITY_LOCKSCREEN_SHUTDOWN_NOTIFIER
20#define UNITY_LOCKSCREEN_SHUTDOWN_NOTIFIER
21
22#include <memory>
23#include <functional>
24
25namespace unity
26{
27namespace lockscreen
28{
29
30typedef std::function<void()> ShutdownCallback;
31
32class ShutdownNotifier
33{
34public:
35 typedef std::shared_ptr<ShutdownNotifier> Ptr;
36
37 ShutdownNotifier();
38 ~ShutdownNotifier();
39
40 bool RegisterInterest(ShutdownCallback const&);
41 void UnregisterInterest();
42
43private:
44 class Impl;
45 std::unique_ptr<Impl> pimpl_;
46};
47
48}
49}
50
51#endif
520
=== added file 'lockscreen/SuspendInhibitorManager.cpp'
--- lockscreen/SuspendInhibitorManager.cpp 1970-01-01 00:00:00 +0000
+++ lockscreen/SuspendInhibitorManager.cpp 2016-04-07 11:57:30 +0000
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include "SuspendInhibitorManager.h"
20
21#include <NuxCore/Logger.h>
22#include "UnityCore/GLibDBusProxy.h"
23
24namespace unity
25{
26namespace lockscreen
27{
28
29DECLARE_LOGGER(logger, "unity.lockscreen.suspendinhibitormanager");
30
31//
32// Private Implementation
33//
34
35class SuspendInhibitorManager::Impl
36{
37public:
38 Impl(SuspendInhibitorManager *parent);
39 ~Impl();
40
41 void Inhibit(std::string const&);
42 void Uninhibit();
43 bool IsInhibited();
44
45private:
46 SuspendInhibitorManager *parent_;
47 std::shared_ptr<glib::DBusProxy> lm_proxy_;
48 gint inhibitor_handler_;
49};
50
51SuspendInhibitorManager::Impl::Impl(SuspendInhibitorManager *parent)
52 : parent_(parent)
53 , inhibitor_handler_(-1)
54{
55 lm_proxy_ = std::make_shared<glib::DBusProxy>("org.freedesktop.login1",
56 "/org/freedesktop/login1",
57 "org.freedesktop.login1.Manager",
58 G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES);
59
60 lm_proxy_->Connect("PrepareForSleep", [this] (GVariant* variant) {
61 if (glib::Variant(variant).GetBool())
62 parent_->about_to_suspend.emit();
63 });
64
65 lm_proxy_->connected.connect(sigc::mem_fun(&parent->connected, &decltype(parent->connected)::emit));
66}
67
68SuspendInhibitorManager::Impl::~Impl()
69{}
70
71void SuspendInhibitorManager::Impl::Inhibit(std::string const& msg)
72{
73 if (IsInhibited())
74 return;
75
76 GVariant* args = g_variant_new("(ssss)", "sleep", "Unity", msg.c_str(), "delay");
77
78 lm_proxy_->CallWithUnixFdList("Inhibit", args, [this] (GVariant* variant, glib::Error const& e) {
79 if (e)
80 {
81 LOG_WARNING(logger) << "Failed to inhbit suspend";
82 return;
83 }
84
85 inhibitor_handler_ = glib::Variant(variant).GetInt32();
86 });
87}
88
89void SuspendInhibitorManager::Impl::Uninhibit()
90{
91 if (IsInhibited())
92 {
93 close(inhibitor_handler_);
94 inhibitor_handler_ = -1;
95 }
96}
97
98bool SuspendInhibitorManager::Impl::IsInhibited()
99{
100 return inhibitor_handler_ >= 0;
101}
102
103//
104// End Private Implementation
105//
106
107SuspendInhibitorManager::SuspendInhibitorManager()
108 : pimpl_(new Impl(this))
109{}
110
111SuspendInhibitorManager::~SuspendInhibitorManager()
112{}
113
114void SuspendInhibitorManager::Inhibit(std::string const& msg)
115{
116 pimpl_->Inhibit(msg);
117}
118
119void SuspendInhibitorManager::Uninhibit()
120{
121 pimpl_->Uninhibit();
122}
123
124bool SuspendInhibitorManager::IsInhibited()
125{
126 return pimpl_->IsInhibited();
127}
128
129
130}
131}
0132
=== added file 'lockscreen/SuspendInhibitorManager.h'
--- lockscreen/SuspendInhibitorManager.h 1970-01-01 00:00:00 +0000
+++ lockscreen/SuspendInhibitorManager.h 2016-04-07 11:57:30 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#ifndef UNITY_LOCKSCREEN_SUSPEND_INHIBITOR_MANAGER
20#define UNITY_LOCKSCREEN_SUSPEND_INHIBITOR_MANAGER
21
22#include <memory>
23#include <string>
24#include <sigc++/signal.h>
25
26namespace unity
27{
28namespace lockscreen
29{
30
31class SuspendInhibitorManager
32{
33public:
34 typedef std::shared_ptr<SuspendInhibitorManager> Ptr;
35
36 SuspendInhibitorManager();
37 ~SuspendInhibitorManager();
38
39 void Inhibit(std::string const&);
40 void Uninhibit();
41 bool IsInhibited();
42
43 sigc::signal<void> connected;
44 sigc::signal<void> about_to_suspend;
45
46private:
47 class Impl;
48 std::unique_ptr<Impl> pimpl_;
49};
50
51}
52}
53
54#endif
055
=== removed file 'lockscreen/SuspendNotifier.cpp'
--- lockscreen/SuspendNotifier.cpp 2014-12-16 19:27:36 +0000
+++ lockscreen/SuspendNotifier.cpp 1970-01-01 00:00:00 +0000
@@ -1,153 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include "SuspendNotifier.h"
20
21#include <NuxCore/Logger.h>
22#include "UnityCore/GLibDBusProxy.h"
23
24namespace unity
25{
26namespace lockscreen
27{
28
29DECLARE_LOGGER(logger, "unity.lockscreen.suspendnotifier");
30
31//
32// Private Implementation
33//
34
35class SuspendNotifier::Impl
36{
37public:
38 Impl();
39 ~Impl();
40
41 bool RegisterInterest(SuspendCallback const& cb);
42 void UnregisterInterest();
43
44 void Inhibit();
45 void Uninhibit();
46 bool IsInhibited() const;
47
48private:
49 std::shared_ptr<glib::DBusProxy> logind_proxy_;
50 SuspendCallback cb_;
51 gint delay_inhibit_fd_;
52};
53
54SuspendNotifier::Impl::Impl()
55 : logind_proxy_(std::make_shared<glib::DBusProxy>("org.freedesktop.login1",
56 "/org/freedesktop/login1",
57 "org.freedesktop.login1.Manager",
58 G_BUS_TYPE_SYSTEM))
59 , delay_inhibit_fd_(-1)
60{}
61
62SuspendNotifier::Impl::~Impl()
63{
64 UnregisterInterest();
65}
66
67bool SuspendNotifier::Impl::RegisterInterest(SuspendCallback const& cb)
68{
69 if (!cb or cb_)
70 return false;
71
72 cb_ = cb;
73
74 Inhibit();
75
76 logind_proxy_->Connect("PrepareForSleep", [this](GVariant* variant) {
77 bool active = glib::Variant(variant).GetBool();
78
79 if (active) // suspending
80 {
81 cb_();
82 Uninhibit();
83 }
84 else // resuming
85 {
86 Inhibit();
87 }
88 });
89
90 return true;
91}
92
93void SuspendNotifier::Impl::UnregisterInterest()
94{
95 Uninhibit();
96
97 logind_proxy_->DisconnectSignal("PrepareForSleep");
98 cb_ = nullptr;
99}
100
101void SuspendNotifier::Impl::Inhibit()
102{
103 if (IsInhibited())
104 return;
105
106 GVariant* args = g_variant_new("(ssss)", "sleep", "Unity Lockscreen", "Unity wants to lock screen before suspending.", "delay");
107
108 logind_proxy_->CallWithUnixFdList("Inhibit", args, [this] (GVariant* variant, glib::Error const& e) {
109 if (e)
110 {
111 LOG_ERROR(logger) << "Failed to inhbit suspend";
112 }
113 delay_inhibit_fd_ = glib::Variant(variant).GetInt32();
114 });
115}
116
117void SuspendNotifier::Impl::Uninhibit()
118{
119 if (!IsInhibited())
120 return;
121
122 close(delay_inhibit_fd_);
123 delay_inhibit_fd_ = -1;
124}
125
126bool SuspendNotifier::Impl::IsInhibited() const
127{
128 return delay_inhibit_fd_ != -1;
129}
130
131//
132// End Private Implementation
133//
134
135SuspendNotifier::SuspendNotifier()
136 : pimpl_(new(Impl))
137{}
138
139SuspendNotifier::~SuspendNotifier()
140{}
141
142bool SuspendNotifier::RegisterInterest(SuspendCallback const& cb)
143{
144 return pimpl_->RegisterInterest(cb);
145}
146
147void SuspendNotifier::UnregisterInterest()
148{
149 pimpl_->UnregisterInterest();
150}
151
152}
153}
1540
=== removed file 'lockscreen/SuspendNotifier.h'
--- lockscreen/SuspendNotifier.h 2014-12-16 19:27:36 +0000
+++ lockscreen/SuspendNotifier.h 1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#ifndef UNITY_LOCKSCREEN_SUSPEND_NOTIFIER
20#define UNITY_LOCKSCREEN_SHUTDOWN_NOTIFIER
21
22#include <memory>
23#include <functional>
24
25namespace unity
26{
27namespace lockscreen
28{
29
30typedef std::function<void()> SuspendCallback;
31
32class SuspendNotifier
33{
34public:
35 typedef std::shared_ptr<SuspendNotifier> Ptr;
36
37 SuspendNotifier();
38 ~SuspendNotifier();
39
40 bool RegisterInterest(SuspendCallback const&);
41 void UnregisterInterest();
42
43private:
44 class Impl;
45 std::unique_ptr<Impl> pimpl_;
46};
47
48}
49}
50
51#endif
52\ No newline at end of file0\ No newline at end of file
531
=== modified file 'lockscreen/UserPromptView.h'
--- lockscreen/UserPromptView.h 2014-12-08 22:02:13 +0000
+++ lockscreen/UserPromptView.h 2016-04-07 11:57:30 +0000
@@ -25,7 +25,7 @@
2525
26#include <Nux/Nux.h>26#include <Nux/Nux.h>
27#include <Nux/View.h>27#include <Nux/View.h>
28#include <UnityCore/SessionManager.h>28#include "UnityCore/SessionManager.h"
2929
30#include "UserAuthenticatorPam.h"30#include "UserAuthenticatorPam.h"
31#include "unity-shared/IMTextEntry.h"31#include "unity-shared/IMTextEntry.h"
3232
=== modified file 'lockscreen/pch/lockscreen_pch.hh'
--- lockscreen/pch/lockscreen_pch.hh 2014-03-07 18:35:10 +0000
+++ lockscreen/pch/lockscreen_pch.hh 2016-04-07 11:57:30 +0000
@@ -28,5 +28,5 @@
28#include <security/pam_appl.h>28#include <security/pam_appl.h>
2929
30#include <Nux/Nux.h>30#include <Nux/Nux.h>
31#include <UnityCore/SessionManager.h>
32#include <UnityCore/Indicators.h>
33\ No newline at end of file31\ No newline at end of file
32#include "UnityCore/SessionManager.h"
33#include "UnityCore/Indicators.h"
34\ No newline at end of file34\ No newline at end of file
3535
=== modified file 'shutdown/SessionController.h'
--- shutdown/SessionController.h 2014-02-17 04:05:06 +0000
+++ shutdown/SessionController.h 2016-04-07 11:57:30 +0000
@@ -26,7 +26,7 @@
26#include <Nux/BaseWindow.h>26#include <Nux/BaseWindow.h>
27#include <Nux/HLayout.h>27#include <Nux/HLayout.h>
28#include <NuxCore/Animation.h>28#include <NuxCore/Animation.h>
29#include <UnityCore/SessionManager.h>29#include "UnityCore/SessionManager.h"
3030
31#include "SessionView.h"31#include "SessionView.h"
3232
3333
=== modified file 'shutdown/SessionDBusManager.h'
--- shutdown/SessionDBusManager.h 2014-03-07 03:26:23 +0000
+++ shutdown/SessionDBusManager.h 2016-04-07 11:57:30 +0000
@@ -20,9 +20,9 @@
20#ifndef UNITYSHELL_SESSION_DBUS_MANAGER_H20#ifndef UNITYSHELL_SESSION_DBUS_MANAGER_H
21#define UNITYSHELL_SESSION_DBUS_MANAGER_H21#define UNITYSHELL_SESSION_DBUS_MANAGER_H
2222
23#include <UnityCore/ConnectionManager.h>23#include "UnityCore/ConnectionManager.h"
24#include <UnityCore/GLibDBusServer.h>24#include "UnityCore/GLibDBusServer.h"
25#include <UnityCore/SessionManager.h>25#include "UnityCore/SessionManager.h"
2626
27namespace unity27namespace unity
28{28{
2929
=== modified file 'shutdown/SessionView.h'
--- shutdown/SessionView.h 2014-07-23 18:56:11 +0000
+++ shutdown/SessionView.h 2016-04-07 11:57:30 +0000
@@ -26,7 +26,7 @@
26#include <Nux/HLayout.h>26#include <Nux/HLayout.h>
2727
28#include <UnityCore/GLibSource.h>28#include <UnityCore/GLibSource.h>
29#include <UnityCore/SessionManager.h>29#include "UnityCore/SessionManager.h"
30#include "unity-shared/EMConverter.h"30#include "unity-shared/EMConverter.h"
31#include "unity-shared/UnityWindowView.h"31#include "unity-shared/UnityWindowView.h"
3232
3333
=== modified file 'tests/test_mock_session_manager.h'
--- tests/test_mock_session_manager.h 2014-07-23 18:56:11 +0000
+++ tests/test_mock_session_manager.h 2016-04-07 11:57:30 +0000
@@ -18,7 +18,7 @@
18 */18 */
1919
20#include <gmock/gmock.h>20#include <gmock/gmock.h>
21#include <UnityCore/SessionManager.h>21#include "UnityCore/SessionManager.h"
2222
23namespace unity23namespace unity
24{24{
2525
=== modified file 'unity-shared/PluginAdapter.cpp'
--- unity-shared/PluginAdapter.cpp 2015-10-15 16:13:20 +0000
+++ unity-shared/PluginAdapter.cpp 2016-04-07 11:57:30 +0000
@@ -1459,26 +1459,6 @@
1459 _last_focused_window = NULL;1459 _last_focused_window = NULL;
1460}1460}
14611461
1462void PluginAdapter::UnmapAllNoNuxWindowsSync()
1463{
1464 for (auto const& window : m_Screen->windows())
1465 {
1466 if (!IsNuxWindow(window) && (window->isMapped() || window->isViewable()))
1467 {
1468 if (window->overrideRedirect())
1469 {
1470 XUnmapWindow(m_Screen->dpy(), window->id());
1471 }
1472 else
1473 {
1474 window->hide();
1475 }
1476 }
1477 }
1478
1479 XSync(m_Screen->dpy(), False);
1480}
1481
1482bool PluginAdapter::IsNuxWindow(CompWindow* value)1462bool PluginAdapter::IsNuxWindow(CompWindow* value)
1483{1463{
1484 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();1464 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
14851465
=== modified file 'unity-shared/PluginAdapter.h'
--- unity-shared/PluginAdapter.h 2014-12-16 19:27:36 +0000
+++ unity-shared/PluginAdapter.h 2016-04-07 11:57:30 +0000
@@ -193,7 +193,6 @@
193193
194 Window GetTopWindowAbove(Window xid) const;194 Window GetTopWindowAbove(Window xid) const;
195195
196 void UnmapAllNoNuxWindowsSync();
197 static bool IsNuxWindow(CompWindow* value);196 static bool IsNuxWindow(CompWindow* value);
198197
199protected:198protected:
200199
=== modified file 'unity-shared/StandaloneWindowManager.h'
--- unity-shared/StandaloneWindowManager.h 2015-05-15 14:12:01 +0000
+++ unity-shared/StandaloneWindowManager.h 2016-04-07 11:57:30 +0000
@@ -164,8 +164,6 @@
164 virtual std::string GetStringProperty(Window window_id, Atom) const;164 virtual std::string GetStringProperty(Window window_id, Atom) const;
165 virtual std::vector<long> GetCardinalProperty(Window window_id, Atom) const;165 virtual std::vector<long> GetCardinalProperty(Window window_id, Atom) const;
166166
167 virtual void UnmapAllNoNuxWindowsSync() {};
168
169 // Mock functions167 // Mock functions
170 StandaloneWindow::Ptr GetWindowByXid(Window window_id) const;168 StandaloneWindow::Ptr GetWindowByXid(Window window_id) const;
171 void AddStandaloneWindow(StandaloneWindow::Ptr const& window);169 void AddStandaloneWindow(StandaloneWindow::Ptr const& window);
172170
=== modified file 'unity-shared/WindowManager.h'
--- unity-shared/WindowManager.h 2015-05-15 14:12:01 +0000
+++ unity-shared/WindowManager.h 2016-04-07 11:57:30 +0000
@@ -170,9 +170,6 @@
170 virtual std::string GetStringProperty(Window, Atom) const = 0;170 virtual std::string GetStringProperty(Window, Atom) const = 0;
171 virtual std::vector<long> GetCardinalProperty(Window, Atom) const = 0;171 virtual std::vector<long> GetCardinalProperty(Window, Atom) const = 0;
172172
173 virtual void UnmapAllNoNuxWindowsSync() = 0;
174
175
176 // Nux Modifiers, Nux Keycode (= X11 KeySym)173 // Nux Modifiers, Nux Keycode (= X11 KeySym)
177 nux::Property<std::pair<unsigned, unsigned>> close_window_key;174 nux::Property<std::pair<unsigned, unsigned>> close_window_key;
178 nux::Property<std::pair<unsigned, unsigned>> activate_indicators_key;175 nux::Property<std::pair<unsigned, unsigned>> activate_indicators_key;

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: