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

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

#include <glib-object.h>
#include <mtk/mtk.h>
#include <glib.h>
#include <meta/window.h>
#include <meta/display.h>

#define GALA_MONITOR_LABEL_WINDOW_MARGIN 24
#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_POSITIONED_WINDOW (gala_positioned_window_get_type ())
#define GALA_POSITIONED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindow))
#define GALA_POSITIONED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindowClass))
#define GALA_IS_POSITIONED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_POSITIONED_WINDOW))
#define GALA_IS_POSITIONED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_POSITIONED_WINDOW))
#define GALA_POSITIONED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindowClass))

typedef struct _GalaPositionedWindow GalaPositionedWindow;
typedef struct _GalaPositionedWindowClass GalaPositionedWindowClass;
typedef struct _GalaPositionedWindowPrivate GalaPositionedWindowPrivate;

#define GALA_TYPE_MONITOR_LABEL_WINDOW (gala_monitor_label_window_get_type ())
#define GALA_MONITOR_LABEL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindow))
#define GALA_MONITOR_LABEL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindowClass))
#define GALA_IS_MONITOR_LABEL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_MONITOR_LABEL_WINDOW))
#define GALA_IS_MONITOR_LABEL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_MONITOR_LABEL_WINDOW))
#define GALA_MONITOR_LABEL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindowClass))

typedef struct _GalaMonitorLabelWindow GalaMonitorLabelWindow;
typedef struct _GalaMonitorLabelWindowClass GalaMonitorLabelWindowClass;
typedef struct _GalaMonitorLabelWindowPrivate GalaMonitorLabelWindowPrivate;
enum  {
	GALA_MONITOR_LABEL_WINDOW_0_PROPERTY,
	GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY,
	GALA_MONITOR_LABEL_WINDOW_NUM_PROPERTIES
};
static GParamSpec* gala_monitor_label_window_properties[GALA_MONITOR_LABEL_WINDOW_NUM_PROPERTIES];

struct _GalaPositionedWindow {
	GObject parent_instance;
	GalaPositionedWindowPrivate * priv;
};

struct _GalaPositionedWindowClass {
	GObjectClass parent_class;
	void (*get_window_position) (GalaPositionedWindow* self, MtkRectangle* window_rect, gint* x, gint* y);
};

struct _GalaMonitorLabelWindow {
	GalaPositionedWindow parent_instance;
	GalaMonitorLabelWindowPrivate * priv;
};

struct _GalaMonitorLabelWindowClass {
	GalaPositionedWindowClass parent_class;
};

struct _GalaMonitorLabelWindowPrivate {
	gint _monitor_index;
};

static gint GalaMonitorLabelWindow_private_offset;
static gpointer gala_monitor_label_window_parent_class = NULL;

VALA_EXTERN GType gala_positioned_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaPositionedWindow, g_object_unref)
VALA_EXTERN GType gala_monitor_label_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaMonitorLabelWindow, g_object_unref)
VALA_EXTERN void gala_positioned_window_get_window_position (GalaPositionedWindow* self,
                                                 MtkRectangle* window_rect,
                                                 gint* x,
                                                 gint* y);
VALA_EXTERN GalaMonitorLabelWindow* gala_monitor_label_window_new (MetaWindow* window,
                                                       gint monitor_index);
VALA_EXTERN GalaMonitorLabelWindow* gala_monitor_label_window_construct (GType object_type,
                                                             MetaWindow* window,
                                                             gint monitor_index);
static void gala_monitor_label_window_real_get_window_position (GalaPositionedWindow* base,
                                                         MtkRectangle* window_rect,
                                                         gint* x,
                                                         gint* y);
VALA_EXTERN gint gala_monitor_label_window_get_monitor_index (GalaMonitorLabelWindow* self);
VALA_EXTERN MetaWindow* gala_positioned_window_get_window (GalaPositionedWindow* self);
static void gala_monitor_label_window_set_monitor_index (GalaMonitorLabelWindow* self,
                                                  gint value);
static void gala_monitor_label_window_finalize (GObject * obj);
static GType gala_monitor_label_window_get_type_once (void);
static void _vala_gala_monitor_label_window_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_monitor_label_window_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gala_monitor_label_window_get_instance_private (GalaMonitorLabelWindow* self)
{
	return G_STRUCT_MEMBER_P (self, GalaMonitorLabelWindow_private_offset);
}

GalaMonitorLabelWindow*
gala_monitor_label_window_construct (GType object_type,
                                     MetaWindow* window,
                                     gint monitor_index)
{
	GalaMonitorLabelWindow * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (GalaMonitorLabelWindow*) g_object_new (object_type, "window", window, "monitor-index", monitor_index, NULL);
	return self;
}

GalaMonitorLabelWindow*
gala_monitor_label_window_new (MetaWindow* window,
                               gint monitor_index)
{
	return gala_monitor_label_window_construct (GALA_TYPE_MONITOR_LABEL_WINDOW, window, monitor_index);
}

