/* notification-manager.c generated by valac 0.56.19, the Vala compiler
 * generated from notification-manager.vala, do not modify */

/*
 * Copyright (c) 2023-2026 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include <glib-object.h>
#include "ft_core.h"
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>

#define FT_NOTIFICATION_MANAGER_WITHDRAW_TIMEOUT_SECONDS ((guint) 30)
#define FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_OPEN_TIMEOUT ((guint) 1000)
#define FT_NOTIFICATION_MANAGER_EXPIRY_TIMEOUT 5000
#define FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TIMEOUT (10 * FT_INTERVAL_SECOND)
#define FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TOLERANCE (5 * FT_INTERVAL_SECOND)
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef enum  {
	FT_NOTIFICATION_TYPE_NULL,
	FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END,
	FT_NOTIFICATION_TYPE_TIME_BLOCK_ENDED,
	FT_NOTIFICATION_TYPE_TIME_BLOCK_STARTED,
	FT_NOTIFICATION_TYPE_TIME_BLOCK_RUNNING,
	FT_NOTIFICATION_TYPE_CONFIRM_ADVANCEMENT
} FtNotificationType;

#define FT_TYPE_NOTIFICATION_TYPE (ft_notification_type_get_type ())
enum  {
	FT_NOTIFICATION_MANAGER_0_PROPERTY,
	FT_NOTIFICATION_MANAGER_TIMER_PROPERTY,
	FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY,
	FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY,
	FT_NOTIFICATION_MANAGER_NUM_PROPERTIES
};
static GParamSpec* ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _ft_notification_unref0(var) ((var == NULL) ? NULL : (var = (ft_notification_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
enum  {
	FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_OPENED_SIGNAL,
	FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_CLOSED_SIGNAL,
	FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_OPEN_SIGNAL,
	FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_CLOSE_SIGNAL,
	FT_NOTIFICATION_MANAGER_NUM_SIGNALS
};
static guint ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_NUM_SIGNALS] = {0};

struct _FtNotificationManagerPrivate {
	FtTimer* _timer;
	FtSessionManager* _session_manager;
	FtNotificationBackendInterface* _backend;
	GSettings* settings;
	FtIdleMonitor* idle_monitor;
	FtLockScreen* lock_screen;
	FtTimerState previous_timer_state;
	gulong timer_state_changed_id;
	gulong timer_tick_id;
	gulong settings_changed_id;
	gulong session_manager_confirm_advancement_id;
	gint inhibit_count;
	gboolean screen_overlay_active;
	guint screen_overlay_open_timeout_id;
	guint update_timeout_id;
	guint withdraw_timeout_id;
	guint lock_screen_idle_id;
	guint reopen_screen_overlay_idle_id;
	FtNotification* notification;
	FtNotificationType notification_type;
	FtTimeBlock* notification_time_block;
};

static gint FtNotificationManager_private_offset;
static gpointer ft_notification_manager_parent_class = NULL;

VALA_EXTERN GType ft_notification_type_get_type (void) G_GNUC_CONST ;
static void ft_notification_manager_screen_overlay_opened (FtNotificationManager* self);
static void ft_notification_manager_screen_overlay_closed (FtNotificationManager* self);
static gchar* ft_notification_manager_format_remaining_time (FtNotificationManager* self,
                                                      FtTimeBlock* time_block);
static gboolean ft_notification_manager_can_open_screen_overlay_later (FtNotificationManager* self);
static gboolean ft_notification_manager_can_open_screen_overlay (FtNotificationManager* self);
static void ft_notification_manager_on_lock_screen_idle (FtNotificationManager* self);
static void ft_notification_manager_on_reopen_screen_overlay_idle (FtNotificationManager* self);
static gint64 ft_notification_manager_get_about_to_end_duration (FtNotificationManager* self);
static void ft_notification_manager_emit_request_screen_overlay_open (FtNotificationManager* self);
static void ft_notification_manager_add_lock_screen_idle_watch (FtNotificationManager* self);
static void _ft_notification_manager_on_lock_screen_idle_ft_callback (gpointer self);
static void ft_notification_manager_remove_lock_screen_idle_watch (FtNotificationManager* self);
static void ft_notification_manager_add_reopen_screen_overlay_idle_watch (FtNotificationManager* self);
static void _ft_notification_manager_on_reopen_screen_overlay_idle_ft_callback (gpointer self);
static void ft_notification_manager_remove_reopen_screen_overlay_idle_watch (FtNotificationManager* self);
static void ft_notification_manager_reset_reopen_screen_overlay_idle_watch (FtNotificationManager* self);
static void ft_notification_manager_remove_withdraw_timeout (FtNotificationManager* self);
static void ft_notification_manager_withdraw_notifications (FtNotificationManager* self);
static void ft_notification_manager_schedule_withdraw_notifications (FtNotificationManager* self);
static gboolean __lambda92_ (FtNotificationManager* self);
static gboolean ___lambda92__gsource_func (gpointer self);
static FtNotification* ft_notification_manager_create_notification (FtNotificationManager* self,
                                                             const gchar* title,
                                                             const gchar* body,
                                                             gboolean activate_screen_overlay);
static void ft_notification_manager_notify_time_block_started (FtNotificationManager* self,
                                                        FtTimeBlock* time_block);
static void ft_notification_manager_notify_time_block_running (FtNotificationManager* self,
                                                        FtTimeBlock* time_block);
static void ft_notification_manager_notify_time_block_about_to_end (FtNotificationManager* self,
                                                             FtTimeBlock* time_block);
static void ft_notification_manager_notify_time_block_ended (FtNotificationManager* self,
                                                      FtTimeBlock* previous_time_block);
static void ft_notification_manager_notify_confirm_advancement (FtNotificationManager* self,
                                                         FtTimeBlock* current_time_block,
                                                         FtTimeBlock* next_time_block);
static void ft_notification_manager_update_full (FtNotificationManager* self,
                                          const FtTimerState* current_state,
                                          const FtTimerState* previous_state,
                                          gboolean allow_screen_overlay);
static void ft_notification_manager_emit_request_screen_overlay_close (FtNotificationManager* self,
                                                                gboolean force_close);
static void ft_notification_manager_update (FtNotificationManager* self,
                                     gboolean allow_screen_overlay);
static void ft_notification_manager_on_timer_state_changed (FtNotificationManager* self,
                                                     const FtTimerState* current_state,
                                                     const FtTimerState* previous_state);
static void ft_notification_manager_on_timer_tick (FtNotificationManager* self,
                                            gint64 timestamp);
static void ft_notification_manager_on_session_manager_confirm_advancement (FtNotificationManager* self,
                                                                     FtTimeBlock* current_time_block,
                                                                     FtTimeBlock* next_time_block);
static void ft_notification_manager_on_settings_changed (FtNotificationManager* self,
                                                  GSettings* settings,
                                                  const gchar* key);
static void ft_notification_manager_schedule_announcements (FtNotificationManager* self);
static void _ft_notification_manager_on_timer_tick_ft_timer_tick (FtTimer* _sender,
                                                           gint64 timestamp,
                                                           gpointer self);
static gboolean __lambda90_ (FtNotificationManager* self);
static gboolean ___lambda90__gsource_func (gpointer self);
static void ft_notification_manager_real_dispose (GObject* base);
static void _ft_notification_manager_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                             const FtTimerState* current_state,
                                                                             const FtTimerState* previous_state,
                                                                             gpointer self);
static void _ft_notification_manager_on_session_manager_confirm_advancement_ft_session_manager_confirm_advancement (FtSessionManager* _sender,
                                                                                                             FtTimeBlock* current_time_block,
                                                                                                             FtTimeBlock* next_time_block,
                                                                                                             gpointer self);
static gboolean __lambda91_ (FtNotificationManager* self);
static gboolean ___lambda91__gsource_func (gpointer self);
static GObject * ft_notification_manager_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void _ft_notification_manager_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                      const gchar* key,
                                                                      gpointer self);
static void ft_notification_manager_finalize (GObject * obj);
static GType ft_notification_manager_get_type_once (void);
static void _vala_ft_notification_manager_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_ft_notification_manager_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GType
ft_notification_type_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_NOTIFICATION_TYPE_NULL, "FT_NOTIFICATION_TYPE_NULL", "null"}, {FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END, "FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END", "time-block-about-to-end"}, {FT_NOTIFICATION_TYPE_TIME_BLOCK_ENDED, "FT_NOTIFICATION_TYPE_TIME_BLOCK_ENDED", "time-block-ended"}, {FT_NOTIFICATION_TYPE_TIME_BLOCK_STARTED, "FT_NOTIFICATION_TYPE_TIME_BLOCK_STARTED", "time-block-started"}, {FT_NOTIFICATION_TYPE_TIME_BLOCK_RUNNING, "FT_NOTIFICATION_TYPE_TIME_BLOCK_RUNNING", "time-block-running"}, {FT_NOTIFICATION_TYPE_CONFIRM_ADVANCEMENT, "FT_NOTIFICATION_TYPE_CONFIRM_ADVANCEMENT", "confirm-advancement"}, {0, NULL, NULL}};
	GType ft_notification_type_type_id;
	ft_notification_type_type_id = g_enum_register_static ("FtNotificationType", values);
	return ft_notification_type_type_id;
}

GType
ft_notification_type_get_type (void)
{
	static volatile gsize ft_notification_type_type_id__once = 0;
	if (g_once_init_enter (&ft_notification_type_type_id__once)) {
		GType ft_notification_type_type_id;
		ft_notification_type_type_id = ft_notification_type_get_type_once ();
		g_once_init_leave (&ft_notification_type_type_id__once, ft_notification_type_type_id);
	}
	return ft_notification_type_type_id__once;
}

static inline gpointer
ft_notification_manager_get_instance_private (FtNotificationManager* self)
{
	return G_STRUCT_MEMBER_P (self, FtNotificationManager_private_offset);
}

FtNotificationManager*
ft_notification_manager_construct (GType object_type)
{
	FtNotificationManager * self = NULL;
	FtTimer* _tmp0_;
	FtSessionManager* _tmp1_;
	FtNotificationBackend* _tmp2_;
	FtNotificationBackend* _tmp3_;
	_tmp0_ = ft_timer_get_default ();
	_tmp1_ = ft_session_manager_get_default ();
	_tmp2_ = ft_notification_backend_new ();
	_tmp3_ = _tmp2_;
	self = (FtNotificationManager*) g_object_new (object_type, "timer", _tmp0_, "session-manager", _tmp1_, "backend", _tmp3_, NULL);
	_g_object_unref0 (_tmp3_);
	return self;
}

FtNotificationManager*
ft_notification_manager_new (void)
{
	return ft_notification_manager_construct (FT_TYPE_NOTIFICATION_MANAGER);
}

FtNotificationManager*
ft_notification_manager_construct_with_backend (GType object_type,
                                                FtNotificationBackendInterface* backend)
{
	FtNotificationManager * self = NULL;
	FtTimer* _tmp0_;
	FtSessionManager* _tmp1_;
	g_return_val_if_fail (backend != NULL, NULL);
	_tmp0_ = ft_timer_get_default ();
	_tmp1_ = ft_session_manager_get_default ();
	self = (FtNotificationManager*) g_object_new (object_type, "timer", _tmp0_, "session-manager", _tmp1_, "backend", backend, NULL);
	return self;
}

FtNotificationManager*
ft_notification_manager_new_with_backend (FtNotificationBackendInterface* backend)
{
	return ft_notification_manager_construct_with_backend (FT_TYPE_NOTIFICATION_MANAGER, backend);
}

static gchar*
ft_notification_manager_format_remaining_time (FtNotificationManager* self,
                                               FtTimeBlock* time_block)
{
	gint64 timestamp = 0LL;
	FtTimer* _tmp0_;
	gdouble seconds = 0.0;
	guint seconds_uint = 0U;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (time_block != NULL, NULL);
	_tmp0_ = self->priv->_timer;
	timestamp = ft_timer_get_last_tick_time (_tmp0_);
	seconds = ft_timestamp_to_seconds (ft_time_block_calculate_remaining (time_block, timestamp));
	seconds_uint = (guint) ft_round_seconds (seconds);
	_tmp1_ = ft_format_time (seconds_uint);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup_printf (_ ("%s remaining"), _tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	result = _tmp4_;
	return result;
}

/**
         * Check basic conditions if the screen overlay is possible for the current timer state.
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gboolean
ft_notification_manager_can_open_screen_overlay_later (FtNotificationManager* self)
{
	FtTimer* _tmp0_;
	FtTimeBlock* current_time_block = NULL;
	FtSessionManager* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtTimeBlock* _tmp4_;
	gboolean _tmp5_ = FALSE;
	FtTimeBlock* _tmp6_;
	GSettings* _tmp10_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_timer;
	if (!ft_timer_is_running (_tmp0_)) {
		result = FALSE;
		return result;
	}
	_tmp1_ = self->priv->_session_manager;
	_tmp2_ = ft_session_manager_get_current_time_block (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	current_time_block = _tmp4_;
	_tmp6_ = current_time_block;
	if (_tmp6_ == NULL) {
		_tmp5_ = TRUE;
	} else {
		FtTimeBlock* _tmp7_;
		FtState _tmp8_;
		FtState _tmp9_;
		_tmp7_ = current_time_block;
		_tmp8_ = ft_time_block_get_state (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp5_ = !ft_state_is_break (_tmp9_);
	}
	if (_tmp5_) {
		result = FALSE;
		_g_object_unref0 (current_time_block);
		return result;
	}
	_tmp10_ = self->priv->settings;
	if (!g_settings_get_boolean (_tmp10_, "screen-overlay")) {
		result = FALSE;
		_g_object_unref0 (current_time_block);
		return result;
	}
	result = TRUE;
	_g_object_unref0 (current_time_block);
	return result;
}

/**
         * Return whether screen overlay can be opened right now.
         */
