/* idle-monitor-provider.c generated by valac 0.56.19, the Vala compiler
 * generated from idle-monitor-provider.vala, do not modify */

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

#include "ft_plugin_wayland.h"
#include <glib.h>
#include <ft-wayland.h>
#include "ft_core.h"
#include <gio/gio.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/wayland/gdkwayland.h>
#include <gdk/gdk.h>
#include <wayland-client.h>

#define WAYLAND_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE (100 * FT_INTERVAL_MILLISECOND)
#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 _WaylandIdleMonitorProviderWatch WaylandIdleMonitorProviderWatch;
enum  {
	WAYLAND_IDLE_MONITOR_PROVIDER_0_PROPERTY,
	WAYLAND_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY,
	WAYLAND_IDLE_MONITOR_PROVIDER_NUM_PROPERTIES
};
static GParamSpec* wayland_idle_monitor_provider_properties[WAYLAND_IDLE_MONITOR_PROVIDER_NUM_PROPERTIES];
#define _ft_wayland_idle_monitor_unref0(var) ((var == NULL) ? NULL : (var = (ft_wayland_idle_monitor_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _wayland_idle_monitor_provider_watch_free0(var) ((var == NULL) ? NULL : (var = (wayland_idle_monitor_provider_watch_free (var), NULL)))
typedef struct _WaylandIdleMonitorProviderInitializeData WaylandIdleMonitorProviderInitializeData;
typedef struct _WaylandIdleMonitorProviderUninitializeData WaylandIdleMonitorProviderUninitializeData;
typedef struct _WaylandIdleMonitorProviderEnableData WaylandIdleMonitorProviderEnableData;
typedef struct _Block1Data Block1Data;
typedef struct _WaylandIdleMonitorProviderDisableData WaylandIdleMonitorProviderDisableData;
#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 _WaylandIdleMonitorProviderPrivate {
	gboolean supports_input_idle;
	FtWaylandIdleMonitor* idle_monitor;
	GHashTable* watches;
	guint32 active_watch_id;
	guint active_watch_use_count;
};

struct _WaylandIdleMonitorProviderWatch {
	guint32 id;
	gint64 absolute_timeout;
	gint64 relative_timeout;
	gint64 reference_time;
	gboolean ignore_inhibitors;
	gboolean has_active_watch;
	gboolean invalid;
};

struct _WaylandIdleMonitorProviderInitializeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	WaylandIdleMonitorProvider* self;
	GCancellable* cancellable;
	GdkDisplay* display;
	GdkDisplay* _tmp0_;
	GdkDisplay* _tmp1_;
	GdkDisplay* _tmp2_;
};

struct _WaylandIdleMonitorProviderUninitializeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	WaylandIdleMonitorProvider* self;
};

struct _WaylandIdleMonitorProviderEnableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	WaylandIdleMonitorProvider* self;
	GCancellable* cancellable;
	FtWaylandIdleMonitor* _tmp0_;
};

struct _Block1Data {
	int _ref_count_;
	WaylandIdleMonitorProvider* self;
	guint32* ids;
	gint ids_length1;
	gint _ids_size_;
	gpointer _async_data_;
};

struct _WaylandIdleMonitorProviderDisableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	WaylandIdleMonitorProvider* self;
	Block1Data* _data1_;
	FtWaylandIdleMonitor* _tmp0_;
	guint32* _tmp1_;
	GHashTable* _tmp2_;
	gint index;
	gboolean _tmp3_;
	gint _tmp4_;
	guint32* _tmp5_;
	gint _tmp5__length1;
	guint32* _tmp6_;
	gint _tmp6__length1;
	guint32 _tmp7_;
	GError* _inner_error0_;
};

static gint WaylandIdleMonitorProvider_private_offset;
static gpointer wayland_idle_monitor_provider_parent_class = NULL;
static FtIdleMonitorProviderIface * wayland_idle_monitor_provider_ft_idle_monitor_provider_parent_iface = NULL;
static GType wayland_idle_monitor_provider_type_id = 0;

static void wayland_idle_monitor_provider_watch_free (WaylandIdleMonitorProviderWatch * self);
static inline guint64 wayland_idle_monitor_provider_to_milliseconds (WaylandIdleMonitorProvider* self,
                                                       gint64 interval);
static void wayland_idle_monitor_provider_remove_active_watch_internal (WaylandIdleMonitorProvider* self,
                                                                 GError** error);
static void wayland_idle_monitor_provider_on_became_active (WaylandIdleMonitorProvider* self);
static void wayland_idle_monitor_provider_on_became_idle (WaylandIdleMonitorProvider* self,
                                                   WaylandIdleMonitorProviderWatch* watch);
static void wayland_idle_monitor_provider_on_notification_idled (guint32 id,
                                                          void* user_data);
static void wayland_idle_monitor_provider_handle_notification_idled (WaylandIdleMonitorProvider* self,
                                                              guint32 id);
static void wayland_idle_monitor_provider_on_notification_resumed (guint32 id,
                                                            void* user_data);
static void wayland_idle_monitor_provider_handle_notification_resumed (WaylandIdleMonitorProvider* self,
                                                                guint32 id);
static void wayland_idle_monitor_provider_update_available (WaylandIdleMonitorProvider* self);
static guint32 wayland_idle_monitor_provider_real_add_idle_watch (FtIdleMonitorProvider* base,
                                                           gint64 timeout,
                                                           gboolean ignore_inhibitors,
                                                           gint64 monotonic_time,
                                                           GError** error);
static void _wayland_idle_monitor_provider_on_notification_idled_ft_wayland_idle_monitor_callback (guint32 id,
                                                                                            void* user_data);
static WaylandIdleMonitorProviderWatch* wayland_idle_monitor_provider_watch_new (void);
static gint64* _int64_dup (gint64* self);
static void wayland_idle_monitor_provider_real_remove_idle_watch (FtIdleMonitorProvider* base,
                                                           guint32 id,
                                                           GError** error);
static guint32 wayland_idle_monitor_provider_real_reset_idle_watch (FtIdleMonitorProvider* base,
                                                             guint32 id,
                                                             gint64 monotonic_time,
                                                             GError** error);
static void wayland_idle_monitor_provider_real_add_active_watch (FtIdleMonitorProvider* base,
                                                          GError** error);
static void _wayland_idle_monitor_provider_on_notification_resumed_ft_wayland_idle_monitor_callback (guint32 id,
                                                                                              void* user_data);