static void
gala_monitor_label_window_real_get_window_position (GalaPositionedWindow* base,
                                                    MtkRectangle* window_rect,
                                                    gint* x,
                                                    gint* y)
{
	GalaMonitorLabelWindow * self;
	gint _vala_x = 0;
	gint _vala_y = 0;
	gboolean _tmp0_ = FALSE;
	gint _tmp1_;
	MtkRectangle monitor_rect = {0};
	MetaWindow* _tmp8_;
	MetaWindow* _tmp9_;
	MetaDisplay* _tmp10_;
	MetaDisplay* _tmp11_;
	gint _tmp12_;
	MtkRectangle _tmp13_ = {0};
	MtkRectangle _tmp14_;
	MtkRectangle _tmp15_;
	self = (GalaMonitorLabelWindow*) base;
	g_return_if_fail (window_rect != NULL);
	_tmp1_ = self->priv->_monitor_index;
	if (_tmp1_ < 0) {
		_tmp0_ = TRUE;
	} else {
		gint _tmp2_;
		MetaWindow* _tmp3_;
		MetaWindow* _tmp4_;
		MetaDisplay* _tmp5_;
		MetaDisplay* _tmp6_;
		_tmp2_ = self->priv->_monitor_index;
		_tmp3_ = gala_positioned_window_get_window ((GalaPositionedWindow*) self);
		_tmp4_ = _tmp3_;
		_tmp5_ = meta_window_get_display (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp2_ >= meta_display_get_n_monitors (_tmp6_);
	}
	if (_tmp0_) {
		gint _tmp7_;
		_tmp7_ = self->priv->_monitor_index;
		g_warning ("MonitorLabelWindow.vala:19: Invalid monitor index %d for MonitorLabelW" \
"indow, monitor count probably changed", _tmp7_);
		_vala_y = 0;
		_vala_x = _vala_y;
		if (x) {
			*x = _vala_x;
		}
		if (y) {
			*y = _vala_y;
		}
		return;
	}
	_tmp8_ = gala_positioned_window_get_window ((GalaPositionedWindow*) self);
	_tmp9_ = _tmp8_;
	_tmp10_ = meta_window_get_display (_tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = self->priv->_monitor_index;
	meta_display_get_monitor_geometry (_tmp11_, _tmp12_, &_tmp13_);
	monitor_rect = _tmp13_;
	_tmp14_ = monitor_rect;
	_vala_x = _tmp14_.x + GALA_MONITOR_LABEL_WINDOW_MARGIN;
	_tmp15_ = monitor_rect;
	_vala_y = _tmp15_.y + GALA_MONITOR_LABEL_WINDOW_MARGIN;
	if (x) {
		*x = _vala_x;
	}
	if (y) {
		*y = _vala_y;
	}
}

gint
gala_monitor_label_window_get_monitor_index (GalaMonitorLabelWindow* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_monitor_index;
	return result;
}

static void
gala_monitor_label_window_set_monitor_index (GalaMonitorLabelWindow* self,
                                             gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_monitor_label_window_get_monitor_index (self);
	if (old_value != value) {
		self->priv->_monitor_index = value;
		g_object_notify_by_pspec ((GObject *) self, gala_monitor_label_window_properties[GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY]);
	}
}

static void
gala_monitor_label_window_class_init (GalaMonitorLabelWindowClass * klass,
                                      gpointer klass_data)
{
	gala_monitor_label_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaMonitorLabelWindow_private_offset);
	((GalaPositionedWindowClass *) klass)->get_window_position = (void (*) (GalaPositionedWindow*, MtkRectangle*, gint*, gint*)) gala_monitor_label_window_real_get_window_position;
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_monitor_label_window_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_monitor_label_window_set_property;
	G_OBJECT_CLASS (klass)->finalize = gala_monitor_label_window_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY, gala_monitor_label_window_properties[GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY] = g_param_spec_int ("monitor-index", "monitor-index", "monitor-index", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
gala_monitor_label_window_instance_init (GalaMonitorLabelWindow * self,
                                         gpointer klass)
{
	self->priv = gala_monitor_label_window_get_instance_private (self);
}

static void
gala_monitor_label_window_finalize (GObject * obj)
{
	GalaMonitorLabelWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindow);
	G_OBJECT_CLASS (gala_monitor_label_window_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_monitor_label_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaMonitorLabelWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_monitor_label_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaMonitorLabelWindow), 0, (GInstanceInitFunc) gala_monitor_label_window_instance_init, NULL };
	GType gala_monitor_label_window_type_id;
	gala_monitor_label_window_type_id = g_type_register_static (GALA_TYPE_POSITIONED_WINDOW, "GalaMonitorLabelWindow", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaMonitorLabelWindow_private_offset = g_type_add_instance_private (gala_monitor_label_window_type_id, sizeof (GalaMonitorLabelWindowPrivate));
	return gala_monitor_label_window_type_id;
}

GType
gala_monitor_label_window_get_type (void)
{
	static gsize gala_monitor_label_window_type_id__once = 0;
	if (g_once_init_enter (&gala_monitor_label_window_type_id__once)) {
		GType gala_monitor_label_window_type_id;
		gala_monitor_label_window_type_id = gala_monitor_label_window_get_type_once ();
		g_once_init_leave (&gala_monitor_label_window_type_id__once, gala_monitor_label_window_type_id);
	}
	return gala_monitor_label_window_type_id__once;
}

static void
_vala_gala_monitor_label_window_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaMonitorLabelWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindow);
	switch (property_id) {
		case GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY:
		g_value_set_int (value, gala_monitor_label_window_get_monitor_index (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_monitor_label_window_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaMonitorLabelWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_MONITOR_LABEL_WINDOW, GalaMonitorLabelWindow);
	switch (property_id) {
		case GALA_MONITOR_LABEL_WINDOW_MONITOR_INDEX_PROPERTY:
		gala_monitor_label_window_set_monitor_index (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

