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

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <granite-7.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib/gi18n-lib.h>
#include <float.h>
#include <math.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GALA_DAEMON_TYPE_KEY_BUTTON (gala_daemon_key_button_get_type ())
#define GALA_DAEMON_KEY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButton))
#define GALA_DAEMON_KEY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButtonClass))
#define GALA_DAEMON_IS_KEY_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEY_BUTTON))
#define GALA_DAEMON_IS_KEY_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEY_BUTTON))
#define GALA_DAEMON_KEY_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButtonClass))

typedef struct _GalaDaemonKeyButton GalaDaemonKeyButton;
typedef struct _GalaDaemonKeyButtonClass GalaDaemonKeyButtonClass;
typedef struct _GalaDaemonKeyButtonPrivate GalaDaemonKeyButtonPrivate;

#define GALA_DAEMON_TYPE_KEY (gala_daemon_key_get_type ())
#define GALA_DAEMON_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_KEY, GalaDaemonKey))
#define GALA_DAEMON_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_KEY, GalaDaemonKeyClass))
#define GALA_DAEMON_IS_KEY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_KEY))
#define GALA_DAEMON_IS_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_KEY))
#define GALA_DAEMON_KEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_KEY, GalaDaemonKeyClass))

typedef struct _GalaDaemonKey GalaDaemonKey;
typedef struct _GalaDaemonKeyClass GalaDaemonKeyClass;
enum  {
	GALA_DAEMON_KEY_BUTTON_0_PROPERTY,
	GALA_DAEMON_KEY_BUTTON_KEY_PROPERTY,
	GALA_DAEMON_KEY_BUTTON_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_key_button_properties[GALA_DAEMON_KEY_BUTTON_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))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GalaDaemonKeyButton {
	GraniteBin parent_instance;
	GalaDaemonKeyButtonPrivate * priv;
};

struct _GalaDaemonKeyButtonClass {
	GraniteBinClass parent_class;
};

struct _GalaDaemonKeyButtonPrivate {
	GalaDaemonKey* _key;
};

static gint GalaDaemonKeyButton_private_offset;
static gpointer gala_daemon_key_button_parent_class = NULL;

VALA_EXTERN GType gala_daemon_key_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKeyButton, g_object_unref)
VALA_EXTERN GType gala_daemon_key_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonKey, g_object_unref)
static void gala_daemon_key_button_on_pressed (GalaDaemonKeyButton* self);
VALA_EXTERN const gchar* gala_daemon_key_get_press_detailed_action_name (GalaDaemonKey* self);
static void gala_daemon_key_button_activate_detailed_action (GalaDaemonKeyButton* self,
                                                      const gchar* detailed_action);
static void gala_daemon_key_button_on_released (GalaDaemonKeyButton* self);
VALA_EXTERN const gchar* gala_daemon_key_get_detailed_action_name (GalaDaemonKey* self);
VALA_EXTERN GalaDaemonKeyButton* gala_daemon_key_button_new (void);
VALA_EXTERN GalaDaemonKeyButton* gala_daemon_key_button_construct (GType object_type);
VALA_EXTERN void gala_daemon_key_button_set_key (GalaDaemonKeyButton* self,
                                     GalaDaemonKey* value);
VALA_EXTERN const gchar* gala_daemon_key_get_label (GalaDaemonKey* self);
VALA_EXTERN GIcon* gala_daemon_key_get_icon (GalaDaemonKey* self);
static GObject * gala_daemon_key_button_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _gala_daemon_key_button_on_pressed_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                                   gint n_press,
                                                                   gdouble x,
                                                                   gdouble y,
                                                                   gpointer self);
static void _gala_daemon_key_button_on_released_gtk_gesture_click_released (GtkGestureClick* _sender,
                                                                     gint n_press,
                                                                     gdouble x,
                                                                     gdouble y,
                                                                     gpointer self);
static void gala_daemon_key_button_finalize (GObject * obj);
static GType gala_daemon_key_button_get_type_once (void);
static void _vala_gala_daemon_key_button_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
gala_daemon_key_button_get_instance_private (GalaDaemonKeyButton* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonKeyButton_private_offset);
}