static gboolean
ft_notification_manager_can_open_screen_overlay (FtNotificationManager* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (!ft_notification_manager_can_open_screen_overlay_later (self)) {
		result = FALSE;
		return result;
	}
	if (self->priv->notification_type == FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END) {
		FtTimeBlock* _tmp2_;
		_tmp2_ = self->priv->notification_time_block;
		_tmp1_ = _tmp2_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FtTimeBlock* _tmp3_;
		FtState _tmp4_;
		FtState _tmp5_;
		_tmp3_ = self->priv->notification_time_block;
		_tmp4_ = ft_time_block_get_state (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp0_ = ft_state_is_break (_tmp5_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}

static void
ft_notification_manager_on_lock_screen_idle (FtNotificationManager* self)
{
	FtLockScreen* _tmp0_;
	g_return_if_fail (self != NULL);
	if (!self->priv->screen_overlay_active) {
		return;
	}
	_tmp0_ = self->priv->lock_screen;
	ft_lock_screen_activate (_tmp0_);
}

static void
ft_notification_manager_on_reopen_screen_overlay_idle (FtNotificationManager* self)
{
	gint64 timestamp = 0LL;
	FtTimer* _tmp0_;
	gint64 about_to_end_threshold = 0LL;
	FtTimer* _tmp1_;
	g_return_if_fail (self != NULL);
	if (self->priv->screen_overlay_active) {
		g_debug ("notification-manager.vala:196: Screen overlay has already opened.");
		return;
	}
	if (!ft_notification_manager_can_open_screen_overlay (self)) {
		g_debug ("notification-manager.vala:201: Screen overlay not allowed.");
		return;
	}
	_tmp0_ = self->priv->_timer;
	timestamp = ft_timer_get_current_time (_tmp0_, FT_TIMESTAMP_UNDEFINED);
	about_to_end_threshold = ft_notification_manager_get_about_to_end_duration (self) + FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TOLERANCE;
	_tmp1_ = self->priv->_timer;
	if (ft_timer_calculate_remaining (_tmp1_, timestamp) <= about_to_end_threshold) {
		return;
	}
	ft_notification_manager_emit_request_screen_overlay_open (self);
}

static void
_ft_notification_manager_on_lock_screen_idle_ft_callback (gpointer self)
{
	ft_notification_manager_on_lock_screen_idle ((FtNotificationManager*) self);
}

static void
ft_notification_manager_add_lock_screen_idle_watch (FtNotificationManager* self)
{
	gint64 lock_delay = 0LL;
	GSettings* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	lock_delay = ft_timestamp_from_milliseconds_uint (g_settings_get_uint (_tmp0_, "screen-overlay-lock-delay") * 1000U);
	if (self->priv->lock_screen_idle_id == ((guint) 0)) {
		_tmp2_ = lock_delay > ((gint64) 0);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		FtIdleMonitor* _tmp3_;
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp3_ = self->priv->idle_monitor;
		_tmp4_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp3_);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		FtIdleMonitor* _tmp6_;
		_tmp6_ = self->priv->idle_monitor;
		self->priv->lock_screen_idle_id = ft_idle_monitor_add_idle_watch (_tmp6_, lock_delay, TRUE, _ft_notification_manager_on_lock_screen_idle_ft_callback, g_object_ref (self), g_object_unref, g_get_monotonic_time ());
	}
}

static void
ft_notification_manager_remove_lock_screen_idle_watch (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->lock_screen_idle_id != ((guint) 0)) {
		FtIdleMonitor* _tmp0_;
		_tmp0_ = self->priv->idle_monitor;
		ft_idle_monitor_remove_watch (_tmp0_, self->priv->lock_screen_idle_id);
		self->priv->lock_screen_idle_id = (guint) 0;
	}
}

static void
_ft_notification_manager_on_reopen_screen_overlay_idle_ft_callback (gpointer self)
{
	ft_notification_manager_on_reopen_screen_overlay_idle ((FtNotificationManager*) self);
}

static void
ft_notification_manager_add_reopen_screen_overlay_idle_watch (FtNotificationManager* self)
{
	gboolean _tmp0_ = FALSE;
	FtIdleMonitor* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gint64 reopen_delay = 0LL;
	GSettings* _tmp4_;
	FtIdleMonitor* _tmp5_;
	g_return_if_fail (self != NULL);
	if (self->priv->reopen_screen_overlay_idle_id != ((guint) 0)) {
		return;
	}
	_tmp1_ = self->priv->idle_monitor;
	_tmp2_ = ft_provided_object_get_enabled ((FtProvidedObject*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = !ft_notification_manager_can_open_screen_overlay_later (self);
	}
	if (_tmp0_) {
		return;
	}
	_tmp4_ = self->priv->settings;
	reopen_delay = ft_timestamp_from_milliseconds_uint (g_settings_get_uint (_tmp4_, "screen-overlay-reopen-delay") * 1000U);
	_tmp5_ = self->priv->idle_monitor;
	self->priv->reopen_screen_overlay_idle_id = ft_idle_monitor_add_idle_watch (_tmp5_, reopen_delay, FALSE, _ft_notification_manager_on_reopen_screen_overlay_idle_ft_callback, g_object_ref (self), g_object_unref, g_get_monotonic_time ());
}

static void
ft_notification_manager_remove_reopen_screen_overlay_idle_watch (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->reopen_screen_overlay_idle_id != ((guint) 0)) {
		FtIdleMonitor* _tmp0_;
		_tmp0_ = self->priv->idle_monitor;
		ft_idle_monitor_remove_watch (_tmp0_, self->priv->reopen_screen_overlay_idle_id);
		self->priv->reopen_screen_overlay_idle_id = (guint) 0;
	}
}

static void
ft_notification_manager_reset_reopen_screen_overlay_idle_watch (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	ft_notification_manager_remove_reopen_screen_overlay_idle_watch (self);
	ft_notification_manager_add_reopen_screen_overlay_idle_watch (self);
}

static void
ft_notification_manager_remove_withdraw_timeout (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->withdraw_timeout_id != 0U) {
		g_source_remove (self->priv->withdraw_timeout_id);
		self->priv->withdraw_timeout_id = 0U;
	}
}

