/* gamepad-mapper.c generated by valac 0.36.1.39-72bb2, the Vala compiler
 * generated from gamepad-mapper.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gamepad.h>
#include <gamepad-input.h>
#include <stdlib.h>
#include <string.h>
#include <event.h>
#include <linux/input-event-codes.h>
#include <glib/gi18n-lib.h>


#define GAMES_TYPE_GAMEPAD_MAPPER (games_gamepad_mapper_get_type ())
#define GAMES_GAMEPAD_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_MAPPER, GamesGamepadMapper))
#define GAMES_GAMEPAD_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_MAPPER, GamesGamepadMapperClass))
#define GAMES_IS_GAMEPAD_MAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_MAPPER))
#define GAMES_IS_GAMEPAD_MAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_MAPPER))
#define GAMES_GAMEPAD_MAPPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_MAPPER, GamesGamepadMapperClass))

typedef struct _GamesGamepadMapper GamesGamepadMapper;
typedef struct _GamesGamepadMapperClass GamesGamepadMapperClass;
typedef struct _GamesGamepadMapperPrivate GamesGamepadMapperPrivate;

#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_GAMEPAD_MAPPING_BUILDER (games_gamepad_mapping_builder_get_type ())
#define GAMES_GAMEPAD_MAPPING_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEPAD_MAPPING_BUILDER, GamesGamepadMappingBuilder))
#define GAMES_GAMEPAD_MAPPING_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEPAD_MAPPING_BUILDER, GamesGamepadMappingBuilderClass))
#define GAMES_IS_GAMEPAD_MAPPING_BUILDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEPAD_MAPPING_BUILDER))
#define GAMES_IS_GAMEPAD_MAPPING_BUILDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEPAD_MAPPING_BUILDER))
#define GAMES_GAMEPAD_MAPPING_BUILDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEPAD_MAPPING_BUILDER, GamesGamepadMappingBuilderClass))

typedef struct _GamesGamepadMappingBuilder GamesGamepadMappingBuilder;
typedef struct _GamesGamepadMappingBuilderClass GamesGamepadMappingBuilderClass;
enum  {
	GAMES_GAMEPAD_MAPPER_DUMMY_PROPERTY,
	GAMES_GAMEPAD_MAPPER_LAST_PROPERTY
};
static GParamSpec* games_gamepad_mapper_properties[GAMES_GAMEPAD_MAPPER_LAST_PROPERTY];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_GAMEPAD_VIEW_CONFIGURATION (games_gamepad_view_configuration_get_type ())

#define GAMES_TYPE_GAMEPAD_INPUT_PATH (games_gamepad_input_path_get_type ())
typedef struct _GamesGamepadInputPath GamesGamepadInputPath;
typedef struct _GamesGamepadViewConfiguration GamesGamepadViewConfiguration;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	GAMES_GAMEPAD_MAPPER_FINISHED_SIGNAL,
	GAMES_GAMEPAD_MAPPER_LAST_SIGNAL
};
static guint games_gamepad_mapper_signals[GAMES_GAMEPAD_MAPPER_LAST_SIGNAL] = {0};

struct _GamesGamepadMapper {
	GtkBox parent_instance;
	GamesGamepadMapperPrivate * priv;
};

struct _GamesGamepadMapperClass {
	GtkBoxClass parent_class;
};

struct _GamesGamepadMapperPrivate {
	GamesGamepadView* gamepad_view;
	GtkLabel* info_message;
	GamesGamepad* gamepad;
	GamesGamepadMappingBuilder* mapping_builder;
	GamesGamepadInput* mapping_inputs;
	gint mapping_inputs_length1;
	gint _mapping_inputs_size_;
	GamesGamepadInput input;
	guint current_input_index;
	gulong gamepad_event_handler_id;
};

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

struct _GamesGamepadViewConfiguration {
	gchar* svg_path;
	GamesGamepadInputPath* input_paths;
	gint input_paths_length1;
	gint _input_paths_size_;
};


static gpointer games_gamepad_mapper_parent_class = NULL;

GType games_gamepad_mapper_get_type (void) G_GNUC_CONST;
GType games_gamepad_view_get_type (void) G_GNUC_CONST;
GType games_gamepad_mapping_builder_get_type (void) G_GNUC_CONST;
#define GAMES_GAMEPAD_MAPPER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_GAMEPAD_MAPPER, GamesGamepadMapperPrivate))
GType games_gamepad_view_configuration_get_type (void) G_GNUC_CONST;
GType games_gamepad_input_path_get_type (void) G_GNUC_CONST;
GamesGamepadInputPath* games_gamepad_input_path_dup (const GamesGamepadInputPath* self);
void games_gamepad_input_path_free (GamesGamepadInputPath* self);
void games_gamepad_input_path_copy (const GamesGamepadInputPath* self, GamesGamepadInputPath* dest);
void games_gamepad_input_path_destroy (GamesGamepadInputPath* self);
GamesGamepadViewConfiguration* games_gamepad_view_configuration_dup (const GamesGamepadViewConfiguration* self);
void games_gamepad_view_configuration_free (GamesGamepadViewConfiguration* self);
void games_gamepad_view_configuration_copy (const GamesGamepadViewConfiguration* self, GamesGamepadViewConfiguration* dest);
void games_gamepad_view_configuration_destroy (GamesGamepadViewConfiguration* self);
GamesGamepadMapper* games_gamepad_mapper_new (GamesGamepad* gamepad, GamesGamepadViewConfiguration* configuration, GamesGamepadInput* mapping_inputs, int mapping_inputs_length1);
GamesGamepadMapper* games_gamepad_mapper_construct (GType object_type, GamesGamepad* gamepad, GamesGamepadViewConfiguration* configuration, GamesGamepadInput* mapping_inputs, int mapping_inputs_length1);
static GamesGamepadInput* _vala_array_dup9 (GamesGamepadInput* self, int length);
void games_gamepad_view_set_configuration (GamesGamepadView* self, GamesGamepadViewConfiguration* configuration, GError** error);
void games_gamepad_mapper_start (GamesGamepadMapper* self);
GamesGamepadMappingBuilder* games_gamepad_mapping_builder_new (void);
GamesGamepadMappingBuilder* games_gamepad_mapping_builder_construct (GType object_type);
static void games_gamepad_mapper_connect_to_gamepad (GamesGamepadMapper* self);
static void games_gamepad_mapper_next_input (GamesGamepadMapper* self);
void games_gamepad_mapper_stop (GamesGamepadMapper* self);
static void games_gamepad_mapper_disconnect_from_gamepad (GamesGamepadMapper* self);
static void games_gamepad_mapper_on_skip_clicked (GamesGamepadMapper* self);
static void _games_gamepad_mapper_on_skip_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self);
static void __lambda27_ (GamesGamepadMapper* self, GamesEvent* event);
static void games_gamepad_mapper_on_button_event (GamesGamepadMapper* self, GamesEventGamepadButton* event);
static void games_gamepad_mapper_on_axis_event (GamesGamepadMapper* self, GamesEventGamepadAxis* event);
static void games_gamepad_mapper_on_hat_event (GamesGamepadMapper* self, GamesEventGamepadHat* event);
static void ___lambda27__games_gamepad_event (GamesGamepad* _sender, GamesEvent* event, gpointer self);
gboolean games_gamepad_mapping_builder_set_button_mapping (GamesGamepadMappingBuilder* self, guint8 hardware_index, GamesGamepadInput* source);
gboolean games_gamepad_mapping_builder_set_axis_mapping (GamesGamepadMappingBuilder* self, guint8 hardware_index, GamesGamepadInput* source);
gboolean games_gamepad_mapping_builder_set_hat_mapping (GamesGamepadMappingBuilder* self, guint8 hardware_index, gint32 value, GamesGamepadInput* source);
gchar* games_gamepad_mapping_builder_build_sdl_string (GamesGamepadMappingBuilder* self);
void games_gamepad_view_reset (GamesGamepadView* self);
gboolean games_gamepad_view_highlight (GamesGamepadView* self, GamesGamepadInput* input, gboolean highlight);
static void games_gamepad_mapper_update_info_message (GamesGamepadMapper* self);
static void games_gamepad_mapper_finalize (GObject * obj);


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


static GamesGamepadInput* _vala_array_dup9 (GamesGamepadInput* self, int length) {
	return g_memdup (self, length * sizeof (GamesGamepadInput));
}


GamesGamepadMapper* games_gamepad_mapper_construct (GType object_type, GamesGamepad* gamepad, GamesGamepadViewConfiguration* configuration, GamesGamepadInput* mapping_inputs, int mapping_inputs_length1) {
	GamesGamepadMapper * self = NULL;
	GamesGamepad* _tmp0_;
	GamesGamepad* _tmp1_;
	GamesGamepadInput* _tmp2_;
	gint _tmp2__length1;
	GamesGamepadInput* _tmp3_;
	gint _tmp3__length1;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (gamepad != NULL, NULL);
	g_return_val_if_fail (configuration != NULL, NULL);
	self = (GamesGamepadMapper*) g_object_new (object_type, NULL);
	_tmp0_ = gamepad;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->gamepad);
	self->priv->gamepad = _tmp1_;
	_tmp2_ = mapping_inputs;
	_tmp2__length1 = mapping_inputs_length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup9 (_tmp2_, _tmp2__length1) : ((gpointer) _tmp2_);
	_tmp3__length1 = _tmp2__length1;
	self->priv->mapping_inputs = (g_free (self->priv->mapping_inputs), NULL);
	self->priv->mapping_inputs = _tmp3_;
	self->priv->mapping_inputs_length1 = _tmp3__length1;
	self->priv->_mapping_inputs_size_ = self->priv->mapping_inputs_length1;
	{
		GamesGamepadView* _tmp4_;
		GamesGamepadViewConfiguration _tmp5_;
		_tmp4_ = self->priv->gamepad_view;
		_tmp5_ = *configuration;
		games_gamepad_view_set_configuration (_tmp4_, &_tmp5_, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch35_g_error;
		}
	}
	goto __finally35;
	__catch35_g_error:
	{
		GError* e = NULL;
		GError* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = e;
		_tmp7_ = _tmp6_->message;
		g_critical ("gamepad-mapper.vala:27: Could not set up gamepad view: %s", _tmp7_);
		_g_error_free0 (e);
	}
	__finally35:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	return self;
}


GamesGamepadMapper* games_gamepad_mapper_new (GamesGamepad* gamepad, GamesGamepadViewConfiguration* configuration, GamesGamepadInput* mapping_inputs, int mapping_inputs_length1) {
	return games_gamepad_mapper_construct (GAMES_TYPE_GAMEPAD_MAPPER, gamepad, configuration, mapping_inputs, mapping_inputs_length1);
}


void games_gamepad_mapper_start (GamesGamepadMapper* self) {
	GamesGamepadMappingBuilder* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_gamepad_mapping_builder_new ();
	_g_object_unref0 (self->priv->mapping_builder);
	self->priv->mapping_builder = _tmp0_;
	self->priv->current_input_index = (guint) 0;
	games_gamepad_mapper_connect_to_gamepad (self);
	games_gamepad_mapper_next_input (self);
}


void games_gamepad_mapper_stop (GamesGamepadMapper* self) {
	g_return_if_fail (self != NULL);
	games_gamepad_mapper_disconnect_from_gamepad (self);
}


static void games_gamepad_mapper_on_skip_clicked (GamesGamepadMapper* self) {
	g_return_if_fail (self != NULL);
	games_gamepad_mapper_next_input (self);
}


static void _games_gamepad_mapper_on_skip_clicked_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	games_gamepad_mapper_on_skip_clicked ((GamesGamepadMapper*) self);
}


static void __lambda27_ (GamesGamepadMapper* self, GamesEvent* event) {
	GamesEvent* _tmp0_;
	GamesEventType _tmp1_;
	g_return_if_fail (event != NULL);
	_tmp0_ = event;
	_tmp1_ = _tmp0_->type;
	switch (_tmp1_) {
		case GAMES_EVENT_GAMEPAD_BUTTON_RELEASE:
		{
			GamesEvent* _tmp2_;
			GamesEventGamepadButton* _tmp3_;
			GamesEventGamepadButton* _tmp4_;
			_tmp2_ = event;
			_tmp3_ = (GamesEventGamepadButton *) (_tmp2_);
			_tmp4_ = _tmp3_;
			games_gamepad_mapper_on_button_event (self, _tmp4_);
			break;
		}
		case GAMES_EVENT_GAMEPAD_AXIS:
		{
			GamesEvent* _tmp5_;
			GamesEventGamepadAxis* _tmp6_;
			GamesEventGamepadAxis* _tmp7_;
			_tmp5_ = event;
			_tmp6_ = (GamesEventGamepadAxis *) (_tmp5_);
			_tmp7_ = _tmp6_;
			games_gamepad_mapper_on_axis_event (self, _tmp7_);
			break;
		}
		case GAMES_EVENT_GAMEPAD_HAT:
		{
			GamesEvent* _tmp8_;
			GamesEventGamepadHat* _tmp9_;
			GamesEventGamepadHat* _tmp10_;
			_tmp8_ = event;
			_tmp9_ = (GamesEventGamepadHat *) (_tmp8_);
			_tmp10_ = _tmp9_;
			games_gamepad_mapper_on_hat_event (self, _tmp10_);
			break;
		}
		default:
		{
			break;
		}
	}
}


static void ___lambda27__games_gamepad_event (GamesGamepad* _sender, GamesEvent* event, gpointer self) {
	__lambda27_ ((GamesGamepadMapper*) self, event);
}


static void games_gamepad_mapper_connect_to_gamepad (GamesGamepadMapper* self) {
	GamesGamepad* _tmp0_;
	gulong _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gamepad;
	_tmp1_ = g_signal_connect_object (_tmp0_, "event", (GCallback) ___lambda27__games_gamepad_event, self, 0);
	self->priv->gamepad_event_handler_id = _tmp1_;
}


static void games_gamepad_mapper_disconnect_from_gamepad (GamesGamepadMapper* self) {
	gulong _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gamepad_event_handler_id;
	if (_tmp0_ != ((gulong) 0)) {
		GamesGamepad* _tmp1_;
		gulong _tmp2_;
		_tmp1_ = self->priv->gamepad;
		_tmp2_ = self->priv->gamepad_event_handler_id;
		g_signal_handler_disconnect ((GObject*) _tmp1_, _tmp2_);
		self->priv->gamepad_event_handler_id = (gulong) 0;
	}
}


static void games_gamepad_mapper_on_button_event (GamesGamepadMapper* self, GamesEventGamepadButton* event) {
	GamesGamepadInput _tmp0_;
	guint16 _tmp1_;
	gboolean success = FALSE;
	GamesGamepadMappingBuilder* _tmp2_;
	GamesEventGamepadButton* _tmp3_;
	GamesEventGamepadButton* _tmp4_;
	GamesEventGamepadButton* _tmp5_;
	guint8 _tmp6_;
	GamesGamepadInput _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp9_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = self->priv->input;
	_tmp1_ = _tmp0_.type;
	if (_tmp1_ == EV_ABS) {
		return;
	}
	_tmp2_ = self->priv->mapping_builder;
	_tmp3_ = event;
	_tmp4_ = (GamesEventGamepadButton *) ((GamesEvent*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_->hardware_index;
	_tmp7_ = self->priv->input;
	_tmp8_ = games_gamepad_mapping_builder_set_button_mapping (_tmp2_, _tmp6_, &_tmp7_);
	success = _tmp8_;
	_tmp9_ = success;
	if (!_tmp9_) {
		return;
	}
	games_gamepad_mapper_next_input (self);
}


static void games_gamepad_mapper_on_axis_event (GamesGamepadMapper* self, GamesEventGamepadAxis* event) {
	GamesGamepadInput _tmp0_;
	guint16 _tmp1_;
	GamesEventGamepadAxis* _tmp2_;
	GamesEventGamepadAxis* _tmp3_;
	GamesEventGamepadAxis* _tmp4_;
	gdouble _tmp5_;
	gdouble _tmp6_;
	gboolean success = FALSE;
	GamesGamepadMappingBuilder* _tmp7_;
	GamesEventGamepadAxis* _tmp8_;
	GamesEventGamepadAxis* _tmp9_;
	GamesEventGamepadAxis* _tmp10_;
	guint8 _tmp11_;
	GamesGamepadInput _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = self->priv->input;
	_tmp1_ = _tmp0_.type;
	if (_tmp1_ == EV_KEY) {
		return;
	}
	_tmp2_ = event;
	_tmp3_ = (GamesEventGamepadAxis *) ((GamesEvent*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_->value;
	_tmp6_ = _tmp5_;
	if (((-0.8) < _tmp6_) && (_tmp6_ < 0.8)) {
		return;
	}
	_tmp7_ = self->priv->mapping_builder;
	_tmp8_ = event;
	_tmp9_ = (GamesEventGamepadAxis *) ((GamesEvent*) _tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->hardware_index;
	_tmp12_ = self->priv->input;
	_tmp13_ = games_gamepad_mapping_builder_set_axis_mapping (_tmp7_, _tmp11_, &_tmp12_);
	success = _tmp13_;
	_tmp14_ = success;
	if (!_tmp14_) {
		return;
	}
	games_gamepad_mapper_next_input (self);
}


static void games_gamepad_mapper_on_hat_event (GamesGamepadMapper* self, GamesEventGamepadHat* event) {
	GamesEventGamepadHat* _tmp0_;
	GamesEventGamepadHat* _tmp1_;
	GamesEventGamepadHat* _tmp2_;
	gint8 _tmp3_;
	gboolean success = FALSE;
	GamesGamepadMappingBuilder* _tmp4_;
	GamesEventGamepadHat* _tmp5_;
	GamesEventGamepadHat* _tmp6_;
	GamesEventGamepadHat* _tmp7_;
	guint8 _tmp8_;
	GamesEventGamepadHat* _tmp9_;
	GamesEventGamepadHat* _tmp10_;
	GamesEventGamepadHat* _tmp11_;
	gint8 _tmp12_;
	GamesGamepadInput _tmp13_;
	gboolean _tmp14_;
	gboolean _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (event != NULL);
	_tmp0_ = event;
	_tmp1_ = (GamesEventGamepadHat *) ((GamesEvent*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_->value;
	if (((gint) _tmp3_) == 0) {
		return;
	}
	_tmp4_ = self->priv->mapping_builder;
	_tmp5_ = event;
	_tmp6_ = (GamesEventGamepadHat *) ((GamesEvent*) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_->hardware_index;
	_tmp9_ = event;
	_tmp10_ = (GamesEventGamepadHat *) ((GamesEvent*) _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = _tmp11_->value;
	_tmp13_ = self->priv->input;
	_tmp14_ = games_gamepad_mapping_builder_set_hat_mapping (_tmp4_, _tmp8_, (gint32) _tmp12_, &_tmp13_);
	success = _tmp14_;
	_tmp15_ = success;
	if (!_tmp15_) {
		return;
	}
	games_gamepad_mapper_next_input (self);
}


static void games_gamepad_mapper_next_input (GamesGamepadMapper* self) {
	guint _tmp0_;
	GamesGamepadInput* _tmp1_;
	gint _tmp1__length1;
	GamesGamepadView* _tmp5_;
	GamesGamepadInput* _tmp6_;
	gint _tmp6__length1;
	guint _tmp7_;
	GamesGamepadInput _tmp8_;
	GamesGamepadView* _tmp9_;
	GamesGamepadInput _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_input_index;
	_tmp1_ = self->priv->mapping_inputs;
	_tmp1__length1 = self->priv->mapping_inputs_length1;
	if (_tmp0_ == ((guint) _tmp1__length1)) {
		gchar* sdl_string = NULL;
		GamesGamepadMappingBuilder* _tmp2_;
		gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp2_ = self->priv->mapping_builder;
		_tmp3_ = games_gamepad_mapping_builder_build_sdl_string (_tmp2_);
		sdl_string = _tmp3_;
		_tmp4_ = sdl_string;
		g_signal_emit (self, games_gamepad_mapper_signals[GAMES_GAMEPAD_MAPPER_FINISHED_SIGNAL], 0, _tmp4_);
		_g_free0 (sdl_string);
		return;
	}
	_tmp5_ = self->priv->gamepad_view;
	games_gamepad_view_reset (_tmp5_);
	_tmp6_ = self->priv->mapping_inputs;
	_tmp6__length1 = self->priv->mapping_inputs_length1;
	_tmp7_ = self->priv->current_input_index;
	self->priv->current_input_index = _tmp7_ + 1;
	_tmp8_ = _tmp6_[_tmp7_];
	self->priv->input = _tmp8_;
	_tmp9_ = self->priv->gamepad_view;
	_tmp10_ = self->priv->input;
	games_gamepad_view_highlight (_tmp9_, &_tmp10_, TRUE);
	games_gamepad_mapper_update_info_message (self);
}


static void games_gamepad_mapper_update_info_message (GamesGamepadMapper* self) {
	GamesGamepadInput _tmp0_;
	guint16 _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->input;
	_tmp1_ = _tmp0_.type;
	switch (_tmp1_) {
		case EV_KEY:
		{
			GtkLabel* _tmp2_;
			_tmp2_ = self->priv->info_message;
			gtk_label_set_label (_tmp2_, _ ("Press suitable button on your gamepad"));
			break;
		}
		case EV_ABS:
		{
			gboolean _tmp3_ = FALSE;
			GamesGamepadInput _tmp4_;
			guint16 _tmp5_;
			_tmp4_ = self->priv->input;
			_tmp5_ = _tmp4_.code;
			if (_tmp5_ == ABS_X) {
				_tmp3_ = TRUE;
			} else {
				GamesGamepadInput _tmp6_;
				guint16 _tmp7_;
				_tmp6_ = self->priv->input;
				_tmp7_ = _tmp6_.code;
				_tmp3_ = _tmp7_ == ABS_RX;
			}
			if (_tmp3_) {
				GtkLabel* _tmp8_;
				_tmp8_ = self->priv->info_message;
				gtk_label_set_label (_tmp8_, _ ("Move suitable axis left/right on your gamepad"));
			} else {
				gboolean _tmp9_ = FALSE;
				GamesGamepadInput _tmp10_;
				guint16 _tmp11_;
				_tmp10_ = self->priv->input;
				_tmp11_ = _tmp10_.code;
				if (_tmp11_ == ABS_Y) {
					_tmp9_ = TRUE;
				} else {
					GamesGamepadInput _tmp12_;
					guint16 _tmp13_;
					_tmp12_ = self->priv->input;
					_tmp13_ = _tmp12_.code;
					_tmp9_ = _tmp13_ == ABS_RY;
				}
				if (_tmp9_) {
					GtkLabel* _tmp14_;
					_tmp14_ = self->priv->info_message;
					gtk_label_set_label (_tmp14_, _ ("Move suitable axis up/down on your gamepad"));
				}
			}
			break;
		}
		default:
		{
			break;
		}
	}
}


static void games_gamepad_mapper_class_init (GamesGamepadMapperClass * klass) {
	gint GamesGamepadMapper_private_offset;
	games_gamepad_mapper_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesGamepadMapperPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_gamepad_mapper_finalize;
	GamesGamepadMapper_private_offset = g_type_class_get_instance_private_offset (klass);
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/ui/gamepad-mapper.ui");
	games_gamepad_mapper_signals[GAMES_GAMEPAD_MAPPER_FINISHED_SIGNAL] = g_signal_new ("finished", GAMES_TYPE_GAMEPAD_MAPPER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "gamepad_view", FALSE, GamesGamepadMapper_private_offset + G_STRUCT_OFFSET (GamesGamepadMapperPrivate, gamepad_view));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "info_message", FALSE, GamesGamepadMapper_private_offset + G_STRUCT_OFFSET (GamesGamepadMapperPrivate, info_message));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_skip_clicked", G_CALLBACK(_games_gamepad_mapper_on_skip_clicked_gtk_button_clicked));
}


static void games_gamepad_mapper_instance_init (GamesGamepadMapper * self) {
	self->priv = GAMES_GAMEPAD_MAPPER_GET_PRIVATE (self);
	g_type_ensure (GAMES_TYPE_GAMEPAD_VIEW);
	gtk_widget_init_template (GTK_WIDGET (self));
}


static void games_gamepad_mapper_finalize (GObject * obj) {
	GamesGamepadMapper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAMEPAD_MAPPER, GamesGamepadMapper);
	_g_object_unref0 (self->priv->gamepad_view);
	_g_object_unref0 (self->priv->info_message);
	_g_object_unref0 (self->priv->gamepad);
	_g_object_unref0 (self->priv->mapping_builder);
	self->priv->mapping_inputs = (g_free (self->priv->mapping_inputs), NULL);
	G_OBJECT_CLASS (games_gamepad_mapper_parent_class)->finalize (obj);
}


GType games_gamepad_mapper_get_type (void) {
	static volatile gsize games_gamepad_mapper_type_id__volatile = 0;
	if (g_once_init_enter (&games_gamepad_mapper_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesGamepadMapperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_gamepad_mapper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGamepadMapper), 0, (GInstanceInitFunc) games_gamepad_mapper_instance_init, NULL };
		GType games_gamepad_mapper_type_id;
		games_gamepad_mapper_type_id = g_type_register_static (gtk_box_get_type (), "GamesGamepadMapper", &g_define_type_info, 0);
		g_once_init_leave (&games_gamepad_mapper_type_id__volatile, games_gamepad_mapper_type_id);
	}
	return games_gamepad_mapper_type_id__volatile;
}



