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

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2013 Tom Beckmann
 *                         2013 Rico Tzschichholz
 *                         2025 elementary, Inc. (https://elementary.io)
 */

#include <meta/meta-background-group.h>
#include <glib-object.h>
#include <meta/display.h>
#include <meta/meta-monitor-manager.h>
#include <meta/meta-context.h>
#include <meta/meta-backend.h>
#include <glib.h>
#include <clutter/clutter.h>
#include <float.h>
#include <math.h>
#include <stdlib.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
#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_BACKGROUND_CONTAINER (gala_background_container_get_type ())
#define GALA_BACKGROUND_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer))
#define GALA_BACKGROUND_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainerClass))
#define GALA_IS_BACKGROUND_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_BACKGROUND_CONTAINER))
#define GALA_IS_BACKGROUND_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_BACKGROUND_CONTAINER))
#define GALA_BACKGROUND_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainerClass))

typedef struct _GalaBackgroundContainer GalaBackgroundContainer;
typedef struct _GalaBackgroundContainerClass GalaBackgroundContainerClass;
typedef struct _GalaBackgroundContainerPrivate GalaBackgroundContainerPrivate;
enum  {
	GALA_BACKGROUND_CONTAINER_0_PROPERTY,
	GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY,
	GALA_BACKGROUND_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* gala_background_container_properties[GALA_BACKGROUND_CONTAINER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_TYPE_BACKGROUND_MANAGER (gala_background_manager_get_type ())
#define GALA_BACKGROUND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManager))
#define GALA_BACKGROUND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManagerClass))
#define GALA_IS_BACKGROUND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_BACKGROUND_MANAGER))
#define GALA_IS_BACKGROUND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_BACKGROUND_MANAGER))
#define GALA_BACKGROUND_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManagerClass))

typedef struct _GalaBackgroundManager GalaBackgroundManager;
typedef struct _GalaBackgroundManagerClass GalaBackgroundManagerClass;
#define __vala_ClutterColor_free0(var) ((var == NULL) ? NULL : (var = (_vala_ClutterColor_free (var), NULL)))
enum  {
	GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL,
	GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL,
	GALA_BACKGROUND_CONTAINER_NUM_SIGNALS
};
static guint gala_background_container_signals[GALA_BACKGROUND_CONTAINER_NUM_SIGNALS] = {0};

struct _GalaBackgroundContainer {
	MetaBackgroundGroup parent_instance;
	GalaBackgroundContainerPrivate * priv;
};

struct _GalaBackgroundContainerClass {
	MetaBackgroundGroupClass parent_class;
};

struct _GalaBackgroundContainerPrivate {
	MetaDisplay* _display;
};

static gint GalaBackgroundContainer_private_offset;
static gpointer gala_background_container_parent_class = NULL;

VALA_EXTERN GType gala_background_container_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaBackgroundContainer, g_object_unref)
VALA_EXTERN MetaDisplay* gala_background_container_get_display (GalaBackgroundContainer* self);
static void gala_background_container_update (GalaBackgroundContainer* self);
static void _gala_background_container_update_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                              gpointer self);
VALA_EXTERN GalaBackgroundContainer* gala_background_container_new (MetaDisplay* display);
VALA_EXTERN GalaBackgroundContainer* gala_background_container_construct (GType object_type,
                                                              MetaDisplay* display);
VALA_EXTERN GType gala_background_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaBackgroundManager, g_object_unref)
static void gala_background_container_background_changed (GalaBackgroundContainer* self);
static void _gala_background_container_background_changed_gala_background_manager_changed (GalaBackgroundManager* _sender,
                                                                                    gpointer self);
VALA_EXTERN GalaBackgroundManager* gala_background_manager_new (MetaDisplay* display,
                                                    gint monitor_index,
                                                    gboolean control_position,
                                                    gboolean rounded_corners);
VALA_EXTERN GalaBackgroundManager* gala_background_manager_construct (GType object_type,
                                                          MetaDisplay* display,
                                                          gint monitor_index,
                                                          gboolean control_position,
                                                          gboolean rounded_corners);
static void gala_background_container_set_display (GalaBackgroundContainer* self,
                                            MetaDisplay* value);
static void g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data);
static GObject * gala_background_container_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static gboolean _gala_background_container___lambda114_ (GalaBackgroundContainer* self,
                                                  ClutterEvent* event);
static gboolean __gala_background_container___lambda114__clutter_actor_button_release_event (ClutterActor* _sender,
                                                                                      ClutterEvent* event,
                                                                                      gpointer self);
static void _vala_ClutterColor_free (ClutterColor* self);
static void gala_background_container_finalize (GObject * obj);
static GType gala_background_container_get_type_once (void);
static void _vala_gala_background_container_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_background_container_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gala_background_container_get_instance_private (GalaBackgroundContainer* self)
{
	return G_STRUCT_MEMBER_P (self, GalaBackgroundContainer_private_offset);
}