static void
ft_notification_manager_withdraw_notifications (FtNotificationManager* self)
{
	FtNotification* _tmp0_;
	FtNotificationBackendInterface* _tmp1_;
	g_return_if_fail (self != NULL);
	ft_notification_manager_remove_withdraw_timeout (self);
	_tmp0_ = self->priv->notification;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->_backend;
	ft_notification_backend_interface_withdraw_notification (_tmp1_, "timer");
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = NULL;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_NULL;
	self->priv->notification_time_block = NULL;
}

static gboolean
__lambda92_ (FtNotificationManager* self)
{
	gboolean result;
	self->priv->withdraw_timeout_id = 0U;
	ft_notification_manager_withdraw_notifications (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda92__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda92_ ((FtNotificationManager*) self);
	return result;
}

static void
ft_notification_manager_schedule_withdraw_notifications (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	ft_notification_manager_remove_withdraw_timeout (self);
	self->priv->withdraw_timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, FT_NOTIFICATION_MANAGER_WITHDRAW_TIMEOUT_SECONDS, ___lambda92__gsource_func, g_object_ref (self), g_object_unref);
	g_source_set_name_by_id (self->priv->withdraw_timeout_id, "Ft.NotificationManager.schedule_withdraw_notifications");
}

static FtNotification*
ft_notification_manager_create_notification (FtNotificationManager* self,
                                             const gchar* title,
                                             const gchar* body,
                                             gboolean activate_screen_overlay)
{
	FtNotification* notification = NULL;
	FtNotification* _tmp0_;
	FtNotification* _tmp1_;
	FtNotification* _tmp2_;
	FtNotification* _tmp3_;
	FtNotification* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	g_return_val_if_fail (body != NULL, NULL);
	_tmp0_ = ft_notification_new (title, body);
	notification = _tmp0_;
	_tmp1_ = notification;
	_tmp1_->priority = FT_NOTIFICATION_PRIORITY_HIGH;
	_tmp2_ = notification;
	_tmp2_->is_transient = TRUE;
	_tmp3_ = notification;
	_tmp3_->suppress_sound = TRUE;
	if (activate_screen_overlay) {
		FtNotification* _tmp4_;
		_tmp4_ = notification;
		ft_notification_set_default_action (_tmp4_, "app.screen-overlay");
	} else {
		FtNotification* _tmp5_;
		GVariant* _tmp6_;
		GVariant* _tmp7_;
		_tmp5_ = notification;
		_tmp6_ = g_variant_new_string ("timer");
		g_variant_ref_sink (_tmp6_);
		_tmp7_ = _tmp6_;
		ft_notification_set_default_action_and_target_value (_tmp5_, "app.window", _tmp7_);
		_g_variant_unref0 (_tmp7_);
	}
	result = notification;
	return result;
}

/**
         * Show notification informing that the time-block has started.
         */
static gpointer
_ft_notification_ref0 (gpointer self)
{
	return self ? ft_notification_ref (self) : NULL;
}

static void
ft_notification_manager_notify_time_block_started (FtNotificationManager* self,
                                                   FtTimeBlock* time_block)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* body = NULL;
	gchar* _tmp1_;
	FtState _tmp2_;
	FtState _tmp3_;
	FtNotification* notification = NULL;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	FtState _tmp10_;
	FtState _tmp11_;
	FtNotification* _tmp12_;
	gchar* _tmp13_;
	FtNotification* _tmp14_;
	FtNotificationBackendInterface* _tmp15_;
	FtNotification* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = ft_notification_manager_format_remaining_time (self, time_block);
	body = _tmp1_;
	_tmp2_ = ft_time_block_get_state (time_block);
	_tmp3_ = _tmp2_;
	switch (_tmp3_) {
		case FT_STATE_POMODORO:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (_ ("Pomodoro"));
			_g_free0 (title);
			title = _tmp4_;
			break;
		}
		case FT_STATE_BREAK:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("Take a break"));
			_g_free0 (title);
			title = _tmp5_;
			break;
		}
		case FT_STATE_SHORT_BREAK:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup (_ ("Take a short break"));
			_g_free0 (title);
			title = _tmp6_;
			break;
		}
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp7_;
			_tmp7_ = g_strdup (_ ("Take a long break"));
			_g_free0 (title);
			title = _tmp7_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp8_ = title;
	_tmp9_ = body;
	_tmp10_ = ft_time_block_get_state (time_block);
	_tmp11_ = _tmp10_;
	_tmp12_ = ft_notification_manager_create_notification (self, _tmp8_, _tmp9_, ft_state_is_break (_tmp11_));
	notification = _tmp12_;
	_tmp13_ = g_strdup ("time-block-started");
	_g_free0 (notification->event_id);
	notification->event_id = _tmp13_;
	notification->expire_timeout = FT_NOTIFICATION_MANAGER_EXPIRY_TIMEOUT;
	_tmp14_ = _ft_notification_ref0 (notification);
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = _tmp14_;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_TIME_BLOCK_STARTED;
	self->priv->notification_time_block = time_block;
	_tmp15_ = self->priv->_backend;
	_tmp16_ = self->priv->notification;
	ft_notification_backend_interface_send_notification (_tmp15_, "timer", _tmp16_);
	ft_notification_manager_schedule_withdraw_notifications (self);
	_ft_notification_unref0 (notification);
	_g_free0 (body);
	_g_free0 (title);
}

/**
         * Show notification with current state and remaining time.
         */
