aboutsummaryrefslogtreecommitdiff
path: root/src/snap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/snap.cpp')
-rw-r--r--src/snap.cpp23
1 files changed, 20 insertions, 3 deletions
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<uin::Awake>(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<uin::Sound> 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<uin::Awake*>(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);