/* WorkspaceRow.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from WorkspaceRow.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 "gala.h"
#include <glib-object.h>
#include <meta/display.h>
#include <clutter/clutter.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <meta/workspace.h>
#include <meta/meta-workspace-manager.h>

#define GALA_WORKSPACE_ROW_WORKSPACE_GAP 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_WORKSPACE_ROW (gala_workspace_row_get_type ())
#define GALA_WORKSPACE_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRow))
#define GALA_WORKSPACE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRowClass))
#define GALA_IS_WORKSPACE_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_WORKSPACE_ROW))
#define GALA_IS_WORKSPACE_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_WORKSPACE_ROW))
#define GALA_WORKSPACE_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRowClass))

typedef struct _GalaWorkspaceRow GalaWorkspaceRow;
typedef struct _GalaWorkspaceRowClass GalaWorkspaceRowClass;
typedef struct _GalaWorkspaceRowPrivate GalaWorkspaceRowPrivate;
enum  {
	GALA_WORKSPACE_ROW_0_PROPERTY,
	GALA_WORKSPACE_ROW_DISPLAY_PROPERTY,
	GALA_WORKSPACE_ROW_NUM_PROPERTIES
};
static GParamSpec* gala_workspace_row_properties[GALA_WORKSPACE_ROW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_TYPE_WORKSPACE_CLONE (gala_workspace_clone_get_type ())
#define GALA_WORKSPACE_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_WORKSPACE_CLONE, GalaWorkspaceClone))
#define GALA_WORKSPACE_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_WORKSPACE_CLONE, GalaWorkspaceCloneClass))
#define GALA_IS_WORKSPACE_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_WORKSPACE_CLONE))
#define GALA_IS_WORKSPACE_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_WORKSPACE_CLONE))
#define GALA_WORKSPACE_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_WORKSPACE_CLONE, GalaWorkspaceCloneClass))

typedef struct _GalaWorkspaceClone GalaWorkspaceClone;
typedef struct _GalaWorkspaceCloneClass GalaWorkspaceCloneClass;

struct _GalaWorkspaceRow {
	GalaActorTarget parent_instance;
	GalaWorkspaceRowPrivate * priv;
};

struct _GalaWorkspaceRowClass {
	GalaActorTargetClass parent_class;
};

struct _GalaWorkspaceRowPrivate {
	MetaDisplay* _display;
};

static gint GalaWorkspaceRow_private_offset;
static gpointer gala_workspace_row_parent_class = NULL;

VALA_EXTERN GType gala_workspace_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaWorkspaceRow, g_object_unref)
VALA_EXTERN GalaWorkspaceRow* gala_workspace_row_new (MetaDisplay* display);
VALA_EXTERN GalaWorkspaceRow* gala_workspace_row_construct (GType object_type,
                                                MetaDisplay* display);
static void gala_workspace_row_real_allocate (ClutterActor* base,
                                       ClutterActorBox* allocation);
static void gala_workspace_row_real_update_progress (GalaActorTarget* base,
                                              GalaGestureAction action,
                                              gdouble to);
static void gala_workspace_row_update_order (GalaWorkspaceRow* self);
VALA_EXTERN GType gala_workspace_clone_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaWorkspaceClone, g_object_unref)
VALA_EXTERN MetaWorkspace* gala_workspace_clone_get_workspace (GalaWorkspaceClone* self);
VALA_EXTERN MetaDisplay* gala_workspace_row_get_display (GalaWorkspaceRow* self);
static void gala_workspace_row_set_display (GalaWorkspaceRow* self,
                                     MetaDisplay* value);
static GObject * gala_workspace_row_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties);
static void _gala_workspace_row_update_order_meta_workspace_manager_workspaces_reordered (MetaWorkspaceManager* _sender,
                                                                                   gpointer self);
static void gala_workspace_row_finalize (GObject * obj);
static GType gala_workspace_row_get_type_once (void);
static void _vala_gala_workspace_row_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_gala_workspace_row_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);

static inline gpointer
gala_workspace_row_get_instance_private (GalaWorkspaceRow* self)
{
	return G_STRUCT_MEMBER_P (self, GalaWorkspaceRow_private_offset);
}

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

GalaWorkspaceRow*
gala_workspace_row_new (MetaDisplay* display)
{
	return gala_workspace_row_construct (GALA_TYPE_WORKSPACE_ROW, display);
}

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

static void
gala_workspace_row_real_allocate (ClutterActor* base,
                                  ClutterActorBox* allocation)
{
	GalaWorkspaceRow * self;
	ClutterActorBox _tmp0_;
	gdouble progress = 0.0;
	gint index = 0;
	self = (GalaWorkspaceRow*) base;
	g_return_if_fail (allocation != NULL);
	_tmp0_ = *allocation;
	clutter_actor_set_allocation ((ClutterActor*) self, &_tmp0_);
	progress = gala_actor_target_get_current_progress ((GalaActorTarget*) self, GALA_GESTURE_ACTION_SWITCH_WORKSPACE);
	index = 0;
	{
		ClutterActor* child = NULL;
		ClutterActor* _tmp1_;
		ClutterActor* _tmp2_;
		_tmp1_ = clutter_actor_get_first_child ((ClutterActor*) self);
		_tmp2_ = _g_object_ref0 (_tmp1_);
		child = _tmp2_;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				ClutterActor* _tmp7_;
				gfloat preferred_width = 0.0F;
				ClutterActor* _tmp8_;
				gfloat _tmp9_ = 0.0F;
				gfloat child_x = 0.0F;
				ClutterActor* _tmp10_;
				gint _tmp11_;
				if (!_tmp3_) {
					ClutterActor* _tmp4_;
					ClutterActor* _tmp5_;
					ClutterActor* _tmp6_;
					_tmp4_ = child;
					_tmp5_ = clutter_actor_get_next_sibling (_tmp4_);
					_tmp6_ = _g_object_ref0 (_tmp5_);
					_g_object_unref0 (child);
					child = _tmp6_;
				}
				_tmp3_ = FALSE;
				_tmp7_ = child;
				if (!(_tmp7_ != NULL)) {
					break;
				}
				_tmp8_ = child;
				clutter_actor_get_preferred_width (_tmp8_, (gfloat) -1, NULL, &_tmp9_);
				preferred_width = _tmp9_;
				child_x = (gfloat) round ((progress + index) * (preferred_width + GALA_WORKSPACE_ROW_WORKSPACE_GAP));
				_tmp10_ = child;
				clutter_actor_allocate_preferred_size (_tmp10_, child_x, (gfloat) 0);
				_tmp11_ = index;
				index = _tmp11_ + 1;
			}
		}
		_g_object_unref0 (child);
	}
}

static void
gala_workspace_row_real_update_progress (GalaActorTarget* base,
                                         GalaGestureAction action,
                                         gdouble to)
{
	GalaWorkspaceRow * self;
	self = (GalaWorkspaceRow*) base;
	if (action == GALA_GESTURE_ACTION_SWITCH_WORKSPACE) {
		clutter_actor_queue_relayout ((ClutterActor*) self);
	}
}

static void
gala_workspace_row_update_order (GalaWorkspaceRow* self)
{
	g_return_if_fail (self != NULL);
	{
		ClutterActor* child = NULL;
		ClutterActor* _tmp0_;
		ClutterActor* _tmp1_;
		_tmp0_ = clutter_actor_get_first_child ((ClutterActor*) self);
		_tmp1_ = _g_object_ref0 (_tmp0_);
		child = _tmp1_;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				ClutterActor* _tmp6_;
				GalaWorkspaceClone* workspace_clone = NULL;
				ClutterActor* _tmp7_;
				GalaWorkspaceClone* _tmp8_;
				GalaWorkspaceClone* _tmp9_;
				MetaWorkspace* _tmp10_;
				MetaWorkspace* _tmp11_;
				if (!_tmp2_) {
					ClutterActor* _tmp3_;
					ClutterActor* _tmp4_;
					ClutterActor* _tmp5_;
					_tmp3_ = child;
					_tmp4_ = clutter_actor_get_next_sibling (_tmp3_);
					_tmp5_ = _g_object_ref0 (_tmp4_);
					_g_object_unref0 (child);
					child = _tmp5_;
				}
				_tmp2_ = FALSE;
				_tmp6_ = child;
				if (!(_tmp6_ != NULL)) {
					break;
				}
				_tmp7_ = child;
				workspace_clone = G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GALA_TYPE_WORKSPACE_CLONE, GalaWorkspaceClone);
				_tmp8_ = workspace_clone;
				_tmp9_ = workspace_clone;
				_tmp10_ = gala_workspace_clone_get_workspace (_tmp9_);
				_tmp11_ = _tmp10_;
				clutter_actor_set_child_at_index ((ClutterActor*) self, (ClutterActor*) _tmp8_, meta_workspace_index (_tmp11_));
			}
		}
		_g_object_unref0 (child);
	}
}

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

static void
gala_workspace_row_set_display (GalaWorkspaceRow* self,
                                MetaDisplay* value)
{
	MetaDisplay* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_workspace_row_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_workspace_row_properties[GALA_WORKSPACE_ROW_DISPLAY_PROPERTY]);
	}
}

static void
_gala_workspace_row_update_order_meta_workspace_manager_workspaces_reordered (MetaWorkspaceManager* _sender,
                                                                              gpointer self)
{
	gala_workspace_row_update_order ((GalaWorkspaceRow*) self);
}

static GObject *
gala_workspace_row_constructor (GType type,
                                guint n_construct_properties,
                                GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaWorkspaceRow * self;
	MetaWorkspaceManager* manager = NULL;
	MetaDisplay* _tmp0_;
	MetaWorkspaceManager* _tmp1_;
	MetaWorkspaceManager* _tmp2_;
	parent_class = G_OBJECT_CLASS (gala_workspace_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRow);
	_tmp0_ = self->priv->_display;
	_tmp1_ = meta_display_get_workspace_manager (_tmp0_);
	manager = _tmp1_;
	_tmp2_ = manager;
	g_signal_connect_object (_tmp2_, "workspaces-reordered", (GCallback) _gala_workspace_row_update_order_meta_workspace_manager_workspaces_reordered, self, 0);
	return obj;
}

static void
gala_workspace_row_class_init (GalaWorkspaceRowClass * klass,
                               gpointer klass_data)
{
	gala_workspace_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaWorkspaceRow_private_offset);
	((ClutterActorClass *) klass)->allocate = (void (*) (ClutterActor*, const ClutterActorBox *)) gala_workspace_row_real_allocate;
	((GalaActorTargetClass *) klass)->update_progress = (void (*) (GalaActorTarget*, GalaGestureAction, gdouble)) gala_workspace_row_real_update_progress;
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_workspace_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_workspace_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_workspace_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_workspace_row_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_WORKSPACE_ROW_DISPLAY_PROPERTY, gala_workspace_row_properties[GALA_WORKSPACE_ROW_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));
}

static void
gala_workspace_row_instance_init (GalaWorkspaceRow * self,
                                  gpointer klass)
{
	self->priv = gala_workspace_row_get_instance_private (self);
}

static void
gala_workspace_row_finalize (GObject * obj)
{
	GalaWorkspaceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRow);
	_g_object_unref0 (self->priv->_display);
	G_OBJECT_CLASS (gala_workspace_row_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_workspace_row_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaWorkspaceRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_workspace_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaWorkspaceRow), 0, (GInstanceInitFunc) gala_workspace_row_instance_init, NULL };
	GType gala_workspace_row_type_id;
	gala_workspace_row_type_id = g_type_register_static (GALA_TYPE_ACTOR_TARGET, "GalaWorkspaceRow", &g_define_type_info, 0);
	GalaWorkspaceRow_private_offset = g_type_add_instance_private (gala_workspace_row_type_id, sizeof (GalaWorkspaceRowPrivate));
	return gala_workspace_row_type_id;
}

GType
gala_workspace_row_get_type (void)
{
	static gsize gala_workspace_row_type_id__once = 0;
	if (g_once_init_enter (&gala_workspace_row_type_id__once)) {
		GType gala_workspace_row_type_id;
		gala_workspace_row_type_id = gala_workspace_row_get_type_once ();
		g_once_init_leave (&gala_workspace_row_type_id__once, gala_workspace_row_type_id);
	}
	return gala_workspace_row_type_id__once;
}

static void
_vala_gala_workspace_row_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	GalaWorkspaceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRow);
	switch (property_id) {
		case GALA_WORKSPACE_ROW_DISPLAY_PROPERTY:
		g_value_set_object (value, gala_workspace_row_get_display (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_workspace_row_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	GalaWorkspaceRow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_WORKSPACE_ROW, GalaWorkspaceRow);
	switch (property_id) {
		case GALA_WORKSPACE_ROW_DISPLAY_PROPERTY:
		gala_workspace_row_set_display (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