static void
ft_notification_manager_notify_time_block_running (FtNotificationManager* self,
                                                   FtTimeBlock* time_block)
{
	gchar* title = NULL;
	FtState _tmp0_;
	FtState _tmp1_;
	gchar* _tmp2_;
	gchar* body = NULL;
	gchar* _tmp3_;
	FtNotification* notification = NULL;
	FtState _tmp4_;
	FtState _tmp5_;
	FtNotification* _tmp6_;
	gchar* _tmp7_;
	FtNotification* _tmp8_;
	FtNotificationBackendInterface* _tmp9_;
	FtNotification* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = ft_time_block_get_state (time_block);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_state_get_label (_tmp1_);
	title = _tmp2_;
	_tmp3_ = ft_notification_manager_format_remaining_time (self, time_block);
	body = _tmp3_;
	_tmp4_ = ft_time_block_get_state (time_block);
	_tmp5_ = _tmp4_;
	_tmp6_ = ft_notification_manager_create_notification (self, title, body, ft_state_is_break (_tmp5_));
	notification = _tmp6_;
	_tmp7_ = g_strdup ("time-block-running");
	_g_free0 (notification->event_id);
	notification->event_id = _tmp7_;
	notification->expire_timeout = FT_NOTIFICATION_MANAGER_EXPIRY_TIMEOUT;
	_tmp8_ = _ft_notification_ref0 (notification);
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = _tmp8_;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_TIME_BLOCK_RUNNING;
	self->priv->notification_time_block = time_block;
	_tmp9_ = self->priv->_backend;
	_tmp10_ = self->priv->notification;
	ft_notification_backend_interface_send_notification (_tmp9_, "timer", _tmp10_);
	ft_notification_manager_schedule_withdraw_notifications (self);
	_ft_notification_unref0 (notification);
	_g_free0 (body);
	_g_free0 (title);
}

/**
         * Show notification informing that the time-block has ended.
         */
static void
ft_notification_manager_notify_time_block_about_to_end (FtNotificationManager* self,
                                                        FtTimeBlock* time_block)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* body = NULL;
	gchar* _tmp1_;
	gchar* action_label = NULL;
	gchar* _tmp2_;
	FtState _tmp3_;
	FtState _tmp4_;
	FtNotification* notification = NULL;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	FtNotification* _tmp11_;
	gchar* _tmp12_;
	GVariant* _tmp13_;
	GVariant* _tmp14_;
	const gchar* _tmp15_;
	FtNotification* _tmp16_;
	FtNotificationBackendInterface* _tmp17_;
	FtNotification* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (time_block != NULL);
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = g_strdup ("");
	body = _tmp1_;
	_tmp2_ = g_strdup ("");
	action_label = _tmp2_;
	_tmp3_ = ft_time_block_get_state (time_block);
	_tmp4_ = _tmp3_;
	switch (_tmp4_) {
		case FT_STATE_POMODORO:
		{
			gchar* _tmp5_;
			gchar* _tmp6_;
			_tmp5_ = g_strdup (_ ("Pomodoro is about to end"));
			_g_free0 (title);
			title = _tmp5_;
			_tmp6_ = g_strdup (_ ("Take a Break"));
			_g_free0 (action_label);
			action_label = _tmp6_;
			break;
		}
		case FT_STATE_BREAK:
		case FT_STATE_SHORT_BREAK:
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp7_;
			gchar* _tmp8_;
			_tmp7_ = g_strdup (_ ("Break is about to end"));
			_g_free0 (title);
			title = _tmp7_;
			_tmp8_ = g_strdup (_ ("Start Pomodoro"));
			_g_free0 (action_label);
			action_label = _tmp8_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp9_ = title;
	_tmp10_ = body;
	_tmp11_ = ft_notification_manager_create_notification (self, _tmp9_, _tmp10_, FALSE);
	notification = _tmp11_;
	notification->priority = FT_NOTIFICATION_PRIORITY_URGENT;
	_tmp12_ = g_strdup ("time-block-about-to-end");
	_g_free0 (notification->event_id);
	notification->event_id = _tmp12_;
	_tmp13_ = g_variant_new_int32 ((gint32) 60);
	g_variant_ref_sink (_tmp13_);
	_tmp14_ = _tmp13_;
	ft_notification_add_button_with_target_value (notification, _ ("+1 minute"), "app.extend", _tmp14_);
	_g_variant_unref0 (_tmp14_);
	_tmp15_ = action_label;
	ft_notification_add_button (notification, _tmp15_, "app.advance");
	_tmp16_ = _ft_notification_ref0 (notification);
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = _tmp16_;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END;
	self->priv->notification_time_block = time_block;
	_tmp17_ = self->priv->_backend;
	_tmp18_ = self->priv->notification;
	ft_notification_backend_interface_send_notification (_tmp17_, "timer", _tmp18_);
	ft_notification_manager_remove_withdraw_timeout (self);
	_ft_notification_unref0 (notification);
	_g_free0 (action_label);
	_g_free0 (body);
	_g_free0 (title);
}

/**
         * Show notification informing that the time-block has ended.
         *
         * It's only shown when waiting for activity.
         */
static void
ft_notification_manager_notify_time_block_ended (FtNotificationManager* self,
                                                 FtTimeBlock* previous_time_block)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* body = NULL;
	gchar* _tmp1_;
	FtState _tmp2_;
	FtState _tmp3_;
	FtNotification* notification = NULL;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	FtNotification* _tmp8_;
	gchar* _tmp9_;
	FtNotification* _tmp10_;
	FtNotificationBackendInterface* _tmp11_;
	FtNotification* _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (previous_time_block != NULL);
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = g_strdup (_ ("Get ready…"));
	body = _tmp1_;
	_tmp2_ = ft_time_block_get_state (previous_time_block);
	_tmp3_ = _tmp2_;
	switch (_tmp3_) {
		case FT_STATE_POMODORO:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (_ ("Pomodoro is over!"));
			_g_free0 (title);
			title = _tmp4_;
			break;
		}
		case FT_STATE_BREAK:
		case FT_STATE_SHORT_BREAK:
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("Break is over!"));
			_g_free0 (title);
			title = _tmp5_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp6_ = title;
	_tmp7_ = body;
	_tmp8_ = ft_notification_manager_create_notification (self, _tmp6_, _tmp7_, FALSE);
	notification = _tmp8_;
	notification->priority = FT_NOTIFICATION_PRIORITY_URGENT;
	_tmp9_ = g_strdup ("time-block-ended");
	_g_free0 (notification->event_id);
	notification->event_id = _tmp9_;
	_tmp10_ = _ft_notification_ref0 (notification);
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = _tmp10_;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_TIME_BLOCK_ENDED;
	self->priv->notification_time_block = previous_time_block;
	_tmp11_ = self->priv->_backend;
	_tmp12_ = self->priv->notification;
	ft_notification_backend_interface_send_notification (_tmp11_, "timer", _tmp12_);
	ft_notification_manager_remove_withdraw_timeout (self);
	_ft_notification_unref0 (notification);
	_g_free0 (body);
	_g_free0 (title);
}

/**
         * Show notification with emphasis on confirming advancement to the next time-block.
         */
