From 9e29a4fdb99b722c43af1268312db68fff17fc60 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 25 Mar 2015 12:42:28 -0500 Subject: 60 seconds after triggering an alarm, release our keepDisplayOn request --- src/snap.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/snap.cpp') diff --git a/src/snap.cpp b/src/snap.cpp index e655d2d..80f200d 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -88,8 +88,9 @@ public: intervention and shouldn't loop the sound. */ const bool interactive = appointment.is_ubuntu_alarm() && m_engine->supports_actions(); - // force the system to stay awake - auto awake = std::make_shared(m_engine->app_name()); + // Force the system to stay awake. + // In a clean world this would be a shared_ptr, but we use it as a GSourceFunc arg... + auto awake = new uin::Awake(m_engine->app_name()); // calendar events are muted in silent mode; alarm clocks never are std::shared_ptr sound; @@ -137,15 +138,31 @@ public: b.add_action ("snooze", _("Snooze")); } + // Don't keep the screen on forever. + // If the alarm keeps going on and on, release our screen-on lock + // after awhile to prevent unneccesary battery drain + constexpr int screen_awake_seconds { 60 }; + auto awake_timeout_func = [](gpointer a){ + static_cast(a)->set_display_forced(false); + return G_SOURCE_REMOVE; + }; + auto awake_timeout_tag = g_timeout_add_seconds (screen_awake_seconds, + awake_timeout_func, + awake); + // add 'sound', 'haptic', and 'awake' objects to the capture so // they stay alive until the closed callback is called; i.e., // for the lifespan of the notficiation - b.set_closed_callback([appointment, snooze, ok, sound, awake, haptic] + b.set_closed_callback([appointment, snooze, ok, sound, haptic, + awake, awake_timeout_tag] (const std::string& action){ if (action == "snooze") snooze(appointment); else ok(appointment); + + g_source_remove(awake_timeout_tag); + delete awake; }); const auto key = m_engine->show(b); -- cgit v1.2.3