summaryrefslogtreecommitdiff
path: root/lockscreen
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2014-10-21 18:16:50 +0200
committerAndrea Azzarone <azzaronea@gmail.com>2014-10-21 18:16:50 +0200
commit33a1d9b33786aa18bb9ce3637838ba546cf66a0a (patch)
tree16526061ed09b1575885bd22a64bd171a01ee35e /lockscreen
parent249c6379179ff80ddad4d2409df4f277daca5371 (diff)
Improve the logic behind SuspendNotifier.
(bzr r3874.1.12)
Diffstat (limited to 'lockscreen')
-rw-r--r--lockscreen/SuspendNotifier.cpp54
1 files changed, 31 insertions, 23 deletions
diff --git a/lockscreen/SuspendNotifier.cpp b/lockscreen/SuspendNotifier.cpp
index 88c267a97..955637385 100644
--- a/lockscreen/SuspendNotifier.cpp
+++ b/lockscreen/SuspendNotifier.cpp
@@ -39,7 +39,10 @@ public:
~Impl();
bool RegisterInterest(SuspendCallback const& cb);
- void UnregisterInterest();
+ //void UnregisterInterest();
+
+ void Inhibit();
+ void Uninhibit();
private:
std::shared_ptr<glib::DBusProxy> logind_proxy_;
@@ -57,26 +60,18 @@ SuspendNotifier::Impl::Impl()
SuspendNotifier::Impl::~Impl()
{
- UnregisterInterest();
- logind_proxy_->DisconnectSignal("PrepareForSleep");
+ //UnregisterInterest();
+ //logind_proxy_->DisconnectSignal("PrepareForSleep");
}
bool SuspendNotifier::Impl::RegisterInterest(SuspendCallback const& cb)
{
- /*if (!cb or cb_)
- return false;*/
+ if (!cb or cb_)
+ return false;
cb_ = cb;
- logind_proxy_->CallWithUnixFdList("Inhibit",
- g_variant_new("(ssss)", "sleep", "Unity Lockscreen", "Screen is locked", "delay"),
- [this](GVariant* variant, glib::Error const& e){
- if (e)
- {
- LOG_ERROR(logger) << "Failed to inhbit suspend";
- }
- delay_inhibit_fd_ = glib::Variant(variant).GetInt32();
- });
+ Inhibit();
logind_proxy_->Connect("PrepareForSleep", [this](GVariant* variant) {
bool active = glib::Variant(variant).GetBool();
@@ -84,26 +79,39 @@ bool SuspendNotifier::Impl::RegisterInterest(SuspendCallback const& cb)
if (active)
{
cb_();
- UnregisterInterest(); // Actually it's just unlock the inhbit
+ Uninhibit();
}
else
{
- RegisterInterest(cb_);
+ Inhibit();
}
});
return true;
}
-void SuspendNotifier::Impl::UnregisterInterest()
+void SuspendNotifier::Impl::Inhibit()
{
- /*if (!cb_)
- return;*/
-
if (delay_inhibit_fd_ != -1)
- close(delay_inhibit_fd_);
+ return;
+
+ logind_proxy_->CallWithUnixFdList("Inhibit",
+ g_variant_new("(ssss)", "sleep", "Unity Lockscreen", "Screen is locked", "delay"),
+ [this](GVariant* variant, glib::Error const& e){
+ if (e)
+ {
+ LOG_ERROR(logger) << "Failed to inhbit suspend";
+ }
+ delay_inhibit_fd_ = glib::Variant(variant).GetInt32();
+ });
+}
+
+void SuspendNotifier::Impl::Uninhibit()
+{
+ if (delay_inhibit_fd_ == -1)
+ return;
- //cb_ = 0;
+ close(delay_inhibit_fd_);
delay_inhibit_fd_ = -1;
}
@@ -125,7 +133,7 @@ bool SuspendNotifier::RegisterInterest(SuspendCallback const& cb)
void SuspendNotifier::UnregisterInterest()
{
- pimpl_->UnregisterInterest();
+ //pimpl_->UnregisterInterest();
}
}