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

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

#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.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

enum  {
	FT_GLOBAL_SHORTCUTS_PROVIDER_SHORTCUT_ACTIVATED_SIGNAL,
	FT_GLOBAL_SHORTCUTS_PROVIDER_ACCELERATOR_CHANGED_SIGNAL,
	FT_GLOBAL_SHORTCUTS_PROVIDER_NUM_SIGNALS
};
static guint ft_global_shortcuts_provider_signals[FT_GLOBAL_SHORTCUTS_PROVIDER_NUM_SIGNALS] = {0};
typedef struct _FtKeyboardManagerShortcut FtKeyboardManagerShortcut;
enum  {
	FT_KEYBOARD_MANAGER_0_PROPERTY,
	FT_KEYBOARD_MANAGER_GLOBAL_SHORTCUTS_SUPPORTED_PROPERTY,
	FT_KEYBOARD_MANAGER_NUM_PROPERTIES
};
static GParamSpec* ft_keyboard_manager_properties[FT_KEYBOARD_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _ft_keyboard_manager_shortcut_free0(var) ((var == NULL) ? NULL : (var = (ft_keyboard_manager_shortcut_free (var), NULL)))
typedef struct _Block21Data Block21Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block22Data Block22Data;
enum  {
	FT_KEYBOARD_MANAGER_SHORTCUT_ACTIVATED_SIGNAL,
	FT_KEYBOARD_MANAGER_SHORTCUT_CHANGED_SIGNAL,
	FT_KEYBOARD_MANAGER_NUM_SIGNALS
};
static guint ft_keyboard_manager_signals[FT_KEYBOARD_MANAGER_NUM_SIGNALS] = {0};
#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 _FtKeyboardManagerPrivate {
	FtProviderSet* providers;
	FtGlobalShortcutsProvider* provider;
	GHashTable* shortcuts;
	gboolean inhibited;
	gboolean _global_shortcuts_supported;
};

struct _FtKeyboardManagerShortcut {
	gchar* name;
	gchar* description;
	gchar* default_accelerator;
};

struct _Block21Data {
	int _ref_count_;
	FtKeyboardManager* self;
	FtGlobalShortcutsProvider* provider;
};

struct _Block22Data {
	int _ref_count_;
	FtKeyboardManager* self;
	FtForeachAcceleratorFunc func;
	gpointer func_target;
};

static gint FtKeyboardManager_private_offset;
static gpointer ft_keyboard_manager_parent_class = NULL;

static GType ft_global_shortcuts_provider_get_type_once (void);
static void ft_keyboard_manager_shortcut_free (FtKeyboardManagerShortcut * self);
static void ft_keyboard_manager_populate_provider (FtKeyboardManager* self);
static void __lambda86_ (FtKeyboardManager* self,
                  const gchar* shortcut_name,
                  FtKeyboardManagerShortcut* shortcut);
static void ___lambda86__gh_func (gconstpointer key,
                           gconstpointer value,
                           gpointer self);
static void ft_keyboard_manager_on_provider_notify_available (FtKeyboardManager* self,
                                                       GObject* object,
                                                       GParamSpec* pspec);
static void ft_keyboard_manager_on_shortcut_activated (FtKeyboardManager* self,
                                                const gchar* shortcut_name);
static void ft_keyboard_manager_on_accelerator_changed (FtKeyboardManager* self,
                                                 const gchar* shortcut_name);
static void ft_keyboard_manager_on_provider_selected (FtKeyboardManager* self,
                                               FtGlobalShortcutsProvider* provider);
static void _ft_keyboard_manager_on_provider_notify_available_g_object_notify (GObject* _sender,
                                                                        GParamSpec* pspec,
                                                                        gpointer self);
static void _ft_keyboard_manager_on_shortcut_activated_ft_global_shortcuts_provider_shortcut_activated (FtGlobalShortcutsProvider* _sender,
                                                                                                 const gchar* name,
                                                                                                 gpointer self);
static void _ft_keyboard_manager_on_accelerator_changed_ft_global_shortcuts_provider_accelerator_changed (FtGlobalShortcutsProvider* _sender,
                                                                                                   const gchar* name,
                                                                                                   gpointer self);
static void ft_keyboard_manager_on_provider_unselected (FtKeyboardManager* self,
                                                 FtGlobalShortcutsProvider* provider);
