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

/*
 * Copyright 2023-2025 elementary, Inc. <https://elementary.io>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <clutter/clutter.h>
#include <glib-object.h>
#include <meta/window.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include "gala.h"
#include <atk/atk.h>
#include <stdlib.h>
#include <string.h>

#define GALA_WINDOW_SWITCHER_ICON_ICON_SIZE 64
#define GALA_WINDOW_SWITCHER_ICON_WRAPPER_BORDER_RADIUS 3
#define GALA_WINDOW_SWITCHER_WRAPPER_PADDING 12
#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_TYPE_WINDOW_SWITCHER_ICON (gala_window_switcher_icon_get_type ())
#define GALA_WINDOW_SWITCHER_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIcon))
#define GALA_WINDOW_SWITCHER_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIconClass))
#define GALA_IS_WINDOW_SWITCHER_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_WINDOW_SWITCHER_ICON))
#define GALA_IS_WINDOW_SWITCHER_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_WINDOW_SWITCHER_ICON))
#define GALA_WINDOW_SWITCHER_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIconClass))

typedef struct _GalaWindowSwitcherIcon GalaWindowSwitcherIcon;
typedef struct _GalaWindowSwitcherIconClass GalaWindowSwitcherIconClass;
typedef struct _GalaWindowSwitcherIconPrivate GalaWindowSwitcherIconPrivate;
enum  {
	GALA_WINDOW_SWITCHER_ICON_0_PROPERTY,
	GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY,
	GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY,
	GALA_WINDOW_SWITCHER_ICON_SELECTED_PROPERTY,
	GALA_WINDOW_SWITCHER_ICON_NUM_PROPERTIES
};
static GParamSpec* gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GalaWindowSwitcherIcon {
	ClutterActor parent_instance;
	GalaWindowSwitcherIconPrivate * priv;
};

struct _GalaWindowSwitcherIconClass {
	ClutterActorClass parent_class;
};

struct _GalaWindowSwitcherIconPrivate {
	MetaWindow* _window;
	gfloat _monitor_scale;
};

static gint GalaWindowSwitcherIcon_private_offset;
static gpointer gala_window_switcher_icon_parent_class = NULL;

VALA_EXTERN GType gala_window_switcher_icon_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaWindowSwitcherIcon, g_object_unref)
VALA_EXTERN GalaWindowSwitcherIcon* gala_window_switcher_icon_new (MetaWindow* window,
                                                       gfloat monitor_scale);
VALA_EXTERN GalaWindowSwitcherIcon* gala_window_switcher_icon_construct (GType object_type,
                                                             MetaWindow* window,
                                                             gfloat monitor_scale);
static void gala_window_switcher_icon_reload_icon (GalaWindowSwitcherIcon* self);
VALA_EXTERN gfloat gala_window_switcher_icon_get_monitor_scale (GalaWindowSwitcherIcon* self);
VALA_EXTERN MetaWindow* gala_window_switcher_icon_get_window (GalaWindowSwitcherIcon* self);
static void gala_window_switcher_icon_set_window (GalaWindowSwitcherIcon* self,
                                           MetaWindow* value);
VALA_EXTERN void gala_window_switcher_icon_set_monitor_scale (GalaWindowSwitcherIcon* self,
                                                  gfloat value);
VALA_EXTERN void gala_window_switcher_icon_set_selected (GalaWindowSwitcherIcon* self,
                                             gboolean value);
static GObject * gala_window_switcher_icon_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void _gala_window_switcher_icon_reload_icon_g_object_notify (GObject* _sender,
                                                             GParamSpec* pspec,
                                                             gpointer self);
static void gala_window_switcher_icon_finalize (GObject * obj);
static GType gala_window_switcher_icon_get_type_once (void);
static void _vala_gala_window_switcher_icon_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_window_switcher_icon_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gala_window_switcher_icon_get_instance_private (GalaWindowSwitcherIcon* self)
{
	return G_STRUCT_MEMBER_P (self, GalaWindowSwitcherIcon_private_offset);
}

GalaWindowSwitcherIcon*
gala_window_switcher_icon_construct (GType object_type,
                                     MetaWindow* window,
                                     gfloat monitor_scale)
{
	GalaWindowSwitcherIcon * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (GalaWindowSwitcherIcon*) g_object_new (object_type, "window", window, "monitor-scale", monitor_scale, NULL);
	return self;
}

GalaWindowSwitcherIcon*
gala_window_switcher_icon_new (MetaWindow* window,
                               gfloat monitor_scale)
{
	return gala_window_switcher_icon_construct (GALA_TYPE_WINDOW_SWITCHER_ICON, window, monitor_scale);
}

static void
gala_window_switcher_icon_reload_icon (GalaWindowSwitcherIcon* self)
{
	gint margin = 0;
	gfloat _tmp0_;
	GalaWindowIcon* icon = NULL;
	MetaWindow* _tmp1_;
	gfloat _tmp2_;
	GalaWindowIcon* _tmp3_ = NULL;
	g_return_if_fail (self != NULL);
	clutter_actor_remove_all_children ((ClutterActor*) self);
	_tmp0_ = self->priv->_monitor_scale;
	margin = gala_utils_scale_to_int (GALA_WINDOW_SWITCHER_WRAPPER_PADDING, _tmp0_);
	_tmp1_ = self->priv->_window;
	_tmp2_ = self->priv->_monitor_scale;
	_tmp3_ = gala_window_icon_new (_tmp1_, gala_utils_scale_to_int (GALA_WINDOW_SWITCHER_ICON_ICON_SIZE, _tmp2_), 1);
	clutter_actor_set_margin_top ((ClutterActor*) _tmp3_, (gfloat) margin);
	clutter_actor_set_margin_right ((ClutterActor*) _tmp3_, (gfloat) margin);
	clutter_actor_set_margin_bottom ((ClutterActor*) _tmp3_, (gfloat) margin);
	clutter_actor_set_margin_left ((ClutterActor*) _tmp3_, (gfloat) margin);
	g_object_ref_sink (_tmp3_);
	icon = _tmp3_;
	clutter_actor_add_child ((ClutterActor*) self, (ClutterActor*) icon);
	_g_object_unref0 (icon);
}

MetaWindow*
gala_window_switcher_icon_get_window (GalaWindowSwitcherIcon* self)
{
	MetaWindow* result;
	MetaWindow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_window;
	result = _tmp0_;
	return result;
}

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

static void
gala_window_switcher_icon_set_window (GalaWindowSwitcherIcon* self,
                                      MetaWindow* value)
{
	MetaWindow* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_window_switcher_icon_get_window (self);
	if (old_value != value) {
		MetaWindow* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_window);
		self->priv->_window = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY]);
	}
}

gfloat
gala_window_switcher_icon_get_monitor_scale (GalaWindowSwitcherIcon* self)
{
	gfloat result;
	g_return_val_if_fail (self != NULL, 0.0F);
	result = self->priv->_monitor_scale;
	return result;
}

void
gala_window_switcher_icon_set_monitor_scale (GalaWindowSwitcherIcon* self,
                                             gfloat value)
{
	gfloat old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_window_switcher_icon_get_monitor_scale (self);
	if (old_value != value) {
		self->priv->_monitor_scale = value;
		g_object_notify_by_pspec ((GObject *) self, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY]);
	}
}

void
gala_window_switcher_icon_set_selected (GalaWindowSwitcherIcon* self,
                                        gboolean value)
{
	AtkObject* _tmp4_;
	AtkObject* _tmp5_;
	g_return_if_fail (self != NULL);
	if (value) {
		GalaDrawingStyleManager* _tmp0_;
		ClutterColor _tmp1_ = {0};
		ClutterColor _tmp2_;
		_tmp0_ = gala_drawing_style_manager_get_instance ();
		gala_drawing_style_manager_get_theme_accent_color (_tmp0_, &_tmp1_);
		_tmp2_ = _tmp1_;
		clutter_actor_set_background_color ((ClutterActor*) self, &_tmp2_);
	} else {
		ClutterColor _tmp3_ = {0};
		_tmp3_.red = (guint8) 0;
		_tmp3_.green = (guint8) 0;
		_tmp3_.blue = (guint8) 0;
		_tmp3_.alpha = (guint8) 0;
		clutter_actor_set_background_color ((ClutterActor*) self, &_tmp3_);
	}
	_tmp4_ = clutter_actor_get_accessible ((ClutterActor*) self);
	atk_object_notify_state_change (_tmp4_, (AtkState) ATK_STATE_SELECTED, value);
	_tmp5_ = clutter_actor_get_accessible ((ClutterActor*) self);
	atk_object_notify_state_change (_tmp5_, (AtkState) ATK_STATE_FOCUSED, value);
	g_object_notify_by_pspec ((GObject *) self, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_SELECTED_PROPERTY]);
}

static void
_gala_window_switcher_icon_reload_icon_g_object_notify (GObject* _sender,
                                                        GParamSpec* pspec,
                                                        gpointer self)
{
	gala_window_switcher_icon_reload_icon ((GalaWindowSwitcherIcon*) self);
}

static GObject *
gala_window_switcher_icon_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaWindowSwitcherIcon * self;
	ClutterBinLayout* _tmp0_;
	ClutterBinLayout* _tmp1_;
	GalaRoundedCornersEffect* rounded_corners_effect = NULL;
	gfloat _tmp2_;
	GalaRoundedCornersEffect* _tmp3_;
	GalaRoundedCornersEffect* _tmp4_;
	GalaRoundedCornersEffect* _tmp5_;
	AtkObject* _tmp6_;
	MetaWindow* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	AtkObject* _tmp10_;
	AtkObject* _tmp11_;
	parent_class = G_OBJECT_CLASS (gala_window_switcher_icon_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIcon);
	_tmp0_ = (ClutterBinLayout*) clutter_bin_layout_new ();
	g_object_ref_sink (_tmp0_);
	_tmp1_ = _tmp0_;
	clutter_actor_set_layout_manager ((ClutterActor*) self, (ClutterLayoutManager*) _tmp1_);
	_g_object_unref0 (_tmp1_);
	clutter_actor_set_reactive ((ClutterActor*) self, TRUE);
	gala_window_switcher_icon_reload_icon (self);
	_tmp2_ = self->priv->_monitor_scale;
	_tmp3_ = gala_rounded_corners_effect_new (GALA_WINDOW_SWITCHER_ICON_WRAPPER_BORDER_RADIUS, _tmp2_);
	g_object_ref_sink (_tmp3_);
	rounded_corners_effect = _tmp3_;
	_tmp4_ = rounded_corners_effect;
	g_object_bind_property_with_closures ((GObject*) self, "monitor-scale", (GObject*) _tmp4_, "monitor-scale", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp5_ = rounded_corners_effect;
	clutter_actor_add_effect ((ClutterActor*) self, (ClutterEffect*) _tmp5_);
	_tmp6_ = clutter_actor_get_accessible ((ClutterActor*) self);
	_tmp7_ = self->priv->_window;
	_tmp8_ = meta_window_get_title (_tmp7_);
	_tmp9_ = _tmp8_;
	g_object_set (_tmp6_, "accessible-name", _tmp9_, NULL);
	_tmp10_ = clutter_actor_get_accessible ((ClutterActor*) self);
	g_object_set (_tmp10_, "accessible-role", ATK_ROLE_LIST_ITEM, NULL);
	_tmp11_ = clutter_actor_get_accessible ((ClutterActor*) self);
	atk_object_notify_state_change (_tmp11_, (AtkState) ATK_STATE_FOCUSABLE, TRUE);
	g_signal_connect_object ((GObject*) self, "notify::monitor-scale", (GCallback) _gala_window_switcher_icon_reload_icon_g_object_notify, self, 0);
	_g_object_unref0 (rounded_corners_effect);
	return obj;
}

static void
gala_window_switcher_icon_class_init (GalaWindowSwitcherIconClass * klass,
                                      gpointer klass_data)
{
	gala_window_switcher_icon_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaWindowSwitcherIcon_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_window_switcher_icon_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_window_switcher_icon_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_window_switcher_icon_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_window_switcher_icon_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY] = g_param_spec_object ("window", "window", "window", meta_window_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY] = g_param_spec_float ("monitor-scale", "monitor-scale", "monitor-scale", -G_MAXFLOAT, G_MAXFLOAT, 0.0F, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_WINDOW_SWITCHER_ICON_SELECTED_PROPERTY, gala_window_switcher_icon_properties[GALA_WINDOW_SWITCHER_ICON_SELECTED_PROPERTY] = g_param_spec_boolean ("selected", "selected", "selected", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
}

static void
gala_window_switcher_icon_instance_init (GalaWindowSwitcherIcon * self,
                                         gpointer klass)
{
	self->priv = gala_window_switcher_icon_get_instance_private (self);
}

static void
gala_window_switcher_icon_finalize (GObject * obj)
{
	GalaWindowSwitcherIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIcon);
	_g_object_unref0 (self->priv->_window);
	G_OBJECT_CLASS (gala_window_switcher_icon_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_window_switcher_icon_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaWindowSwitcherIconClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_window_switcher_icon_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaWindowSwitcherIcon), 0, (GInstanceInitFunc) gala_window_switcher_icon_instance_init, NULL };
	GType gala_window_switcher_icon_type_id;
	gala_window_switcher_icon_type_id = g_type_register_static (clutter_actor_get_type (), "GalaWindowSwitcherIcon", &g_define_type_info, 0);
	GalaWindowSwitcherIcon_private_offset = g_type_add_instance_private (gala_window_switcher_icon_type_id, sizeof (GalaWindowSwitcherIconPrivate));
	return gala_window_switcher_icon_type_id;
}

GType
gala_window_switcher_icon_get_type (void)
{
	static gsize gala_window_switcher_icon_type_id__once = 0;
	if (g_once_init_enter (&gala_window_switcher_icon_type_id__once)) {
		GType gala_window_switcher_icon_type_id;
		gala_window_switcher_icon_type_id = gala_window_switcher_icon_get_type_once ();
		g_once_init_leave (&gala_window_switcher_icon_type_id__once, gala_window_switcher_icon_type_id);
	}
	return gala_window_switcher_icon_type_id__once;
}

static void
_vala_gala_window_switcher_icon_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaWindowSwitcherIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIcon);
	switch (property_id) {
		case GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY:
		g_value_set_object (value, gala_window_switcher_icon_get_window (self));
		break;
		case GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY:
		g_value_set_float (value, gala_window_switcher_icon_get_monitor_scale (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_window_switcher_icon_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaWindowSwitcherIcon * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_WINDOW_SWITCHER_ICON, GalaWindowSwitcherIcon);
	switch (property_id) {
		case GALA_WINDOW_SWITCHER_ICON_WINDOW_PROPERTY:
		gala_window_switcher_icon_set_window (self, g_value_get_object (value));
		break;
		case GALA_WINDOW_SWITCHER_ICON_MONITOR_SCALE_PROPERTY:
		gala_window_switcher_icon_set_monitor_scale (self, g_value_get_float (value));
		break;
		case GALA_WINDOW_SWITCHER_ICON_SELECTED_PROPERTY:
		gala_window_switcher_icon_set_selected (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