static void
ft_notification_manager_notify_confirm_advancement (FtNotificationManager* self,
                                                    FtTimeBlock* current_time_block,
                                                    FtTimeBlock* next_time_block)
{
	gchar* title = NULL;
	gchar* _tmp0_;
	gchar* body = NULL;
	gchar* _tmp1_;
	gchar* action_label = NULL;
	gchar* _tmp2_;
	FtState _tmp3_;
	FtState _tmp4_;
	FtState _tmp7_;
	FtState _tmp8_;
	FtNotification* notification = NULL;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	FtNotification* _tmp19_;
	FtNotification* _tmp20_;
	FtNotification* _tmp21_;
	gchar* _tmp22_;
	FtState _tmp23_;
	FtState _tmp24_;
	FtNotification* _tmp28_;
	const gchar* _tmp29_;
	FtNotification* _tmp30_;
	FtNotification* _tmp31_;
	FtNotificationBackendInterface* _tmp32_;
	FtNotification* _tmp33_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_time_block != NULL);
	g_return_if_fail (next_time_block != NULL);
	_tmp0_ = g_strdup ("");
	title = _tmp0_;
	_tmp1_ = g_strdup ("");
	body = _tmp1_;
	_tmp2_ = g_strdup ("");
	action_label = _tmp2_;
	_tmp3_ = ft_time_block_get_state (current_time_block);
	_tmp4_ = _tmp3_;
	switch (_tmp4_) {
		case FT_STATE_POMODORO:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("Pomodoro is over!"));
			_g_free0 (title);
			title = _tmp5_;
			break;
		}
		case FT_STATE_BREAK:
		case FT_STATE_SHORT_BREAK:
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup (_ ("Break is over!"));
			_g_free0 (title);
			title = _tmp6_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp7_ = ft_time_block_get_state (next_time_block);
	_tmp8_ = _tmp7_;
	switch (_tmp8_) {
		case FT_STATE_POMODORO:
		{
			gchar* _tmp9_;
			gchar* _tmp10_;
			_tmp9_ = g_strdup (_ ("Confirm the start of a Pomodoro…"));
			_g_free0 (body);
			body = _tmp9_;
			_tmp10_ = g_strdup (_ ("Start Pomodoro"));
			_g_free0 (action_label);
			action_label = _tmp10_;
			break;
		}
		case FT_STATE_BREAK:
		{
			gchar* _tmp11_;
			gchar* _tmp12_;
			_tmp11_ = g_strdup (_ ("Confirm the start of a break…"));
			_g_free0 (body);
			body = _tmp11_;
			_tmp12_ = g_strdup (_ ("Take a Break"));
			_g_free0 (action_label);
			action_label = _tmp12_;
			break;
		}
		case FT_STATE_SHORT_BREAK:
		{
			gchar* _tmp13_;
			gchar* _tmp14_;
			_tmp13_ = g_strdup (_ ("Confirm the start of a short break…"));
			_g_free0 (body);
			body = _tmp13_;
			_tmp14_ = g_strdup (_ ("Take a Break"));
			_g_free0 (action_label);
			action_label = _tmp14_;
			break;
		}
		case FT_STATE_LONG_BREAK:
		{
			gchar* _tmp15_;
			gchar* _tmp16_;
			_tmp15_ = g_strdup (_ ("Confirm the start of a long break…"));
			_g_free0 (body);
			body = _tmp15_;
			_tmp16_ = g_strdup (_ ("Take a Break"));
			_g_free0 (action_label);
			action_label = _tmp16_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp17_ = title;
	_tmp18_ = body;
	_tmp19_ = ft_notification_manager_create_notification (self, _tmp17_, _tmp18_, FALSE);
	notification = _tmp19_;
	_tmp20_ = notification;
	_tmp20_->priority = FT_NOTIFICATION_PRIORITY_URGENT;
	_tmp21_ = notification;
	_tmp22_ = g_strdup ("confirm-advancement");
	_g_free0 (_tmp21_->event_id);
	_tmp21_->event_id = _tmp22_;
	_tmp23_ = ft_time_block_get_state (next_time_block);
	_tmp24_ = _tmp23_;
	if (ft_state_is_break (_tmp24_)) {
		FtNotification* _tmp25_;
		GVariant* _tmp26_;
		GVariant* _tmp27_;
		_tmp25_ = notification;
		_tmp26_ = g_variant_new_string ("pomodoro");
		g_variant_ref_sink (_tmp26_);
		_tmp27_ = _tmp26_;
		ft_notification_add_button_with_target_value (_tmp25_, _ ("Skip Break"), "app.advance-to-state", _tmp27_);
		_g_variant_unref0 (_tmp27_);
	}
	_tmp28_ = notification;
	_tmp29_ = action_label;
	ft_notification_add_button (_tmp28_, _tmp29_, "app.advance");
	_tmp30_ = notification;
	_tmp31_ = _ft_notification_ref0 (_tmp30_);
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = _tmp31_;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_CONFIRM_ADVANCEMENT;
	self->priv->notification_time_block = current_time_block;
	_tmp32_ = self->priv->_backend;
	_tmp33_ = self->priv->notification;
	ft_notification_backend_interface_send_notification (_tmp32_, "timer", _tmp33_);
	ft_notification_manager_remove_withdraw_timeout (self);
	_ft_notification_unref0 (notification);
	_g_free0 (action_label);
	_g_free0 (body);
	_g_free0 (title);
}

static gint64
ft_notification_manager_get_about_to_end_duration (FtNotificationManager* self)
{
	GSettings* _tmp0_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_tmp0_ = self->priv->settings;
	if (!g_settings_get_boolean (_tmp0_, "announce-about-to-end")) {
		result = (gint64) 0;
		return result;
	}
	result = FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TIMEOUT;
	return result;
}

static void
ft_notification_manager_update_full (FtNotificationManager* self,
                                     const FtTimerState* current_state,
                                     const FtTimerState* previous_state,
                                     gboolean allow_screen_overlay)
{
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp1_;
	FtSession* _tmp2_;
	FtSession* _tmp3_;
	FtTimeBlock* current_time_block = NULL;
	FtTimerState _tmp4_;
	void* _tmp5_;
	FtTimeBlock* _tmp6_;
	FtTimeBlock* previous_time_block = NULL;
	FtTimerState _tmp7_;
	void* _tmp8_;
	FtTimeBlock* _tmp9_;
	gint64 timestamp = 0LL;
	FtTimer* _tmp10_;
	FtTimerState _tmp11_ = {0};
	gboolean _tmp12_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	_tmp0_ = ft_notification_manager_get_session_manager (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_session_manager_get_current_session (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == NULL) {
		ft_notification_manager_withdraw_notifications (self);
		return;
	}
	if (self->priv->update_timeout_id != 0U) {
		g_source_remove (self->priv->update_timeout_id);
		self->priv->update_timeout_id = 0U;
	}
	_tmp4_ = *current_state;
	_tmp5_ = _tmp4_.user_data;
	_tmp6_ = _g_object_ref0 (FT_IS_TIME_BLOCK (_tmp5_) ? ((FtTimeBlock*) _tmp5_) : NULL);
	current_time_block = _tmp6_;
	_tmp7_ = *previous_state;
	_tmp8_ = _tmp7_.user_data;
	_tmp9_ = _g_object_ref0 (FT_IS_TIME_BLOCK (_tmp8_) ? ((FtTimeBlock*) _tmp8_) : NULL);
	previous_time_block = _tmp9_;
	_tmp10_ = self->priv->_timer;
	timestamp = ft_timer_get_current_time (_tmp10_, FT_TIMESTAMP_UNDEFINED);
	ft_timer_state_copy (previous_state, &_tmp11_);
	self->priv->previous_timer_state = _tmp11_;
	if (!ft_notification_manager_can_open_screen_overlay_later (self)) {
		ft_notification_manager_emit_request_screen_overlay_close (self, TRUE);
		ft_notification_manager_remove_reopen_screen_overlay_idle_watch (self);
	}
	if (ft_timer_state_is_paused (current_state)) {
		_tmp12_ = TRUE;
	} else {
		FtTimeBlock* _tmp13_;
		_tmp13_ = current_time_block;
		_tmp12_ = _tmp13_ == NULL;
	}
	if (_tmp12_) {
		ft_notification_manager_withdraw_notifications (self);
	} else {
		if (ft_timer_state_is_finished (current_state)) {
		} else {
			if (!ft_timer_state_is_started (current_state)) {
				FtTimeBlock* _tmp14_;
				_tmp14_ = previous_time_block;
				if (_tmp14_ != NULL) {
					FtTimeBlock* _tmp15_;
					_tmp15_ = previous_time_block;
					ft_notification_manager_notify_time_block_ended (self, _tmp15_);
				}
			} else {
				if (ft_timer_state_is_running (current_state)) {
					gint64 remaining = 0LL;
					FtTimer* _tmp16_;
					gint64 about_to_end_duration = 0LL;
					gboolean _tmp17_ = FALSE;
					gboolean _tmp18_ = FALSE;
					FtTimerState _tmp19_;
					void* _tmp20_;
					FtTimerState _tmp21_;
					void* _tmp22_;
					gboolean is_rewinding = FALSE;
					FtTimeBlock* _tmp27_;
					FtState _tmp28_;
					FtState _tmp29_;
					FtTimerState _tmp33_;
					_tmp16_ = self->priv->_timer;
					remaining = ft_timer_calculate_remaining (_tmp16_, timestamp);
					about_to_end_duration = ft_notification_manager_get_about_to_end_duration (self) + FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TOLERANCE;
					_tmp19_ = *current_state;
					_tmp20_ = _tmp19_.user_data;
					_tmp21_ = *previous_state;
					_tmp22_ = _tmp21_.user_data;
					if (_tmp20_ == _tmp22_) {
						FtTimerState _tmp23_;
						FtTimerState _tmp24_;
						_tmp23_ = *current_state;
						_tmp24_ = *previous_state;
						_tmp18_ = _tmp23_.paused_time == _tmp24_.paused_time;
					} else {
						_tmp18_ = FALSE;
					}
					if (_tmp18_) {
						FtTimerState _tmp25_;
						FtTimerState _tmp26_;
						_tmp25_ = *current_state;
						_tmp26_ = *previous_state;
						_tmp17_ = _tmp25_.offset != _tmp26_.offset;
					} else {
						_tmp17_ = FALSE;
					}
					is_rewinding = _tmp17_;
					_tmp27_ = current_time_block;
					_tmp28_ = ft_time_block_get_state (_tmp27_);
					_tmp29_ = _tmp28_;
					if (ft_state_is_break (_tmp29_)) {
						gboolean _tmp30_ = FALSE;
						gboolean _tmp31_ = FALSE;
						gboolean _tmp32_ = FALSE;
						if (remaining >= about_to_end_duration) {
							_tmp32_ = !is_rewinding;
						} else {
							_tmp32_ = FALSE;
						}
						if (_tmp32_) {
							_tmp31_ = allow_screen_overlay;
						} else {
							_tmp31_ = FALSE;
						}
						if (_tmp31_) {
							_tmp30_ = ft_notification_manager_can_open_screen_overlay (self);
						} else {
							_tmp30_ = FALSE;
						}
						if (_tmp30_) {
							ft_notification_manager_emit_request_screen_overlay_open (self);
							_g_object_unref0 (previous_time_block);
							_g_object_unref0 (current_time_block);
							return;
						}
					}
					ft_notification_manager_add_reopen_screen_overlay_idle_watch (self);
					_tmp33_ = *current_state;
					if (_tmp33_.started_time == timestamp) {
						FtTimeBlock* _tmp34_;
						_tmp34_ = current_time_block;
						ft_notification_manager_notify_time_block_started (self, _tmp34_);
					} else {
						if (remaining < about_to_end_duration) {
							FtTimeBlock* _tmp35_;
							_tmp35_ = current_time_block;
							ft_notification_manager_notify_time_block_about_to_end (self, _tmp35_);
						} else {
							FtTimeBlock* _tmp36_;
							_tmp36_ = current_time_block;
							ft_notification_manager_notify_time_block_running (self, _tmp36_);
						}
					}
				} else {
					g_assert_not_reached ();
				}
			}
		}
	}
	_g_object_unref0 (previous_time_block);
	_g_object_unref0 (current_time_block);
}

static void
ft_notification_manager_update (FtNotificationManager* self,
                                gboolean allow_screen_overlay)
{
	FtTimer* _tmp0_;
	FtTimerState _tmp1_ = {0};
	FtTimerState _tmp2_;
	FtTimerState _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_timer;
	ft_timer_get_state (_tmp0_, &_tmp1_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->priv->previous_timer_state;
	ft_notification_manager_update_full (self, &_tmp2_, &_tmp3_, allow_screen_overlay);
}

static void
ft_notification_manager_on_timer_state_changed (FtNotificationManager* self,
                                                const FtTimerState* current_state,
                                                const FtTimerState* previous_state)
{
	FtTimerState _tmp0_;
	FtTimerState _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	_tmp0_ = *current_state;
	_tmp1_ = *previous_state;
	ft_notification_manager_update_full (self, &_tmp0_, &_tmp1_, TRUE);
}

static void
ft_notification_manager_on_timer_tick (FtNotificationManager* self,
                                       gint64 timestamp)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gint64 remaining = 0LL;
	FtTimer* _tmp2_;
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->screen_overlay_active) {
		return;
	}
	if (self->priv->notification_type == FT_NOTIFICATION_TYPE_TIME_BLOCK_ABOUT_TO_END) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self->priv->notification_type == FT_NOTIFICATION_TYPE_TIME_BLOCK_ENDED;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->notification_type == FT_NOTIFICATION_TYPE_CONFIRM_ADVANCEMENT;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = self->priv->_timer;
	remaining = ft_timer_calculate_remaining (_tmp2_, timestamp);
	if (remaining <= ft_notification_manager_get_about_to_end_duration (self)) {
		_tmp3_ = remaining >= FT_NOTIFICATION_MANAGER_TIME_BLOCK_ABOUT_TO_END_TOLERANCE;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		FtSessionManager* _tmp4_;
		FtSessionManager* _tmp5_;
		FtTimeBlock* _tmp6_;
		FtTimeBlock* _tmp7_;
		_tmp4_ = ft_notification_manager_get_session_manager (self);
		_tmp5_ = _tmp4_;
		_tmp6_ = ft_session_manager_get_current_time_block (_tmp5_);
		_tmp7_ = _tmp6_;
		ft_notification_manager_notify_time_block_about_to_end (self, _tmp7_);
	}
}

static void
ft_notification_manager_on_session_manager_confirm_advancement (FtNotificationManager* self,
                                                                FtTimeBlock* current_time_block,
                                                                FtTimeBlock* next_time_block)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_time_block != NULL);
	g_return_if_fail (next_time_block != NULL);
	ft_notification_manager_emit_request_screen_overlay_close (self, FALSE);
	ft_notification_manager_notify_confirm_advancement (self, current_time_block, next_time_block);
}