static void wayland_idle_monitor_provider_real_remove_active_watch (FtIdleMonitorProvider* base,
                                                             GError** error);
static void wayland_idle_monitor_provider_real_initialize_data_free (gpointer _data);
static void wayland_idle_monitor_provider_real_initialize (FtProvider* base,
                                                    GCancellable* cancellable,
                                                    GAsyncReadyCallback _callback_,
                                                    gpointer _user_data_);
static gboolean wayland_idle_monitor_provider_real_initialize_co (WaylandIdleMonitorProviderInitializeData* _data_);
static void wayland_idle_monitor_provider_real_uninitialize_data_free (gpointer _data);
static void wayland_idle_monitor_provider_real_uninitialize (FtProvider* base,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_);
static gboolean wayland_idle_monitor_provider_real_uninitialize_co (WaylandIdleMonitorProviderUninitializeData* _data_);
static void wayland_idle_monitor_provider_real_enable_data_free (gpointer _data);
static void wayland_idle_monitor_provider_real_enable (FtProvider* base,
                                                GCancellable* cancellable,
                                                GAsyncReadyCallback _callback_,
                                                gpointer _user_data_);
static gboolean wayland_idle_monitor_provider_real_enable_co (WaylandIdleMonitorProviderEnableData* _data_);
static void wayland_idle_monitor_provider_real_disable_data_free (gpointer _data);
static void wayland_idle_monitor_provider_real_disable (FtProvider* base,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_);
static gboolean wayland_idle_monitor_provider_real_disable_co (WaylandIdleMonitorProviderDisableData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda4_ (Block1Data* _data1_,
                 gint64* id,
                 WaylandIdleMonitorProviderWatch* watch);
static void _vala_array_add1 (guint32* * array,
                       gint* length,
                       gint* size,
                       guint32 value);
static void ___lambda4__gh_func (gconstpointer key,
                          gconstpointer value,
                          gpointer self);
static void wayland_idle_monitor_provider_real_dispose (GObject* base);
static void wayland_idle_monitor_provider_watch_instance_init (WaylandIdleMonitorProviderWatch * self);
static GObject * wayland_idle_monitor_provider_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static void _g_free0_ (gpointer var);
static void _wayland_idle_monitor_provider_watch_free0_ (gpointer var);
static void wayland_idle_monitor_provider_finalize (GObject * obj);
static void _vala_wayland_idle_monitor_provider_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);

static inline gpointer
wayland_idle_monitor_provider_get_instance_private (WaylandIdleMonitorProvider* self)
{
	return G_STRUCT_MEMBER_P (self, WaylandIdleMonitorProvider_private_offset);
}

static inline guint64
wayland_idle_monitor_provider_to_milliseconds (WaylandIdleMonitorProvider* self,
                                               gint64 interval)
{
	guint64 result;
	g_return_val_if_fail (self != NULL, 0ULL);
	result = ((guint64) MAX (interval, (gint64) 0)) / FT_INTERVAL_MILLISECOND;
	return result;
}

static void
wayland_idle_monitor_provider_remove_active_watch_internal (WaylandIdleMonitorProvider* self,
                                                            GError** error)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (self->priv->active_watch_id != ((guint32) 0)) {
		FtWaylandIdleMonitor* _tmp1_;
		_tmp1_ = self->priv->idle_monitor;
		_tmp0_ = _tmp1_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		guint32 watch_id = 0U;
		FtWaylandIdleMonitor* _tmp2_;
		watch_id = self->priv->active_watch_id;
		self->priv->active_watch_id = (guint32) 0;
		self->priv->active_watch_use_count = (guint) 0;
		_tmp2_ = self->priv->idle_monitor;
		ft_wayland_idle_monitor_remove_notification (_tmp2_, watch_id);
	}
}

static void
wayland_idle_monitor_provider_on_became_active (WaylandIdleMonitorProvider* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = ft_provider_get_enabled ((FtProvider*) self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		return;
	}
	{
		wayland_idle_monitor_provider_remove_active_watch_internal (self, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = _error_;
		_tmp3_ = _tmp2_->message;
		g_warning ("idle-monitor-provider.vala:70: Error while removing active-watch: %s", _tmp3_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
	g_signal_emit_by_name ((FtIdleMonitorProvider*) self, "became-active");
}

static void
wayland_idle_monitor_provider_on_became_idle (WaylandIdleMonitorProvider* self,
                                              WaylandIdleMonitorProviderWatch* watch)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	gint64 monotonic_time = 0LL;
	gint64 min_elapsed = 0LL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (watch != NULL);
	_tmp0_ = ft_provider_get_enabled ((FtProvider*) self);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		return;
	}
	monotonic_time = g_get_monotonic_time ();
	min_elapsed = MAX (watch->relative_timeout - WAYLAND_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE, watch->relative_timeout / 2);
	if ((monotonic_time - watch->reference_time) >= min_elapsed) {
		g_signal_emit_by_name ((FtIdleMonitorProvider*) self, "became-idle", watch->id);
	}
}

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

static void
wayland_idle_monitor_provider_on_notification_idled (guint32 id,
                                                     void* user_data)
{
	WaylandIdleMonitorProvider* provider = NULL;
	WaylandIdleMonitorProvider* _tmp0_;
	gboolean _tmp1_ = FALSE;
	WaylandIdleMonitorProvider* _tmp2_;
	WaylandIdleMonitorProvider* _tmp5_;
	_tmp0_ = _g_object_ref0 (WAYLAND_IS_IDLE_MONITOR_PROVIDER (user_data) ? ((WaylandIdleMonitorProvider*) user_data) : NULL);
	provider = _tmp0_;
	_tmp2_ = provider;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		WaylandIdleMonitorProvider* _tmp3_;
		FtWaylandIdleMonitor* _tmp4_;
		_tmp3_ = provider;
		_tmp4_ = _tmp3_->priv->idle_monitor;
		_tmp1_ = _tmp4_ == NULL;
	}
	if (_tmp1_) {
		_g_object_unref0 (provider);
		return;
	}
	_tmp5_ = provider;
	wayland_idle_monitor_provider_handle_notification_idled (_tmp5_, id);
	_g_object_unref0 (provider);
}

