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

/*
 * Copyright (c) 2021-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_ui.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gtk/gtk.h>
#include "ft_core.h"
#include <gio/gio.h>
#include <adwaita.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdk.h>
#include <graphene-gobject.h>
#include <cairo-gobject.h>

#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 struct _FtTimerProgressBar FtTimerProgressBar;
typedef struct _FtTimerProgressBarClass FtTimerProgressBarClass;
typedef struct _FtSessionProgressBar FtSessionProgressBar;
typedef struct _FtSessionProgressBarClass FtSessionProgressBarClass;
typedef struct _FtTimerControlButtons FtTimerControlButtons;
typedef struct _FtTimerControlButtonsClass FtTimerControlButtonsClass;
enum  {
	FT_TIMER_VIEW_0_PROPERTY,
	FT_TIMER_VIEW_NUM_PROPERTIES
};
static GParamSpec* ft_timer_view_properties[FT_TIMER_VIEW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gdk_event_unref0(var) ((var == NULL) ? NULL : (var = (gdk_event_unref (var), NULL)))
#define __vala_GdkEventSequence_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEventSequence_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FtTimerViewPrivate {
	gint MIN_PADDING;
	gint MAX_PADDING;
	gint BOTTOM_PADDING;
	gint MIN_WIDTH;
	gint NAT_WIDTH;
	gint MAX_WIDTH;
	gint MIN_SPACING;
	gint NAT_SPACING;
	gint MAX_SPACING;
	gfloat INNER_RELATIVE_WIDTH;
	gfloat MAX_PROGRESSRING_RELATIVE_HEIGHT;
	GtkMenuButton* state_menubutton;
	GtkButton* open_screen_overlay_button;
	GtkBox* header_box;
	GtkBox* inner_box;
	FtTimerProgressBar* timer_progressbar;
	FtSessionProgressBar* session_progressbar;
	FtTimerLabel* timer_label;
	FtTimerControlButtons* timer_control_buttons;
	GtkGestureClick* click_gesture;
	GtkGestureDrag* drag_gesture;
	FtSessionManager* session_manager;
	FtTimer* timer;
	GSettings* settings;
	GMenuModel* state_menu;
	GMenuModel* uniform_state_menu;
	gulong timer_state_changed_id;
	gulong session_expired_id;
	gulong notify_current_time_block_id;
	gulong notify_has_uniform_breaks_id;
	gulong current_time_block_changed_id;
	gulong settings_changed_id;
	AdwToast* session_expired_toast;
	FtTimeBlock* current_time_block;
};

static gint FtTimerView_private_offset;
static gpointer ft_timer_view_parent_class = NULL;
static GtkBuildableIface * ft_timer_view_gtk_buildable_parent_iface = NULL;

static gchar* ft_timer_view_get_state_label (FtTimerView* self);
static void ft_timer_view_update_buttons (FtTimerView* self);
static void ft_timer_view_update_timer_label_placeholder (FtTimerView* self);
static void ft_timer_view_update (FtTimerView* self);
static void ft_timer_view_on_timer_state_changed (FtTimerView* self,
                                           const FtTimerState* current_state,
                                           const FtTimerState* previous_state);
static void ft_timer_view_on_pressed (FtTimerView* self,
                               GtkGestureClick* gesture,
                               gint n_press,
                               gdouble x,
                               gdouble y);
static void _vala_GdkEventSequence_free (GdkEventSequence* self);
static void _ft_timer_view_on_pressed_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                          gint n_press,
                                                          gdouble x,
                                                          gdouble y,
                                                          gpointer self);
static void ft_timer_view_on_drag_update (FtTimerView* self,
                                   GtkGestureDrag* gesture,
                                   gdouble offset_x,
                                   gdouble offset_y);
static void _ft_timer_view_on_drag_update_gtk_gesture_drag_drag_update (GtkGestureDrag* _sender,
                                                                 gdouble offset_x,
                                                                 gdouble offset_y,
                                                                 gpointer self);
static void ft_timer_view_on_session_expired (FtTimerView* self,
                                       FtSession* session);
static gboolean __lambda47_ (FtTimerView* self,
                      FtTimeBlock* time_block);
static gboolean ___lambda47__ft_filter_func (gconstpointer item,
                                      gpointer self);
static void __lambda48_ (FtTimerView* self);
static void ___lambda48__adw_toast_dismissed (AdwToast* _sender,
                                       gpointer self);
static void ft_timer_view_on_current_time_block_changed (FtTimerView* self);
static void ft_timer_view_on_session_manager_notify_current_time_block (FtTimerView* self);
static void _ft_timer_view_on_current_time_block_changed_ft_time_block_changed (FtTimeBlock* _sender,
                                                                         gpointer self);
static void ft_timer_view_on_session_manager_notify_has_uniform_breaks (FtTimerView* self);
static void ft_timer_view_on_settings_changed (FtTimerView* self,
                                        GSettings* settings,
                                        const gchar* key);
static void ft_timer_view_connect_signals (FtTimerView* self);
static void _ft_timer_view_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                                   const FtTimerState* current_state,
                                                                   const FtTimerState* previous_state,
                                                                   gpointer self);
static void ft_timer_view_disconnect_signals (FtTimerView* self);
static void ft_timer_view_calculate_height_for_width (FtTimerView* self,
                                               gint avaliable_width,
                                               gint* minimum_height,
                                               gint* natural_height);
static void ft_timer_view_calculate_width_for_height (FtTimerView* self,
                                               gint avaliable_height,
                                               gint* minimum_width,
                                               gint* natural_width);
static gint ft_timer_view_calculate_padding (FtTimerView* self,
                                      gint width);
static gint ft_timer_view_calculate_padding_inv (FtTimerView* self,
                                          gint padded_width);
static GtkSizeRequestMode ft_timer_view_real_get_request_mode (GtkWidget* base);
static void ft_timer_view_real_measure (GtkWidget* base,
                                 GtkOrientation orientation,
                                 gint for_size,
                                 gint* minimum,
                                 gint* natural,
                                 gint* minimum_baseline,
                                 gint* natural_baseline);
static void ft_timer_view_real_size_allocate (GtkWidget* base,
                                       gint width,
                                       gint height,
                                       gint baseline);
static void ft_timer_view_real_map (GtkWidget* base);
static void ft_timer_view_real_unmap (GtkWidget* base);
static void ft_timer_view_real_dispose (GObject* base);
static GObject * ft_timer_view_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties);
static void _ft_timer_view_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                            const gchar* key,
                                                            gpointer self);
static void _ft_timer_view_on_session_expired_ft_session_manager_session_expired (FtSessionManager* _sender,
                                                                           FtSession* session,
                                                                           gint64 timestamp,
                                                                           gpointer self);
static void _ft_timer_view_on_session_manager_notify_current_time_block_g_object_notify (GObject* _sender,
                                                                                  GParamSpec* pspec,
                                                                                  gpointer self);
static void _ft_timer_view_on_session_manager_notify_has_uniform_breaks_g_object_notify (GObject* _sender,
                                                                                  GParamSpec* pspec,
                                                                                  gpointer self);
static void ft_timer_view_finalize (GObject * obj);
static GType ft_timer_view_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_timer_view_get_instance_private (FtTimerView* self)
{
	return G_STRUCT_MEMBER_P (self, FtTimerView_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gchar*
ft_timer_view_get_state_label (FtTimerView* self)
{
	FtTimeBlock* current_time_block = NULL;
	FtSessionManager* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtState _tmp4_ = 0;
	FtTimeBlock* _tmp5_;
	FtState current_state = 0;
	gchar* _tmp9_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->session_manager;
	_tmp1_ = ft_session_manager_get_current_time_block (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	current_time_block = _tmp3_;
	_tmp5_ = current_time_block;
	if (_tmp5_ != NULL) {
		FtTimeBlock* _tmp6_;
		FtState _tmp7_;
		FtState _tmp8_;
		_tmp6_ = current_time_block;
		_tmp7_ = ft_time_block_get_state (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_;
	} else {
		_tmp4_ = FT_STATE_STOPPED;
	}
	current_state = _tmp4_;
	_tmp9_ = ft_state_get_label (current_state);
	result = _tmp9_;
	_g_object_unref0 (current_time_block);
	return result;
}

static void
ft_timer_view_update_buttons (FtTimerView* self)
{
	FtState _tmp0_ = 0;
	FtTimeBlock* _tmp1_;
	FtState current_state = 0;
	gchar* _tmp5_ = NULL;
	FtTimer* _tmp6_;
	GtkMenuButton* _tmp9_;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_ = FALSE;
	GSettings* _tmp12_;
	GtkButton* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->current_time_block;
	if (_tmp1_ != NULL) {
		FtTimeBlock* _tmp2_;
		FtState _tmp3_;
		FtState _tmp4_;
		_tmp2_ = self->priv->current_time_block;
		_tmp3_ = ft_time_block_get_state (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FT_STATE_STOPPED;
	}
	current_state = _tmp0_;
	_tmp6_ = self->priv->timer;
	if (!ft_timer_is_finished (_tmp6_)) {
		gchar* _tmp7_;
		_tmp7_ = ft_timer_view_get_state_label (self);
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp7_;
	} else {
		gchar* _tmp8_;
		_tmp8_ = g_strdup (_ ("Finished!"));
		_g_free0 (_tmp5_);
		_tmp5_ = _tmp8_;
	}
	_tmp9_ = self->priv->state_menubutton;
	gtk_menu_button_set_label (_tmp9_, _tmp5_);
	_tmp12_ = self->priv->settings;
	if (g_settings_get_boolean (_tmp12_, "screen-overlay")) {
		_tmp11_ = ft_state_is_break (current_state);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		FtTimer* _tmp13_;
		_tmp13_ = self->priv->timer;
		_tmp10_ = !ft_timer_is_finished (_tmp13_);
	} else {
		_tmp10_ = FALSE;
	}
	_tmp14_ = self->priv->open_screen_overlay_button;
	gtk_widget_set_visible ((GtkWidget*) _tmp14_, _tmp10_);
	_g_free0 (_tmp5_);
}

static void
ft_timer_view_update_timer_label_placeholder (FtTimerView* self)
{
	FtSessionTemplate session_template = {0};
	FtSessionManager* _tmp0_;
	FtScheduler* _tmp1_;
	FtScheduler* _tmp2_;
	FtSessionTemplate _tmp3_ = {0};
	FtSessionTemplate _tmp4_;
	FtTimerLabel* _tmp5_;
	FtSessionTemplate _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->session_manager;
	_tmp1_ = ft_session_manager_get_scheduler (_tmp0_);
	_tmp2_ = _tmp1_;
	ft_scheduler_get_session_template (_tmp2_, &_tmp3_);
	_tmp4_ = _tmp3_;
	session_template = _tmp4_;
	_tmp5_ = self->priv->timer_label;
	_tmp6_ = session_template;
	ft_timer_label_set_placeholder_has_hours (_tmp5_, _tmp6_.pomodoro_duration >= FT_INTERVAL_HOUR);
}

static void
ft_timer_view_update (FtTimerView* self)
{
	gboolean _tmp0_ = FALSE;
	AdwToast* _tmp1_;
	g_return_if_fail (self != NULL);
	ft_timer_view_update_buttons (self);
	ft_timer_view_update_timer_label_placeholder (self);
	_tmp1_ = self->priv->session_expired_toast;
	if (_tmp1_ != NULL) {
		FtTimer* _tmp2_;
		_tmp2_ = self->priv->timer;
		_tmp0_ = ft_timer_is_running (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		AdwToast* _tmp3_;
		_tmp3_ = self->priv->session_expired_toast;
		adw_toast_dismiss (_tmp3_);
	}
}

static void
ft_timer_view_on_timer_state_changed (FtTimerView* self,
                                      const FtTimerState* current_state,
                                      const FtTimerState* previous_state)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (current_state != NULL);
	g_return_if_fail (previous_state != NULL);
	ft_timer_view_update (self);
}

static gpointer
_gdk_event_ref0 (gpointer self)
{
	return self ? gdk_event_ref (self) : NULL;
}

static void
_vala_GdkEventSequence_free (GdkEventSequence* self)
{
	g_boxed_free (gdk_event_sequence_get_type (), self);
}

static void
ft_timer_view_on_pressed (FtTimerView* self,
                          GtkGestureClick* gesture,
                          gint n_press,
                          gdouble x,
                          gdouble y)
{
	GdkEventSequence* sequence = NULL;
	GdkEventSequence* _tmp0_;
	GdkEvent* event = NULL;
	GdkEventSequence* _tmp1_;
	GdkEvent* _tmp2_;
	GdkEvent* _tmp3_;
	GdkEvent* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gesture != NULL);
	_tmp0_ = gtk_gesture_single_get_current_sequence ((GtkGestureSingle*) gesture);
	sequence = _tmp0_;
	_tmp1_ = sequence;
	_tmp2_ = gtk_gesture_get_last_event ((GtkGesture*) gesture, _tmp1_);
	_tmp3_ = _gdk_event_ref0 (_tmp2_);
	event = _tmp3_;
	_tmp4_ = event;
	if (_tmp4_ == NULL) {
		_gdk_event_unref0 (event);
		__vala_GdkEventSequence_free0 (sequence);
		return;
	}
	if (n_press > 1) {
		GtkGestureDrag* _tmp5_;
		_tmp5_ = self->priv->drag_gesture;
		gtk_gesture_set_state ((GtkGesture*) _tmp5_, GTK_EVENT_SEQUENCE_DENIED);
	}
	_gdk_event_unref0 (event);
	__vala_GdkEventSequence_free0 (sequence);
}

static void
_ft_timer_view_on_pressed_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                     gint n_press,
                                                     gdouble x,
                                                     gdouble y,
                                                     gpointer self)
{
	ft_timer_view_on_pressed ((FtTimerView*) self, _sender, n_press, x, y);
}

static void
ft_timer_view_on_drag_update (FtTimerView* self,
                              GtkGestureDrag* gesture,
                              gdouble offset_x,
                              gdouble offset_y)
{
	gdouble start_x = 0.0;
	gdouble start_y = 0.0;
	gdouble native_x = 0.0;
	gdouble native_y = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble _tmp1_ = 0.0;
	graphene_point_t widget_point = {0};
	graphene_point_t native_point = {0};
	GtkNative* native = NULL;
	GtkNative* _tmp2_;
	GtkNative* _tmp3_;
	GdkToplevel* toplevel = NULL;
	GtkNative* _tmp4_;
	GdkSurface* _tmp5_;
	GdkToplevel* _tmp6_;
	gboolean _tmp7_ = FALSE;
	GdkToplevel* _tmp8_;
	GtkGestureDrag* _tmp22_;
	GtkGestureClick* _tmp23_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (gesture != NULL);
	if (!gtk_drag_check_threshold ((GtkWidget*) self, 0, 0, (gint) offset_x, (gint) offset_y)) {
		return;
	}
	gtk_gesture_set_state ((GtkGesture*) gesture, GTK_EVENT_SEQUENCE_CLAIMED);
	gtk_gesture_drag_get_start_point (gesture, &_tmp0_, &_tmp1_);
	start_x = _tmp0_;
	start_y = _tmp1_;
	memset (&widget_point, 0, sizeof (graphene_point_t));
	graphene_point_init (&widget_point, (gfloat) start_x, (gfloat) start_x);
	memset (&native_point, 0, sizeof (graphene_point_t));
	_tmp2_ = gtk_widget_get_native ((GtkWidget*) self);
	_tmp3_ = _g_object_ref0 (_tmp2_);
	native = _tmp3_;
	_tmp4_ = native;
	_tmp5_ = gtk_native_get_surface (_tmp4_);
	_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, gdk_toplevel_get_type ()) ? ((GdkToplevel*) _tmp5_) : NULL);
	toplevel = _tmp6_;
	_tmp8_ = toplevel;
	if (_tmp8_ != NULL) {
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		GtkNative* _tmp11_;
		graphene_point_t _tmp12_;
		graphene_point_t _tmp13_ = {0};
		gboolean _tmp14_;
		_tmp9_ = gtk_event_controller_get_widget ((GtkEventController*) gesture);
		_tmp10_ = _tmp9_;
		_tmp11_ = native;
		_tmp12_ = widget_point;
		_tmp14_ = gtk_widget_compute_point (_tmp10_, (GtkWidget*) _tmp11_, &_tmp12_, &_tmp13_);
		native_point = _tmp13_;
		_tmp7_ = _tmp14_;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		GtkNative* _tmp15_;
		gdouble _tmp16_ = 0.0;
		gdouble _tmp17_ = 0.0;
		GdkToplevel* _tmp18_;
		GdkDevice* _tmp19_;
		graphene_point_t _tmp20_;
		graphene_point_t _tmp21_;
		_tmp15_ = native;
		gtk_native_get_surface_transform (_tmp15_, &_tmp16_, &_tmp17_);
		native_x = _tmp16_;
		native_y = _tmp17_;
		_tmp18_ = toplevel;
		_tmp19_ = gtk_gesture_get_device ((GtkGesture*) gesture);
		_tmp20_ = native_point;
		_tmp21_ = native_point;
		gdk_toplevel_begin_move (_tmp18_, _tmp19_, (gint) gtk_gesture_single_get_current_button ((GtkGestureSingle*) gesture), native_x + ((gdouble) _tmp20_.x), native_y + ((gdouble) _tmp21_.y), gtk_event_controller_get_current_event_time ((GtkEventController*) gesture));
	}
	_tmp22_ = self->priv->drag_gesture;
	gtk_event_controller_reset ((GtkEventController*) _tmp22_);
	_tmp23_ = self->priv->click_gesture;
	gtk_event_controller_reset ((GtkEventController*) _tmp23_);
	_g_object_unref0 (toplevel);
	_g_object_unref0 (native);
}

static void
_ft_timer_view_on_drag_update_gtk_gesture_drag_drag_update (GtkGestureDrag* _sender,
                                                            gdouble offset_x,
                                                            gdouble offset_y,
                                                            gpointer self)
{
	ft_timer_view_on_drag_update ((FtTimerView*) self, _sender, offset_x, offset_y);
}

/**
         * We want to notify that the app stopped the timer because session has expired.
         * But, its not worth users attention in cases where resetting a session is to be expected.
         */