static void
ft_notification_manager_on_settings_changed (FtNotificationManager* self,
                                             GSettings* settings,
                                             const gchar* key)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
	if (self->priv->inhibit_count > 0) {
		return;
	}
	_tmp0_ = key;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("announce-about-to-end")))) {
		switch (0) {
			default:
			{
				ft_notification_manager_schedule_announcements (self);
				break;
			}
		}
	} else if ((_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("screen-overlay")))) || (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("screen-overlay-reopen-delay"))))) {
		switch (0) {
			default:
			{
				if (self->priv->reopen_screen_overlay_idle_id != ((guint) 0)) {
					ft_notification_manager_reset_reopen_screen_overlay_idle_watch (self);
				}
				break;
			}
		}
	}
}

static void
_ft_notification_manager_on_timer_tick_ft_timer_tick (FtTimer* _sender,
                                                      gint64 timestamp,
                                                      gpointer self)
{
	ft_notification_manager_on_timer_tick ((FtNotificationManager*) self, timestamp);
}

static void
ft_notification_manager_schedule_announcements (FtNotificationManager* self)
{
	GSettings* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	if (g_settings_get_boolean (_tmp0_, "announce-about-to-end")) {
		if (self->priv->timer_tick_id == ((gulong) 0)) {
			FtTimer* _tmp1_;
			gulong _tmp2_;
			_tmp1_ = self->priv->_timer;
			_tmp2_ = g_signal_connect_object (_tmp1_, "tick", (GCallback) _ft_notification_manager_on_timer_tick_ft_timer_tick, self, 0);
			self->priv->timer_tick_id = _tmp2_;
		}
	} else {
		if (self->priv->timer_tick_id != ((gulong) 0)) {
			FtTimer* _tmp3_;
			_tmp3_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->timer_tick_id);
			self->priv->timer_tick_id = (gulong) 0;
		}
	}
}

static gboolean
__lambda90_ (FtNotificationManager* self)
{
	gboolean result;
	self->priv->screen_overlay_open_timeout_id = (guint) 0;
	ft_notification_manager_remove_lock_screen_idle_watch (self);
	ft_notification_manager_update (self, FALSE);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda90__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda90_ ((FtNotificationManager*) self);
	return result;
}

static void
ft_notification_manager_emit_request_screen_overlay_open (FtNotificationManager* self)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->screen_overlay_active) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->screen_overlay_open_timeout_id != 0U;
	}
	if (_tmp0_) {
		return;
	}
	self->priv->screen_overlay_open_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_OPEN_TIMEOUT, ___lambda90__gsource_func, g_object_ref (self), g_object_unref);
	g_source_set_name_by_id (self->priv->screen_overlay_open_timeout_id, "Ft.NotificationManager.emit_request_screen_overlay_open");
	g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_OPEN_SIGNAL], 0);
}

static void
ft_notification_manager_emit_request_screen_overlay_close (FtNotificationManager* self,
                                                           gboolean force_close)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	if (!force_close) {
		_tmp1_ = !self->priv->screen_overlay_active;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		_tmp0_ = self->priv->screen_overlay_open_timeout_id == 0U;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	if (self->priv->screen_overlay_open_timeout_id != 0U) {
		g_source_remove (self->priv->screen_overlay_open_timeout_id);
		self->priv->screen_overlay_open_timeout_id = 0U;
	}
	if (self->priv->screen_overlay_active) {
		g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_CLOSE_SIGNAL], 0);
	}
	if (force_close) {
		_tmp2_ = self->priv->screen_overlay_active;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_CLOSED_SIGNAL], 0);
	}
}