static void
wayland_idle_monitor_provider_on_notification_resumed (guint32 id,
                                                       void* user_data)
{
	WaylandIdleMonitorProvider* provider = NULL;
	WaylandIdleMonitorProvider* _tmp0_;
	gboolean _tmp1_ = FALSE;
	WaylandIdleMonitorProvider* _tmp2_;
	WaylandIdleMonitorProvider* _tmp5_;
	_tmp0_ = _g_object_ref0 (WAYLAND_IS_IDLE_MONITOR_PROVIDER (user_data) ? ((WaylandIdleMonitorProvider*) user_data) : NULL);
	provider = _tmp0_;
	_tmp2_ = provider;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		WaylandIdleMonitorProvider* _tmp3_;
		FtWaylandIdleMonitor* _tmp4_;
		_tmp3_ = provider;
		_tmp4_ = _tmp3_->priv->idle_monitor;
		_tmp1_ = _tmp4_ == NULL;
	}
	if (_tmp1_) {
		_g_object_unref0 (provider);
		return;
	}
	_tmp5_ = provider;
	wayland_idle_monitor_provider_handle_notification_resumed (_tmp5_, id);
	_g_object_unref0 (provider);
}

static void
wayland_idle_monitor_provider_handle_notification_idled (WaylandIdleMonitorProvider* self,
                                                         guint32 id)
{
	gboolean _tmp0_ = FALSE;
	WaylandIdleMonitorProviderWatch* watch = NULL;
	GHashTable* _tmp1_;
	gint64 _tmp2_;
	gconstpointer _tmp3_;
	gboolean _tmp4_ = FALSE;
	WaylandIdleMonitorProviderWatch* _tmp5_;
	g_return_if_fail (self != NULL);
	if (id == ((guint32) 0)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = id == self->priv->active_watch_id;
	}
	if (_tmp0_) {
		return;
	}
	_tmp1_ = self->priv->watches;
	_tmp2_ = (gint64) id;
	_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
	watch = (WaylandIdleMonitorProviderWatch*) _tmp3_;
	_tmp5_ = watch;
	if (_tmp5_ != NULL) {
		WaylandIdleMonitorProviderWatch* _tmp6_;
		_tmp6_ = watch;
		_tmp4_ = !_tmp6_->invalid;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		WaylandIdleMonitorProviderWatch* _tmp7_;
		_tmp7_ = watch;
		wayland_idle_monitor_provider_on_became_idle (self, _tmp7_);
	}
}

static void
wayland_idle_monitor_provider_handle_notification_resumed (WaylandIdleMonitorProvider* self,
                                                           guint32 id)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	if (id != ((guint32) 0)) {
		_tmp0_ = id == self->priv->active_watch_id;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		wayland_idle_monitor_provider_on_became_active (self);
	}
}

static void
wayland_idle_monitor_provider_update_available (WaylandIdleMonitorProvider* self)
{
	GdkWaylandDisplay* display = NULL;
	GdkDisplay* _tmp0_;
	GdkWaylandDisplay* _tmp1_;
	GdkWaylandDisplay* _tmp2_;
	GdkWaylandSeat* seat = NULL;
	GdkWaylandDisplay* _tmp3_;
	GdkSeat* _tmp4_;
	GdkWaylandSeat* _tmp5_;
	GdkWaylandSeat* _tmp6_;
	FtWaylandIdleMonitor* _tmp7_;
	FtWaylandIdleMonitor* _tmp13_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gdk_wayland_display_get_type ()) ? ((GdkWaylandDisplay*) _tmp0_) : NULL);
	display = _tmp1_;
	_tmp2_ = display;
	if (_tmp2_ == NULL) {
		ft_provider_set_available ((FtProvider*) self, FALSE);
	}
	_tmp3_ = display;
	_tmp4_ = gdk_display_get_default_seat ((GdkDisplay*) _tmp3_);
	_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, gdk_wayland_seat_get_type ()) ? ((GdkWaylandSeat*) _tmp4_) : NULL);
	seat = _tmp5_;
	_tmp6_ = seat;
	if (_tmp6_ == NULL) {
		ft_provider_set_available ((FtProvider*) self, FALSE);
		_g_object_unref0 (seat);
		_g_object_unref0 (display);
		return;
	}
	_tmp7_ = self->priv->idle_monitor;
	if (_tmp7_ == NULL) {
		GdkWaylandDisplay* _tmp8_;
		struct wl_display* _tmp9_;
		GdkWaylandSeat* _tmp10_;
		struct wl_seat* _tmp11_;
		FtWaylandIdleMonitor* _tmp12_;
		_tmp8_ = display;
		_tmp9_ = gdk_wayland_display_get_wl_display (_tmp8_);
		_tmp10_ = seat;
		_tmp11_ = gdk_wayland_seat_get_wl_seat (_tmp10_);
		_tmp12_ = ft_wayland_idle_monitor_new (_tmp9_, _tmp11_);
		_ft_wayland_idle_monitor_unref0 (self->priv->idle_monitor);
		self->priv->idle_monitor = _tmp12_;
	}
	_tmp13_ = self->priv->idle_monitor;
	if (ft_wayland_idle_monitor_is_ready (_tmp13_)) {
		FtWaylandIdleMonitor* _tmp14_;
		_tmp14_ = self->priv->idle_monitor;
		self->priv->supports_input_idle = ft_wayland_idle_monitor_supports_input_idle (_tmp14_);
		ft_provider_set_available ((FtProvider*) self, TRUE);
	} else {
		ft_provider_set_available ((FtProvider*) self, FALSE);
	}
	_g_object_unref0 (seat);
	_g_object_unref0 (display);
}

static void
_wayland_idle_monitor_provider_on_notification_idled_ft_wayland_idle_monitor_callback (guint32 id,
                                                                                       void* user_data)
{
	wayland_idle_monitor_provider_on_notification_idled (id, user_data);
}

static gint64*
_int64_dup (gint64* self)
{
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}

static gpointer
__int64_dup0 (gpointer self)
{
	return self ? _int64_dup (self) : NULL;
}

static gpointer
_g_error_copy0 (gpointer self)
{
	return self ? g_error_copy (self) : NULL;
}