static gboolean
__lambda47_ (FtTimerView* self,
             FtTimeBlock* time_block)
{
	gboolean _tmp0_ = FALSE;
	FtState _tmp1_;
	FtState _tmp2_;
	gboolean result;
	g_return_val_if_fail (time_block != NULL, FALSE);
	_tmp1_ = ft_time_block_get_state (time_block);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == FT_STATE_POMODORO) {
		_tmp0_ = ft_time_block_get_status (time_block) == FT_TIME_BLOCK_STATUS_COMPLETED;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static gboolean
___lambda47__ft_filter_func (gconstpointer item,
                             gpointer self)
{
	gboolean result;
	result = __lambda47_ ((FtTimerView*) self, (FtTimeBlock*) item);
	return result;
}

static void
__lambda48_ (FtTimerView* self)
{
	_g_object_unref0 (self->priv->session_expired_toast);
	self->priv->session_expired_toast = NULL;
}

static void
___lambda48__adw_toast_dismissed (AdwToast* _sender,
                                  gpointer self)
{
	__lambda48_ ((FtTimerView*) self);
}

static void
ft_timer_view_on_session_expired (FtTimerView* self,
                                  FtSession* session)
{
	gint64 timestamp = 0LL;
	guint completed_time_blocks_count = 0U;
	gboolean _tmp0_ = FALSE;
	FtTimer* _tmp1_;
	gint64 _tmp2_;
	gint64 _tmp3_;
	FtWindow* window = NULL;
	GtkRoot* _tmp4_;
	FtWindow* _tmp5_;
	FtWindow* _tmp6_;
	AdwToast* toast = NULL;
	AdwToast* _tmp7_;
	AdwToast* _tmp8_;
	AdwToast* _tmp9_;
	AdwToast* _tmp10_;
	AdwToast* _tmp11_;
	AdwToast* _tmp12_;
	FtWindow* _tmp13_;
	AdwToast* _tmp14_;
	AdwToast* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	timestamp = ft_timestamp_from_now ();
	completed_time_blocks_count = ft_session_count_time_blocks (session, ___lambda47__ft_filter_func, self);
	_tmp1_ = self->priv->timer;
	if (!ft_timer_is_started (_tmp1_)) {
		_tmp0_ = completed_time_blocks_count == 0U;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = ft_session_get_expiry_time (session);
	_tmp3_ = _tmp2_;
	if ((timestamp - _tmp3_) >= (4 * FT_INTERVAL_HOUR)) {
		return;
	}
	_tmp4_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp5_ = _g_object_ref0 (FT_IS_WINDOW (_tmp4_) ? ((FtWindow*) _tmp4_) : NULL);
	window = _tmp5_;
	_tmp6_ = window;
	_vala_assert (_tmp6_ != NULL, "window != null");
	_tmp7_ = adw_toast_new (_ ("Session has expired"));
	toast = _tmp7_;
	_tmp8_ = toast;
	adw_toast_set_use_markup (_tmp8_, FALSE);
	_tmp9_ = toast;
	adw_toast_set_priority (_tmp9_, ADW_TOAST_PRIORITY_HIGH);
	_tmp10_ = toast;
	g_signal_connect_object (_tmp10_, "dismissed", (GCallback) ___lambda48__adw_toast_dismissed, self, 0);
	_tmp11_ = toast;
	_tmp12_ = _g_object_ref0 (_tmp11_);
	_g_object_unref0 (self->priv->session_expired_toast);
	self->priv->session_expired_toast = _tmp12_;
	_tmp13_ = window;
	_tmp14_ = toast;
	_tmp15_ = _g_object_ref0 (_tmp14_);
	ft_window_add_toast (_tmp13_, _tmp15_);
	_g_object_unref0 (toast);
	_g_object_unref0 (window);
}

static void
ft_timer_view_on_current_time_block_changed (FtTimerView* self)
{
	g_return_if_fail (self != NULL);
	ft_timer_view_update_buttons (self);
}

static void
_ft_timer_view_on_current_time_block_changed_ft_time_block_changed (FtTimeBlock* _sender,
                                                                    gpointer self)
{
	ft_timer_view_on_current_time_block_changed ((FtTimerView*) self);
}

static void
ft_timer_view_on_session_manager_notify_current_time_block (FtTimerView* self)
{
	FtTimeBlock* current_time_block = NULL;
	FtSessionManager* _tmp0_;
	FtTimeBlock* _tmp1_;
	FtTimeBlock* _tmp2_;
	FtTimeBlock* _tmp3_;
	FtTimeBlock* _tmp5_;
	FtTimeBlock* _tmp8_;
	FtTimeBlock* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->session_manager;
	_tmp1_ = ft_session_manager_get_current_time_block (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	current_time_block = _tmp3_;
	if (self->priv->current_time_block_changed_id != ((gulong) 0)) {
		FtTimeBlock* _tmp4_;
		_tmp4_ = self->priv->current_time_block;
		g_signal_handler_disconnect ((GObject*) _tmp4_, self->priv->current_time_block_changed_id);
		self->priv->current_time_block_changed_id = (gulong) 0;
	}
	_tmp5_ = current_time_block;
	if (_tmp5_ != NULL) {
		FtTimeBlock* _tmp6_;
		gulong _tmp7_;
		_tmp6_ = current_time_block;
		_tmp7_ = g_signal_connect_object (_tmp6_, "changed", (GCallback) _ft_timer_view_on_current_time_block_changed_ft_time_block_changed, self, 0);
		self->priv->current_time_block_changed_id = _tmp7_;
	}
	_tmp8_ = current_time_block;
	_tmp9_ = _g_object_ref0 (_tmp8_);
	_g_object_unref0 (self->priv->current_time_block);
	self->priv->current_time_block = _tmp9_;
	ft_timer_view_on_current_time_block_changed (self);
	_g_object_unref0 (current_time_block);
}

static void
ft_timer_view_on_session_manager_notify_has_uniform_breaks (FtTimerView* self)
{
	GMenuModel* _tmp0_ = NULL;
	FtSessionManager* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	GtkMenuButton* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->session_manager;
	_tmp2_ = ft_session_manager_get_has_uniform_breaks (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		GMenuModel* _tmp4_;
		_tmp4_ = self->priv->uniform_state_menu;
		_tmp0_ = _tmp4_;
	} else {
		GMenuModel* _tmp5_;
		_tmp5_ = self->priv->state_menu;
		_tmp0_ = _tmp5_;
	}
	_tmp6_ = self->priv->state_menubutton;
	gtk_menu_button_set_menu_model (_tmp6_, _tmp0_);
}

static void
ft_timer_view_on_settings_changed (FtTimerView* self,
                                   GSettings* settings,
                                   const gchar* key)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (settings != NULL);
	g_return_if_fail (key != NULL);
	_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 ("screen-overlay")))) {
		switch (0) {
			default:
			{
				ft_timer_view_update_buttons (self);
				break;
			}
		}
	}
}