void
ft_notification_manager_inhibit (FtNotificationManager* self)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->inhibit_count;
	self->priv->inhibit_count = _tmp0_ + 1;
	if (self->priv->inhibit_count == 1) {
		FtTimer* _tmp1_;
		FtSessionManager* _tmp2_;
		ft_notification_manager_withdraw_notifications (self);
		ft_notification_manager_remove_reopen_screen_overlay_idle_watch (self);
		ft_notification_manager_remove_lock_screen_idle_watch (self);
		_tmp1_ = self->priv->_timer;
		g_signal_handler_block (_tmp1_, self->priv->timer_state_changed_id);
		_tmp2_ = self->priv->_session_manager;
		g_signal_handler_block (_tmp2_, self->priv->session_manager_confirm_advancement_id);
		if (self->priv->timer_tick_id != ((gulong) 0)) {
			FtTimer* _tmp3_;
			_tmp3_ = self->priv->_timer;
			g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->timer_tick_id);
			self->priv->timer_tick_id = (gulong) 0;
		}
	}
}

void
ft_notification_manager_uninhibit (FtNotificationManager* self,
                                   gboolean notify)
{
	gint _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->inhibit_count;
	self->priv->inhibit_count = _tmp0_ - 1;
	if (self->priv->inhibit_count == 0) {
		FtTimer* _tmp1_;
		FtSessionManager* _tmp2_;
		_tmp1_ = self->priv->_timer;
		g_signal_handler_unblock (_tmp1_, self->priv->timer_state_changed_id);
		_tmp2_ = self->priv->_session_manager;
		g_signal_handler_unblock (_tmp2_, self->priv->session_manager_confirm_advancement_id);
		ft_notification_manager_schedule_announcements (self);
		if (notify) {
			ft_notification_manager_update (self, FALSE);
		}
	}
}

void
ft_notification_manager_emit_screen_overlay_opened (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_OPENED_SIGNAL], 0);
}

void
ft_notification_manager_emit_screen_overlay_closed (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_CLOSED_SIGNAL], 0);
}

void
ft_notification_manager_destroy (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	ft_notification_manager_withdraw_notifications (self);
	if (self->priv->update_timeout_id != 0U) {
		g_source_remove (self->priv->update_timeout_id);
		self->priv->update_timeout_id = 0U;
	}
	if (self->priv->screen_overlay_open_timeout_id != 0U) {
		g_source_remove (self->priv->screen_overlay_open_timeout_id);
		self->priv->screen_overlay_open_timeout_id = 0U;
	}
	if (self->priv->screen_overlay_active) {
		g_signal_emit (self, ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_CLOSE_SIGNAL], 0);
	}
	if (self->priv->timer_tick_id != ((gulong) 0)) {
		FtTimer* _tmp0_;
		_tmp0_ = self->priv->_timer;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->timer_tick_id);
		self->priv->timer_tick_id = (gulong) 0;
	}
	if (self->priv->timer_state_changed_id != ((gulong) 0)) {
		FtTimer* _tmp1_;
		_tmp1_ = self->priv->_timer;
		g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->timer_state_changed_id);
		self->priv->timer_state_changed_id = (gulong) 0;
	}
	if (self->priv->session_manager_confirm_advancement_id != ((gulong) 0)) {
		FtSessionManager* _tmp2_;
		_tmp2_ = self->priv->_session_manager;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->session_manager_confirm_advancement_id);
		self->priv->session_manager_confirm_advancement_id = (gulong) 0;
	}
	if (self->priv->settings_changed_id != ((gulong) 0)) {
		GSettings* _tmp3_;
		_tmp3_ = self->priv->settings;
		g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->settings_changed_id);
		self->priv->settings_changed_id = (gulong) 0;
	}
	ft_notification_manager_remove_reopen_screen_overlay_idle_watch (self);
	ft_notification_manager_remove_lock_screen_idle_watch (self);
}

static void
ft_notification_manager_real_dispose (GObject* base)
{
	FtNotificationManager * self;
	self = (FtNotificationManager*) base;
	ft_notification_manager_destroy (self);
	_g_object_unref0 (self->priv->_timer);
	self->priv->_timer = NULL;
	_g_object_unref0 (self->priv->_session_manager);
	self->priv->_session_manager = NULL;
	_g_object_unref0 (self->priv->_backend);
	self->priv->_backend = NULL;
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	_ft_notification_unref0 (self->priv->notification);
	self->priv->notification = NULL;
	self->priv->notification_time_block = NULL;
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
	_g_object_unref0 (self->priv->lock_screen);
	self->priv->lock_screen = NULL;
	G_OBJECT_CLASS (ft_notification_manager_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

FtTimer*
ft_notification_manager_get_timer (FtNotificationManager* self)
{
	FtTimer* result;
	FtTimer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_timer;
	result = _tmp0_;
	return result;
}

static void
_ft_notification_manager_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                        const FtTimerState* current_state,
                                                                        const FtTimerState* previous_state,
                                                                        gpointer self)
{
	ft_notification_manager_on_timer_state_changed ((FtNotificationManager*) self, current_state, previous_state);
}

static void
ft_notification_manager_set_timer (FtNotificationManager* self,
                                   FtTimer* value)
{
	FtTimer* _tmp0_;
	FtTimer* _tmp1_;
	FtTimerState _tmp2_ = {0};
	FtTimerState _tmp3_;
	FtTimerState _tmp4_ = {0};
	FtTimer* _tmp5_;
	gulong _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_timer);
	self->priv->_timer = _tmp0_;
	_tmp1_ = self->priv->_timer;
	ft_timer_get_state (_tmp1_, &_tmp2_);
	_tmp3_ = _tmp2_;
	ft_timer_state_copy (&_tmp3_, &_tmp4_);
	self->priv->previous_timer_state = _tmp4_;
	_tmp5_ = self->priv->_timer;
	_tmp6_ = g_signal_connect_object (_tmp5_, "state-changed", (GCallback) _ft_notification_manager_on_timer_state_changed_ft_timer_state_changed, self, 0);
	self->priv->timer_state_changed_id = _tmp6_;
	g_object_notify_by_pspec ((GObject *) self, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_TIMER_PROPERTY]);
}

FtSessionManager*
ft_notification_manager_get_session_manager (FtNotificationManager* self)
{
	FtSessionManager* result;
	FtSessionManager* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_session_manager;
	result = _tmp0_;
	return result;
}

static void
_ft_notification_manager_on_session_manager_confirm_advancement_ft_session_manager_confirm_advancement (FtSessionManager* _sender,
                                                                                                        FtTimeBlock* current_time_block,
                                                                                                        FtTimeBlock* next_time_block,
                                                                                                        gpointer self)
{
	ft_notification_manager_on_session_manager_confirm_advancement ((FtNotificationManager*) self, current_time_block, next_time_block);
}

static void
ft_notification_manager_set_session_manager (FtNotificationManager* self,
                                             FtSessionManager* value)
{
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp1_;
	gulong _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_session_manager);
	self->priv->_session_manager = _tmp0_;
	_tmp1_ = self->priv->_session_manager;
	_tmp2_ = g_signal_connect_object (_tmp1_, "confirm-advancement", (GCallback) _ft_notification_manager_on_session_manager_confirm_advancement_ft_session_manager_confirm_advancement, self, 0);
	self->priv->session_manager_confirm_advancement_id = _tmp2_;
	g_object_notify_by_pspec ((GObject *) self, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY]);
}

FtNotificationBackendInterface*
ft_notification_manager_get_backend (FtNotificationManager* self)
{
	FtNotificationBackendInterface* result;
	FtNotificationBackendInterface* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_backend;
	result = _tmp0_;
	return result;
}

static void
ft_notification_manager_set_backend (FtNotificationManager* self,
                                     FtNotificationBackendInterface* value)
{
	FtNotificationBackendInterface* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_backend);
	self->priv->_backend = _tmp0_;
	g_object_notify_by_pspec ((GObject *) self, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY]);
}

static void
ft_notification_manager_real_screen_overlay_opened (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->screen_overlay_open_timeout_id != 0U) {
		g_source_remove (self->priv->screen_overlay_open_timeout_id);
		self->priv->screen_overlay_open_timeout_id = 0U;
	}
	self->priv->screen_overlay_active = TRUE;
	ft_notification_manager_remove_reopen_screen_overlay_idle_watch (self);
	ft_notification_manager_add_lock_screen_idle_watch (self);
	ft_notification_manager_withdraw_notifications (self);
}

