From ce5234162fa0c534ff9abf3fce3d03f4b01e893e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Apr 2016 09:43:44 -0500 Subject: don't prompt when the greeter's not running yet: change greeter's payload from an 'is_active' bool to a three-value state of active, inactive, and unavailable --- src/greeter.cpp | 18 +++++++++--------- src/greeter.h | 6 ++++-- src/usb-manager.cpp | 14 ++++++++++---- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/greeter.cpp b/src/greeter.cpp index d41160f..317a829 100644 --- a/src/greeter.cpp +++ b/src/greeter.cpp @@ -41,9 +41,9 @@ public: ~Impl() =default; - core::Property& is_active() + core::Property& state() { - return m_is_active; + return m_state; } private: @@ -130,7 +130,7 @@ private: auto self = static_cast(gself); self->m_owner.clear(); - self->m_is_active.set(false); + self->m_state.set(State::UNAVAILABLE); } static void on_get_is_active_ready( @@ -147,7 +147,7 @@ private: } else { GVariant* is_active {}; g_variant_get_child(v, 0, "v", &is_active); - static_cast(gself)->m_is_active.set(g_variant_get_boolean(is_active)); + static_cast(gself)->m_state.set(g_variant_get_boolean(is_active) ? State::ACTIVE : State::INACTIVE); g_clear_pointer(&is_active, g_variant_unref); } g_clear_pointer(&v, g_variant_unref); @@ -175,12 +175,12 @@ private: if (g_variant_lookup(v, "IsActive", "b", &is_active)) { g_debug("%s is_active changed to %d", G_STRLOC, int(is_active)); - self->m_is_active.set(is_active); + self->m_state.set(is_active ? State::ACTIVE : State::INACTIVE); } g_clear_pointer(&v, g_variant_unref); } - core::Property m_is_active {false}; + core::Property m_state {State::UNAVAILABLE}; std::shared_ptr m_cancellable; std::shared_ptr m_bus; std::string m_owner; @@ -201,8 +201,8 @@ UnityGreeter::UnityGreeter(): UnityGreeter::~UnityGreeter() =default; -core::Property& -UnityGreeter::is_active() +core::Property& +UnityGreeter::state() { - return impl->is_active(); + return impl->state(); } diff --git a/src/greeter.h b/src/greeter.h index e084d25..cde1429 100644 --- a/src/greeter.h +++ b/src/greeter.h @@ -29,7 +29,9 @@ class Greeter public: Greeter(); virtual ~Greeter(); - virtual core::Property& is_active() =0; + + enum class State { UNAVAILABLE, INACTIVE, ACTIVE }; + virtual core::Property& state() =0; }; @@ -38,7 +40,7 @@ class UnityGreeter: public Greeter public: UnityGreeter(); virtual ~UnityGreeter(); - core::Property& is_active() override; + core::Property& state() override; protected: class Impl; diff --git a/src/usb-manager.cpp b/src/usb-manager.cpp index 4d750c0..80b274b 100644 --- a/src/usb-manager.cpp +++ b/src/usb-manager.cpp @@ -49,7 +49,7 @@ public: restart(); }); - m_greeter->is_active().changed().connect([this](bool /*is_active*/) { + m_greeter->state().changed().connect([this](Greeter::State /*state*/) { maybe_snap(); }); @@ -92,9 +92,15 @@ private: void maybe_snap() { - // don't prompt in the greeter! - if (!m_req.public_key.empty() && !m_greeter->is_active().get()) - snap(); + // only prompt if there's something to prompt about + if (m_req.public_key.empty()) + return; + + // only prompt in an unlocked session + if (m_greeter->state().get() != Greeter::State::INACTIVE) + return; + + snap(); } void snap() -- cgit v1.2.3