static void
_ft_timer_view_on_timer_state_changed_ft_timer_state_changed (FtTimer* _sender,
                                                              const FtTimerState* current_state,
                                                              const FtTimerState* previous_state,
                                                              gpointer self)
{
	ft_timer_view_on_timer_state_changed ((FtTimerView*) self, current_state, previous_state);
}

static void
ft_timer_view_connect_signals (FtTimerView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->timer_state_changed_id == ((gulong) 0)) {
		FtTimer* _tmp0_;
		gulong _tmp1_;
		_tmp0_ = self->priv->timer;
		_tmp1_ = g_signal_connect_object (_tmp0_, "state-changed", (GCallback) _ft_timer_view_on_timer_state_changed_ft_timer_state_changed, self, 0);
		self->priv->timer_state_changed_id = _tmp1_;
	}
}

static void
ft_timer_view_disconnect_signals (FtTimerView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->timer_state_changed_id != ((gulong) 0)) {
		FtTimer* _tmp0_;
		_tmp0_ = self->priv->timer;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->timer_state_changed_id);
		self->priv->timer_state_changed_id = (gulong) 0;
	}
}

static void
ft_timer_view_calculate_height_for_width (FtTimerView* self,
                                          gint avaliable_width,
                                          gint* minimum_height,
                                          gint* natural_height)
{
	gint _vala_minimum_height = 0;
	gint _vala_natural_height = 0;
	gint tmp_minimum_height = 0;
	gint tmp_natural_height = 0;
	GtkBox* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	FtTimerProgressBar* _tmp3_;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	FtTimerControlButtons* _tmp6_;
	gint _tmp7_ = 0;
	gint _tmp8_ = 0;
	g_return_if_fail (self != NULL);
	tmp_minimum_height = 0;
	tmp_natural_height = 0;
	_vala_minimum_height = 2 * self->priv->MIN_SPACING;
	_vala_natural_height = 2 * self->priv->NAT_SPACING;
	_tmp0_ = self->priv->header_box;
	gtk_widget_measure ((GtkWidget*) _tmp0_, GTK_ORIENTATION_VERTICAL, avaliable_width, &_tmp1_, &_tmp2_, NULL, NULL);
	tmp_minimum_height = _tmp1_;
	tmp_natural_height = _tmp2_;
	_vala_minimum_height = _vala_minimum_height + tmp_minimum_height;
	_vala_natural_height = _vala_natural_height + tmp_natural_height;
	_tmp3_ = self->priv->timer_progressbar;
	gtk_widget_measure ((GtkWidget*) _tmp3_, GTK_ORIENTATION_VERTICAL, avaliable_width, &_tmp4_, &_tmp5_, NULL, NULL);
	tmp_minimum_height = _tmp4_;
	tmp_natural_height = _tmp5_;
	_vala_minimum_height = _vala_minimum_height + tmp_minimum_height;
	_vala_natural_height = _vala_natural_height + tmp_natural_height;
	_tmp6_ = self->priv->timer_control_buttons;
	gtk_widget_measure ((GtkWidget*) _tmp6_, GTK_ORIENTATION_VERTICAL, avaliable_width, &_tmp7_, &_tmp8_, NULL, NULL);
	tmp_minimum_height = _tmp7_;
	tmp_natural_height = _tmp8_;
	_vala_minimum_height = _vala_minimum_height + tmp_minimum_height;
	_vala_natural_height = _vala_natural_height + tmp_natural_height;
	if (minimum_height) {
		*minimum_height = _vala_minimum_height;
	}
	if (natural_height) {
		*natural_height = _vala_natural_height;
	}
}

