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

/*
 * Copyright 2024 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <handy.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>

#define GALA_DAEMON_MONITOR_LABEL_SPACING 12
#define GALA_DAEMON_MONITOR_LABEL_COLORED_STYLE_CSS "\n" \
"    .%s {\n" \
"        background-color: alpha(%s, 0.8);\n" \
"        color: %s;\n" \
"    }\n" \
"    "
#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_MONITOR_LABEL (gala_daemon_monitor_label_get_type ())
#define GALA_DAEMON_MONITOR_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabel))
#define GALA_DAEMON_MONITOR_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabelClass))
#define GALA_DAEMON_IS_MONITOR_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_MONITOR_LABEL))
#define GALA_DAEMON_IS_MONITOR_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_MONITOR_LABEL))
#define GALA_DAEMON_MONITOR_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabelClass))

typedef struct _GalaDaemonMonitorLabel GalaDaemonMonitorLabel;
typedef struct _GalaDaemonMonitorLabelClass GalaDaemonMonitorLabelClass;
typedef struct _GalaDaemonMonitorLabelPrivate GalaDaemonMonitorLabelPrivate;

#define GALA_DAEMON_TYPE_MONITOR_LABEL_INFO (gala_daemon_monitor_label_info_get_type ())
typedef struct _GalaDaemonMonitorLabelInfo GalaDaemonMonitorLabelInfo;
enum  {
	GALA_DAEMON_MONITOR_LABEL_0_PROPERTY,
	GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY,
	GALA_DAEMON_MONITOR_LABEL_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_monitor_label_properties[GALA_DAEMON_MONITOR_LABEL_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_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GalaDaemonMonitorLabel {
	HdyWindow parent_instance;
	GalaDaemonMonitorLabelPrivate * priv;
};

struct _GalaDaemonMonitorLabelClass {
	HdyWindowClass parent_class;
};

struct _GalaDaemonMonitorLabelInfo {
	gint monitor;
	gchar* label;
	gchar* background_color;
	gchar* text_color;
	gint x;
	gint y;
};

struct _GalaDaemonMonitorLabelPrivate {
	GalaDaemonMonitorLabelInfo _info;
};

static gint GalaDaemonMonitorLabel_private_offset;
static gpointer gala_daemon_monitor_label_parent_class = NULL;

VALA_EXTERN GType gala_daemon_monitor_label_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonMonitorLabel, g_object_unref)
VALA_EXTERN GType gala_daemon_monitor_label_info_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GalaDaemonMonitorLabelInfo* gala_daemon_monitor_label_info_dup (const GalaDaemonMonitorLabelInfo* self);
VALA_EXTERN void gala_daemon_monitor_label_info_free (GalaDaemonMonitorLabelInfo* self);
VALA_EXTERN void gala_daemon_monitor_label_info_copy (const GalaDaemonMonitorLabelInfo* self,
                                          GalaDaemonMonitorLabelInfo* dest);
VALA_EXTERN void gala_daemon_monitor_label_info_destroy (GalaDaemonMonitorLabelInfo* self);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (GalaDaemonMonitorLabelInfo, gala_daemon_monitor_label_info_destroy)
VALA_EXTERN GalaDaemonMonitorLabel* gala_daemon_monitor_label_new (GalaDaemonMonitorLabelInfo* info);
VALA_EXTERN GalaDaemonMonitorLabel* gala_daemon_monitor_label_construct (GType object_type,
                                                             GalaDaemonMonitorLabelInfo* info);
VALA_EXTERN void gala_daemon_monitor_label_get_info (GalaDaemonMonitorLabel* self,
                                         GalaDaemonMonitorLabelInfo * result);
static void gala_daemon_monitor_label_set_info (GalaDaemonMonitorLabel* self,
                                         GalaDaemonMonitorLabelInfo * value);
static gboolean _gala_daemon_monitor_label_info_equal (const GalaDaemonMonitorLabelInfo * s1,
                                                const GalaDaemonMonitorLabelInfo * s2);
static GObject * gala_daemon_monitor_label_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void gala_daemon_monitor_label_finalize (GObject * obj);
static GType gala_daemon_monitor_label_get_type_once (void);
static void _vala_gala_daemon_monitor_label_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_daemon_monitor_label_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gala_daemon_monitor_label_get_instance_private (GalaDaemonMonitorLabel* self)
{
	return G_STRUCT_MEMBER_P (self, GalaDaemonMonitorLabel_private_offset);
}

GalaDaemonMonitorLabel*
gala_daemon_monitor_label_construct (GType object_type,
                                     GalaDaemonMonitorLabelInfo* info)
{
	GalaDaemonMonitorLabel * self = NULL;
	GalaDaemonMonitorLabelInfo _tmp0_;
	g_return_val_if_fail (info != NULL, NULL);
	_tmp0_ = *info;
	self = (GalaDaemonMonitorLabel*) g_object_new (object_type, "info", &_tmp0_, NULL);
	return self;
}

GalaDaemonMonitorLabel*
gala_daemon_monitor_label_new (GalaDaemonMonitorLabelInfo* info)
{
	return gala_daemon_monitor_label_construct (GALA_DAEMON_TYPE_MONITOR_LABEL, info);
}

void
gala_daemon_monitor_label_get_info (GalaDaemonMonitorLabel* self,
                                    GalaDaemonMonitorLabelInfo * result)
{
	GalaDaemonMonitorLabelInfo _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_info;
	*result = _tmp0_;
	return;
}

static gboolean
_gala_daemon_monitor_label_info_equal (const GalaDaemonMonitorLabelInfo * s1,
                                       const GalaDaemonMonitorLabelInfo * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	if (s1->monitor != s2->monitor) {
		return FALSE;
	}
	if (g_strcmp0 (s1->label, s2->label)) {
		return FALSE;
	}
	if (g_strcmp0 (s1->background_color, s2->background_color)) {
		return FALSE;
	}
	if (g_strcmp0 (s1->text_color, s2->text_color)) {
		return FALSE;
	}
	if (s1->x != s2->x) {
		return FALSE;
	}
	if (s1->y != s2->y) {
		return FALSE;
	}
	return TRUE;
}

static void
gala_daemon_monitor_label_set_info (GalaDaemonMonitorLabel* self,
                                    GalaDaemonMonitorLabelInfo * value)
{
	GalaDaemonMonitorLabelInfo old_value;
	g_return_if_fail (self != NULL);
	gala_daemon_monitor_label_get_info (self, &old_value);
	if (_gala_daemon_monitor_label_info_equal (value, &old_value) != TRUE) {
		GalaDaemonMonitorLabelInfo _tmp0_;
		GalaDaemonMonitorLabelInfo _tmp1_;
		GalaDaemonMonitorLabelInfo _tmp2_ = {0};
		_tmp0_ = *value;
		_tmp1_ = _tmp0_;
		gala_daemon_monitor_label_info_copy (&_tmp1_, &_tmp2_);
		gala_daemon_monitor_label_info_destroy (&self->priv->_info);
		self->priv->_info = _tmp2_;
		g_object_notify_by_pspec ((GObject *) self, gala_daemon_monitor_label_properties[GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY]);
	}
}

static GObject *
gala_daemon_monitor_label_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaDaemonMonitorLabel * self;
	GalaDaemonMonitorLabelInfo _tmp0_;
	const gchar* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GalaDaemonMonitorLabelInfo _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gint scale_factor = 0;
	GtkStyleContext* _tmp7_;
	GalaDaemonMonitorLabelInfo _tmp8_;
	GalaDaemonMonitorLabelInfo _tmp9_;
	GtkCssProvider* provider = NULL;
	GtkCssProvider* _tmp10_;
	GError* _inner_error0_ = NULL;
	parent_class = G_OBJECT_CLASS (gala_daemon_monitor_label_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabel);
	_tmp0_ = self->priv->_info;
	_tmp1_ = _tmp0_.label;
	_tmp2_ = (GtkLabel*) gtk_label_new (_tmp1_);
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	g_object_set ((GtkContainer*) self, "child", (GtkWidget*) _tmp3_, NULL);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = self->priv->_info;
	_tmp5_ = g_strdup_printf ("LABEL-%i", _tmp4_.monitor);
	_tmp6_ = _tmp5_;
	gtk_window_set_title ((GtkWindow*) self, _tmp6_);
	_g_free0 (_tmp6_);
	gtk_widget_input_shape_combine_region ((GtkWidget*) self, NULL);
	gtk_window_set_accept_focus ((GtkWindow*) self, FALSE);
	gtk_window_set_decorated ((GtkWindow*) self, FALSE);
	gtk_window_set_resizable ((GtkWindow*) self, FALSE);
	gtk_window_set_deletable ((GtkWindow*) self, FALSE);
	gtk_widget_set_can_focus ((GtkWidget*) self, FALSE);
	gtk_window_set_skip_taskbar_hint ((GtkWindow*) self, TRUE);
	gtk_window_set_skip_pager_hint ((GtkWindow*) self, TRUE);
	gtk_window_set_type_hint ((GtkWindow*) self, GDK_WINDOW_TYPE_HINT_TOOLTIP);
	gtk_window_set_keep_above ((GtkWindow*) self, TRUE);
	gtk_window_stick ((GtkWindow*) self);
	_tmp7_ = gtk_widget_get_style_context ((GtkWidget*) self);
	scale_factor = gtk_style_context_get_scale (_tmp7_);
	_tmp8_ = self->priv->_info;
	_tmp9_ = self->priv->_info;
	gtk_window_move ((GtkWindow*) self, ((gint) (_tmp8_.x / scale_factor)) + GALA_DAEMON_MONITOR_LABEL_SPACING, ((gint) (_tmp9_.y / scale_factor)) + GALA_DAEMON_MONITOR_LABEL_SPACING);
	_tmp10_ = gtk_css_provider_new ();
	provider = _tmp10_;
	{
		GtkCssProvider* _tmp11_;
		const gchar* _tmp12_;
		const gchar* _tmp13_;
		GalaDaemonMonitorLabelInfo _tmp14_;
		const gchar* _tmp15_;
		GalaDaemonMonitorLabelInfo _tmp16_;
		const gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		GtkStyleContext* _tmp20_;
		const gchar* _tmp21_;
		const gchar* _tmp22_;
		GtkStyleContext* _tmp23_;
		GdkScreen* _tmp24_;
		GtkCssProvider* _tmp25_;
		_tmp11_ = provider;
		_tmp12_ = gtk_window_get_title ((GtkWindow*) self);
		_tmp13_ = _tmp12_;
		_tmp14_ = self->priv->_info;
		_tmp15_ = _tmp14_.background_color;
		_tmp16_ = self->priv->_info;
		_tmp17_ = _tmp16_.text_color;
		_tmp18_ = g_strdup_printf (GALA_DAEMON_MONITOR_LABEL_COLORED_STYLE_CSS, _tmp13_, _tmp15_, _tmp17_);
		_tmp19_ = _tmp18_;
		gtk_css_provider_load_from_data (_tmp11_, _tmp19_, (gssize) -1, &_inner_error0_);
		_g_free0 (_tmp19_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp20_ = gtk_widget_get_style_context ((GtkWidget*) self);
		_tmp21_ = gtk_window_get_title ((GtkWindow*) self);
		_tmp22_ = _tmp21_;
		gtk_style_context_add_class (_tmp20_, _tmp22_);
		_tmp23_ = gtk_widget_get_style_context ((GtkWidget*) self);
		gtk_style_context_add_class (_tmp23_, "monitor-label");
		_tmp24_ = gdk_screen_get_default ();
		_tmp25_ = provider;
		gtk_style_context_add_provider_for_screen (_tmp24_, (GtkStyleProvider*) _tmp25_, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp26_;
		const gchar* _tmp27_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp26_ = e;
		_tmp27_ = _tmp26_->message;
		g_warning ("MonitorLabel.vala:57: Failed to load CSS: %s", _tmp27_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (provider);
		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_);
	}
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (provider);
	return obj;
}

static void
gala_daemon_monitor_label_class_init (GalaDaemonMonitorLabelClass * klass,
                                      gpointer klass_data)
{
	gala_daemon_monitor_label_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaDaemonMonitorLabel_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_daemon_monitor_label_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_daemon_monitor_label_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_daemon_monitor_label_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_daemon_monitor_label_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY, gala_daemon_monitor_label_properties[GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY] = g_param_spec_boxed ("info", "info", "info", GALA_DAEMON_TYPE_MONITOR_LABEL_INFO, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
gala_daemon_monitor_label_instance_init (GalaDaemonMonitorLabel * self,
                                         gpointer klass)
{
	self->priv = gala_daemon_monitor_label_get_instance_private (self);
}

static void
gala_daemon_monitor_label_finalize (GObject * obj)
{
	GalaDaemonMonitorLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabel);
	gala_daemon_monitor_label_info_destroy (&self->priv->_info);
	G_OBJECT_CLASS (gala_daemon_monitor_label_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_daemon_monitor_label_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonMonitorLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_monitor_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonMonitorLabel), 0, (GInstanceInitFunc) gala_daemon_monitor_label_instance_init, NULL };
	GType gala_daemon_monitor_label_type_id;
	gala_daemon_monitor_label_type_id = g_type_register_static (hdy_window_get_type (), "GalaDaemonMonitorLabel", &g_define_type_info, 0);
	GalaDaemonMonitorLabel_private_offset = g_type_add_instance_private (gala_daemon_monitor_label_type_id, sizeof (GalaDaemonMonitorLabelPrivate));
	return gala_daemon_monitor_label_type_id;
}

GType
gala_daemon_monitor_label_get_type (void)
{
	static gsize gala_daemon_monitor_label_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_monitor_label_type_id__once)) {
		GType gala_daemon_monitor_label_type_id;
		gala_daemon_monitor_label_type_id = gala_daemon_monitor_label_get_type_once ();
		g_once_init_leave (&gala_daemon_monitor_label_type_id__once, gala_daemon_monitor_label_type_id);
	}
	return gala_daemon_monitor_label_type_id__once;
}

static void
_vala_gala_daemon_monitor_label_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonMonitorLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabel);
	switch (property_id) {
		case GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY:
		{
			GalaDaemonMonitorLabelInfo boxed;
			gala_daemon_monitor_label_get_info (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_daemon_monitor_label_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaDaemonMonitorLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_DAEMON_TYPE_MONITOR_LABEL, GalaDaemonMonitorLabel);
	switch (property_id) {
		case GALA_DAEMON_MONITOR_LABEL_INFO_PROPERTY:
		gala_daemon_monitor_label_set_info (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

