/* ShellWindow.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from ShellWindow.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 <meta/meta-window-actor.h>
#include <meta/window.h>
#include <glib.h>
#include <clutter/clutter.h>
#include <mtk/mtk.h>
#include <meta/display.h>
#include <float.h>
#include <math.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 GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW (greeter_compositor_positioned_window_get_type ())
#define GREETER_COMPOSITOR_POSITIONED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW, GreeterCompositorPositionedWindow))
#define GREETER_COMPOSITOR_POSITIONED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW, GreeterCompositorPositionedWindowClass))
#define GREETER_COMPOSITOR_IS_POSITIONED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW))
#define GREETER_COMPOSITOR_IS_POSITIONED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW))
#define GREETER_COMPOSITOR_POSITIONED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW, GreeterCompositorPositionedWindowClass))

typedef struct _GreeterCompositorPositionedWindow GreeterCompositorPositionedWindow;
typedef struct _GreeterCompositorPositionedWindowClass GreeterCompositorPositionedWindowClass;
typedef struct _GreeterCompositorPositionedWindowPrivate GreeterCompositorPositionedWindowPrivate;

#define GREETER_COMPOSITOR_TYPE_SHELL_WINDOW (greeter_compositor_shell_window_get_type ())
#define GREETER_COMPOSITOR_SHELL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindow))
#define GREETER_COMPOSITOR_SHELL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindowClass))
#define GREETER_COMPOSITOR_IS_SHELL_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_COMPOSITOR_TYPE_SHELL_WINDOW))
#define GREETER_COMPOSITOR_IS_SHELL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_COMPOSITOR_TYPE_SHELL_WINDOW))
#define GREETER_COMPOSITOR_SHELL_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindowClass))

typedef struct _GreeterCompositorShellWindow GreeterCompositorShellWindow;
typedef struct _GreeterCompositorShellWindowClass GreeterCompositorShellWindowClass;
typedef struct _GreeterCompositorShellWindowPrivate GreeterCompositorShellWindowPrivate;
enum  {
	GREETER_COMPOSITOR_SHELL_WINDOW_0_PROPERTY,
	GREETER_COMPOSITOR_SHELL_WINDOW_ACTOR_PROPERTY,
	GREETER_COMPOSITOR_SHELL_WINDOW_NUM_PROPERTIES
};
static GParamSpec* greeter_compositor_shell_window_properties[GREETER_COMPOSITOR_SHELL_WINDOW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef enum  {
	GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_TOP,
	GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_BOTTOM,
	GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_CENTER,
	GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_FULLSCREEN
} GreeterCompositorPositionedWindowPosition;

#define GREETER_COMPOSITOR_POSITIONED_WINDOW_TYPE_POSITION (greeter_compositor_positioned_window_position_get_type ())

struct _GreeterCompositorPositionedWindow {
	GObject parent_instance;
	GreeterCompositorPositionedWindowPrivate * priv;
};

struct _GreeterCompositorPositionedWindowClass {
	GObjectClass parent_class;
};

struct _GreeterCompositorShellWindow {
	GreeterCompositorPositionedWindow parent_instance;
	GreeterCompositorShellWindowPrivate * priv;
};

struct _GreeterCompositorShellWindowClass {
	GreeterCompositorPositionedWindowClass parent_class;
};

struct _GreeterCompositorShellWindowPrivate {
	MetaWindowActor* window_actor;
};

static gint GreeterCompositorShellWindow_private_offset;
static gpointer greeter_compositor_shell_window_parent_class = NULL;

VALA_EXTERN GType greeter_compositor_positioned_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterCompositorPositionedWindow, g_object_unref)
VALA_EXTERN GType greeter_compositor_shell_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterCompositorShellWindow, g_object_unref)
VALA_EXTERN GType greeter_compositor_positioned_window_position_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GreeterCompositorShellWindow* greeter_compositor_shell_window_new (MetaWindow* window,
                                                                   GreeterCompositorPositionedWindowPosition position,
                                                                   GVariant* position_data);
VALA_EXTERN GreeterCompositorShellWindow* greeter_compositor_shell_window_construct (GType object_type,
                                                                         MetaWindow* window,
                                                                         GreeterCompositorPositionedWindowPosition position,
                                                                         GVariant* position_data);
VALA_EXTERN GreeterCompositorPositionedWindow* greeter_compositor_positioned_window_new (MetaWindow* window,
                                                                             GreeterCompositorPositionedWindowPosition position,
                                                                             GVariant* position_data);
VALA_EXTERN GreeterCompositorPositionedWindow* greeter_compositor_positioned_window_construct (GType object_type,
                                                                                   MetaWindow* window,
                                                                                   GreeterCompositorPositionedWindowPosition position,
                                                                                   GVariant* position_data);
static void greeter_compositor_shell_window_update_clip (GreeterCompositorShellWindow* self);
VALA_EXTERN GreeterCompositorPositionedWindowPosition greeter_compositor_positioned_window_get_position (GreeterCompositorPositionedWindow* self);
VALA_EXTERN MetaWindow* greeter_compositor_positioned_window_get_window (GreeterCompositorPositionedWindow* self);
VALA_EXTERN ClutterActor* greeter_compositor_shell_window_get_actor (GreeterCompositorShellWindow* self);
static GObject * greeter_compositor_shell_window_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void _greeter_compositor_shell_window_update_clip_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void greeter_compositor_shell_window_finalize (GObject * obj);
static GType greeter_compositor_shell_window_get_type_once (void);
static void _vala_greeter_compositor_shell_window_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec);

static inline gpointer
greeter_compositor_shell_window_get_instance_private (GreeterCompositorShellWindow* self)
{
	return G_STRUCT_MEMBER_P (self, GreeterCompositorShellWindow_private_offset);
}

GreeterCompositorShellWindow*
greeter_compositor_shell_window_construct (GType object_type,
                                           MetaWindow* window,
                                           GreeterCompositorPositionedWindowPosition position,
                                           GVariant* position_data)
{
	GreeterCompositorShellWindow * self = NULL;
	g_return_val_if_fail (window != NULL, NULL);
	self = (GreeterCompositorShellWindow*) greeter_compositor_positioned_window_construct (object_type, window, position, position_data);
	return self;
}

GreeterCompositorShellWindow*
greeter_compositor_shell_window_new (MetaWindow* window,
                                     GreeterCompositorPositionedWindowPosition position,
                                     GVariant* position_data)
{
	return greeter_compositor_shell_window_construct (GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, window, position, position_data);
}

static void
greeter_compositor_shell_window_update_clip (GreeterCompositorShellWindow* self)
{
	gboolean _tmp0_ = FALSE;
	GreeterCompositorPositionedWindowPosition _tmp1_;
	GreeterCompositorPositionedWindowPosition _tmp2_;
	MtkRectangle monitor_geom = {0};
	MetaWindow* _tmp6_;
	MetaWindow* _tmp7_;
	MetaDisplay* _tmp8_;
	MetaDisplay* _tmp9_;
	MetaWindow* _tmp10_;
	MetaWindow* _tmp11_;
	MtkRectangle _tmp12_ = {0};
	gfloat y = 0.0F;
	MetaWindowActor* _tmp13_;
	gfloat _tmp14_;
	gfloat _tmp15_;
	MetaWindowActor* _tmp16_;
	gfloat _tmp17_;
	gfloat _tmp18_;
	MetaWindowActor* _tmp19_;
	gfloat _tmp20_;
	gfloat _tmp21_;
	MtkRectangle _tmp22_;
	MtkRectangle _tmp23_;
	g_return_if_fail (self != NULL);
	_tmp1_ = greeter_compositor_positioned_window_get_position ((GreeterCompositorPositionedWindow*) self);
	_tmp2_ = _tmp1_;
	if (_tmp2_ != GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_TOP) {
		GreeterCompositorPositionedWindowPosition _tmp3_;
		GreeterCompositorPositionedWindowPosition _tmp4_;
		_tmp3_ = greeter_compositor_positioned_window_get_position ((GreeterCompositorPositionedWindow*) self);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ != GREETER_COMPOSITOR_POSITIONED_WINDOW_POSITION_BOTTOM;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		MetaWindowActor* _tmp5_;
		_tmp5_ = self->priv->window_actor;
		clutter_actor_remove_clip ((ClutterActor*) _tmp5_);
		return;
	}
	_tmp6_ = greeter_compositor_positioned_window_get_window ((GreeterCompositorPositionedWindow*) self);
	_tmp7_ = _tmp6_;
	_tmp8_ = meta_window_get_display (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = greeter_compositor_positioned_window_get_window ((GreeterCompositorPositionedWindow*) self);
	_tmp11_ = _tmp10_;
	meta_display_get_monitor_geometry (_tmp9_, meta_window_get_monitor (_tmp11_), &_tmp12_);
	monitor_geom = _tmp12_;
	_tmp13_ = self->priv->window_actor;
	_tmp14_ = clutter_actor_get_y ((ClutterActor*) _tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = self->priv->window_actor;
	g_object_get ((ClutterActor*) _tmp16_, "translation-y", &_tmp17_, NULL);
	_tmp18_ = _tmp17_;
	y = _tmp15_ + _tmp18_;
	_tmp19_ = self->priv->window_actor;
	_tmp20_ = clutter_actor_get_height ((ClutterActor*) _tmp19_);
	_tmp21_ = _tmp20_;
	_tmp22_ = monitor_geom;
	_tmp23_ = monitor_geom;
	if ((y + _tmp21_) > ((gfloat) (_tmp22_.y + _tmp23_.height))) {
		MetaWindowActor* _tmp24_;
		MetaWindowActor* _tmp25_;
		gfloat _tmp26_;
		gfloat _tmp27_;
		MtkRectangle _tmp28_;
		MtkRectangle _tmp29_;
		_tmp24_ = self->priv->window_actor;
		_tmp25_ = self->priv->window_actor;
		_tmp26_ = clutter_actor_get_width ((ClutterActor*) _tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = monitor_geom;
		_tmp29_ = monitor_geom;
		clutter_actor_set_clip ((ClutterActor*) _tmp24_, (gfloat) 0, (gfloat) 0, _tmp27_, (_tmp28_.y + _tmp29_.height) - y);
	} else {
		MtkRectangle _tmp30_;
		_tmp30_ = monitor_geom;
		if (y < ((gfloat) _tmp30_.y)) {
			MetaWindowActor* _tmp31_;
			MtkRectangle _tmp32_;
			MetaWindowActor* _tmp33_;
			gfloat _tmp34_;
			gfloat _tmp35_;
			MetaWindowActor* _tmp36_;
			gfloat _tmp37_;
			gfloat _tmp38_;
			_tmp31_ = self->priv->window_actor;
			_tmp32_ = monitor_geom;
			_tmp33_ = self->priv->window_actor;
			_tmp34_ = clutter_actor_get_width ((ClutterActor*) _tmp33_);
			_tmp35_ = _tmp34_;
			_tmp36_ = self->priv->window_actor;
			_tmp37_ = clutter_actor_get_height ((ClutterActor*) _tmp36_);
			_tmp38_ = _tmp37_;
			clutter_actor_set_clip ((ClutterActor*) _tmp31_, (gfloat) 0, _tmp32_.y - y, _tmp35_, _tmp38_);
		} else {
			MetaWindowActor* _tmp39_;
			_tmp39_ = self->priv->window_actor;
			clutter_actor_remove_clip ((ClutterActor*) _tmp39_);
		}
	}
}

ClutterActor*
greeter_compositor_shell_window_get_actor (GreeterCompositorShellWindow* self)
{
	ClutterActor* result;
	MetaWindowActor* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->window_actor;
	result = (ClutterActor*) _tmp0_;
	return result;
}

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

static void
_greeter_compositor_shell_window_update_clip_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	greeter_compositor_shell_window_update_clip ((GreeterCompositorShellWindow*) self);
}

static GObject *
greeter_compositor_shell_window_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GreeterCompositorShellWindow * self;
	MetaWindow* _tmp0_;
	MetaWindow* _tmp1_;
	GObject* _tmp2_;
	MetaWindowActor* _tmp3_;
	MetaWindowActor* _tmp4_;
	MetaWindowActor* _tmp5_;
	MetaWindowActor* _tmp6_;
	parent_class = G_OBJECT_CLASS (greeter_compositor_shell_window_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindow);
	_tmp0_ = greeter_compositor_positioned_window_get_window ((GreeterCompositorPositionedWindow*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = meta_window_get_compositor_private (_tmp1_);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, meta_window_actor_get_type (), MetaWindowActor));
	_g_object_unref0 (self->priv->window_actor);
	self->priv->window_actor = _tmp3_;
	_tmp4_ = self->priv->window_actor;
	g_signal_connect_object ((GObject*) _tmp4_, "notify::width", (GCallback) _greeter_compositor_shell_window_update_clip_g_object_notify, self, 0);
	_tmp5_ = self->priv->window_actor;
	g_signal_connect_object ((GObject*) _tmp5_, "notify::height", (GCallback) _greeter_compositor_shell_window_update_clip_g_object_notify, self, 0);
	_tmp6_ = self->priv->window_actor;
	g_signal_connect_object ((GObject*) _tmp6_, "notify::translation-y", (GCallback) _greeter_compositor_shell_window_update_clip_g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::position", (GCallback) _greeter_compositor_shell_window_update_clip_g_object_notify, self, 0);
	return obj;
}

static void
greeter_compositor_shell_window_class_init (GreeterCompositorShellWindowClass * klass,
                                            gpointer klass_data)
{
	greeter_compositor_shell_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GreeterCompositorShellWindow_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_greeter_compositor_shell_window_get_property;
	G_OBJECT_CLASS (klass)->constructor = greeter_compositor_shell_window_constructor;
	G_OBJECT_CLASS (klass)->finalize = greeter_compositor_shell_window_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GREETER_COMPOSITOR_SHELL_WINDOW_ACTOR_PROPERTY, greeter_compositor_shell_window_properties[GREETER_COMPOSITOR_SHELL_WINDOW_ACTOR_PROPERTY] = g_param_spec_object ("actor", "actor", "actor", clutter_actor_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
greeter_compositor_shell_window_instance_init (GreeterCompositorShellWindow * self,
                                               gpointer klass)
{
	self->priv = greeter_compositor_shell_window_get_instance_private (self);
}

static void
greeter_compositor_shell_window_finalize (GObject * obj)
{
	GreeterCompositorShellWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindow);
	_g_object_unref0 (self->priv->window_actor);
	G_OBJECT_CLASS (greeter_compositor_shell_window_parent_class)->finalize (obj);
}

static GType
greeter_compositor_shell_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GreeterCompositorShellWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) greeter_compositor_shell_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GreeterCompositorShellWindow), 0, (GInstanceInitFunc) greeter_compositor_shell_window_instance_init, NULL };
	GType greeter_compositor_shell_window_type_id;
	greeter_compositor_shell_window_type_id = g_type_register_static (GREETER_COMPOSITOR_TYPE_POSITIONED_WINDOW, "GreeterCompositorShellWindow", &g_define_type_info, 0);
	GreeterCompositorShellWindow_private_offset = g_type_add_instance_private (greeter_compositor_shell_window_type_id, sizeof (GreeterCompositorShellWindowPrivate));
	return greeter_compositor_shell_window_type_id;
}

GType
greeter_compositor_shell_window_get_type (void)
{
	static volatile gsize greeter_compositor_shell_window_type_id__once = 0;
	if (g_once_init_enter (&greeter_compositor_shell_window_type_id__once)) {
		GType greeter_compositor_shell_window_type_id;
		greeter_compositor_shell_window_type_id = greeter_compositor_shell_window_get_type_once ();
		g_once_init_leave (&greeter_compositor_shell_window_type_id__once, greeter_compositor_shell_window_type_id);
	}
	return greeter_compositor_shell_window_type_id__once;
}

static void
_vala_greeter_compositor_shell_window_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec)
{
	GreeterCompositorShellWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GREETER_COMPOSITOR_TYPE_SHELL_WINDOW, GreeterCompositorShellWindow);
	switch (property_id) {
		case GREETER_COMPOSITOR_SHELL_WINDOW_ACTOR_PROPERTY:
		g_value_set_object (value, greeter_compositor_shell_window_get_actor (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