static void
ft_timer_view_calculate_width_for_height (FtTimerView* self,
                                          gint avaliable_height,
                                          gint* minimum_width,
                                          gint* natural_width)
{
	gint _vala_minimum_width = 0;
	gint _vala_natural_width = 0;
	gint tmp_minimum_width = 0;
	gint tmp_natural_width = 0;
	gint tmp_natural_height = 0;
	GtkBox* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	GtkBox* _tmp3_;
	gint _tmp4_ = 0;
	FtTimerControlButtons* _tmp5_;
	gint _tmp6_ = 0;
	FtTimerProgressBar* _tmp7_;
	gint _tmp8_ = 0;
	g_return_if_fail (self != NULL);
	tmp_minimum_width = 0;
	tmp_natural_width = 0;
	tmp_natural_height = 0;
	_vala_minimum_width = self->priv->MIN_WIDTH;
	_vala_natural_width = self->priv->MIN_WIDTH;
	avaliable_height = avaliable_height - (2 * self->priv->NAT_SPACING);
	_tmp0_ = self->priv->header_box;
	gtk_widget_measure ((GtkWidget*) _tmp0_, GTK_ORIENTATION_HORIZONTAL, -1, &_tmp1_, &_tmp2_, NULL, NULL);
	tmp_minimum_width = _tmp1_;
	tmp_natural_width = _tmp2_;
	_vala_minimum_width = MAX (_vala_minimum_width, tmp_minimum_width);
	_vala_natural_width = MAX (_vala_natural_width, tmp_natural_width);
	_tmp3_ = self->priv->header_box;
	gtk_widget_measure ((GtkWidget*) _tmp3_, GTK_ORIENTATION_VERTICAL, _vala_natural_width, NULL, &_tmp4_, NULL, NULL);
	tmp_natural_height = _tmp4_;
	avaliable_height = avaliable_height - tmp_natural_height;
	_tmp5_ = self->priv->timer_control_buttons;
	gtk_widget_measure ((GtkWidget*) _tmp5_, GTK_ORIENTATION_VERTICAL, _vala_natural_width, NULL, &_tmp6_, NULL, NULL);
	tmp_natural_height = _tmp6_;
	avaliable_height = avaliable_height - tmp_natural_height;
	_tmp7_ = self->priv->timer_progressbar;
	gtk_widget_measure ((GtkWidget*) _tmp7_, GTK_ORIENTATION_HORIZONTAL, avaliable_height, NULL, &_tmp8_, NULL, NULL);
	tmp_natural_width = _tmp8_;
	_vala_natural_width = MAX (_vala_natural_width, tmp_natural_width);
	if (_vala_natural_width > self->priv->MAX_WIDTH) {
		_vala_natural_width = self->priv->MAX_WIDTH;
	}
	if (minimum_width) {
		*minimum_width = _vala_minimum_width;
	}
	if (natural_width) {
		*natural_width = _vala_natural_width;
	}
}

