diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/awake.cpp | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/src/awake.cpp b/src/awake.cpp index 57358ab..e1bec6c 100644 --- a/src/awake.cpp +++ b/src/awake.cpp @@ -48,10 +48,16 @@ public: g_cancellable_cancel (m_cancellable); g_object_unref (m_cancellable); + if (m_display_on_timer) + { + g_source_remove (m_display_on_timer); + m_display_on_timer = 0; + } + if (m_system_bus != nullptr) { unforce_awake (); - unforce_screen (); + remove_display_on_request (); g_object_unref (m_system_bus); } } @@ -106,7 +112,7 @@ private: G_DBUS_CALL_FLAGS_NONE, -1, self->m_cancellable, - on_force_screen_response, + on_keep_display_on_response, self); g_object_unref (system_bus); @@ -146,9 +152,9 @@ private: } } - static void on_force_screen_response (GObject * connection, - GAsyncResult * res, - gpointer gself) + static void on_keep_display_on_response (GObject * connection, + GAsyncResult * res, + gpointer gself) { GError * error; GVariant * args; @@ -171,14 +177,29 @@ private: { auto self = static_cast<Impl*>(gself); - self->m_screen_cookie = NO_SCREEN_COOKIE; - g_variant_get (args, "(i)", &self->m_screen_cookie); - g_debug ("m_screen_cookie is now '%d'", self->m_screen_cookie); + self->m_display_on_cookie = NO_DISPLAY_ON_COOKIE; + g_variant_get (args, "(i)", &self->m_display_on_cookie); + g_debug ("m_display_on_cookie is now '%d'", self->m_display_on_cookie); + + self->m_display_on_timer = g_timeout_add_seconds (self->m_display_on_seconds, + on_display_on_timer, + gself); g_variant_unref (args); } } + static gboolean on_display_on_timer (gpointer gself) + { + auto self = static_cast<Impl*>(gself); + + self->m_display_on_timer = 0; + self->remove_display_on_request(); + + return G_SOURCE_REMOVE; + } + + void unforce_awake () { g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); @@ -202,18 +223,18 @@ private: } } - void unforce_screen () + void remove_display_on_request () { g_return_if_fail (G_IS_DBUS_CONNECTION(m_system_bus)); - if (m_screen_cookie != NO_SCREEN_COOKIE) + if (m_display_on_cookie != NO_DISPLAY_ON_COOKIE) { g_dbus_connection_call (m_system_bus, BUS_SCREEN_NAME, BUS_SCREEN_PATH, BUS_SCREEN_INTERFACE, "removeDisplayOnRequest", - g_variant_new("(i)", m_screen_cookie), + g_variant_new("(i)", m_display_on_cookie), nullptr, G_DBUS_CALL_FLAGS_NONE, -1, @@ -221,7 +242,7 @@ private: nullptr, nullptr); - m_screen_cookie = NO_SCREEN_COOKIE; + m_display_on_cookie = NO_DISPLAY_ON_COOKIE; } } @@ -229,9 +250,21 @@ private: GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; char * m_awake_cookie = nullptr; - int32_t m_screen_cookie = NO_SCREEN_COOKIE; - static constexpr int32_t NO_SCREEN_COOKIE { std::numeric_limits<int32_t>::min() }; + /** + * As described by bug #1434637, alarms should have the display turn on, + * dim, and turn off "just like it would if you'd woken it up yourself". + * USC may be adding an intent-based bus API to handle this use case, + * e.g. turnDisplayOnTemporarily(intent), but there's no timeframe for it. + * + * Until that's avaialble, we can get close to Design's specs by + * requesting a display-on cookie and then releasing the cookie + * a moment later. */ + const guint m_display_on_seconds = 1; + guint m_display_on_timer = 0; + int32_t m_display_on_cookie = NO_DISPLAY_ON_COOKIE; + + static constexpr int32_t NO_DISPLAY_ON_COOKIE { std::numeric_limits<int32_t>::min() }; }; /*** @@ -239,7 +272,7 @@ private: ***/ Awake::Awake(const std::string& app_name): - impl(new Impl (app_name)) + impl(new Impl(app_name)) { } |