static void ft_keyboard_manager_on_provider_enabled (FtKeyboardManager* self,
                                              FtGlobalShortcutsProvider* provider);
static void ft_keyboard_manager_on_provider_disabled (FtKeyboardManager* self,
                                               FtGlobalShortcutsProvider* provider);
static FtKeyboardManagerShortcut* ft_keyboard_manager_shortcut_new (const gchar* name,
                                                             const gchar* description,
                                                             const gchar* default_accelerator);
static Block21Data* block21_data_ref (Block21Data* _data21_);
static void block21_data_unref (void * _userdata_);
static void __lambda87_ (Block21Data* _data21_,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda87__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static Block22Data* block22_data_ref (Block22Data* _data22_);
static void block22_data_unref (void * _userdata_);
static void __lambda88_ (Block22Data* _data22_,
                  const gchar* shortcut_name,
                  FtKeyboardManagerShortcut* shortcut);
static void ___lambda88__gh_func (gconstpointer key,
                           gconstpointer value,
                           gpointer self);
static void ft_keyboard_manager_real_dispose (GObject* base);
static void ft_keyboard_manager_shortcut_instance_init (FtKeyboardManagerShortcut * self);
static GObject * ft_keyboard_manager_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void _g_free0_ (gpointer var);
static void _ft_keyboard_manager_shortcut_free0_ (gpointer var);
static void _ft_keyboard_manager_on_provider_selected_ft_provider_set_provider_selected (FtProviderSet* _sender,
                                                                                  gconstpointer provider,
                                                                                  gpointer self);
static void _ft_keyboard_manager_on_provider_unselected_ft_provider_set_provider_unselected (FtProviderSet* _sender,
                                                                                      gconstpointer provider,
                                                                                      gpointer self);
static void _ft_keyboard_manager_on_provider_enabled_ft_provider_set_provider_enabled (FtProviderSet* _sender,
                                                                                gconstpointer provider,
                                                                                gpointer self);
static void _ft_keyboard_manager_on_provider_disabled_ft_provider_set_provider_disabled (FtProviderSet* _sender,
                                                                                  gconstpointer provider,
                                                                                  gpointer self);
static void ft_keyboard_manager_finalize (GObject * obj);
static GType ft_keyboard_manager_get_type_once (void);
static void _vala_ft_keyboard_manager_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

void
ft_global_shortcuts_provider_add_shortcut (FtGlobalShortcutsProvider* self,
                                           const gchar* name,
                                           const gchar* description,
                                           const gchar* default_accelerator)
{
	FtGlobalShortcutsProviderIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = FT_GLOBAL_SHORTCUTS_PROVIDER_GET_INTERFACE (self);
	if (_iface_->add_shortcut) {
		_iface_->add_shortcut (self, name, description, default_accelerator);
	}
}

gchar*
ft_global_shortcuts_provider_lookup_accelerator (FtGlobalShortcutsProvider* self,
                                                 const gchar* name)
{
	FtGlobalShortcutsProviderIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = FT_GLOBAL_SHORTCUTS_PROVIDER_GET_INTERFACE (self);
	if (_iface_->lookup_accelerator) {
		return _iface_->lookup_accelerator (self, name);
	}
	return NULL;
}

void
ft_global_shortcuts_provider_open_edit_dialog (FtGlobalShortcutsProvider* self,
                                               const gchar* window_identifier,
                                               GAsyncReadyCallback _callback_,
                                               gpointer _user_data_)
{
	FtGlobalShortcutsProviderIface* _iface_;
	_iface_ = FT_GLOBAL_SHORTCUTS_PROVIDER_GET_INTERFACE (self);
	if (_iface_->open_edit_dialog) {
		_iface_->open_edit_dialog (self, window_identifier, _callback_, _user_data_);
	}
}

void
ft_global_shortcuts_provider_open_edit_dialog_finish (FtGlobalShortcutsProvider* self,
                                                      GAsyncResult* _res_,
                                                      GError** error)
{
	FtGlobalShortcutsProviderIface* _iface_;
	_iface_ = FT_GLOBAL_SHORTCUTS_PROVIDER_GET_INTERFACE (self);
	if (_iface_->open_edit_dialog_finish) {
		_iface_->open_edit_dialog_finish (self, _res_, error);
	}
}

static void
ft_global_shortcuts_provider_default_init (FtGlobalShortcutsProviderIface * iface,
                                           gpointer iface_data)
{
	ft_global_shortcuts_provider_signals[FT_GLOBAL_SHORTCUTS_PROVIDER_SHORTCUT_ACTIVATED_SIGNAL] = g_signal_new ("shortcut-activated", FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
	ft_global_shortcuts_provider_signals[FT_GLOBAL_SHORTCUTS_PROVIDER_ACCELERATOR_CHANGED_SIGNAL] = g_signal_new ("accelerator-changed", FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static GType
ft_global_shortcuts_provider_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtGlobalShortcutsProviderIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_global_shortcuts_provider_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType ft_global_shortcuts_provider_type_id;
	ft_global_shortcuts_provider_type_id = g_type_register_static (G_TYPE_INTERFACE, "FtGlobalShortcutsProvider", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (ft_global_shortcuts_provider_type_id, FT_TYPE_PROVIDER);
	return ft_global_shortcuts_provider_type_id;
}

GType
ft_global_shortcuts_provider_get_type (void)
{
	static volatile gsize ft_global_shortcuts_provider_type_id__once = 0;
	if (g_once_init_enter (&ft_global_shortcuts_provider_type_id__once)) {
		GType ft_global_shortcuts_provider_type_id;
		ft_global_shortcuts_provider_type_id = ft_global_shortcuts_provider_get_type_once ();
		g_once_init_leave (&ft_global_shortcuts_provider_type_id__once, ft_global_shortcuts_provider_type_id);
	}
	return ft_global_shortcuts_provider_type_id__once;
}

static inline gpointer
ft_keyboard_manager_get_instance_private (FtKeyboardManager* self)
{
	return G_STRUCT_MEMBER_P (self, FtKeyboardManager_private_offset);
}

static void
__lambda86_ (FtKeyboardManager* self,
             const gchar* shortcut_name,
             FtKeyboardManagerShortcut* shortcut)
{
	FtGlobalShortcutsProvider* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	g_return_if_fail (shortcut_name != NULL);
	g_return_if_fail (shortcut != NULL);
	_tmp0_ = self->priv->provider;
	_tmp1_ = shortcut->name;
	_tmp2_ = shortcut->description;
	_tmp3_ = shortcut->default_accelerator;
	ft_global_shortcuts_provider_add_shortcut (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
}

static void
___lambda86__gh_func (gconstpointer key,
                      gconstpointer value,
                      gpointer self)
{
	__lambda86_ ((FtKeyboardManager*) self, (const gchar*) key, (FtKeyboardManagerShortcut*) value);
}

static void
ft_keyboard_manager_populate_provider (FtKeyboardManager* self)
{
	FtGlobalShortcutsProvider* _tmp0_;
	GHashTable* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->provider;
	_vala_return_if_fail (_tmp0_ != NULL, "this.provider != null");
	_tmp1_ = self->priv->shortcuts;
	g_hash_table_foreach (_tmp1_, ___lambda86__gh_func, self);
}

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

static void
ft_keyboard_manager_on_provider_notify_available (FtKeyboardManager* self,
                                                  GObject* object,
                                                  GParamSpec* pspec)
{
	FtGlobalShortcutsProvider* provider = NULL;
	FtGlobalShortcutsProvider* _tmp0_;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, FtGlobalShortcutsProvider));
	provider = _tmp0_;
	if (!self->priv->_global_shortcuts_supported) {
		FtGlobalShortcutsProvider* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = provider;
		_tmp3_ = ft_provider_get_available ((FtProvider*) _tmp2_);
		_tmp4_ = _tmp3_;
		_tmp1_ = _tmp4_;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		self->priv->_global_shortcuts_supported = TRUE;
		g_object_notify ((GObject*) self, "global-shortcuts-supported");
	}
	_g_object_unref0 (provider);
}

static void
ft_keyboard_manager_on_shortcut_activated (FtKeyboardManager* self,
                                           const gchar* shortcut_name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (shortcut_name != NULL);
	if (!self->priv->inhibited) {
		g_signal_emit (self, ft_keyboard_manager_signals[FT_KEYBOARD_MANAGER_SHORTCUT_ACTIVATED_SIGNAL], 0, shortcut_name);
	}
}

static void
ft_keyboard_manager_on_accelerator_changed (FtKeyboardManager* self,
                                            const gchar* shortcut_name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (shortcut_name != NULL);
	g_signal_emit (self, ft_keyboard_manager_signals[FT_KEYBOARD_MANAGER_SHORTCUT_CHANGED_SIGNAL], 0, shortcut_name);
}

static void
_ft_keyboard_manager_on_provider_notify_available_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self)
{
	ft_keyboard_manager_on_provider_notify_available ((FtKeyboardManager*) self, _sender, pspec);
}

static void
_ft_keyboard_manager_on_shortcut_activated_ft_global_shortcuts_provider_shortcut_activated (FtGlobalShortcutsProvider* _sender,
                                                                                            const gchar* name,
                                                                                            gpointer self)
{
	ft_keyboard_manager_on_shortcut_activated ((FtKeyboardManager*) self, name);
}

static void
_ft_keyboard_manager_on_accelerator_changed_ft_global_shortcuts_provider_accelerator_changed (FtGlobalShortcutsProvider* _sender,
                                                                                              const gchar* name,
                                                                                              gpointer self)
{
	ft_keyboard_manager_on_accelerator_changed ((FtKeyboardManager*) self, name);
}

static void
ft_keyboard_manager_on_provider_selected (FtKeyboardManager* self,
                                          FtGlobalShortcutsProvider* provider)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (provider != NULL);
	g_signal_connect_object ((GObject*) provider, "notify::available", (GCallback) _ft_keyboard_manager_on_provider_notify_available_g_object_notify, self, 0);
	g_signal_connect_object (provider, "shortcut-activated", (GCallback) _ft_keyboard_manager_on_shortcut_activated_ft_global_shortcuts_provider_shortcut_activated, self, 0);
	g_signal_connect_object (provider, "accelerator-changed", (GCallback) _ft_keyboard_manager_on_accelerator_changed_ft_global_shortcuts_provider_accelerator_changed, self, 0);
	if (!self->priv->_global_shortcuts_supported) {
		gboolean _tmp1_;
		gboolean _tmp2_;
		_tmp1_ = ft_provider_get_available ((FtProvider*) provider);
		_tmp2_ = _tmp1_;
		_tmp0_ = _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		self->priv->_global_shortcuts_supported = TRUE;
		g_object_notify ((GObject*) self, "global-shortcuts-supported");
	}
}

static void
ft_keyboard_manager_on_provider_unselected (FtKeyboardManager* self,
                                            FtGlobalShortcutsProvider* provider)
{
	guint _tmp0_;
	GQuark _tmp1_;
	guint _tmp2_;
	guint _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (provider != NULL);
	g_signal_parse_name ("notify::available", G_TYPE_OBJECT, &_tmp0_, &_tmp1_, TRUE);
	g_signal_handlers_disconnect_matched ((GObject*) provider, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, _tmp1_, NULL, (GCallback) _ft_keyboard_manager_on_provider_notify_available_g_object_notify, self);
	g_signal_parse_name ("shortcut-activated", FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, &_tmp2_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (provider, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_keyboard_manager_on_shortcut_activated_ft_global_shortcuts_provider_shortcut_activated, self);
	g_signal_parse_name ("accelerator-changed", FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, &_tmp3_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (provider, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _ft_keyboard_manager_on_accelerator_changed_ft_global_shortcuts_provider_accelerator_changed, self);
	if (self->priv->_global_shortcuts_supported) {
		self->priv->_global_shortcuts_supported = FALSE;
		g_object_notify ((GObject*) self, "global-shortcuts-supported");
	}
}

static void
ft_keyboard_manager_on_provider_enabled (FtKeyboardManager* self,
                                         FtGlobalShortcutsProvider* provider)
{
	FtGlobalShortcutsProvider* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (provider != NULL);
	self->priv->provider = provider;
	_tmp0_ = self->priv->provider;
	if (_tmp0_ != NULL) {
		ft_keyboard_manager_populate_provider (self);
	}
}

static void
ft_keyboard_manager_on_provider_disabled (FtKeyboardManager* self,
                                          FtGlobalShortcutsProvider* provider)
{
	FtGlobalShortcutsProvider* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (provider != NULL);
	_tmp0_ = self->priv->provider;
	if (_tmp0_ == provider) {
		self->priv->provider = NULL;
	}
}

void
ft_keyboard_manager_add_shortcut (FtKeyboardManager* self,
                                  const gchar* name,
                                  const gchar* description,
                                  const gchar* default_accelerator)
{
	FtKeyboardManagerShortcut* shortcut = NULL;
	FtKeyboardManagerShortcut* _tmp0_;
	GHashTable* _tmp1_;
	gchar* _tmp2_;
	FtKeyboardManagerShortcut* _tmp3_;
	gboolean _tmp4_ = FALSE;
	FtGlobalShortcutsProvider* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (description != NULL);
	g_return_if_fail (default_accelerator != NULL);
	_tmp0_ = ft_keyboard_manager_shortcut_new (name, description, default_accelerator);
	shortcut = _tmp0_;
	_tmp1_ = self->priv->shortcuts;
	_tmp2_ = g_strdup (name);
	_tmp3_ = shortcut;
	shortcut = NULL;
	g_hash_table_insert (_tmp1_, _tmp2_, _tmp3_);
	_tmp5_ = self->priv->provider;
	if (_tmp5_ != NULL) {
		FtGlobalShortcutsProvider* _tmp6_;
		gboolean _tmp7_;
		gboolean _tmp8_;
		_tmp6_ = self->priv->provider;
		_tmp7_ = ft_provider_get_enabled ((FtProvider*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp4_ = _tmp8_;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		FtGlobalShortcutsProvider* _tmp9_;
		_tmp9_ = self->priv->provider;
		ft_global_shortcuts_provider_add_shortcut (_tmp9_, name, description, default_accelerator);
	}
	_ft_keyboard_manager_shortcut_free0 (shortcut);
}

/**
         * Opens a system dialog for editing shortcuts.
         */
static Block21Data*
block21_data_ref (Block21Data* _data21_)
{
	g_atomic_int_inc (&_data21_->_ref_count_);
	return _data21_;
}

static void
block21_data_unref (void * _userdata_)
{
	Block21Data* _data21_;
	_data21_ = (Block21Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data21_->_ref_count_)) {
		FtKeyboardManager* self;
		self = _data21_->self;
		_g_object_unref0 (_data21_->provider);
		_g_object_unref0 (self);
		g_slice_free (Block21Data, _data21_);
	}
}

static void
__lambda87_ (Block21Data* _data21_,
             GObject* obj,
             GAsyncResult* res)
{
	FtKeyboardManager* self;
	GError* _inner_error0_ = NULL;
	self = _data21_->self;
	g_return_if_fail (res != NULL);
	{
		FtGlobalShortcutsProvider* _tmp0_;
		_tmp0_ = _data21_->provider;
		ft_global_shortcuts_provider_open_edit_dialog_finish (_tmp0_, res, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp1_;
		const gchar* _tmp2_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp1_ = _error_;
		_tmp2_ = _tmp1_->message;
		g_warning ("keyboard-manager.vala:197: Error opening shortcuts dialog: %s", _tmp2_);
		_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;
	}
}

static void
___lambda87__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda87_ (self, source_object, res);
	block21_data_unref (self);
}

void
ft_keyboard_manager_open_edit_dialog (FtKeyboardManager* self,
                                      const gchar* window_identifier)
{
	Block21Data* _data21_;
	FtGlobalShortcutsProvider* _tmp0_;
	FtGlobalShortcutsProvider* _tmp1_;
	FtGlobalShortcutsProvider* _tmp2_;
	FtGlobalShortcutsProvider* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window_identifier != NULL);
	_data21_ = g_slice_new0 (Block21Data);
	_data21_->_ref_count_ = 1;
	_data21_->self = g_object_ref (self);
	_tmp0_ = self->priv->provider;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data21_->provider = _tmp1_;
	_tmp2_ = _data21_->provider;
	if (_tmp2_ == NULL) {
		block21_data_unref (_data21_);
		_data21_ = NULL;
		return;
	}
	_tmp3_ = _data21_->provider;
	ft_global_shortcuts_provider_open_edit_dialog (_tmp3_, window_identifier, ___lambda87__gasync_ready_callback, block21_data_ref (_data21_));
	block21_data_unref (_data21_);
	_data21_ = NULL;
}

void
ft_keyboard_manager_inhibit (FtKeyboardManager* self)
{
	g_return_if_fail (self != NULL);
	self->priv->inhibited = TRUE;
}

void
ft_keyboard_manager_uninhibit (FtKeyboardManager* self)
{
	g_return_if_fail (self != NULL);
	self->priv->inhibited = FALSE;
}

gchar*
ft_keyboard_manager_lookup_accelerator (FtKeyboardManager* self,
                                        const gchar* shortcut_name)
{
	gchar* _tmp0_ = NULL;
	FtGlobalShortcutsProvider* _tmp1_;
	gchar* _tmp5_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (shortcut_name != NULL, NULL);
	_tmp1_ = self->priv->provider;
	if (_tmp1_ != NULL) {
		FtGlobalShortcutsProvider* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = self->priv->provider;
		_tmp3_ = ft_global_shortcuts_provider_lookup_accelerator (_tmp2_, shortcut_name);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp5_;
	_g_free0 (_tmp0_);
	return result;
}

static Block22Data*
block22_data_ref (Block22Data* _data22_)
{
	g_atomic_int_inc (&_data22_->_ref_count_);
	return _data22_;
}

static void
block22_data_unref (void * _userdata_)
{
	Block22Data* _data22_;
	_data22_ = (Block22Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data22_->_ref_count_)) {
		FtKeyboardManager* self;
		self = _data22_->self;
		_g_object_unref0 (self);
		g_slice_free (Block22Data, _data22_);
	}
}

static void
__lambda88_ (Block22Data* _data22_,
             const gchar* shortcut_name,
             FtKeyboardManagerShortcut* shortcut)
{
	FtKeyboardManager* self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	self = _data22_->self;
	g_return_if_fail (shortcut_name != NULL);
	g_return_if_fail (shortcut != NULL);
	_tmp0_ = ft_keyboard_manager_lookup_accelerator (self, shortcut_name);
	_tmp1_ = _tmp0_;
	_data22_->func (shortcut_name, _tmp1_, _data22_->func_target);
	_g_free0 (_tmp1_);
}

static void
___lambda88__gh_func (gconstpointer key,
                      gconstpointer value,
                      gpointer self)
{
	__lambda88_ (self, (const gchar*) key, (FtKeyboardManagerShortcut*) value);
}

void
ft_keyboard_manager_foreach_accelerator (FtKeyboardManager* self,
                                         FtForeachAcceleratorFunc func,
                                         gpointer func_target)
{
	Block22Data* _data22_;
	GHashTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_data22_ = g_slice_new0 (Block22Data);
	_data22_->_ref_count_ = 1;
	_data22_->self = g_object_ref (self);
	_data22_->func = func;
	_data22_->func_target = func_target;
	_tmp0_ = self->priv->shortcuts;
	g_hash_table_foreach (_tmp0_, ___lambda88__gh_func, _data22_);
	block22_data_unref (_data22_);
	_data22_ = NULL;
}

static void
ft_keyboard_manager_real_dispose (GObject* base)
{
	FtKeyboardManager * self;
	self = (FtKeyboardManager*) base;
	_g_object_unref0 (self->priv->providers);
	self->priv->providers = NULL;
	self->priv->provider = NULL;
	G_OBJECT_CLASS (ft_keyboard_manager_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

FtKeyboardManager*
ft_keyboard_manager_construct (GType object_type)
{
	FtKeyboardManager * self = NULL;
	self = (FtKeyboardManager*) g_object_new (object_type, NULL);
	return self;
}

FtKeyboardManager*
ft_keyboard_manager_new (void)
{
	return ft_keyboard_manager_construct (FT_TYPE_KEYBOARD_MANAGER);
}

gboolean
ft_keyboard_manager_get_global_shortcuts_supported (FtKeyboardManager* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_global_shortcuts_supported;
	return result;
}

static FtKeyboardManagerShortcut*
ft_keyboard_manager_shortcut_new (const gchar* name,
                                  const gchar* description,
                                  const gchar* default_accelerator)
{
	FtKeyboardManagerShortcut* self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (description != NULL, NULL);
	g_return_val_if_fail (default_accelerator != NULL, NULL);
	self = g_slice_new0 (FtKeyboardManagerShortcut);
	ft_keyboard_manager_shortcut_instance_init (self);
	_tmp0_ = g_strdup (name);
	_g_free0 (self->name);
	self->name = _tmp0_;
	_tmp1_ = g_strdup (description);
	_g_free0 (self->description);
	self->description = _tmp1_;
	_tmp2_ = g_strdup (default_accelerator);
	_g_free0 (self->default_accelerator);
	self->default_accelerator = _tmp2_;
	return self;
}

static void
ft_keyboard_manager_shortcut_instance_init (FtKeyboardManagerShortcut * self)
{
}

static void
ft_keyboard_manager_shortcut_free (FtKeyboardManagerShortcut * self)
{
	_g_free0 (self->name);
	self->name = NULL;
	_g_free0 (self->description);
	self->description = NULL;
	_g_free0 (self->default_accelerator);
	self->default_accelerator = NULL;
	_g_free0 (self->name);
	_g_free0 (self->description);
	_g_free0 (self->default_accelerator);
	g_slice_free (FtKeyboardManagerShortcut, self);
}

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

static void
_ft_keyboard_manager_shortcut_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (ft_keyboard_manager_shortcut_free (var), NULL));
}

static void
_ft_keyboard_manager_on_provider_selected_ft_provider_set_provider_selected (FtProviderSet* _sender,
                                                                             gconstpointer provider,
                                                                             gpointer self)
{
	ft_keyboard_manager_on_provider_selected ((FtKeyboardManager*) self, (FtGlobalShortcutsProvider*) provider);
}

static void
_ft_keyboard_manager_on_provider_unselected_ft_provider_set_provider_unselected (FtProviderSet* _sender,
                                                                                 gconstpointer provider,
                                                                                 gpointer self)
{
	ft_keyboard_manager_on_provider_unselected ((FtKeyboardManager*) self, (FtGlobalShortcutsProvider*) provider);
}

static void
_ft_keyboard_manager_on_provider_enabled_ft_provider_set_provider_enabled (FtProviderSet* _sender,
                                                                           gconstpointer provider,
                                                                           gpointer self)
{
	ft_keyboard_manager_on_provider_enabled ((FtKeyboardManager*) self, (FtGlobalShortcutsProvider*) provider);
}

static void
_ft_keyboard_manager_on_provider_disabled_ft_provider_set_provider_disabled (FtProviderSet* _sender,
                                                                             gconstpointer provider,
                                                                             gpointer self)
{
	ft_keyboard_manager_on_provider_disabled ((FtKeyboardManager*) self, (FtGlobalShortcutsProvider*) provider);
}

static GObject *
ft_keyboard_manager_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	static GWeakRef FtKeyboardManager_singleton__ref;
	static GMutex FtKeyboardManager_singleton__lock;
	FtKeyboardManager * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	FtProviderSet* _tmp3_;
	FtProviderSet* _tmp4_;
	FtProviderSet* _tmp5_;
	FtProviderSet* _tmp6_;
	FtProviderSet* _tmp7_;
	FtProviderSet* _tmp8_;
	FtProviderSet* _tmp9_;
	g_mutex_lock (&FtKeyboardManager_singleton__lock);
	obj = g_weak_ref_get (&FtKeyboardManager_singleton__ref);
	if (obj != NULL) {
		g_mutex_unlock (&FtKeyboardManager_singleton__lock);
		return obj;
	}
	parent_class = G_OBJECT_CLASS (ft_keyboard_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_KEYBOARD_MANAGER, FtKeyboardManager);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _ft_keyboard_manager_shortcut_free0_);
	_g_hash_table_unref0 (self->priv->shortcuts);
	self->priv->shortcuts = _tmp2_;
	_tmp3_ = ft_provider_set_new (FT_TYPE_GLOBAL_SHORTCUTS_PROVIDER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, FT_SELECTION_MODE_SINGLE);
	_g_object_unref0 (self->priv->providers);
	self->priv->providers = _tmp3_;
	_tmp4_ = self->priv->providers;
	g_signal_connect_object (_tmp4_, "provider-selected", (GCallback) _ft_keyboard_manager_on_provider_selected_ft_provider_set_provider_selected, self, 0);
	_tmp5_ = self->priv->providers;
	g_signal_connect_object (_tmp5_, "provider-unselected", (GCallback) _ft_keyboard_manager_on_provider_unselected_ft_provider_set_provider_unselected, self, 0);
	_tmp6_ = self->priv->providers;
	g_signal_connect_object (_tmp6_, "provider-enabled", (GCallback) _ft_keyboard_manager_on_provider_enabled_ft_provider_set_provider_enabled, self, 0);
	_tmp7_ = self->priv->providers;
	g_signal_connect_object (_tmp7_, "provider-disabled", (GCallback) _ft_keyboard_manager_on_provider_disabled_ft_provider_set_provider_disabled, self, 0);
	_tmp8_ = self->priv->providers;
	ft_provider_set_discover (_tmp8_);
	_tmp9_ = self->priv->providers;
	ft_provider_set_enable (_tmp9_);
	g_weak_ref_set (&FtKeyboardManager_singleton__ref, obj);
	g_mutex_unlock (&FtKeyboardManager_singleton__lock);
	return obj;
}

static void
ft_keyboard_manager_class_init (FtKeyboardManagerClass * klass,
                                gpointer klass_data)
{
	ft_keyboard_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtKeyboardManager_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_keyboard_manager_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_keyboard_manager_get_property;
	G_OBJECT_CLASS (klass)->constructor = ft_keyboard_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_keyboard_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_KEYBOARD_MANAGER_GLOBAL_SHORTCUTS_SUPPORTED_PROPERTY, ft_keyboard_manager_properties[FT_KEYBOARD_MANAGER_GLOBAL_SHORTCUTS_SUPPORTED_PROPERTY] = g_param_spec_boolean ("global-shortcuts-supported", "global-shortcuts-supported", "global-shortcuts-supported", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	ft_keyboard_manager_signals[FT_KEYBOARD_MANAGER_SHORTCUT_ACTIVATED_SIGNAL] = g_signal_new ("shortcut-activated", FT_TYPE_KEYBOARD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
	ft_keyboard_manager_signals[FT_KEYBOARD_MANAGER_SHORTCUT_CHANGED_SIGNAL] = g_signal_new ("shortcut-changed", FT_TYPE_KEYBOARD_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
ft_keyboard_manager_instance_init (FtKeyboardManager * self,
                                   gpointer klass)
{
	self->priv = ft_keyboard_manager_get_instance_private (self);
	self->priv->provider = NULL;
	self->priv->shortcuts = NULL;
	self->priv->inhibited = FALSE;
	self->priv->_global_shortcuts_supported = FALSE;
}

static void
ft_keyboard_manager_finalize (GObject * obj)
{
	FtKeyboardManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_KEYBOARD_MANAGER, FtKeyboardManager);
	_g_object_unref0 (self->priv->providers);
	_g_hash_table_unref0 (self->priv->shortcuts);
	G_OBJECT_CLASS (ft_keyboard_manager_parent_class)->finalize (obj);
}

static GType
ft_keyboard_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtKeyboardManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_keyboard_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtKeyboardManager), 0, (GInstanceInitFunc) ft_keyboard_manager_instance_init, NULL };
	GType ft_keyboard_manager_type_id;
	ft_keyboard_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "FtKeyboardManager", &g_define_type_info, 0);
	FtKeyboardManager_private_offset = g_type_add_instance_private (ft_keyboard_manager_type_id, sizeof (FtKeyboardManagerPrivate));
	return ft_keyboard_manager_type_id;
}

GType
ft_keyboard_manager_get_type (void)
{
	static volatile gsize ft_keyboard_manager_type_id__once = 0;
	if (g_once_init_enter (&ft_keyboard_manager_type_id__once)) {
		GType ft_keyboard_manager_type_id;
		ft_keyboard_manager_type_id = ft_keyboard_manager_get_type_once ();
		g_once_init_leave (&ft_keyboard_manager_type_id__once, ft_keyboard_manager_type_id);
	}
	return ft_keyboard_manager_type_id__once;
}

static void
_vala_ft_keyboard_manager_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	FtKeyboardManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_KEYBOARD_MANAGER, FtKeyboardManager);
	switch (property_id) {
		case FT_KEYBOARD_MANAGER_GLOBAL_SHORTCUTS_SUPPORTED_PROPERTY:
		g_value_set_boolean (value, ft_keyboard_manager_get_global_shortcuts_supported (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