static guint32
wayland_idle_monitor_provider_real_add_idle_watch (FtIdleMonitorProvider* base,
                                                   gint64 timeout,
                                                   gboolean ignore_inhibitors,
                                                   gint64 monotonic_time,
                                                   GError** error)
{
	WaylandIdleMonitorProvider * self;
	FtWaylandIdleMonitor* _tmp0_;
	gint64 relative_timeout = 0LL;
	gint64 absolute_timeout = 0LL;
	guint32 watch_id = 0U;
	gboolean _tmp1_ = FALSE;
	WaylandIdleMonitorProviderWatch* watch = NULL;
	WaylandIdleMonitorProviderWatch* _tmp8_;
	WaylandIdleMonitorProviderWatch* _tmp9_;
	WaylandIdleMonitorProviderWatch* _tmp10_;
	WaylandIdleMonitorProviderWatch* _tmp11_;
	WaylandIdleMonitorProviderWatch* _tmp12_;
	WaylandIdleMonitorProviderWatch* _tmp13_;
	WaylandIdleMonitorProviderWatch* _watch = NULL;
	WaylandIdleMonitorProviderWatch* _tmp14_;
	GHashTable* _tmp15_;
	gint64 _tmp16_;
	gint64* _tmp17_;
	WaylandIdleMonitorProviderWatch* _tmp18_;
	gboolean _tmp19_ = FALSE;
	WaylandIdleMonitorProviderWatch* _tmp20_;
	GError* _inner_error0_ = NULL;
	guint32 result;
	self = (WaylandIdleMonitorProvider*) base;
	_tmp0_ = self->priv->idle_monitor;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.idle_monitor != null", 0U);
	relative_timeout = timeout;
	absolute_timeout = timeout;
	if (ft_timestamp_is_undefined (monotonic_time)) {
		monotonic_time = g_get_monotonic_time () - relative_timeout;
	} else {
		absolute_timeout = ft_idle_monitor_provider_calculate_absolute_timeout (relative_timeout, (gint64) 0, monotonic_time);
		if (llabs (absolute_timeout - relative_timeout) < WAYLAND_IDLE_MONITOR_PROVIDER_TIMEOUT_TOLERANCE) {
			absolute_timeout = relative_timeout;
		}
	}
	if (ignore_inhibitors) {
		gboolean _tmp2_;
		gboolean _tmp3_;
		_tmp2_ = ft_idle_monitor_provider_get_can_ignore_inhibitors ((FtIdleMonitorProvider*) self);
		_tmp3_ = _tmp2_;
		_tmp1_ = !_tmp3_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		ignore_inhibitors = FALSE;
	}
	if (ignore_inhibitors) {
		FtWaylandIdleMonitor* _tmp4_;
		_tmp4_ = self->priv->idle_monitor;
		watch_id = ft_wayland_idle_monitor_add_input_notification (_tmp4_, (guint32) wayland_idle_monitor_provider_to_milliseconds (self, timeout), _wayland_idle_monitor_provider_on_notification_idled_ft_wayland_idle_monitor_callback, NULL, self);
	} else {
		FtWaylandIdleMonitor* _tmp5_;
		_tmp5_ = self->priv->idle_monitor;
		watch_id = ft_wayland_idle_monitor_add_notification (_tmp5_, (guint32) wayland_idle_monitor_provider_to_milliseconds (self, timeout), _wayland_idle_monitor_provider_on_notification_idled_ft_wayland_idle_monitor_callback, NULL, self);
	}
	if (watch_id == ((guint32) 0)) {
		GError* _tmp6_;
		guint32 _tmp7_ = 0U;
		_tmp6_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to add Wayland idle notification");
		_inner_error0_ = _tmp6_;
		g_propagate_error (error, _inner_error0_);
		return _tmp7_;
	}
	_tmp8_ = wayland_idle_monitor_provider_watch_new ();
	watch = _tmp8_;
	_tmp9_ = watch;
	_tmp9_->id = watch_id;
	_tmp10_ = watch;
	_tmp10_->relative_timeout = relative_timeout;
	_tmp11_ = watch;
	_tmp11_->absolute_timeout = absolute_timeout;
	_tmp12_ = watch;
	_tmp12_->reference_time = monotonic_time;
	_tmp13_ = watch;
	_tmp13_->ignore_inhibitors = ignore_inhibitors;
	_tmp14_ = watch;
	_watch = _tmp14_;
	_tmp15_ = self->priv->watches;
	_tmp16_ = (gint64) watch_id;
	_tmp17_ = __int64_dup0 (&_tmp16_);
	_tmp18_ = watch;
	watch = NULL;
	g_hash_table_insert (_tmp15_, _tmp17_, _tmp18_);
	_tmp20_ = _watch;
	if (!_tmp20_->has_active_watch) {
		WaylandIdleMonitorProviderWatch* _tmp21_;
		WaylandIdleMonitorProviderWatch* _tmp22_;
		_tmp21_ = _watch;
		_tmp22_ = _watch;
		_tmp19_ = _tmp21_->absolute_timeout != _tmp22_->relative_timeout;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		{
			WaylandIdleMonitorProviderWatch* _tmp23_;
			ft_idle_monitor_provider_add_active_watch ((FtIdleMonitorProvider*) self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp23_ = _watch;
			_tmp23_->has_active_watch = TRUE;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _error_ = NULL;
			GError* _tmp24_;
			const gchar* _tmp25_;
			GError* _tmp26_;
			GError* _tmp27_;
			_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp24_ = _error_;
			_tmp25_ = _tmp24_->message;
			g_debug ("idle-monitor-provider.vala:228: Unable to add active watch: %s", _tmp25_);
			ft_idle_monitor_provider_remove_idle_watch ((FtIdleMonitorProvider*) self, watch_id, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_error_free0 (_error_);
				goto __finally0;
			}
			_tmp26_ = _error_;
			_tmp27_ = _g_error_copy0 (_tmp26_);
			_inner_error0_ = _tmp27_;
			_g_error_free0 (_error_);
			goto __finally0;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			guint32 _tmp28_ = 0U;
			g_propagate_error (error, _inner_error0_);
			_wayland_idle_monitor_provider_watch_free0 (watch);
			return _tmp28_;
		}
	}
	result = watch_id;
	_wayland_idle_monitor_provider_watch_free0 (watch);
	return result;
}

static void
wayland_idle_monitor_provider_real_remove_idle_watch (FtIdleMonitorProvider* base,
                                                      guint32 id,
                                                      GError** error)
{
	WaylandIdleMonitorProvider * self;
	FtWaylandIdleMonitor* _tmp0_;
	WaylandIdleMonitorProviderWatch* watch = NULL;
	GHashTable* _tmp1_;
	gint64 _tmp2_;
	gconstpointer _tmp3_;
	WaylandIdleMonitorProviderWatch* _tmp4_;
	WaylandIdleMonitorProviderWatch* _tmp5_;
	WaylandIdleMonitorProviderWatch* _tmp6_;
	FtWaylandIdleMonitor* _tmp10_;
	WaylandIdleMonitorProviderWatch* _tmp11_;
	WaylandIdleMonitorProviderWatch* _tmp12_;
	GError* _inner_error0_ = NULL;
	self = (WaylandIdleMonitorProvider*) base;
	_tmp0_ = self->priv->idle_monitor;
	_vala_return_if_fail (_tmp0_ != NULL, "this.idle_monitor != null");
	_tmp1_ = self->priv->watches;
	_tmp2_ = (gint64) id;
	_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
	watch = (WaylandIdleMonitorProviderWatch*) _tmp3_;
	_tmp4_ = watch;
	if (_tmp4_ == NULL) {
		return;
	}
	_tmp5_ = watch;
	_tmp5_->invalid = TRUE;
	_tmp6_ = watch;
	if (_tmp6_->has_active_watch) {
		{
			WaylandIdleMonitorProviderWatch* _tmp7_;
			ft_idle_monitor_provider_remove_active_watch ((FtIdleMonitorProvider*) self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp7_ = watch;
			_tmp7_->has_active_watch = FALSE;
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* _error_ = NULL;
			GError* _tmp8_;
			const gchar* _tmp9_;
			_error_ = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp8_ = _error_;
			_tmp9_ = _tmp8_->message;
			g_warning ("idle-monitor-provider.vala:257: Unable to remove active watch: %s", _tmp9_);
			_g_error_free0 (_error_);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
	_tmp10_ = self->priv->idle_monitor;
	_tmp11_ = watch;
	ft_wayland_idle_monitor_remove_notification (_tmp10_, _tmp11_->id);
	_tmp12_ = watch;
	if (!_tmp12_->has_active_watch) {
		GHashTable* _tmp13_;
		gint64 _tmp14_;
		_tmp13_ = self->priv->watches;
		_tmp14_ = (gint64) id;
		g_hash_table_remove (_tmp13_, &_tmp14_);
	}
}

static guint32
wayland_idle_monitor_provider_real_reset_idle_watch (FtIdleMonitorProvider* base,
                                                     guint32 id,
                                                     gint64 monotonic_time,
                                                     GError** error)
{
	WaylandIdleMonitorProvider * self;
	FtWaylandIdleMonitor* _tmp0_;
	WaylandIdleMonitorProviderWatch* watch = NULL;
	GHashTable* _tmp1_;
	gint64 _tmp2_;
	gconstpointer _tmp3_;
	gboolean _tmp4_ = FALSE;
	WaylandIdleMonitorProviderWatch* _tmp5_;
	guint32 new_id = 0U;
	WaylandIdleMonitorProviderWatch* _tmp8_;
	WaylandIdleMonitorProviderWatch* _tmp9_;
	FtWaylandIdleMonitor* _tmp11_;
	WaylandIdleMonitorProviderWatch* _tmp12_;
	GHashTable* _tmp13_;
	gint64 _tmp14_;
	GError* _inner_error0_ = NULL;
	guint32 result;
	self = (WaylandIdleMonitorProvider*) base;
	_tmp0_ = self->priv->idle_monitor;
	_vala_return_val_if_fail (_tmp0_ != NULL, "this.idle_monitor != null", 0U);
	_tmp1_ = self->priv->watches;
	_tmp2_ = (gint64) id;
	_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
	watch = (WaylandIdleMonitorProviderWatch*) _tmp3_;
	_tmp5_ = watch;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		WaylandIdleMonitorProviderWatch* _tmp6_;
		WaylandIdleMonitorProviderWatch* _tmp7_;
		_tmp6_ = watch;
		_tmp7_ = watch;
		_tmp4_ = _tmp6_->absolute_timeout == _tmp7_->relative_timeout;
	}
	if (_tmp4_) {
		result = id;
		return result;
	}
	_tmp8_ = watch;
	_tmp9_ = watch;
	new_id = ft_idle_monitor_provider_add_idle_watch ((FtIdleMonitorProvider*) self, _tmp8_->relative_timeout, _tmp9_->ignore_inhibitors, monotonic_time, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint32 _tmp10_ = 0U;
		g_propagate_error (error, _inner_error0_);
		return _tmp10_;
	}
	_tmp11_ = self->priv->idle_monitor;
	_tmp12_ = watch;
	ft_wayland_idle_monitor_remove_notification (_tmp11_, _tmp12_->id);
	_tmp13_ = self->priv->watches;
	_tmp14_ = (gint64) id;
	g_hash_table_remove (_tmp13_, &_tmp14_);
	result = new_id;
	return result;
}

static void
_wayland_idle_monitor_provider_on_notification_resumed_ft_wayland_idle_monitor_callback (guint32 id,
                                                                                         void* user_data)
{
	wayland_idle_monitor_provider_on_notification_resumed (id, user_data);
}

static void
wayland_idle_monitor_provider_real_add_active_watch (FtIdleMonitorProvider* base,
                                                     GError** error)
{
	WaylandIdleMonitorProvider * self;
	FtWaylandIdleMonitor* _tmp0_;
	guint _tmp13_;
	GError* _inner_error0_ = NULL;
	self = (WaylandIdleMonitorProvider*) base;
	_tmp0_ = self->priv->idle_monitor;
	_vala_return_if_fail (_tmp0_ != NULL, "this.idle_monitor != null");
	if (self->priv->active_watch_id == ((guint32) 0)) {
		gboolean ignore_inhibitors = FALSE;
		gboolean _tmp1_;
		gboolean _tmp2_;
		WaylandIdleMonitorProviderWatch* active_watch = NULL;
		WaylandIdleMonitorProviderWatch* _tmp6_;
		WaylandIdleMonitorProviderWatch* _tmp7_;
		WaylandIdleMonitorProviderWatch* _tmp8_;
		GHashTable* _tmp9_;
		gint64 _tmp10_;
		gint64* _tmp11_;
		WaylandIdleMonitorProviderWatch* _tmp12_;
		_tmp1_ = ft_idle_monitor_provider_get_can_ignore_inhibitors ((FtIdleMonitorProvider*) self);
		_tmp2_ = _tmp1_;
		ignore_inhibitors = _tmp2_;
		if (ignore_inhibitors) {
			FtWaylandIdleMonitor* _tmp3_;
			_tmp3_ = self->priv->idle_monitor;
			self->priv->active_watch_id = ft_wayland_idle_monitor_add_input_notification (_tmp3_, (guint32) 0, NULL, _wayland_idle_monitor_provider_on_notification_resumed_ft_wayland_idle_monitor_callback, self);
		} else {
			FtWaylandIdleMonitor* _tmp4_;
			_tmp4_ = self->priv->idle_monitor;
			self->priv->active_watch_id = ft_wayland_idle_monitor_add_notification (_tmp4_, (guint32) 0, NULL, _wayland_idle_monitor_provider_on_notification_resumed_ft_wayland_idle_monitor_callback, self);
		}
		if (self->priv->active_watch_id == ((guint32) 0)) {
			GError* _tmp5_;
			_tmp5_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to add Wayland active-watch notification");
			_inner_error0_ = _tmp5_;
			g_propagate_error (error, _inner_error0_);
			return;
		}
		_tmp6_ = wayland_idle_monitor_provider_watch_new ();
		active_watch = _tmp6_;
		_tmp7_ = active_watch;
		_tmp7_->id = self->priv->active_watch_id;
		_tmp8_ = active_watch;
		_tmp8_->ignore_inhibitors = ignore_inhibitors;
		_tmp9_ = self->priv->watches;
		_tmp10_ = (gint64) self->priv->active_watch_id;
		_tmp11_ = __int64_dup0 (&_tmp10_);
		_tmp12_ = active_watch;
		active_watch = NULL;
		g_hash_table_insert (_tmp9_, _tmp11_, _tmp12_);
		_wayland_idle_monitor_provider_watch_free0 (active_watch);
	}
	_tmp13_ = self->priv->active_watch_use_count;
	self->priv->active_watch_use_count = _tmp13_ + 1;
}

static void
wayland_idle_monitor_provider_real_remove_active_watch (FtIdleMonitorProvider* base,
                                                        GError** error)
{
	WaylandIdleMonitorProvider * self;
	GError* _inner_error0_ = NULL;
	self = (WaylandIdleMonitorProvider*) base;
	_vala_return_if_fail (self->priv->active_watch_use_count > ((guint) 0), "this.active_watch_use_count > 0");
	if (self->priv->active_watch_use_count > ((guint) 1)) {
		guint _tmp0_;
		_tmp0_ = self->priv->active_watch_use_count;
		self->priv->active_watch_use_count = _tmp0_ - 1;
	} else {
		if (self->priv->active_watch_use_count == ((guint) 1)) {
			guint32 watch_id = 0U;
			watch_id = self->priv->active_watch_id;
			wayland_idle_monitor_provider_remove_active_watch_internal (self, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				return;
			}
			if (watch_id != ((guint32) 0)) {
				GHashTable* _tmp1_;
				gint64 _tmp2_;
				_tmp1_ = self->priv->watches;
				_tmp2_ = (gint64) watch_id;
				g_hash_table_remove (_tmp1_, &_tmp2_);
			}
		}
	}
}

static void
wayland_idle_monitor_provider_real_initialize_data_free (gpointer _data)
{
	WaylandIdleMonitorProviderInitializeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (WaylandIdleMonitorProviderInitializeData, _data_);
}

static void
wayland_idle_monitor_provider_real_initialize (FtProvider* base,
                                               GCancellable* cancellable,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	WaylandIdleMonitorProvider * self;
	WaylandIdleMonitorProviderInitializeData* _data_;
	WaylandIdleMonitorProvider* _tmp0_;
	GCancellable* _tmp1_;
	self = (WaylandIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (WaylandIdleMonitorProviderInitializeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, wayland_idle_monitor_provider_real_initialize_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	wayland_idle_monitor_provider_real_initialize_co (_data_);
}

static void
wayland_idle_monitor_provider_initialize_finish (FtProvider* base,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	WaylandIdleMonitorProviderInitializeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
wayland_idle_monitor_provider_real_initialize_co (WaylandIdleMonitorProviderInitializeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gdk_display_get_default ();
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->display = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->display;
	if (_data_->_tmp2_ == NULL) {
		g_debug ("idle-monitor-provider.vala:345: Wayland idle monitor: no default Gdk d" \
"isplay");
		_g_object_unref0 (_data_->display);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	wayland_idle_monitor_provider_update_available (_data_->self);
	_g_object_unref0 (_data_->display);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
wayland_idle_monitor_provider_real_uninitialize_data_free (gpointer _data)
{
	WaylandIdleMonitorProviderUninitializeData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (WaylandIdleMonitorProviderUninitializeData, _data_);
}

static void
wayland_idle_monitor_provider_real_uninitialize (FtProvider* base,
                                                 GAsyncReadyCallback _callback_,
                                                 gpointer _user_data_)
{
	WaylandIdleMonitorProvider * self;
	WaylandIdleMonitorProviderUninitializeData* _data_;
	WaylandIdleMonitorProvider* _tmp0_;
	self = (WaylandIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (WaylandIdleMonitorProviderUninitializeData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, wayland_idle_monitor_provider_real_uninitialize_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	wayland_idle_monitor_provider_real_uninitialize_co (_data_);
}

static void
wayland_idle_monitor_provider_uninitialize_finish (FtProvider* base,
                                                   GAsyncResult* _res_,
                                                   GError** error)
{
	WaylandIdleMonitorProviderUninitializeData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
wayland_idle_monitor_provider_real_uninitialize_co (WaylandIdleMonitorProviderUninitializeData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	ft_provider_set_available ((FtProvider*) _data_->self, FALSE);
	_ft_wayland_idle_monitor_unref0 (_data_->self->priv->idle_monitor);
	_data_->self->priv->idle_monitor = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
wayland_idle_monitor_provider_real_enable_data_free (gpointer _data)
{
	WaylandIdleMonitorProviderEnableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (WaylandIdleMonitorProviderEnableData, _data_);
}

static void
wayland_idle_monitor_provider_real_enable (FtProvider* base,
                                           GCancellable* cancellable,
                                           GAsyncReadyCallback _callback_,
                                           gpointer _user_data_)
{
	WaylandIdleMonitorProvider * self;
	WaylandIdleMonitorProviderEnableData* _data_;
	WaylandIdleMonitorProvider* _tmp0_;
	GCancellable* _tmp1_;
	self = (WaylandIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (WaylandIdleMonitorProviderEnableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, wayland_idle_monitor_provider_real_enable_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	wayland_idle_monitor_provider_real_enable_co (_data_);
}

static void
wayland_idle_monitor_provider_enable_finish (FtProvider* base,
                                             GAsyncResult* _res_,
                                             GError** error)
{
	WaylandIdleMonitorProviderEnableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
wayland_idle_monitor_provider_real_enable_co (WaylandIdleMonitorProviderEnableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->idle_monitor;
	_vala_assert (_data_->_tmp0_ != NULL, "this.idle_monitor != null");
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
wayland_idle_monitor_provider_real_disable_data_free (gpointer _data)
{
	WaylandIdleMonitorProviderDisableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (WaylandIdleMonitorProviderDisableData, _data_);
}

static void
wayland_idle_monitor_provider_real_disable (FtProvider* base,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	WaylandIdleMonitorProvider * self;
	WaylandIdleMonitorProviderDisableData* _data_;
	WaylandIdleMonitorProvider* _tmp0_;
	self = (WaylandIdleMonitorProvider*) base;
	_data_ = g_slice_new0 (WaylandIdleMonitorProviderDisableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, wayland_idle_monitor_provider_real_disable_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	wayland_idle_monitor_provider_real_disable_co (_data_);
}

static void
wayland_idle_monitor_provider_disable_finish (FtProvider* base,
                                              GAsyncResult* _res_,
                                              GError** error)
{
	WaylandIdleMonitorProviderDisableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		WaylandIdleMonitorProvider* self;
		self = _data1_->self;
		_data1_->ids = (g_free (_data1_->ids), NULL);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
_vala_array_add1 (guint32* * array,
                  gint* length,
                  gint* size,
                  guint32 value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (guint32, *array, *size);
	}
	(*array)[(*length)++] = value;
}

static void
__lambda4_ (Block1Data* _data1_,
            gint64* id,
            WaylandIdleMonitorProviderWatch* watch)
{
	WaylandIdleMonitorProvider* self;
	self = _data1_->self;
	g_return_if_fail (watch != NULL);
	_vala_array_add1 (&_data1_->ids, &_data1_->ids_length1, &_data1_->_ids_size_, watch->id);
}

static void
___lambda4__gh_func (gconstpointer key,
                     gconstpointer value,
                     gpointer self)
{
	__lambda4_ (self, (gint64*) key, (WaylandIdleMonitorProviderWatch*) value);
}

static gboolean
wayland_idle_monitor_provider_real_disable_co (WaylandIdleMonitorProviderDisableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_data1_->self = g_object_ref (_data_->self);
	_data_->_data1_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->self->priv->idle_monitor;
	if (_data_->_tmp0_ == NULL) {
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = g_new0 (guint32, 0);
	_data_->_data1_->ids = _data_->_tmp1_;
	_data_->_data1_->ids_length1 = 0;
	_data_->_data1_->_ids_size_ = _data_->_data1_->ids_length1;
	_data_->_tmp2_ = _data_->self->priv->watches;
	g_hash_table_foreach (_data_->_tmp2_, ___lambda4__gh_func, _data_->_data1_);
	{
		_data_->index = 0;
		{
			_data_->_tmp3_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp3_) {
					_data_->_tmp4_ = _data_->index;
					_data_->index = _data_->_tmp4_ + 1;
				}
				_data_->_tmp3_ = FALSE;
				_data_->_tmp5_ = _data_->_data1_->ids;
				_data_->_tmp5__length1 = _data_->_data1_->ids_length1;
				if (!(_data_->index < _data_->_tmp5__length1)) {
					break;
				}
				_data_->_tmp6_ = _data_->_data1_->ids;
				_data_->_tmp6__length1 = _data_->_data1_->ids_length1;
				_data_->_tmp7_ = _data_->_tmp6_[_data_->index];
				ft_idle_monitor_provider_remove_idle_watch ((FtIdleMonitorProvider*) _data_->self, _data_->_tmp7_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
					block1_data_unref (_data_->_data1_);
					_data_->_data1_ = NULL;
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
			}
		}
	}
	wayland_idle_monitor_provider_remove_active_watch_internal (_data_->self, &_data_->_inner_error0_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = NULL;
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
wayland_idle_monitor_provider_real_dispose (GObject* base)
{
	WaylandIdleMonitorProvider * self;
	self = (WaylandIdleMonitorProvider*) base;
	_g_hash_table_unref0 (self->priv->watches);
	self->priv->watches = NULL;
	_ft_wayland_idle_monitor_unref0 (self->priv->idle_monitor);
	self->priv->idle_monitor = NULL;
	G_OBJECT_CLASS (wayland_idle_monitor_provider_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_PROVIDER, FtProvider));
}

WaylandIdleMonitorProvider*
wayland_idle_monitor_provider_construct (GType object_type)
{
	WaylandIdleMonitorProvider * self = NULL;
	self = (WaylandIdleMonitorProvider*) ft_provider_construct (object_type);
	return self;
}

WaylandIdleMonitorProvider*
wayland_idle_monitor_provider_new (void)
{
	return wayland_idle_monitor_provider_construct (WAYLAND_TYPE_IDLE_MONITOR_PROVIDER);
}

static gboolean
wayland_idle_monitor_provider_real_get_can_ignore_inhibitors (FtIdleMonitorProvider* base)
{
	gboolean result;
	WaylandIdleMonitorProvider* self;
	self = (WaylandIdleMonitorProvider*) base;
	result = self->priv->supports_input_idle;
	return result;
}

static WaylandIdleMonitorProviderWatch*
wayland_idle_monitor_provider_watch_new (void)
{
	WaylandIdleMonitorProviderWatch* self;
	self = g_slice_new0 (WaylandIdleMonitorProviderWatch);
	wayland_idle_monitor_provider_watch_instance_init (self);
	return self;
}

static void
wayland_idle_monitor_provider_watch_instance_init (WaylandIdleMonitorProviderWatch * self)
{
	self->id = (guint32) 0;
	self->absolute_timeout = (gint64) 0;
	self->relative_timeout = (gint64) 0;
	self->reference_time = FT_TIMESTAMP_UNDEFINED;
	self->ignore_inhibitors = FALSE;
	self->has_active_watch = FALSE;
	self->invalid = FALSE;
}

static void
wayland_idle_monitor_provider_watch_free (WaylandIdleMonitorProviderWatch * self)
{
	g_slice_free (WaylandIdleMonitorProviderWatch, self);
}

static void
_g_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_free (var), NULL));
}

static void
_wayland_idle_monitor_provider_watch_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (wayland_idle_monitor_provider_watch_free (var), NULL));
}

static GObject *
wayland_idle_monitor_provider_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WaylandIdleMonitorProvider * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	parent_class = G_OBJECT_CLASS (wayland_idle_monitor_provider_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WAYLAND_TYPE_IDLE_MONITOR_PROVIDER, WaylandIdleMonitorProvider);
	_tmp0_ = g_int64_hash;
	_tmp1_ = g_int64_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _wayland_idle_monitor_provider_watch_free0_);
	_g_hash_table_unref0 (self->priv->watches);
	self->priv->watches = _tmp2_;
	return obj;
}

static void
wayland_idle_monitor_provider_class_init (WaylandIdleMonitorProviderClass * klass,
                                          gpointer klass_data)
{
	wayland_idle_monitor_provider_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WaylandIdleMonitorProvider_private_offset);
	((FtProviderClass *) klass)->initialize = (void (*) (FtProvider*, GCancellable*, GAsyncReadyCallback, gpointer)) wayland_idle_monitor_provider_real_initialize;
	((FtProviderClass *) klass)->initialize_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) wayland_idle_monitor_provider_initialize_finish;
	((FtProviderClass *) klass)->uninitialize = (void (*) (FtProvider*, GAsyncReadyCallback, gpointer)) wayland_idle_monitor_provider_real_uninitialize;
	((FtProviderClass *) klass)->uninitialize_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) wayland_idle_monitor_provider_uninitialize_finish;
	((FtProviderClass *) klass)->enable = (void (*) (FtProvider*, GCancellable*, GAsyncReadyCallback, gpointer)) wayland_idle_monitor_provider_real_enable;
	((FtProviderClass *) klass)->enable_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) wayland_idle_monitor_provider_enable_finish;
	((FtProviderClass *) klass)->disable = (void (*) (FtProvider*, GAsyncReadyCallback, gpointer)) wayland_idle_monitor_provider_real_disable;
	((FtProviderClass *) klass)->disable_finish = (void (*) (FtProvider*, GAsyncResult*, GError**)) wayland_idle_monitor_provider_disable_finish;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) wayland_idle_monitor_provider_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_wayland_idle_monitor_provider_get_property;
	G_OBJECT_CLASS (klass)->constructor = wayland_idle_monitor_provider_constructor;
	G_OBJECT_CLASS (klass)->finalize = wayland_idle_monitor_provider_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WAYLAND_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY, wayland_idle_monitor_provider_properties[WAYLAND_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY] = g_param_spec_boolean ("can-ignore-inhibitors", "can-ignore-inhibitors", "can-ignore-inhibitors", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
wayland_idle_monitor_provider_ft_idle_monitor_provider_interface_init (FtIdleMonitorProviderIface * iface,
                                                                       gpointer iface_data)
{
	wayland_idle_monitor_provider_ft_idle_monitor_provider_parent_iface = g_type_interface_peek_parent (iface);
	iface->add_idle_watch = (guint32 (*) (FtIdleMonitorProvider*, gint64, gboolean, gint64, GError**)) wayland_idle_monitor_provider_real_add_idle_watch;
	iface->remove_idle_watch = (void (*) (FtIdleMonitorProvider*, guint32, GError**)) wayland_idle_monitor_provider_real_remove_idle_watch;
	iface->reset_idle_watch = (guint32 (*) (FtIdleMonitorProvider*, guint32, gint64, GError**)) wayland_idle_monitor_provider_real_reset_idle_watch;
	iface->add_active_watch = (void (*) (FtIdleMonitorProvider*, GError**)) wayland_idle_monitor_provider_real_add_active_watch;
	iface->remove_active_watch = (void (*) (FtIdleMonitorProvider*, GError**)) wayland_idle_monitor_provider_real_remove_active_watch;
	iface->get_can_ignore_inhibitors = wayland_idle_monitor_provider_real_get_can_ignore_inhibitors;
}

static void
wayland_idle_monitor_provider_instance_init (WaylandIdleMonitorProvider * self,
                                             gpointer klass)
{
	self->priv = wayland_idle_monitor_provider_get_instance_private (self);
	self->priv->supports_input_idle = FALSE;
	self->priv->idle_monitor = NULL;
	self->priv->watches = NULL;
	self->priv->active_watch_id = (guint32) 0;
	self->priv->active_watch_use_count = (guint) 0;
}

static void
wayland_idle_monitor_provider_finalize (GObject * obj)
{
	WaylandIdleMonitorProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WAYLAND_TYPE_IDLE_MONITOR_PROVIDER, WaylandIdleMonitorProvider);
	_ft_wayland_idle_monitor_unref0 (self->priv->idle_monitor);
	_g_hash_table_unref0 (self->priv->watches);
	G_OBJECT_CLASS (wayland_idle_monitor_provider_parent_class)->finalize (obj);
}

GType
wayland_idle_monitor_provider_get_type (void)
{
	return wayland_idle_monitor_provider_type_id;
}

GType
wayland_idle_monitor_provider_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (WaylandIdleMonitorProviderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wayland_idle_monitor_provider_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WaylandIdleMonitorProvider), 0, (GInstanceInitFunc) wayland_idle_monitor_provider_instance_init, NULL };
	static const GInterfaceInfo ft_idle_monitor_provider_info = { (GInterfaceInitFunc) wayland_idle_monitor_provider_ft_idle_monitor_provider_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	wayland_idle_monitor_provider_type_id = g_type_module_register_type (module, FT_TYPE_PROVIDER, "WaylandIdleMonitorProvider", &g_define_type_info, 0);
	g_type_module_add_interface (module, wayland_idle_monitor_provider_type_id, FT_TYPE_IDLE_MONITOR_PROVIDER, &ft_idle_monitor_provider_info);
	WaylandIdleMonitorProvider_private_offset = sizeof (WaylandIdleMonitorProviderPrivate);
	return wayland_idle_monitor_provider_type_id;
}

static void
_vala_wayland_idle_monitor_provider_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	WaylandIdleMonitorProvider * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WAYLAND_TYPE_IDLE_MONITOR_PROVIDER, WaylandIdleMonitorProvider);
	switch (property_id) {
		case WAYLAND_IDLE_MONITOR_PROVIDER_CAN_IGNORE_INHIBITORS_PROPERTY:
		g_value_set_boolean (value, ft_idle_monitor_provider_get_can_ignore_inhibitors ((FtIdleMonitorProvider*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