static gint
ft_timer_view_calculate_padding (FtTimerView* self,
                                 gint width)
{
	gfloat min_padding = 0.0F;
	gfloat max_padding = 0.0F;
	gfloat t = 0.0F;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	min_padding = (gfloat) self->priv->MIN_PADDING;
	max_padding = (gfloat) self->priv->MAX_PADDING;
	t = CLAMP (((gfloat) (width - self->priv->MIN_WIDTH)) / ((gfloat) self->priv->MAX_WIDTH), 0.0f, 1.0f);
	result = (gint) roundf (((1.0f - t) * min_padding) + (t * max_padding));
	return result;
}

static gint
ft_timer_view_calculate_padding_inv (FtTimerView* self,
                                     gint padded_width)
{
	gfloat min_padded_width = 0.0F;
	gfloat max_padded_width = 0.0F;
	gfloat t = 0.0F;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	min_padded_width = (gfloat) (self->priv->MIN_WIDTH + (2 * self->priv->MIN_PADDING));
	max_padded_width = (gfloat) (self->priv->MAX_WIDTH + (2 * self->priv->MAX_PADDING));
	t = (padded_width - min_padded_width) / (max_padded_width - min_padded_width);
	result = ((gint) roundf (2.0f * (((1.0f - t) * ((gfloat) self->priv->MIN_WIDTH)) + (t * ((gfloat) self->priv->MAX_WIDTH))))) / 2;
	return result;
}

static GtkSizeRequestMode
ft_timer_view_real_get_request_mode (GtkWidget* base)
{
	FtTimerView * self;
	GtkSizeRequestMode result;
	self = (FtTimerView*) base;
	result = GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
	return result;
}

/**
         * Define two main guides: outer and inner. Outer is intended as a
         * container for major widgets. Inner is intended for the timer
         * label and session progress bar.
         *
         * The constraints try to fit height of the outer guide to the window.
         * Than its constrained by max width.
         */
static void
ft_timer_view_real_measure (GtkWidget* base,
                            GtkOrientation orientation,
                            gint for_size,
                            gint* minimum,
                            gint* natural,
                            gint* minimum_baseline,
                            gint* natural_baseline)
{
	FtTimerView * self;
	gint _vala_minimum = 0;
	gint _vala_natural = 0;
	gint _vala_minimum_baseline = 0;
	gint _vala_natural_baseline = 0;
	gint minimum_padding = 0;
	gint natural_padding = 0;
	self = (FtTimerView*) base;
	minimum_padding = self->priv->MIN_PADDING;
	natural_padding = self->priv->MIN_PADDING;
	_vala_minimum = self->priv->MIN_WIDTH;
	_vala_natural = self->priv->NAT_WIDTH;
	if (orientation == GTK_ORIENTATION_HORIZONTAL) {
		if (for_size != -1) {
			gint _tmp0_ = 0;
			gint _tmp1_ = 0;
			ft_timer_view_calculate_width_for_height (self, for_size, &_tmp0_, &_tmp1_);
			_vala_minimum = _tmp0_;
			_vala_natural = _tmp1_;
		}
		natural_padding = ft_timer_view_calculate_padding (self, _vala_natural);
	} else {
		gint _tmp2_ = 0;
		gint _tmp3_ = 0;
		ft_timer_view_calculate_height_for_width (self, self->priv->MIN_WIDTH, &_tmp2_, &_tmp3_);
		_vala_minimum = _tmp2_;
		_vala_minimum = _tmp3_;
		if (for_size != -1) {
			gint _tmp4_ = 0;
			ft_timer_view_calculate_height_for_width (self, CLAMP (for_size, self->priv->MIN_WIDTH, self->priv->MAX_WIDTH), NULL, &_tmp4_);
			_vala_natural = _tmp4_;
		}
	}
	if (_vala_natural < _vala_minimum) {
		_vala_natural = _vala_minimum;
	}
	_vala_minimum = _vala_minimum + (minimum_padding * 2);
	_vala_natural = _vala_natural + (natural_padding * 2);
	_vala_minimum_baseline = -1;
	_vala_natural_baseline = -1;
	if (minimum) {
		*minimum = _vala_minimum;
	}
	if (natural) {
		*natural = _vala_natural;
	}
	if (minimum_baseline) {
		*minimum_baseline = _vala_minimum_baseline;
	}
	if (natural_baseline) {
		*natural_baseline = _vala_natural_baseline;
	}
}