static void
_gala_background_container_update_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                         gpointer self)
{
	gala_background_container_update ((GalaBackgroundContainer*) self);
}

GalaBackgroundContainer*
gala_background_container_construct (GType object_type,
                                     MetaDisplay* display)
{
	GalaBackgroundContainer * self = NULL;
	g_return_val_if_fail (display != NULL, NULL);
	self = (GalaBackgroundContainer*) g_object_new (object_type, "display", display, NULL);
	return self;
}

GalaBackgroundContainer*
gala_background_container_new (MetaDisplay* display)
{
	return gala_background_container_construct (GALA_TYPE_BACKGROUND_CONTAINER, display);
}

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

static void
_gala_background_container_background_changed_gala_background_manager_changed (GalaBackgroundManager* _sender,
                                                                               gpointer self)
{
	gala_background_container_background_changed ((GalaBackgroundContainer*) self);
}

static void
gala_background_container_update (GalaBackgroundContainer* self)
{
	GalaBackgroundManager* reference_child = NULL;
	ClutterActor* _tmp0_;
	GalaBackgroundManager* _tmp1_;
	GalaBackgroundManager* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = clutter_actor_get_child_at_index ((ClutterActor*) self, 0);
	_tmp1_ = _g_object_ref0 (GALA_IS_BACKGROUND_MANAGER (_tmp0_) ? ((GalaBackgroundManager*) _tmp0_) : NULL);
	reference_child = _tmp1_;
	_tmp2_ = reference_child;
	if (_tmp2_ != NULL) {
		GalaBackgroundManager* _tmp3_;
		guint _tmp4_;
		_tmp3_ = reference_child;
		g_signal_parse_name ("changed", GALA_TYPE_BACKGROUND_MANAGER, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _gala_background_container_background_changed_gala_background_manager_changed, self);
	}
	clutter_actor_destroy_all_children ((ClutterActor*) self);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				MetaDisplay* _tmp7_;
				GalaBackgroundManager* background = NULL;
				MetaDisplay* _tmp8_;
				GalaBackgroundManager* _tmp9_;
				GalaBackgroundManager* _tmp10_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->priv->_display;
				if (!(i < meta_display_get_n_monitors (_tmp7_))) {
					break;
				}
				_tmp8_ = self->priv->_display;
				_tmp9_ = gala_background_manager_new (_tmp8_, i, TRUE, TRUE);
				g_object_ref_sink (_tmp9_);
				background = _tmp9_;
				_tmp10_ = background;
				clutter_actor_add_child ((ClutterActor*) self, (ClutterActor*) _tmp10_);
				if (i == 0) {
					GalaBackgroundManager* _tmp11_;
					_tmp11_ = background;
					g_signal_connect_object (_tmp11_, "changed", (GCallback) _gala_background_container_background_changed_gala_background_manager_changed, self, 0);
				}
				_g_object_unref0 (background);
			}
		}
	}
	_g_object_unref0 (reference_child);
}

static void
gala_background_container_background_changed (GalaBackgroundContainer* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, gala_background_container_signals[GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL], 0);
}

MetaDisplay*
gala_background_container_get_display (GalaBackgroundContainer* self)
{
	MetaDisplay* result;
	MetaDisplay* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_display;
	result = _tmp0_;
	return result;
}

static void
gala_background_container_set_display (GalaBackgroundContainer* self,
                                       MetaDisplay* value)
{
	MetaDisplay* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_background_container_get_display (self);
	if (old_value != value) {
		MetaDisplay* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_display);
		self->priv->_display = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_background_container_properties[GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                       GValue * return_value,
                                       guint n_param_values,
                                       const GValue * param_values,
                                       gpointer invocation_hint,
                                       gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1, gint arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), data2);
}

static gboolean
_gala_background_container___lambda114_ (GalaBackgroundContainer* self,
                                         ClutterEvent* event)
{
	gfloat x = 0.0F;
	gfloat y = 0.0F;
	gfloat _tmp0_ = 0.0F;
	gfloat _tmp1_ = 0.0F;
	gboolean result;
	g_return_val_if_fail (event != NULL, FALSE);
	clutter_event_get_coords (event, &_tmp0_, &_tmp1_);
	x = _tmp0_;
	y = _tmp1_;
	if (clutter_event_get_button (event) == CLUTTER_BUTTON_SECONDARY) {
		g_signal_emit (self, gala_background_container_signals[GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL], 0, (gint) x, (gint) y);
	}
	result = G_SOURCE_CONTINUE;
	return result;
}

static gboolean
__gala_background_container___lambda114__clutter_actor_button_release_event (ClutterActor* _sender,
                                                                             ClutterEvent* event,
                                                                             gpointer self)
{
	gboolean result;
	result = _gala_background_container___lambda114_ ((GalaBackgroundContainer*) self, event);
	return result;
}

static ClutterColor*
_vala_clutter_color_from_string (const gchar* str)
{
	ClutterColor* color = NULL;
	ClutterColor* _tmp0_;
	ClutterColor* result;
	g_return_val_if_fail (str != NULL, NULL);
	_tmp0_ = clutter_color_alloc ();
	color = _tmp0_;
	clutter_color_from_string (color, str);
	result = color;
	return result;
}

