/* keyboard-mapper.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from keyboard-mapper.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <retro-gtk.h>
#include <glib/gi18n-lib.h>
#include "gnome-games.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

#define GAMES_TYPE_KEYBOARD_MAPPER (games_keyboard_mapper_get_type ())
#define GAMES_KEYBOARD_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapper))
#define GAMES_KEYBOARD_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapperClass))
#define GAMES_IS_KEYBOARD_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_KEYBOARD_MAPPER))
#define GAMES_IS_KEYBOARD_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_KEYBOARD_MAPPER))
#define GAMES_KEYBOARD_MAPPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapperClass))

typedef struct _GamesKeyboardMapper GamesKeyboardMapper;
typedef struct _GamesKeyboardMapperClass GamesKeyboardMapperClass;
typedef struct _GamesKeyboardMapperPrivate GamesKeyboardMapperPrivate;

#define GAMES_TYPE_GAMEPAD_VIEW (games_gamepad_view_get_type ())
#define GAMES_GAMEPAD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_VIEW, GamesGamepadView))
#define GAMES_GAMEPAD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_VIEW, GamesGamepadViewClass))
#define GAMES_IS_GAMEPAD_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_VIEW))
#define GAMES_IS_GAMEPAD_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_VIEW))
#define GAMES_GAMEPAD_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_VIEW, GamesGamepadViewClass))

typedef struct _GamesGamepadView GamesGamepadView;
typedef struct _GamesGamepadViewClass GamesGamepadViewClass;

#define GAMES_TYPE_KEYBOARD_MAPPING_BUILDER (games_keyboard_mapping_builder_get_type ())
#define GAMES_KEYBOARD_MAPPING_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_KEYBOARD_MAPPING_BUILDER, GamesKeyboardMappingBuilder))
#define GAMES_KEYBOARD_MAPPING_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_KEYBOARD_MAPPING_BUILDER, GamesKeyboardMappingBuilderClass))
#define GAMES_IS_KEYBOARD_MAPPING_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_KEYBOARD_MAPPING_BUILDER))
#define GAMES_IS_KEYBOARD_MAPPING_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_KEYBOARD_MAPPING_BUILDER))
#define GAMES_KEYBOARD_MAPPING_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_KEYBOARD_MAPPING_BUILDER, GamesKeyboardMappingBuilderClass))

typedef struct _GamesKeyboardMappingBuilder GamesKeyboardMappingBuilder;
typedef struct _GamesKeyboardMappingBuilderClass GamesKeyboardMappingBuilderClass;

#define GAMES_TYPE_GAMEPAD_INPUT (games_gamepad_input_get_type ())
typedef struct _GamesGamepadInput GamesGamepadInput;

#define GAMES_TYPE_GAMEPAD_VIEW_CONFIGURATION (games_gamepad_view_configuration_get_type ())
typedef struct _GamesGamepadViewConfiguration GamesGamepadViewConfiguration;

#define GAMES_TYPE_GAMEPAD_BUTTON_PATH (games_gamepad_button_path_get_type ())
typedef struct _GamesGamepadButtonPath GamesGamepadButtonPath;

#define GAMES_TYPE_GAMEPAD_ANALOG_PATH (games_gamepad_analog_path_get_type ())
typedef struct _GamesGamepadAnalogPath GamesGamepadAnalogPath;
enum  {
	GAMES_KEYBOARD_MAPPER_0_PROPERTY,
	GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY,
	GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY,
	GAMES_KEYBOARD_MAPPER_NUM_PROPERTIES
};
static GParamSpec* games_keyboard_mapper_properties[GAMES_KEYBOARD_MAPPER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	GAMES_KEYBOARD_MAPPER_FINISHED_SIGNAL,
	GAMES_KEYBOARD_MAPPER_NUM_SIGNALS
};
static guint games_keyboard_mapper_signals[GAMES_KEYBOARD_MAPPER_NUM_SIGNALS] = {0};

struct _GamesKeyboardMapper {
	GtkBin parent_instance;
	GamesKeyboardMapperPrivate * priv;
};

struct _GamesKeyboardMapperClass {
	GtkBinClass parent_class;
};

struct _GamesGamepadInput {
	guint16 type;
	guint16 code;
};

struct _GamesGamepadButtonPath {
	GamesGamepadInput input;
	gchar* path;
};

struct _GamesGamepadAnalogPath {
	GamesGamepadInput input_x;
	GamesGamepadInput input_y;
	gdouble offset_radius;
	gchar* path;
};

struct _GamesGamepadViewConfiguration {
	gchar* svg_path;
	GamesGamepadButtonPath* button_paths;
	gint button_paths_length1;
	gint _button_paths_size_;
	GamesGamepadAnalogPath* analog_paths;
	gint analog_paths_length1;
	gint _analog_paths_size_;
	gchar** background_paths;
	gint background_paths_length1;
	gint _background_paths_size_;
};

struct _GamesKeyboardMapperPrivate {
	GamesGamepadView* gamepad_view;
	GamesKeyboardMappingBuilder* mapping_builder;
	GamesGamepadInput* mapping_inputs;
	gint mapping_inputs_length1;
	gint _mapping_inputs_size_;
	GamesGamepadInput input;
	guint current_input_index;
	gchar* _info_message;
	GamesGamepadViewConfiguration _configuration;
};

static gint GamesKeyboardMapper_private_offset;
static gpointer games_keyboard_mapper_parent_class = NULL;

VALA_EXTERN GType games_keyboard_mapper_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_gamepad_view_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_keyboard_mapping_builder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_gamepad_input_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesGamepadInput* games_gamepad_input_dup (const GamesGamepadInput* self);
VALA_EXTERN void games_gamepad_input_free (GamesGamepadInput* self);
VALA_EXTERN GType games_gamepad_view_configuration_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_gamepad_button_path_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesGamepadButtonPath* games_gamepad_button_path_dup (const GamesGamepadButtonPath* self);
VALA_EXTERN void games_gamepad_button_path_free (GamesGamepadButtonPath* self);
VALA_EXTERN void games_gamepad_button_path_copy (const GamesGamepadButtonPath* self,
                                     GamesGamepadButtonPath* dest);
VALA_EXTERN void games_gamepad_button_path_destroy (GamesGamepadButtonPath* self);
VALA_EXTERN GType games_gamepad_analog_path_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesGamepadAnalogPath* games_gamepad_analog_path_dup (const GamesGamepadAnalogPath* self);
VALA_EXTERN void games_gamepad_analog_path_free (GamesGamepadAnalogPath* self);
VALA_EXTERN void games_gamepad_analog_path_copy (const GamesGamepadAnalogPath* self,
                                     GamesGamepadAnalogPath* dest);
VALA_EXTERN void games_gamepad_analog_path_destroy (GamesGamepadAnalogPath* self);
VALA_EXTERN GamesGamepadViewConfiguration* games_gamepad_view_configuration_dup (const GamesGamepadViewConfiguration* self);
VALA_EXTERN void games_gamepad_view_configuration_free (GamesGamepadViewConfiguration* self);
VALA_EXTERN void games_gamepad_view_configuration_copy (const GamesGamepadViewConfiguration* self,
                                            GamesGamepadViewConfiguration* dest);
VALA_EXTERN void games_gamepad_view_configuration_destroy (GamesGamepadViewConfiguration* self);
VALA_EXTERN GamesKeyboardMapper* games_keyboard_mapper_new (GamesGamepadViewConfiguration* configuration,
                                                GamesGamepadInput* mapping_inputs,
                                                gint mapping_inputs_length1);
VALA_EXTERN GamesKeyboardMapper* games_keyboard_mapper_construct (GType object_type,
                                                      GamesGamepadViewConfiguration* configuration,
                                                      GamesGamepadInput* mapping_inputs,
                                                      gint mapping_inputs_length1);
static GamesGamepadInput* _vala_array_dup14 (GamesGamepadInput* self,
                                      gssize length);
VALA_EXTERN void games_keyboard_mapper_start (GamesKeyboardMapper* self);
VALA_EXTERN GamesKeyboardMappingBuilder* games_keyboard_mapping_builder_new (void);
VALA_EXTERN GamesKeyboardMappingBuilder* games_keyboard_mapping_builder_construct (GType object_type);
static void games_keyboard_mapper_connect_to_keyboard (GamesKeyboardMapper* self);
static void games_keyboard_mapper_next_input (GamesKeyboardMapper* self);
VALA_EXTERN void games_keyboard_mapper_stop (GamesKeyboardMapper* self);
static void games_keyboard_mapper_disconnect_from_keyboard (GamesKeyboardMapper* self);
VALA_EXTERN void games_keyboard_mapper_skip (GamesKeyboardMapper* self);
static gboolean games_keyboard_mapper_on_keyboard_event (GamesKeyboardMapper* self,
                                                  GdkEventKey* key);
static gboolean _games_keyboard_mapper_on_keyboard_event_gtk_widget_key_release_event (GtkWidget* _sender,
                                                                                GdkEventKey* event,
                                                                                gpointer self);
VALA_EXTERN gboolean games_keyboard_mapping_builder_set_input_mapping (GamesKeyboardMappingBuilder* self,
                                                           GamesGamepadInput* input,
                                                           guint16 keycode);
VALA_EXTERN RetroKeyJoypadMapping* games_keyboard_mapping_builder_get_mapping (GamesKeyboardMappingBuilder* self);
VALA_EXTERN void games_gamepad_view_reset (GamesGamepadView* self);
VALA_EXTERN gboolean games_gamepad_view_highlight (GamesGamepadView* self,
                                       GamesGamepadInput* input,
                                       gboolean highlight);
VALA_EXTERN const gchar* games_keyboard_mapper_get_info_message (GamesKeyboardMapper* self);
static void games_keyboard_mapper_set_info_message (GamesKeyboardMapper* self,
                                             const gchar* value);
VALA_EXTERN void games_keyboard_mapper_get_configuration (GamesKeyboardMapper* self,
                                              GamesGamepadViewConfiguration * result);
static void games_keyboard_mapper_set_configuration (GamesKeyboardMapper* self,
                                              GamesGamepadViewConfiguration * value);
VALA_EXTERN void games_gamepad_view_set_configuration (GamesGamepadView* self,
                                           GamesGamepadViewConfiguration * value);
static GObject * games_keyboard_mapper_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static void games_keyboard_mapper_finalize (GObject * obj);
static GType games_keyboard_mapper_get_type_once (void);
static void _vala_games_keyboard_mapper_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_games_keyboard_mapper_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_keyboard_mapper_get_instance_private (GamesKeyboardMapper* self)
{
	return G_STRUCT_MEMBER_P (self, GamesKeyboardMapper_private_offset);
}

static GamesGamepadInput*
_vala_array_dup14 (GamesGamepadInput* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (GamesGamepadInput));
	}
	return NULL;
}

GamesKeyboardMapper*
games_keyboard_mapper_construct (GType object_type,
                                 GamesGamepadViewConfiguration* configuration,
                                 GamesGamepadInput* mapping_inputs,
                                 gint mapping_inputs_length1)
{
	GamesKeyboardMapper * self = NULL;
	GamesGamepadViewConfiguration _tmp0_;
	GamesGamepadInput* _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (configuration != NULL, NULL);
	_tmp0_ = *configuration;
	self = (GamesKeyboardMapper*) g_object_new (object_type, "configuration", &_tmp0_, NULL);
	_tmp1_ = (mapping_inputs != NULL) ? _vala_array_dup14 (mapping_inputs, mapping_inputs_length1) : mapping_inputs;
	_tmp1__length1 = mapping_inputs_length1;
	self->priv->mapping_inputs = (g_free (self->priv->mapping_inputs), NULL);
	self->priv->mapping_inputs = _tmp1_;
	self->priv->mapping_inputs_length1 = _tmp1__length1;
	self->priv->_mapping_inputs_size_ = self->priv->mapping_inputs_length1;
	return self;
}

GamesKeyboardMapper*
games_keyboard_mapper_new (GamesGamepadViewConfiguration* configuration,
                           GamesGamepadInput* mapping_inputs,
                           gint mapping_inputs_length1)
{
	return games_keyboard_mapper_construct (GAMES_TYPE_KEYBOARD_MAPPER, configuration, mapping_inputs, mapping_inputs_length1);
}

void
games_keyboard_mapper_start (GamesKeyboardMapper* self)
{
	GamesKeyboardMappingBuilder* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_keyboard_mapping_builder_new ();
	_g_object_unref0 (self->priv->mapping_builder);
	self->priv->mapping_builder = _tmp0_;
	self->priv->current_input_index = (guint) 0;
	games_keyboard_mapper_connect_to_keyboard (self);
	games_keyboard_mapper_next_input (self);
}

void
games_keyboard_mapper_stop (GamesKeyboardMapper* self)
{
	g_return_if_fail (self != NULL);
	games_keyboard_mapper_disconnect_from_keyboard (self);
}

void
games_keyboard_mapper_skip (GamesKeyboardMapper* self)
{
	g_return_if_fail (self != NULL);
	games_keyboard_mapper_next_input (self);
}

static gboolean
_games_keyboard_mapper_on_keyboard_event_gtk_widget_key_release_event (GtkWidget* _sender,
                                                                       GdkEventKey* event,
                                                                       gpointer self)
{
	gboolean result;
	result = games_keyboard_mapper_on_keyboard_event ((GamesKeyboardMapper*) self, event);
	return result;
}

static void
games_keyboard_mapper_connect_to_keyboard (GamesKeyboardMapper* self)
{
	GtkWidget* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	g_signal_connect_object (_tmp0_, "key-release-event", (GCallback) _games_keyboard_mapper_on_keyboard_event_gtk_widget_key_release_event, self, 0);
}

static void
games_keyboard_mapper_disconnect_from_keyboard (GamesKeyboardMapper* self)
{
	GtkWidget* _tmp0_;
	guint _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	g_signal_parse_name ("key-release-event", gtk_widget_get_type (), &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _games_keyboard_mapper_on_keyboard_event_gtk_widget_key_release_event, self);
}

static gboolean
games_keyboard_mapper_on_keyboard_event (GamesKeyboardMapper* self,
                                         GdkEventKey* key)
{
	GamesKeyboardMappingBuilder* _tmp0_;
	GamesGamepadInput _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = self->priv->mapping_builder;
	_tmp1_ = self->priv->input;
	if (games_keyboard_mapping_builder_set_input_mapping (_tmp0_, &_tmp1_, key->hardware_keycode)) {
		games_keyboard_mapper_next_input (self);
	}
	result = TRUE;
	return result;
}

static void
games_keyboard_mapper_next_input (GamesKeyboardMapper* self)
{
	GamesGamepadInput* _tmp0_;
	gint _tmp0__length1;
	GamesGamepadView* _tmp4_;
	GamesGamepadInput* _tmp5_;
	gint _tmp5__length1;
	guint _tmp6_;
	GamesGamepadInput _tmp7_;
	GamesGamepadView* _tmp8_;
	GamesGamepadInput _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->mapping_inputs;
	_tmp0__length1 = self->priv->mapping_inputs_length1;
	if (self->priv->current_input_index == ((guint) _tmp0__length1)) {
		GamesKeyboardMappingBuilder* _tmp1_;
		RetroKeyJoypadMapping* _tmp2_;
		RetroKeyJoypadMapping* _tmp3_;
		_tmp1_ = self->priv->mapping_builder;
		_tmp2_ = games_keyboard_mapping_builder_get_mapping (_tmp1_);
		_tmp3_ = _tmp2_;
		g_signal_emit (self, games_keyboard_mapper_signals[GAMES_KEYBOARD_MAPPER_FINISHED_SIGNAL], 0, _tmp3_);
		return;
	}
	_tmp4_ = self->priv->gamepad_view;
	games_gamepad_view_reset (_tmp4_);
	_tmp5_ = self->priv->mapping_inputs;
	_tmp5__length1 = self->priv->mapping_inputs_length1;
	_tmp6_ = self->priv->current_input_index;
	self->priv->current_input_index = _tmp6_ + 1;
	_tmp7_ = _tmp5_[_tmp6_];
	self->priv->input = _tmp7_;
	_tmp8_ = self->priv->gamepad_view;
	_tmp9_ = self->priv->input;
	games_gamepad_view_highlight (_tmp8_, &_tmp9_, TRUE);
}

const gchar*
games_keyboard_mapper_get_info_message (GamesKeyboardMapper* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_info_message;
	result = _tmp0_;
	return result;
}

static void
games_keyboard_mapper_set_info_message (GamesKeyboardMapper* self,
                                        const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = games_keyboard_mapper_get_info_message (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_info_message);
		self->priv->_info_message = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, games_keyboard_mapper_properties[GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY]);
	}
}

void
games_keyboard_mapper_get_configuration (GamesKeyboardMapper* self,
                                         GamesGamepadViewConfiguration * result)
{
	GamesGamepadViewConfiguration _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_configuration;
	*result = _tmp0_;
	return;
}

static void
games_keyboard_mapper_set_configuration (GamesKeyboardMapper* self,
                                         GamesGamepadViewConfiguration * value)
{
	GamesGamepadViewConfiguration _tmp0_;
	GamesGamepadViewConfiguration _tmp1_;
	GamesGamepadViewConfiguration _tmp2_ = {0};
	GamesGamepadView* _tmp3_;
	GamesGamepadViewConfiguration _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = *value;
	_tmp1_ = _tmp0_;
	games_gamepad_view_configuration_copy (&_tmp1_, &_tmp2_);
	games_gamepad_view_configuration_destroy (&self->priv->_configuration);
	self->priv->_configuration = _tmp2_;
	_tmp3_ = self->priv->gamepad_view;
	_tmp4_ = *value;
	games_gamepad_view_set_configuration (_tmp3_, &_tmp4_);
	g_object_notify_by_pspec ((GObject *) self, games_keyboard_mapper_properties[GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY]);
}

static GObject *
games_keyboard_mapper_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GamesKeyboardMapper * self;
	parent_class = G_OBJECT_CLASS (games_keyboard_mapper_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapper);
	games_keyboard_mapper_set_info_message (self, _ ("Press suitable key on your keyboard"));
	return obj;
}

static void
games_keyboard_mapper_class_init (GamesKeyboardMapperClass * klass,
                                  gpointer klass_data)
{
	games_keyboard_mapper_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesKeyboardMapper_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_keyboard_mapper_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_keyboard_mapper_set_property;
	G_OBJECT_CLASS (klass)->constructor = games_keyboard_mapper_constructor;
	G_OBJECT_CLASS (klass)->finalize = games_keyboard_mapper_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY, games_keyboard_mapper_properties[GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY] = g_param_spec_string ("info-message", "info-message", "info-message", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY, games_keyboard_mapper_properties[GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY] = g_param_spec_boxed ("configuration", "configuration", "configuration", GAMES_TYPE_GAMEPAD_VIEW_CONFIGURATION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/keyboard/keyboard-mapper.ui");
	games_keyboard_mapper_signals[GAMES_KEYBOARD_MAPPER_FINISHED_SIGNAL] = g_signal_new ("finished", GAMES_TYPE_KEYBOARD_MAPPER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, retro_key_joypad_mapping_get_type ());
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "gamepad_view", FALSE, GamesKeyboardMapper_private_offset + G_STRUCT_OFFSET (GamesKeyboardMapperPrivate, gamepad_view));
}

static void
games_keyboard_mapper_instance_init (GamesKeyboardMapper * self,
                                     gpointer klass)
{
	self->priv = games_keyboard_mapper_get_instance_private (self);
	g_type_ensure (GAMES_TYPE_GAMEPAD_VIEW);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
games_keyboard_mapper_finalize (GObject * obj)
{
	GamesKeyboardMapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapper);
	_g_object_unref0 (self->priv->mapping_builder);
	self->priv->mapping_inputs = (g_free (self->priv->mapping_inputs), NULL);
	_g_free0 (self->priv->_info_message);
	games_gamepad_view_configuration_destroy (&self->priv->_configuration);
	G_OBJECT_CLASS (games_keyboard_mapper_parent_class)->finalize (obj);
}

static GType
games_keyboard_mapper_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesKeyboardMapperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_keyboard_mapper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesKeyboardMapper), 0, (GInstanceInitFunc) games_keyboard_mapper_instance_init, NULL };
	GType games_keyboard_mapper_type_id;
	games_keyboard_mapper_type_id = g_type_register_static (gtk_bin_get_type (), "GamesKeyboardMapper", &g_define_type_info, 0);
	GamesKeyboardMapper_private_offset = g_type_add_instance_private (games_keyboard_mapper_type_id, sizeof (GamesKeyboardMapperPrivate));
	return games_keyboard_mapper_type_id;
}

GType
games_keyboard_mapper_get_type (void)
{
	static volatile gsize games_keyboard_mapper_type_id__once = 0;
	if (g_once_init_enter (&games_keyboard_mapper_type_id__once)) {
		GType games_keyboard_mapper_type_id;
		games_keyboard_mapper_type_id = games_keyboard_mapper_get_type_once ();
		g_once_init_leave (&games_keyboard_mapper_type_id__once, games_keyboard_mapper_type_id);
	}
	return games_keyboard_mapper_type_id__once;
}

static void
_vala_games_keyboard_mapper_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	GamesKeyboardMapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapper);
	switch (property_id) {
		case GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY:
		g_value_set_string (value, games_keyboard_mapper_get_info_message (self));
		break;
		case GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY:
		{
			GamesGamepadViewConfiguration boxed;
			games_keyboard_mapper_get_configuration (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_keyboard_mapper_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	GamesKeyboardMapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_KEYBOARD_MAPPER, GamesKeyboardMapper);
	switch (property_id) {
		case GAMES_KEYBOARD_MAPPER_INFO_MESSAGE_PROPERTY:
		games_keyboard_mapper_set_info_message (self, g_value_get_string (value));
		break;
		case GAMES_KEYBOARD_MAPPER_CONFIGURATION_PROPERTY:
		games_keyboard_mapper_set_configuration (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