static void
ft_timer_view_real_size_allocate (GtkWidget* base,
                                  gint width,
                                  gint height,
                                  gint baseline)
{
	FtTimerView * self;
	GtkAllocation allocation = {0};
	GtkAllocation _tmp0_ = {0};
	GtkAllocation _tmp1_;
	gint tmp_natural_height = 0;
	gint tmp_minimum_width = 0;
	gint tmp_natural_width = 0;
	GtkAllocation _tmp2_;
	gint _tmp3_ = 0;
	GtkAllocation _tmp4_;
	GtkAllocation header_box_allocation = {0};
	GtkAllocation _tmp7_;
	GtkAllocation _tmp8_ = {0};
	GtkBox* _tmp9_;
	GtkAllocation _tmp10_;
	gint _tmp11_ = 0;
	GtkAllocation timer_progressbar_allocation = {0};
	GtkAllocation _tmp12_;
	GtkAllocation _tmp13_;
	GtkAllocation _tmp14_ = {0};
	GtkAllocation inner_box_allocation = {0};
	GtkAllocation _tmp15_;
	GtkAllocation _tmp16_ = {0};
	GtkBox* _tmp17_;
	GtkAllocation _tmp18_;
	gint _tmp19_ = 0;
	GtkAllocation timer_control_buttons_allocation = {0};
	FtTimerControlButtons* _tmp20_;
	gint _tmp21_ = 0;
	gint _tmp22_ = 0;
	GtkAllocation _tmp23_;
	GtkAllocation _tmp24_;
	FtTimerControlButtons* _tmp25_;
	GtkAllocation _tmp26_;
	gint _tmp27_ = 0;
	GtkAllocation _tmp28_;
	GtkAllocation _tmp29_;
	GtkAllocation _tmp30_;
	GtkAllocation _tmp31_;
	GtkAllocation _tmp32_;
	GtkAllocation _tmp33_;
	GtkAllocation _tmp34_;
	GtkAllocation _tmp35_;
	gint spacing = 0;
	GtkAllocation _tmp36_;
	GtkAllocation _tmp37_;
	GtkAllocation _tmp38_;
	GtkAllocation _tmp39_;
	GtkAllocation _tmp40_;
	GtkAllocation _tmp41_;
	GtkAllocation _tmp42_;
	GtkAllocation _tmp43_;
	GtkBox* _tmp44_;
	GtkAllocation _tmp45_;
	FtTimerProgressBar* _tmp46_;
	GtkAllocation _tmp47_;
	GtkBox* _tmp48_;
	GtkAllocation _tmp49_;
	FtTimerControlButtons* _tmp50_;
	GtkAllocation _tmp51_;
	self = (FtTimerView*) base;
	memset (&_tmp0_, 0, sizeof (GtkAllocation));
	_tmp0_.width = CLAMP (ft_timer_view_calculate_padding_inv (self, width), self->priv->MIN_WIDTH, self->priv->MAX_WIDTH);
	_tmp0_.height = height - self->priv->BOTTOM_PADDING;
	allocation = _tmp0_;
	_tmp1_ = allocation;
	allocation.width = MIN (_tmp1_.width, (gint) floorf (self->priv->MAX_PROGRESSRING_RELATIVE_HEIGHT * ((gfloat) height)));
	tmp_natural_height = 0;
	tmp_minimum_width = 0;
	tmp_natural_width = 0;
	_tmp2_ = allocation;
	ft_timer_view_calculate_height_for_width (self, _tmp2_.width, NULL, &_tmp3_);
	tmp_natural_height = _tmp3_;
	_tmp4_ = allocation;
	if (tmp_natural_height > _tmp4_.height) {
		GtkAllocation _tmp5_;
		gint _tmp6_ = 0;
		_tmp5_ = allocation;
		ft_timer_view_calculate_width_for_height (self, _tmp5_.height, NULL, &_tmp6_);
		allocation.width = _tmp6_;
	}
	_tmp7_ = allocation;
	memset (&_tmp8_, 0, sizeof (GtkAllocation));
	_tmp8_.width = _tmp7_.width;
	header_box_allocation = _tmp8_;
	_tmp9_ = self->priv->header_box;
	_tmp10_ = header_box_allocation;
	gtk_widget_measure ((GtkWidget*) _tmp9_, GTK_ORIENTATION_VERTICAL, _tmp10_.width, NULL, &_tmp11_, NULL, NULL);
	header_box_allocation.height = _tmp11_;
	_tmp12_ = allocation;
	_tmp13_ = allocation;
	memset (&_tmp14_, 0, sizeof (GtkAllocation));
	_tmp14_.width = _tmp12_.width;
	_tmp14_.height = _tmp13_.width;
	timer_progressbar_allocation = _tmp14_;
	_tmp15_ = timer_progressbar_allocation;
	memset (&_tmp16_, 0, sizeof (GtkAllocation));
	_tmp16_.width = ((gint) roundf ((_tmp15_.width * self->priv->INNER_RELATIVE_WIDTH) / 2.0f)) * 2;
	_tmp16_.height = 0;
	inner_box_allocation = _tmp16_;
	_tmp17_ = self->priv->inner_box;
	_tmp18_ = inner_box_allocation;
	gtk_widget_measure ((GtkWidget*) _tmp17_, GTK_ORIENTATION_VERTICAL, _tmp18_.width, NULL, &_tmp19_, NULL, NULL);
	inner_box_allocation.height = _tmp19_;
	memset (&timer_control_buttons_allocation, 0, sizeof (GtkAllocation));
	_tmp20_ = self->priv->timer_control_buttons;
	gtk_widget_measure ((GtkWidget*) _tmp20_, GTK_ORIENTATION_HORIZONTAL, -1, &_tmp21_, &_tmp22_, NULL, NULL);
	tmp_minimum_width = _tmp21_;
	tmp_natural_width = _tmp22_;
	_tmp23_ = allocation;
	_tmp24_ = inner_box_allocation;
	timer_control_buttons_allocation.width = MAX (CLAMP (_tmp23_.width, tmp_minimum_width, tmp_natural_width), _tmp24_.width + 60);
	_tmp25_ = self->priv->timer_control_buttons;
	_tmp26_ = timer_control_buttons_allocation;
	gtk_widget_measure ((GtkWidget*) _tmp25_, GTK_ORIENTATION_VERTICAL, _tmp26_.width, NULL, &_tmp27_, NULL, NULL);
	timer_control_buttons_allocation.height = _tmp27_;
	_tmp28_ = allocation;
	allocation.x = (width - _tmp28_.width) / 2;
	_tmp29_ = allocation;
	header_box_allocation.x = _tmp29_.x;
	_tmp30_ = allocation;
	timer_progressbar_allocation.x = _tmp30_.x;
	_tmp31_ = inner_box_allocation;
	inner_box_allocation.x = (width - _tmp31_.width) / 2;
	_tmp32_ = timer_control_buttons_allocation;
	timer_control_buttons_allocation.x = (width - _tmp32_.width) / 2;
	_tmp33_ = header_box_allocation;
	_tmp34_ = timer_progressbar_allocation;
	_tmp35_ = timer_control_buttons_allocation;
	tmp_natural_height = (_tmp33_.height + _tmp34_.height) + _tmp35_.height;
	spacing = CLAMP ((height - tmp_natural_height) / 4, self->priv->MIN_SPACING, self->priv->MAX_SPACING);
	allocation.y = (((height - tmp_natural_height) - (2 * spacing)) / 2) - self->priv->BOTTOM_PADDING;
	_tmp36_ = allocation;
	header_box_allocation.y = _tmp36_.y;
	_tmp37_ = header_box_allocation;
	_tmp38_ = header_box_allocation;
	timer_progressbar_allocation.y = (_tmp37_.y + _tmp38_.height) + spacing;
	_tmp39_ = timer_progressbar_allocation;
	_tmp40_ = timer_progressbar_allocation;
	_tmp41_ = inner_box_allocation;
	inner_box_allocation.y = _tmp39_.y + ((_tmp40_.height - _tmp41_.height) / 2);
	_tmp42_ = timer_progressbar_allocation;
	_tmp43_ = timer_progressbar_allocation;
	timer_control_buttons_allocation.y = (_tmp42_.y + _tmp43_.height) + spacing;
	_tmp44_ = self->priv->header_box;
	_tmp45_ = header_box_allocation;
	gtk_widget_size_allocate ((GtkWidget*) _tmp44_, &_tmp45_, -1);
	_tmp46_ = self->priv->timer_progressbar;
	_tmp47_ = timer_progressbar_allocation;
	gtk_widget_size_allocate ((GtkWidget*) _tmp46_, &_tmp47_, -1);
	_tmp48_ = self->priv->inner_box;
	_tmp49_ = inner_box_allocation;
	gtk_widget_size_allocate ((GtkWidget*) _tmp48_, &_tmp49_, -1);
	_tmp50_ = self->priv->timer_control_buttons;
	_tmp51_ = timer_control_buttons_allocation;
	gtk_widget_size_allocate ((GtkWidget*) _tmp50_, &_tmp51_, -1);
}

