/* input-mode-switcher.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from input-mode-switcher.vala, do not modify */

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

#include <gtk/gtk.h>
#include <glib-object.h>
#include "gnome-games.h"
#include <glib.h>
#include <string.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_INPUT_MODE_SWITCHER (games_input_mode_switcher_get_type ())
#define GAMES_INPUT_MODE_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcher))
#define GAMES_INPUT_MODE_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcherClass))
#define GAMES_IS_INPUT_MODE_SWITCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_INPUT_MODE_SWITCHER))
#define GAMES_IS_INPUT_MODE_SWITCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_INPUT_MODE_SWITCHER))
#define GAMES_INPUT_MODE_SWITCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcherClass))

typedef struct _GamesInputModeSwitcher GamesInputModeSwitcher;
typedef struct _GamesInputModeSwitcherClass GamesInputModeSwitcherClass;
typedef struct _GamesInputModeSwitcherPrivate GamesInputModeSwitcherPrivate;
enum  {
	GAMES_INPUT_MODE_SWITCHER_0_PROPERTY,
	GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY,
	GAMES_INPUT_MODE_SWITCHER_NUM_PROPERTIES
};
static GParamSpec* games_input_mode_switcher_properties[GAMES_INPUT_MODE_SWITCHER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesInputModeSwitcher {
	GtkBox parent_instance;
	GamesInputModeSwitcherPrivate * priv;
};

struct _GamesInputModeSwitcherClass {
	GtkBoxClass parent_class;
};

struct _GamesInputModeSwitcherPrivate {
	GamesRunner* _runner;
	GtkRadioButton* keyboard_mode;
	GtkRadioButton* gamepad_mode;
};

static gint GamesInputModeSwitcher_private_offset;
static gpointer games_input_mode_switcher_parent_class = NULL;

VALA_EXTERN GType games_input_mode_switcher_get_type (void) G_GNUC_CONST ;
static void games_input_mode_switcher_on_keyboard_button_toggled (GamesInputModeSwitcher* self);
VALA_EXTERN GamesRunner* games_input_mode_switcher_get_runner (GamesInputModeSwitcher* self);
static void _games_input_mode_switcher_on_keyboard_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                      gpointer self);
static void games_input_mode_switcher_on_gamepad_button_toggled (GamesInputModeSwitcher* self);
static void _games_input_mode_switcher_on_gamepad_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                     gpointer self);
static void games_input_mode_switcher_on_input_mode_changed (GamesInputModeSwitcher* self);
VALA_EXTERN GamesInputModeSwitcher* games_input_mode_switcher_new (void);
VALA_EXTERN GamesInputModeSwitcher* games_input_mode_switcher_construct (GType object_type);
VALA_EXTERN void games_input_mode_switcher_set_runner (GamesInputModeSwitcher* self,
                                           GamesRunner* value);
static void _games_input_mode_switcher_on_input_mode_changed_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self);
static void games_input_mode_switcher_finalize (GObject * obj);
static GType games_input_mode_switcher_get_type_once (void);
static void _vala_games_input_mode_switcher_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_games_input_mode_switcher_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_input_mode_switcher_get_instance_private (GamesInputModeSwitcher* self)
{
	return G_STRUCT_MEMBER_P (self, GamesInputModeSwitcher_private_offset);
}

static void
games_input_mode_switcher_on_keyboard_button_toggled (GamesInputModeSwitcher* self)
{
	GtkRadioButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->keyboard_mode;
	_tmp1_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GamesRunner* _tmp3_;
		GamesRunner* _tmp4_;
		_tmp3_ = games_input_mode_switcher_get_runner (self);
		_tmp4_ = _tmp3_;
		games_runner_set_input_mode (_tmp4_, GAMES_INPUT_MODE_KEYBOARD);
	}
}

static void
_games_input_mode_switcher_on_keyboard_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                 gpointer self)
{
	games_input_mode_switcher_on_keyboard_button_toggled ((GamesInputModeSwitcher*) self);
}