static void
_vala_ClutterColor_free (ClutterColor* self)
{
	g_boxed_free (clutter_color_get_type (), self);
}

static GObject *
gala_background_container_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaBackgroundContainer * self;
	MetaMonitorManager* monitor_manager = NULL;
	MetaDisplay* _tmp0_;
	MetaContext* _tmp1_;
	MetaBackend* _tmp2_;
	MetaMonitorManager* _tmp3_;
	MetaMonitorManager* _tmp4_;
	ClutterColor* _tmp5_;
	ClutterColor* _tmp6_;
	ClutterColor _tmp7_;
	parent_class = G_OBJECT_CLASS (gala_background_container_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	_tmp0_ = self->priv->_display;
	_tmp1_ = meta_display_get_context (_tmp0_);
	_tmp2_ = meta_context_get_backend (_tmp1_);
	_tmp3_ = meta_backend_get_monitor_manager (_tmp2_);
	monitor_manager = _tmp3_;
	_tmp4_ = monitor_manager;
	g_signal_connect_object (_tmp4_, "monitors-changed", (GCallback) _gala_background_container_update_meta_monitor_manager_monitors_changed, self, 0);
	clutter_actor_set_reactive ((ClutterActor*) self, TRUE);
	g_signal_connect_object ((ClutterActor*) self, "button-release-event", (GCallback) __gala_background_container___lambda114__clutter_actor_button_release_event, self, 0);
	_tmp5_ = _vala_clutter_color_from_string ("Black");
	_tmp6_ = _tmp5_;
	_tmp7_ = *_tmp6_;
	clutter_actor_set_background_color ((ClutterActor*) self, &_tmp7_);
	__vala_ClutterColor_free0 (_tmp6_);
	gala_background_container_update (self);
	return obj;
}

static void
gala_background_container_class_init (GalaBackgroundContainerClass * klass,
                                      gpointer klass_data)
{
	gala_background_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaBackgroundContainer_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_background_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_background_container_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_background_container_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_background_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY, gala_background_container_properties[GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY] = g_param_spec_object ("display", "display", "display", meta_display_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	gala_background_container_signals[GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL] = g_signal_new ("changed", GALA_TYPE_BACKGROUND_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gala_background_container_signals[GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL] = g_signal_new ("show-background-menu", GALA_TYPE_BACKGROUND_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
}

static void
gala_background_container_instance_init (GalaBackgroundContainer * self,
                                         gpointer klass)
{
	self->priv = gala_background_container_get_instance_private (self);
}

static void
gala_background_container_finalize (GObject * obj)
{
	GalaBackgroundContainer * self;
	MetaMonitorManager* monitor_manager = NULL;
	MetaDisplay* _tmp0_;
	MetaContext* _tmp1_;
	MetaBackend* _tmp2_;
	MetaMonitorManager* _tmp3_;
	MetaMonitorManager* _tmp4_;
	guint _tmp5_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	_tmp0_ = self->priv->_display;
	_tmp1_ = meta_display_get_context (_tmp0_);
	_tmp2_ = meta_context_get_backend (_tmp1_);
	_tmp3_ = meta_backend_get_monitor_manager (_tmp2_);
	monitor_manager = _tmp3_;
	_tmp4_ = monitor_manager;
	g_signal_parse_name ("monitors-changed", meta_monitor_manager_get_type (), &_tmp5_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp4_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp5_, 0, NULL, (GCallback) _gala_background_container_update_meta_monitor_manager_monitors_changed, self);
	_g_object_unref0 (self->priv->_display);
	G_OBJECT_CLASS (gala_background_container_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_background_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaBackgroundContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_background_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaBackgroundContainer), 0, (GInstanceInitFunc) gala_background_container_instance_init, NULL };
	GType gala_background_container_type_id;
	gala_background_container_type_id = g_type_register_static (meta_background_group_get_type (), "GalaBackgroundContainer", &g_define_type_info, 0);
	GalaBackgroundContainer_private_offset = g_type_add_instance_private (gala_background_container_type_id, sizeof (GalaBackgroundContainerPrivate));
	return gala_background_container_type_id;
}

GType
gala_background_container_get_type (void)
{
	static gsize gala_background_container_type_id__once = 0;
	if (g_once_init_enter (&gala_background_container_type_id__once)) {
		GType gala_background_container_type_id;
		gala_background_container_type_id = gala_background_container_get_type_once ();
		g_once_init_leave (&gala_background_container_type_id__once, gala_background_container_type_id);
	}
	return gala_background_container_type_id__once;
}

static void
_vala_gala_background_container_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaBackgroundContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	switch (property_id) {
		case GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY:
		g_value_set_object (value, gala_background_container_get_display (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_background_container_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaBackgroundContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	switch (property_id) {
		case GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY:
		gala_background_container_set_display (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