static void
ft_timer_view_real_map (GtkWidget* base)
{
	FtTimerView * self;
	FtSessionManager* _tmp0_;
	self = (FtTimerView*) base;
	_tmp0_ = self->priv->session_manager;
	ft_session_manager_ensure_session (_tmp0_, FT_TIMESTAMP_UNDEFINED);
	ft_timer_view_update (self);
	GTK_WIDGET_CLASS (ft_timer_view_parent_class)->map (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	ft_timer_view_connect_signals (self);
}

static void
ft_timer_view_real_unmap (GtkWidget* base)
{
	FtTimerView * self;
	self = (FtTimerView*) base;
	GTK_WIDGET_CLASS (ft_timer_view_parent_class)->unmap (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	ft_timer_view_disconnect_signals (self);
}

static void
ft_timer_view_real_dispose (GObject* base)
{
	FtTimerView * self;
	self = (FtTimerView*) base;
	ft_timer_view_disconnect_signals (self);
	if (self->priv->session_expired_id != ((gulong) 0)) {
		FtSessionManager* _tmp0_;
		_tmp0_ = self->priv->session_manager;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->session_expired_id);
		self->priv->session_expired_id = (gulong) 0;
	}
	if (self->priv->current_time_block_changed_id != ((gulong) 0)) {
		FtTimeBlock* _tmp1_;
		_tmp1_ = self->priv->current_time_block;
		g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->current_time_block_changed_id);
		self->priv->current_time_block_changed_id = (gulong) 0;
	}
	if (self->priv->notify_current_time_block_id != ((gulong) 0)) {
		FtSessionManager* _tmp2_;
		_tmp2_ = self->priv->session_manager;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->notify_current_time_block_id);
		self->priv->notify_current_time_block_id = (gulong) 0;
	}
	if (self->priv->notify_has_uniform_breaks_id != ((gulong) 0)) {
		FtSessionManager* _tmp3_;
		_tmp3_ = self->priv->session_manager;
		g_signal_handler_disconnect ((GObject*) _tmp3_, self->priv->notify_has_uniform_breaks_id);
		self->priv->notify_has_uniform_breaks_id = (gulong) 0;
	}
	if (self->priv->settings_changed_id != ((gulong) 0)) {
		GSettings* _tmp4_;
		_tmp4_ = self->priv->settings;
		g_signal_handler_disconnect ((GObject*) _tmp4_, self->priv->settings_changed_id);
		self->priv->settings_changed_id = (gulong) 0;
	}
	_g_object_unref0 (self->priv->session_expired_toast);
	self->priv->session_expired_toast = NULL;
	_g_object_unref0 (self->priv->state_menu);
	self->priv->state_menu = NULL;
	_g_object_unref0 (self->priv->uniform_state_menu);
	self->priv->uniform_state_menu = NULL;
	_g_object_unref0 (self->priv->current_time_block);
	self->priv->current_time_block = NULL;
	_g_object_unref0 (self->priv->session_manager);
	self->priv->session_manager = NULL;
	_g_object_unref0 (self->priv->timer);
	self->priv->timer = NULL;
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = NULL;
	gtk_widget_dispose_template ((GtkWidget*) self, FT_TYPE_TIMER_VIEW);
	G_OBJECT_CLASS (ft_timer_view_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

FtTimerView*
ft_timer_view_construct (GType object_type)
{
	FtTimerView * self = NULL;
	self = (FtTimerView*) g_object_new (object_type, NULL);
	return self;
}

FtTimerView*
ft_timer_view_new (void)
{
	return ft_timer_view_construct (FT_TYPE_TIMER_VIEW);
}

static void
_ft_timer_view_on_settings_changed_g_settings_changed (GSettings* _sender,
                                                       const gchar* key,
                                                       gpointer self)
{
	ft_timer_view_on_settings_changed ((FtTimerView*) self, _sender, key);
}

static void
_ft_timer_view_on_session_expired_ft_session_manager_session_expired (FtSessionManager* _sender,
                                                                      FtSession* session,
                                                                      gint64 timestamp,
                                                                      gpointer self)
{
	ft_timer_view_on_session_expired ((FtTimerView*) self, session);
}

static void
_ft_timer_view_on_session_manager_notify_current_time_block_g_object_notify (GObject* _sender,
                                                                             GParamSpec* pspec,
                                                                             gpointer self)
{
	ft_timer_view_on_session_manager_notify_current_time_block ((FtTimerView*) self);
}

static void
_ft_timer_view_on_session_manager_notify_has_uniform_breaks_g_object_notify (GObject* _sender,
                                                                             GParamSpec* pspec,
                                                                             gpointer self)
{
	ft_timer_view_on_session_manager_notify_has_uniform_breaks ((FtTimerView*) self);
}

static GObject *
ft_timer_view_constructor (GType type,
                           guint n_construct_properties,
                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtTimerView * self;
	FtSessionManager* _tmp0_;
	FtSessionManager* _tmp1_;
	FtSessionManager* _tmp2_;
	FtTimer* _tmp3_;
	FtTimer* _tmp4_;
	FtTimer* _tmp5_;
	GSettings* _tmp6_;
	GSettings* _tmp7_;
	GtkBuilder* builder = NULL;
	GtkBuilder* _tmp8_;
	GtkBuilder* _tmp9_;
	GObject* _tmp10_;
	GMenuModel* _tmp11_;
	GtkBuilder* _tmp12_;
	GObject* _tmp13_;
	GMenuModel* _tmp14_;
	FtSessionManager* _tmp15_;
	FtSessionProgressBar* _tmp16_;
	GSettings* _tmp17_;
	gulong _tmp18_;
	FtSessionManager* _tmp19_;
	gulong _tmp20_;
	FtSessionManager* _tmp21_;
	gulong _tmp22_;
	FtSessionManager* _tmp23_;
	gulong _tmp24_;
	parent_class = G_OBJECT_CLASS (ft_timer_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIMER_VIEW, FtTimerView);
	_tmp0_ = ft_session_manager_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->session_manager);
	self->priv->session_manager = _tmp1_;
	_tmp2_ = self->priv->session_manager;
	_tmp3_ = ft_session_manager_get_timer (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_g_object_unref0 (self->priv->timer);
	self->priv->timer = _tmp5_;
	_tmp6_ = ft_get_settings ();
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp7_;
	_tmp8_ = gtk_builder_new_from_resource ("/io/github/focustimerhq/FocusTimer/ui/main/timer/menus.ui");
	builder = _tmp8_;
	_tmp9_ = builder;
	_tmp10_ = gtk_builder_get_object (_tmp9_, "state_menu");
	_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, g_menu_model_get_type (), GMenuModel));
	_g_object_unref0 (self->priv->state_menu);
	self->priv->state_menu = _tmp11_;
	_tmp12_ = builder;
	_tmp13_ = gtk_builder_get_object (_tmp12_, "uniform_state_menu");
	_tmp14_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp13_, g_menu_model_get_type (), GMenuModel));
	_g_object_unref0 (self->priv->uniform_state_menu);
	self->priv->uniform_state_menu = _tmp14_;
	_tmp15_ = self->priv->session_manager;
	_tmp16_ = self->priv->session_progressbar;
	g_object_bind_property_with_closures ((GObject*) _tmp15_, "current-session", (GObject*) _tmp16_, "session", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp17_ = self->priv->settings;
	_tmp18_ = g_signal_connect_object (_tmp17_, "changed", (GCallback) _ft_timer_view_on_settings_changed_g_settings_changed, self, 0);
	self->priv->settings_changed_id = _tmp18_;
	_tmp19_ = self->priv->session_manager;
	_tmp20_ = g_signal_connect_object (_tmp19_, "session-expired", (GCallback) _ft_timer_view_on_session_expired_ft_session_manager_session_expired, self, 0);
	self->priv->session_expired_id = _tmp20_;
	_tmp21_ = self->priv->session_manager;
	_tmp22_ = g_signal_connect_object ((GObject*) _tmp21_, "notify::current-time-block", (GCallback) _ft_timer_view_on_session_manager_notify_current_time_block_g_object_notify, self, 0);
	self->priv->notify_current_time_block_id = _tmp22_;
	_tmp23_ = self->priv->session_manager;
	_tmp24_ = g_signal_connect_object ((GObject*) _tmp23_, "notify::has-uniform-breaks", (GCallback) _ft_timer_view_on_session_manager_notify_has_uniform_breaks_g_object_notify, self, 0);
	self->priv->notify_has_uniform_breaks_id = _tmp24_;
	ft_timer_view_on_session_manager_notify_current_time_block (self);
	ft_timer_view_on_session_manager_notify_has_uniform_breaks (self);
	_g_object_unref0 (builder);
	return obj;
}