static gboolean
__lambda91_ (FtNotificationManager* self)
{
	gboolean result;
	self->priv->update_timeout_id = (guint) 0;
	ft_notification_manager_update (self, FALSE);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda91__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda91_ ((FtNotificationManager*) self);
	return result;
}

static void
ft_notification_manager_real_screen_overlay_closed (FtNotificationManager* self)
{
	g_return_if_fail (self != NULL);
	self->priv->screen_overlay_active = FALSE;
	ft_notification_manager_remove_lock_screen_idle_watch (self);
	self->priv->update_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 100, ___lambda91__gsource_func, g_object_ref (self), g_object_unref);
}

static void
_ft_notification_manager_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                                 const gchar* key,
                                                                 gpointer self)
{
	ft_notification_manager_on_settings_changed ((FtNotificationManager*) self, _sender, key);
}

static GObject *
ft_notification_manager_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	static GWeakRef FtNotificationManager_singleton__ref;
	static GMutex FtNotificationManager_singleton__lock;
	FtNotificationManager * self;
	GSettings* _tmp0_;
	GSettings* _tmp1_;
	FtIdleMonitor* _tmp2_;
	FtLockScreen* _tmp3_;
	GSettings* _tmp4_;
	gulong _tmp5_;
	FtNotification* _tmp6_;
	g_mutex_lock (&FtNotificationManager_singleton__lock);
	obj = g_weak_ref_get (&FtNotificationManager_singleton__ref);
	if (obj != NULL) {
		g_mutex_unlock (&FtNotificationManager_singleton__lock);
		return obj;
	}
	parent_class = G_OBJECT_CLASS (ft_notification_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_NOTIFICATION_MANAGER, FtNotificationManager);
	_tmp0_ = ft_get_settings ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp1_;
	_tmp2_ = ft_idle_monitor_new ();
	_g_object_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = _tmp2_;
	_tmp3_ = ft_lock_screen_new ();
	_g_object_unref0 (self->priv->lock_screen);
	self->priv->lock_screen = _tmp3_;
	_tmp4_ = self->priv->settings;
	_tmp5_ = g_signal_connect_object (_tmp4_, "changed", (GCallback) _ft_notification_manager_on_settings_changed_g_settings_changed, self, 0);
	self->priv->settings_changed_id = _tmp5_;
	ft_notification_manager_schedule_announcements (self);
	_tmp6_ = self->priv->notification;
	if (_tmp6_ == NULL) {
		FtNotificationBackendInterface* _tmp7_;
		_tmp7_ = self->priv->_backend;
		ft_notification_backend_interface_withdraw_notification (_tmp7_, "timer");
	}
	g_weak_ref_set (&FtNotificationManager_singleton__ref, obj);
	g_mutex_unlock (&FtNotificationManager_singleton__lock);
	return obj;
}

static void
ft_notification_manager_class_init (FtNotificationManagerClass * klass,
                                    gpointer klass_data)
{
	ft_notification_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtNotificationManager_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_notification_manager_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_notification_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_notification_manager_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_notification_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_notification_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_NOTIFICATION_MANAGER_TIMER_PROPERTY, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_TIMER_PROPERTY] = g_param_spec_object ("timer", "timer", "timer", FT_TYPE_TIMER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY] = g_param_spec_object ("session-manager", "session-manager", "session-manager", FT_TYPE_SESSION_MANAGER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY, ft_notification_manager_properties[FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY] = g_param_spec_object ("backend", "backend", "backend", FT_TYPE_NOTIFICATION_BACKEND_INTERFACE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	/**
	         * Notify manager that screen overlay has opened.
	         */
	ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_OPENED_SIGNAL] = g_signal_new_class_handler ("screen-overlay-opened", FT_TYPE_NOTIFICATION_MANAGER, G_SIGNAL_RUN_LAST, (GCallback) ft_notification_manager_real_screen_overlay_opened, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	/**
	         * Notify manager that screen overlay has closed.
	         */
	ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_SCREEN_OVERLAY_CLOSED_SIGNAL] = g_signal_new_class_handler ("screen-overlay-closed", FT_TYPE_NOTIFICATION_MANAGER, G_SIGNAL_RUN_LAST, (GCallback) ft_notification_manager_real_screen_overlay_closed, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_OPEN_SIGNAL] = g_signal_new ("request-screen-overlay-open", FT_TYPE_NOTIFICATION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	ft_notification_manager_signals[FT_NOTIFICATION_MANAGER_REQUEST_SCREEN_OVERLAY_CLOSE_SIGNAL] = g_signal_new ("request-screen-overlay-close", FT_TYPE_NOTIFICATION_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ft_notification_manager_instance_init (FtNotificationManager * self,
                                       gpointer klass)
{
	self->priv = ft_notification_manager_get_instance_private (self);
	self->priv->_timer = NULL;
	self->priv->_session_manager = NULL;
	self->priv->_backend = NULL;
	self->priv->settings = NULL;
	self->priv->idle_monitor = NULL;
	self->priv->lock_screen = NULL;
	self->priv->timer_state_changed_id = (gulong) 0;
	self->priv->timer_tick_id = (gulong) 0;
	self->priv->settings_changed_id = (gulong) 0;
	self->priv->session_manager_confirm_advancement_id = (gulong) 0;
	self->priv->inhibit_count = 0;
	self->priv->screen_overlay_active = FALSE;
	self->priv->screen_overlay_open_timeout_id = 0U;
	self->priv->update_timeout_id = 0U;
	self->priv->withdraw_timeout_id = 0U;
	self->priv->lock_screen_idle_id = 0U;
	self->priv->reopen_screen_overlay_idle_id = 0U;
	self->priv->notification = NULL;
	self->priv->notification_type = FT_NOTIFICATION_TYPE_NULL;
	self->priv->notification_time_block = NULL;
}

static void
ft_notification_manager_finalize (GObject * obj)
{
	FtNotificationManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_NOTIFICATION_MANAGER, FtNotificationManager);
	_g_object_unref0 (self->priv->_timer);
	_g_object_unref0 (self->priv->_session_manager);
	_g_object_unref0 (self->priv->_backend);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->idle_monitor);
	_g_object_unref0 (self->priv->lock_screen);
	_ft_notification_unref0 (self->priv->notification);
	G_OBJECT_CLASS (ft_notification_manager_parent_class)->finalize (obj);
}

/**
     * `NotificationManager` manages notification popups and the screen overlay.
     */
static GType
ft_notification_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtNotificationManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_notification_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtNotificationManager), 0, (GInstanceInitFunc) ft_notification_manager_instance_init, NULL };
	GType ft_notification_manager_type_id;
	ft_notification_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "FtNotificationManager", &g_define_type_info, 0);
	FtNotificationManager_private_offset = g_type_add_instance_private (ft_notification_manager_type_id, sizeof (FtNotificationManagerPrivate));
	return ft_notification_manager_type_id;
}

GType
ft_notification_manager_get_type (void)
{
	static volatile gsize ft_notification_manager_type_id__once = 0;
	if (g_once_init_enter (&ft_notification_manager_type_id__once)) {
		GType ft_notification_manager_type_id;
		ft_notification_manager_type_id = ft_notification_manager_get_type_once ();
		g_once_init_leave (&ft_notification_manager_type_id__once, ft_notification_manager_type_id);
	}
	return ft_notification_manager_type_id__once;
}

static void
_vala_ft_notification_manager_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	FtNotificationManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_NOTIFICATION_MANAGER, FtNotificationManager);
	switch (property_id) {
		case FT_NOTIFICATION_MANAGER_TIMER_PROPERTY:
		g_value_set_object (value, ft_notification_manager_get_timer (self));
		break;
		case FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY:
		g_value_set_object (value, ft_notification_manager_get_session_manager (self));
		break;
		case FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY:
		g_value_set_object (value, ft_notification_manager_get_backend (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_notification_manager_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	FtNotificationManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_NOTIFICATION_MANAGER, FtNotificationManager);
	switch (property_id) {
		case FT_NOTIFICATION_MANAGER_TIMER_PROPERTY:
		ft_notification_manager_set_timer (self, g_value_get_object (value));
		break;
		case FT_NOTIFICATION_MANAGER_SESSION_MANAGER_PROPERTY:
		ft_notification_manager_set_session_manager (self, g_value_get_object (value));
		break;
		case FT_NOTIFICATION_MANAGER_BACKEND_PROPERTY:
		ft_notification_manager_set_backend (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