static void
games_input_mode_switcher_on_gamepad_button_toggled (GamesInputModeSwitcher* self)
{
	GtkRadioButton* _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gamepad_mode;
	_tmp1_ = gtk_toggle_button_get_active ((GtkToggleButton*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_) {
		GamesRunner* _tmp3_;
		GamesRunner* _tmp4_;
		_tmp3_ = games_input_mode_switcher_get_runner (self);
		_tmp4_ = _tmp3_;
		games_runner_set_input_mode (_tmp4_, GAMES_INPUT_MODE_GAMEPAD);
	}
}

static void
_games_input_mode_switcher_on_gamepad_button_toggled_gtk_toggle_button_toggled (GtkToggleButton* _sender,
                                                                                gpointer self)
{
	games_input_mode_switcher_on_gamepad_button_toggled ((GamesInputModeSwitcher*) self);
}

static void
games_input_mode_switcher_on_input_mode_changed (GamesInputModeSwitcher* self)
{
	GamesRunner* _tmp0_;
	GamesRunner* _tmp1_;
	GamesInputMode _tmp2_;
	GamesInputMode _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_input_mode_switcher_get_runner (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = games_runner_get_input_mode (_tmp1_);
	_tmp3_ = _tmp2_;
	switch (_tmp3_) {
		case GAMES_INPUT_MODE_GAMEPAD:
		{
			GtkRadioButton* _tmp4_;
			_tmp4_ = self->priv->gamepad_mode;
			gtk_toggle_button_set_active ((GtkToggleButton*) _tmp4_, TRUE);
			break;
		}
		case GAMES_INPUT_MODE_KEYBOARD:
		{
			GtkRadioButton* _tmp5_;
			_tmp5_ = self->priv->keyboard_mode;
			gtk_toggle_button_set_active ((GtkToggleButton*) _tmp5_, TRUE);
			break;
		}
		case GAMES_INPUT_MODE_NONE:
		{
			break;
		}
		default:
		break;
	}
}

GamesInputModeSwitcher*
games_input_mode_switcher_construct (GType object_type)
{
	GamesInputModeSwitcher * self = NULL;
	self = (GamesInputModeSwitcher*) g_object_new (object_type, NULL);
	return self;
}

GamesInputModeSwitcher*
games_input_mode_switcher_new (void)
{
	return games_input_mode_switcher_construct (GAMES_TYPE_INPUT_MODE_SWITCHER);
}

GamesRunner*
games_input_mode_switcher_get_runner (GamesInputModeSwitcher* self)
{
	GamesRunner* result;
	GamesRunner* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_runner;
	result = _tmp0_;
	return result;
}

static void
_games_input_mode_switcher_on_input_mode_changed_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self)
{
	games_input_mode_switcher_on_input_mode_changed ((GamesInputModeSwitcher*) self);
}

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

void
games_input_mode_switcher_set_runner (GamesInputModeSwitcher* self,
                                      GamesRunner* value)
{
	GamesRunner* _tmp0_;
	GamesRunner* _tmp1_;
	GamesRunner* _tmp6_;
	GamesRunner* _tmp7_;
	GamesRunner* _tmp8_;
	gint _tmp9_ = 0;
	GamesInputMode* _tmp10_;
	GamesInputMode* _tmp11_;
	gint _tmp11__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = games_input_mode_switcher_get_runner (self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		GamesRunner* _tmp2_;
		GamesRunner* _tmp3_;
		guint _tmp4_;
		GQuark _tmp5_;
		_tmp2_ = games_input_mode_switcher_get_runner (self);
		_tmp3_ = _tmp2_;
		g_signal_parse_name ("notify::input-mode", G_TYPE_OBJECT, &_tmp4_, &_tmp5_, TRUE);
		g_signal_handlers_disconnect_matched ((GObject*) _tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, _tmp5_, NULL, (GCallback) _games_input_mode_switcher_on_input_mode_changed_g_object_notify, self);
	}
	_tmp6_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_runner);
	self->priv->_runner = _tmp6_;
	if (value == NULL) {
		gtk_widget_set_visible ((GtkWidget*) self, FALSE);
		return;
	}
	_tmp7_ = games_input_mode_switcher_get_runner (self);
	_tmp8_ = _tmp7_;
	g_signal_connect_object ((GObject*) _tmp8_, "notify::input-mode", (GCallback) _games_input_mode_switcher_on_input_mode_changed_g_object_notify, self, 0);
	_tmp10_ = games_runner_get_available_input_modes (value, &_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp11__length1 = _tmp9_;
	gtk_widget_set_visible ((GtkWidget*) self, _tmp9_ >= 2);
	_tmp11_ = (g_free (_tmp11_), NULL);
	games_input_mode_switcher_on_input_mode_changed (self);
	g_object_notify_by_pspec ((GObject *) self, games_input_mode_switcher_properties[GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY]);
}

static void
games_input_mode_switcher_class_init (GamesInputModeSwitcherClass * klass,
                                      gpointer klass_data)
{
	games_input_mode_switcher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesInputModeSwitcher_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_games_input_mode_switcher_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_games_input_mode_switcher_set_property;
	G_OBJECT_CLASS (klass)->finalize = games_input_mode_switcher_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY, games_input_mode_switcher_properties[GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY] = g_param_spec_object ("runner", "runner", "runner", GAMES_TYPE_RUNNER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/org/gnome/Games/ui/input-mode-switcher.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "keyboard_mode", FALSE, GamesInputModeSwitcher_private_offset + G_STRUCT_OFFSET (GamesInputModeSwitcherPrivate, keyboard_mode));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "gamepad_mode", FALSE, GamesInputModeSwitcher_private_offset + G_STRUCT_OFFSET (GamesInputModeSwitcherPrivate, gamepad_mode));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_keyboard_button_toggled", G_CALLBACK(_games_input_mode_switcher_on_keyboard_button_toggled_gtk_toggle_button_toggled));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_gamepad_button_toggled", G_CALLBACK(_games_input_mode_switcher_on_gamepad_button_toggled_gtk_toggle_button_toggled));
}