static void
ft_timer_view_class_init (FtTimerViewClass * klass,
                          gpointer klass_data)
{
	ft_timer_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtTimerView_private_offset);
	((GtkWidgetClass *) klass)->get_request_mode = (GtkSizeRequestMode (*) (GtkWidget*)) ft_timer_view_real_get_request_mode;
	((GtkWidgetClass *) klass)->measure = (void (*) (GtkWidget*, GtkOrientation, gint, gint*, gint*, gint*, gint*)) ft_timer_view_real_measure;
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, gint, gint, gint)) ft_timer_view_real_size_allocate;
	((GtkWidgetClass *) klass)->map = (void (*) (GtkWidget*)) ft_timer_view_real_map;
	((GtkWidgetClass *) klass)->unmap = (void (*) (GtkWidget*)) ft_timer_view_real_unmap;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_timer_view_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = ft_timer_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_timer_view_finalize;
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/timer/timer-view.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "state_menubutton", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, state_menubutton));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "open_screen_overlay_button", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, open_screen_overlay_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "header_box", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, header_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "inner_box", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, inner_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "timer_progressbar", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, timer_progressbar));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "session_progressbar", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, session_progressbar));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "timer_label", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, timer_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "timer_control_buttons", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, timer_control_buttons));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "click_gesture", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, click_gesture));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "drag_gesture", FALSE, FtTimerView_private_offset + G_STRUCT_OFFSET (FtTimerViewPrivate, drag_gesture));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_pressed", G_CALLBACK(_ft_timer_view_on_pressed_gtk_gesture_click_pressed));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_drag_update", G_CALLBACK(_ft_timer_view_on_drag_update_gtk_gesture_drag_drag_update));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "timerview");
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_minus, GDK_CONTROL_MASK, "timer.shorten", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_equal, GDK_CONTROL_MASK, "timer.extend", NULL, NULL);
}

static void
ft_timer_view_gtk_buildable_interface_init (GtkBuildableIface * iface,
                                            gpointer iface_data)
{
	ft_timer_view_gtk_buildable_parent_iface = g_type_interface_peek_parent (iface);
}

static void
ft_timer_view_instance_init (FtTimerView * self,
                             gpointer klass)
{
	self->priv = ft_timer_view_get_instance_private (self);
	self->priv->MIN_PADDING = 24;
	self->priv->MAX_PADDING = 72;
	self->priv->BOTTOM_PADDING = 5;
	self->priv->MIN_WIDTH = 300;
	self->priv->NAT_WIDTH = 400;
	self->priv->MAX_WIDTH = 450;
	self->priv->MIN_SPACING = 12;
	self->priv->NAT_SPACING = 24;
	self->priv->MAX_SPACING = 50;
	self->priv->INNER_RELATIVE_WIDTH = 0.70f;
	self->priv->MAX_PROGRESSRING_RELATIVE_HEIGHT = 0.618f;
	self->priv->settings = NULL;
	self->priv->timer_state_changed_id = (gulong) 0;
	self->priv->session_expired_id = (gulong) 0;
	self->priv->notify_current_time_block_id = (gulong) 0;
	self->priv->notify_has_uniform_breaks_id = (gulong) 0;
	self->priv->current_time_block_changed_id = (gulong) 0;
	self->priv->settings_changed_id = (gulong) 0;
	g_type_ensure (FT_TYPE_TIMER_PROGRESS_BAR);
	g_type_ensure (FT_TYPE_SESSION_PROGRESS_BAR);
	g_type_ensure (FT_TYPE_TIMER_LABEL);
	g_type_ensure (FT_TYPE_TIMER_CONTROL_BUTTONS);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_timer_view_finalize (GObject * obj)
{
	FtTimerView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIMER_VIEW, FtTimerView);
	_g_object_unref0 (self->priv->session_manager);
	_g_object_unref0 (self->priv->timer);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->state_menu);
	_g_object_unref0 (self->priv->uniform_state_menu);
	_g_object_unref0 (self->priv->session_expired_toast);
	_g_object_unref0 (self->priv->current_time_block);
	G_OBJECT_CLASS (ft_timer_view_parent_class)->finalize (obj);
}

static GType
ft_timer_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtTimerViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_timer_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtTimerView), 0, (GInstanceInitFunc) ft_timer_view_instance_init, NULL };
	static const GInterfaceInfo gtk_buildable_info = { (GInterfaceInitFunc) ft_timer_view_gtk_buildable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType ft_timer_view_type_id;
	ft_timer_view_type_id = g_type_register_static (gtk_widget_get_type (), "FtTimerView", &g_define_type_info, 0);
	g_type_add_interface_static (ft_timer_view_type_id, gtk_buildable_get_type (), &gtk_buildable_info);
	FtTimerView_private_offset = g_type_add_instance_private (ft_timer_view_type_id, sizeof (FtTimerViewPrivate));
	return ft_timer_view_type_id;
}

GType
ft_timer_view_get_type (void)
{
	static volatile gsize ft_timer_view_type_id__once = 0;
	if (g_once_init_enter (&ft_timer_view_type_id__once)) {
		GType ft_timer_view_type_id;
		ft_timer_view_type_id = ft_timer_view_get_type_once ();
		g_once_init_leave (&ft_timer_view_type_id__once, ft_timer_view_type_id);
	}
	return ft_timer_view_type_id__once;
}

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;
}