static void
gala_daemon_key_button_on_pressed (GalaDaemonKeyButton* self)
{
	GalaDaemonKey* _tmp0_ = NULL;
	GalaDaemonKey* _tmp1_;
	const gchar* _tmp2_ = NULL;
	GalaDaemonKey* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_key;
	_tmp0_ = _tmp1_;
	_tmp2_ = NULL;
	if (_tmp0_ != NULL) {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = gala_daemon_key_get_press_detailed_action_name (_tmp0_);
		_tmp4_ = _tmp3_;
		_tmp2_ = _tmp4_;
	}
	if (_tmp2_ == NULL) {
		return;
	}
	_tmp5_ = self->priv->_key;
	_tmp6_ = gala_daemon_key_get_press_detailed_action_name (_tmp5_);
	_tmp7_ = _tmp6_;
	gala_daemon_key_button_activate_detailed_action (self, _tmp7_);
}

static void
gala_daemon_key_button_on_released (GalaDaemonKeyButton* self)
{
	GalaDaemonKey* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_key;
	_tmp1_ = gala_daemon_key_get_detailed_action_name (_tmp0_);
	_tmp2_ = _tmp1_;
	gala_daemon_key_button_activate_detailed_action (self, _tmp2_);
}

static void
gala_daemon_key_button_activate_detailed_action (GalaDaemonKeyButton* self,
                                                 const gchar* detailed_action)
{
	gchar* action_name = NULL;
	GVariant* target = NULL;
	const gchar* _tmp4_;
	GVariant* _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (detailed_action != NULL);
	{
		gchar* _tmp0_ = NULL;
		GVariant* _tmp1_ = NULL;
		g_action_parse_detailed_name (detailed_action, &_tmp0_, &_tmp1_, &_inner_error0_);
		_g_free0 (action_name);
		action_name = _tmp0_;
		_g_variant_unref0 (target);
		target = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_warning ("KeyButton.vala:56: Failed to parse action name %s: %s", detailed_action, _tmp3_);
		_g_error_free0 (e);
		_g_variant_unref0 (target);
		_g_free0 (action_name);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_variant_unref0 (target);
		_g_free0 (action_name);
		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;
	}
	_tmp4_ = action_name;
	_tmp5_ = target;
	gtk_widget_activate_action_variant ((GtkWidget*) self, _tmp4_, _tmp5_);
	_g_variant_unref0 (target);
	_g_free0 (action_name);
}

GalaDaemonKeyButton*
gala_daemon_key_button_construct (GType object_type)
{
	GalaDaemonKeyButton * self = NULL;
	self = (GalaDaemonKeyButton*) granite_bin_construct (object_type);
	return self;
}

GalaDaemonKeyButton*
gala_daemon_key_button_new (void)
{
	return gala_daemon_key_button_construct (GALA_DAEMON_TYPE_KEY_BUTTON);
}

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

void
gala_daemon_key_button_set_key (GalaDaemonKeyButton* self,
                                GalaDaemonKey* value)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GalaDaemonKey* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gala_daemon_key_get_label (value);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		const gchar* _tmp2_;
		const gchar* _tmp3_;
		GtkLabel* _tmp4_;
		GtkLabel* _tmp5_;
		_tmp2_ = gala_daemon_key_get_label (value);
		_tmp3_ = _tmp2_;
		_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
		g_object_ref_sink (_tmp4_);
		_tmp5_ = _tmp4_;
		granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp5_);
		_g_object_unref0 (_tmp5_);
	} else {
		GIcon* _tmp6_;
		GIcon* _tmp7_;
		_tmp6_ = gala_daemon_key_get_icon (value);
		_tmp7_ = _tmp6_;
		if (_tmp7_ != NULL) {
			GIcon* _tmp8_;
			GIcon* _tmp9_;
			GtkImage* _tmp10_;
			GtkImage* _tmp11_;
			_tmp8_ = gala_daemon_key_get_icon (value);
			_tmp9_ = _tmp8_;
			_tmp10_ = (GtkImage*) gtk_image_new_from_gicon (_tmp9_);
			g_object_ref_sink (_tmp10_);
			_tmp11_ = _tmp10_;
			granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp11_);
			_g_object_unref0 (_tmp11_);
		} else {
			GtkLabel* _tmp12_;
			GtkLabel* _tmp13_;
			_tmp12_ = (GtkLabel*) gtk_label_new (_ ("Unknown Key"));
			g_object_ref_sink (_tmp12_);
			_tmp13_ = _tmp12_;
			granite_bin_set_child ((GraniteBin*) self, (GtkWidget*) _tmp13_);
			_g_object_unref0 (_tmp13_);
		}
	}
	_tmp14_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_key);
	self->priv->_key = _tmp14_;
	g_object_notify_by_pspec ((GObject *) self, gala_daemon_key_button_properties[GALA_DAEMON_KEY_BUTTON_KEY_PROPERTY]);
}