static void
games_input_mode_switcher_instance_init (GamesInputModeSwitcher * self,
                                         gpointer klass)
{
	self->priv = games_input_mode_switcher_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
games_input_mode_switcher_finalize (GObject * obj)
{
	GamesInputModeSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcher);
	_g_object_unref0 (self->priv->_runner);
	G_OBJECT_CLASS (games_input_mode_switcher_parent_class)->finalize (obj);
}

static GType
games_input_mode_switcher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesInputModeSwitcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_input_mode_switcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesInputModeSwitcher), 0, (GInstanceInitFunc) games_input_mode_switcher_instance_init, NULL };
	GType games_input_mode_switcher_type_id;
	games_input_mode_switcher_type_id = g_type_register_static (gtk_box_get_type (), "GamesInputModeSwitcher", &g_define_type_info, 0);
	GamesInputModeSwitcher_private_offset = g_type_add_instance_private (games_input_mode_switcher_type_id, sizeof (GamesInputModeSwitcherPrivate));
	return games_input_mode_switcher_type_id;
}

GType
games_input_mode_switcher_get_type (void)
{
	static volatile gsize games_input_mode_switcher_type_id__once = 0;
	if (g_once_init_enter (&games_input_mode_switcher_type_id__once)) {
		GType games_input_mode_switcher_type_id;
		games_input_mode_switcher_type_id = games_input_mode_switcher_get_type_once ();
		g_once_init_leave (&games_input_mode_switcher_type_id__once, games_input_mode_switcher_type_id);
	}
	return games_input_mode_switcher_type_id__once;
}

static void
_vala_games_input_mode_switcher_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GamesInputModeSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcher);
	switch (property_id) {
		case GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY:
		g_value_set_object (value, games_input_mode_switcher_get_runner (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_games_input_mode_switcher_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GamesInputModeSwitcher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GAMES_TYPE_INPUT_MODE_SWITCHER, GamesInputModeSwitcher);
	switch (property_id) {
		case GAMES_INPUT_MODE_SWITCHER_RUNNER_PROPERTY:
		games_input_mode_switcher_set_runner (self, g_value_get_object (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;
}

