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

/*
 * Copyright 2024 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/meta-monitor-manager.h>
#include <meta/display.h>
#include <meta/meta-context.h>
#include <meta/meta-backend.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_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;
enum  {
	GALA_POSITIONED_WINDOW_0_PROPERTY,
	GALA_POSITIONED_WINDOW_WINDOW_PROPERTY,
	GALA_POSITIONED_WINDOW_NUM_PROPERTIES
};
static GParamSpec* gala_positioned_window_properties[GALA_POSITIONED_WINDOW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

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 _GalaPositionedWindowPrivate {
	MetaWindow* _window;
	gulong position_changed_id;
};

static gint GalaPositionedWindow_private_offset;
static gpointer gala_positioned_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 void gala_positioned_window_get_window_position (GalaPositionedWindow* self,
                                                 MtkRectangle* window_rect,
                                                 gint* x,
                                                 gint* y);
VALA_EXTERN void gala_positioned_window_position_window (GalaPositionedWindow* self);
VALA_EXTERN MetaWindow* gala_positioned_window_get_window (GalaPositionedWindow* self);
static void gala_positioned_window_real_get_window_position (GalaPositionedWindow* self,
                                                      MtkRectangle* window_rect,
                                                      gint* x,
                                                      gint* y);
VALA_EXTERN GalaPositionedWindow* gala_positioned_window_construct (GType object_type);
static void gala_positioned_window_set_window (GalaPositionedWindow* self,
                                        MetaWindow* value);
static GObject * gala_positioned_window_constructor (GType type,
                                              guint n_construct_properties,
                                              GObjectConstructParam * construct_properties);
static void _gala_positioned_window_position_window_meta_window_size_changed (MetaWindow* _sender,
                                                                       gpointer self);
static void _gala_positioned_window_position_window_meta_window_position_changed (MetaWindow* _sender,
                                                                           gpointer self);
static void _gala_positioned_window_position_window_meta_window_shown (MetaWindow* _sender,
                                                                gpointer self);
static void _gala_positioned_window_position_window_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                                    gpointer self);
static void _gala_positioned_window_position_window_meta_monitor_manager_monitors_changed_internal (MetaMonitorManager* _sender,
                                                                                             gpointer self);
static void gala_positioned_window_finalize (GObject * obj);
static GType gala_positioned_window_get_type_once (void);
static void _vala_gala_positioned_window_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_gala_positioned_window_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);

static inline gpointer
gala_positioned_window_get_instance_private (GalaPositionedWindow* self)
{
	return G_STRUCT_MEMBER_P (self, GalaPositionedWindow_private_offset);
}

void
gala_positioned_window_position_window (GalaPositionedWindow* self)
{
	MtkRectangle window_rect = {0};
	MetaWindow* _tmp0_;
	MtkRectangle _tmp1_ = {0};
	gint x = 0;
	gint y = 0;
	MtkRectangle _tmp2_;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	MetaWindow* _tmp5_;
	MetaWindow* _tmp6_;
	MetaWindow* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_window;
	meta_window_get_frame_rect (_tmp0_, &_tmp1_);
	window_rect = _tmp1_;
	x = 0;
	y = 0;
	_tmp2_ = window_rect;
	gala_positioned_window_get_window_position (self, &_tmp2_, &_tmp3_, &_tmp4_);
	x = _tmp3_;
	y = _tmp4_;
	_tmp5_ = self->priv->_window;
	g_signal_handler_block (_tmp5_, self->priv->position_changed_id);
	_tmp6_ = self->priv->_window;
	meta_window_move_frame (_tmp6_, FALSE, x, y);
	_tmp7_ = self->priv->_window;
	g_signal_handler_unblock (_tmp7_, self->priv->position_changed_id);
}

static void
gala_positioned_window_real_get_window_position (GalaPositionedWindow* self,
                                                 MtkRectangle* window_rect,
                                                 gint* x,
                                                 gint* y)
{
	g_critical ("Type `%s' does not implement abstract method `gala_positioned_window_get_window_position'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
gala_positioned_window_get_window_position (GalaPositionedWindow* self,
                                            MtkRectangle* window_rect,
                                            gint* x,
                                            gint* y)
{
	GalaPositionedWindowClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = GALA_POSITIONED_WINDOW_GET_CLASS (self);
	if (_klass_->get_window_position) {
		_klass_->get_window_position (self, window_rect, x, y);
	}
}

GalaPositionedWindow*
gala_positioned_window_construct (GType object_type)
{
	GalaPositionedWindow * self = NULL;
	self = (GalaPositionedWindow*) g_object_new (object_type, NULL);
	return self;
}

MetaWindow*
gala_positioned_window_get_window (GalaPositionedWindow* 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_positioned_window_set_window (GalaPositionedWindow* self,
                                   MetaWindow* value)
{
	MetaWindow* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_positioned_window_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_positioned_window_properties[GALA_POSITIONED_WINDOW_WINDOW_PROPERTY]);
	}
}

static void
_gala_positioned_window_position_window_meta_window_size_changed (MetaWindow* _sender,
                                                                  gpointer self)
{
	gala_positioned_window_position_window ((GalaPositionedWindow*) self);
}

static void
_gala_positioned_window_position_window_meta_window_position_changed (MetaWindow* _sender,
                                                                      gpointer self)
{
	gala_positioned_window_position_window ((GalaPositionedWindow*) self);
}

static void
_gala_positioned_window_position_window_meta_window_shown (MetaWindow* _sender,
                                                           gpointer self)
{
	gala_positioned_window_position_window ((GalaPositionedWindow*) self);
}

static void
_gala_positioned_window_position_window_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                               gpointer self)
{
	gala_positioned_window_position_window ((GalaPositionedWindow*) self);
}

static void
_gala_positioned_window_position_window_meta_monitor_manager_monitors_changed_internal (MetaMonitorManager* _sender,
                                                                                        gpointer self)
{
	gala_positioned_window_position_window ((GalaPositionedWindow*) self);
}

static GObject *
gala_positioned_window_constructor (GType type,
                                    guint n_construct_properties,
                                    GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaPositionedWindow * self;
	MetaWindow* _tmp0_;
	MetaWindow* _tmp1_;
	MetaWindow* _tmp2_;
	gulong _tmp3_;
	MetaWindow* _tmp4_;
	MetaMonitorManager* monitor_manager = NULL;
	MetaWindow* _tmp5_;
	MetaDisplay* _tmp6_;
	MetaDisplay* _tmp7_;
	MetaContext* _tmp8_;
	MetaBackend* _tmp9_;
	MetaMonitorManager* _tmp10_;
	MetaMonitorManager* _tmp11_;
	MetaMonitorManager* _tmp12_;
	parent_class = G_OBJECT_CLASS (gala_positioned_window_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindow);
	_tmp0_ = self->priv->_window;
	meta_window_stick (_tmp0_);
	_tmp1_ = self->priv->_window;
	g_signal_connect_object (_tmp1_, "size-changed", (GCallback) _gala_positioned_window_position_window_meta_window_size_changed, self, 0);
	_tmp2_ = self->priv->_window;
	_tmp3_ = g_signal_connect_object (_tmp2_, "position-changed", (GCallback) _gala_positioned_window_position_window_meta_window_position_changed, self, 0);
	self->priv->position_changed_id = _tmp3_;
	_tmp4_ = self->priv->_window;
	g_signal_connect_object (_tmp4_, "shown", (GCallback) _gala_positioned_window_position_window_meta_window_shown, self, 0);
	_tmp5_ = self->priv->_window;
	_tmp6_ = meta_window_get_display (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = meta_display_get_context (_tmp7_);
	_tmp9_ = meta_context_get_backend (_tmp8_);
	_tmp10_ = meta_backend_get_monitor_manager (_tmp9_);
	monitor_manager = _tmp10_;
	_tmp11_ = monitor_manager;
	g_signal_connect_object (_tmp11_, "monitors-changed", (GCallback) _gala_positioned_window_position_window_meta_monitor_manager_monitors_changed, self, 0);
	_tmp12_ = monitor_manager;
	g_signal_connect_object (_tmp12_, "monitors-changed-internal", (GCallback) _gala_positioned_window_position_window_meta_monitor_manager_monitors_changed_internal, self, 0);
	return obj;
}

static void
gala_positioned_window_class_init (GalaPositionedWindowClass * klass,
                                   gpointer klass_data)
{
	gala_positioned_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaPositionedWindow_private_offset);
	((GalaPositionedWindowClass *) klass)->get_window_position = (void (*) (GalaPositionedWindow*, MtkRectangle*, gint*, gint*)) gala_positioned_window_real_get_window_position;
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_positioned_window_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_positioned_window_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_positioned_window_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_positioned_window_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_POSITIONED_WINDOW_WINDOW_PROPERTY, gala_positioned_window_properties[GALA_POSITIONED_WINDOW_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));
}

static void
gala_positioned_window_instance_init (GalaPositionedWindow * self,
                                      gpointer klass)
{
	self->priv = gala_positioned_window_get_instance_private (self);
}

static void
gala_positioned_window_finalize (GObject * obj)
{
	GalaPositionedWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindow);
	_g_object_unref0 (self->priv->_window);
	G_OBJECT_CLASS (gala_positioned_window_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_positioned_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaPositionedWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_positioned_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaPositionedWindow), 0, (GInstanceInitFunc) gala_positioned_window_instance_init, NULL };
	GType gala_positioned_window_type_id;
	gala_positioned_window_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaPositionedWindow", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	GalaPositionedWindow_private_offset = g_type_add_instance_private (gala_positioned_window_type_id, sizeof (GalaPositionedWindowPrivate));
	return gala_positioned_window_type_id;
}

GType
gala_positioned_window_get_type (void)
{
	static gsize gala_positioned_window_type_id__once = 0;
	if (g_once_init_enter (&gala_positioned_window_type_id__once)) {
		GType gala_positioned_window_type_id;
		gala_positioned_window_type_id = gala_positioned_window_get_type_once ();
		g_once_init_leave (&gala_positioned_window_type_id__once, gala_positioned_window_type_id);
	}
	return gala_positioned_window_type_id__once;
}

static void
_vala_gala_positioned_window_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	GalaPositionedWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindow);
	switch (property_id) {
		case GALA_POSITIONED_WINDOW_WINDOW_PROPERTY:
		g_value_set_object (value, gala_positioned_window_get_window (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_positioned_window_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	GalaPositionedWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_POSITIONED_WINDOW, GalaPositionedWindow);
	switch (property_id) {
		case GALA_POSITIONED_WINDOW_WINDOW_PROPERTY:
		gala_positioned_window_set_window (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