static void
_gala_daemon_key_button_on_pressed_gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                                              gint n_press,
                                                              gdouble x,
                                                              gdouble y,
                                                              gpointer self)
{
	gala_daemon_key_button_on_pressed ((GalaDaemonKeyButton*) self);
}

static void
_gala_daemon_key_button_on_released_gtk_gesture_click_released (GtkGestureClick* _sender,
                                                                gint n_press,
                                                                gdouble x,
                                                                gdouble y,
                                                                gpointer self)
{
	gala_daemon_key_button_on_released ((GalaDaemonKeyButton*) self);
}

static GObject *
gala_daemon_key_button_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonKeyButton * self;
	GtkGestureClick* click_gesture = NULL;
	GtkGestureClick* _tmp0_;
	GtkGestureClick* _tmp1_;
	GtkGestureClick* _tmp2_;
	GtkGestureClick* _tmp3_;
	GtkEventController* _tmp4_;
	parent_class = G_OBJECT_CLASS (gala_daemon_key_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButton);
	_tmp0_ = (GtkGestureClick*) gtk_gesture_click_new ();
	click_gesture = _tmp0_;
	_tmp1_ = click_gesture;
	g_signal_connect_object (_tmp1_, "pressed", (GCallback) _gala_daemon_key_button_on_pressed_gtk_gesture_click_pressed, self, 0);
	_tmp2_ = click_gesture;
	g_signal_connect_object (_tmp2_, "released", (GCallback) _gala_daemon_key_button_on_released_gtk_gesture_click_released, self, 0);
	_tmp3_ = click_gesture;
	_tmp4_ = _g_object_ref0 ((GtkEventController*) _tmp3_);
	gtk_widget_add_controller ((GtkWidget*) self, _tmp4_);
	gtk_widget_add_css_class ((GtkWidget*) self, "keycap");
	_g_object_unref0 (click_gesture);
	return obj;
}

static void
gala_daemon_key_button_base_init (GalaDaemonKeyButtonClass * klass)
{
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "button");
}

static void
gala_daemon_key_button_class_init (GalaDaemonKeyButtonClass * klass,
                                   gpointer klass_data)
{
	gala_daemon_key_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonKeyButton_private_offset);
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_daemon_key_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_key_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_key_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_KEY_BUTTON_KEY_PROPERTY, gala_daemon_key_button_properties[GALA_DAEMON_KEY_BUTTON_KEY_PROPERTY] = g_param_spec_object ("key", "key", "key", GALA_DAEMON_TYPE_KEY, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
gala_daemon_key_button_instance_init (GalaDaemonKeyButton * self,
                                      gpointer klass)
{
	self->priv = gala_daemon_key_button_get_instance_private (self);
}

static void
gala_daemon_key_button_finalize (GObject * obj)
{
	GalaDaemonKeyButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButton);
	_g_object_unref0 (self->priv->_key);
	G_OBJECT_CLASS (gala_daemon_key_button_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_key_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonKeyButtonClass), (GBaseInitFunc) gala_daemon_key_button_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_key_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonKeyButton), 0, (GInstanceInitFunc) gala_daemon_key_button_instance_init, NULL };
	GType gala_daemon_key_button_type_id;
	gala_daemon_key_button_type_id = g_type_register_static (GRANITE_TYPE_BIN, "GalaDaemonKeyButton", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaDaemonKeyButton_private_offset = g_type_add_instance_private (gala_daemon_key_button_type_id, sizeof (GalaDaemonKeyButtonPrivate));
	return gala_daemon_key_button_type_id;
}

GType
gala_daemon_key_button_get_type (void)
{
	static gsize gala_daemon_key_button_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_key_button_type_id__once)) {
		GType gala_daemon_key_button_type_id;
		gala_daemon_key_button_type_id = gala_daemon_key_button_get_type_once ();
		g_once_init_leave (&gala_daemon_key_button_type_id__once, gala_daemon_key_button_type_id);
	}
	return gala_daemon_key_button_type_id__once;
}

static void
_vala_gala_daemon_key_button_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	GalaDaemonKeyButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_KEY_BUTTON, GalaDaemonKeyButton);
	switch (property_id) {
		case GALA_DAEMON_KEY_BUTTON_KEY_PROPERTY:
		gala_daemon_key_button_set_key (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

