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

/**/
/*  Copyright (C) 2014 Tom Beckmann*/
/**/
/*  This program is free software: you can redistribute it and/or modify*/
/*  it under the terms of the GNU General Public License as published by*/
/*  the Free Software Foundation, either version 3 of the License, or*/
/*  (at your option) any later version.*/
/**/
/*  This program is distributed in the hope that it will be useful,*/
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of*/
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*/
/*  GNU General Public License for more details.*/
/**/
/*  You should have received a copy of the GNU General Public License*/
/*  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
/**/

#include <clutter/clutter.h>
#include <glib-object.h>
#include <meta/window.h>
#include <glib.h>
#include <meta/meta-window-actor.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_SAFE_WINDOW_CLONE (greeter_compositor_safe_window_clone_get_type ())
#define GREETER_COMPOSITOR_SAFE_WINDOW_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowClone))
#define GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowCloneClass))
#define GREETER_COMPOSITOR_IS_SAFE_WINDOW_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE))
#define GREETER_COMPOSITOR_IS_SAFE_WINDOW_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE))
#define GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowCloneClass))

typedef struct _GreeterCompositorSafeWindowClone GreeterCompositorSafeWindowClone;
typedef struct _GreeterCompositorSafeWindowCloneClass GreeterCompositorSafeWindowCloneClass;
typedef struct _GreeterCompositorSafeWindowClonePrivate GreeterCompositorSafeWindowClonePrivate;
enum  {
	GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_0_PROPERTY,
	GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_WINDOW_PROPERTY,
	GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY,
	GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_NUM_PROPERTIES
};
static GParamSpec* greeter_compositor_safe_window_clone_properties[GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GreeterCompositorSafeWindowClone {
	ClutterClone parent_instance;
	GreeterCompositorSafeWindowClonePrivate * priv;
};

struct _GreeterCompositorSafeWindowCloneClass {
	ClutterCloneClass parent_class;
};

struct _GreeterCompositorSafeWindowClonePrivate {
	MetaWindow* _window;
	gboolean _destroy_on_unmanaged;
};

static gint GreeterCompositorSafeWindowClone_private_offset;
static gpointer greeter_compositor_safe_window_clone_parent_class = NULL;

VALA_EXTERN GType greeter_compositor_safe_window_clone_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterCompositorSafeWindowClone, g_object_unref)
VALA_EXTERN MetaWindow* greeter_compositor_safe_window_clone_get_window (GreeterCompositorSafeWindowClone* self);
static void greeter_compositor_safe_window_clone_reset_source (GreeterCompositorSafeWindowClone* self);
static void _greeter_compositor_safe_window_clone_reset_source_meta_window_unmanaged (MetaWindow* _sender,
                                                                               gpointer self);
VALA_EXTERN GreeterCompositorSafeWindowClone* greeter_compositor_safe_window_clone_new (MetaWindow* window,
                                                                            gboolean destroy_on_unmanaged);
VALA_EXTERN GreeterCompositorSafeWindowClone* greeter_compositor_safe_window_clone_construct (GType object_type,
                                                                                  MetaWindow* window,
                                                                                  gboolean destroy_on_unmanaged);
VALA_EXTERN gboolean greeter_compositor_safe_window_clone_get_destroy_on_unmanaged (GreeterCompositorSafeWindowClone* self);
static void greeter_compositor_safe_window_clone_set_window (GreeterCompositorSafeWindowClone* self,
                                                      MetaWindow* value);
VALA_EXTERN void greeter_compositor_safe_window_clone_set_destroy_on_unmanaged (GreeterCompositorSafeWindowClone* self,
                                                                    gboolean value);
static GObject * greeter_compositor_safe_window_clone_constructor (GType type,
                                                            guint n_construct_properties,
                                                            GObjectConstructParam * construct_properties);
static void greeter_compositor_safe_window_clone_finalize (GObject * obj);
static GType greeter_compositor_safe_window_clone_get_type_once (void);
static void _vala_greeter_compositor_safe_window_clone_get_property (GObject * object,
                                                              guint property_id,
                                                              GValue * value,
                                                              GParamSpec * pspec);
static void _vala_greeter_compositor_safe_window_clone_set_property (GObject * object,
                                                              guint property_id,
                                                              const GValue * value,
                                                              GParamSpec * pspec);

static inline gpointer
greeter_compositor_safe_window_clone_get_instance_private (GreeterCompositorSafeWindowClone* self)
{
	return G_STRUCT_MEMBER_P (self, GreeterCompositorSafeWindowClone_private_offset);
}

static void
_greeter_compositor_safe_window_clone_reset_source_meta_window_unmanaged (MetaWindow* _sender,
                                                                          gpointer self)
{
	greeter_compositor_safe_window_clone_reset_source ((GreeterCompositorSafeWindowClone*) self);
}

/**
         * Creates a new SafeWindowClone
         *
         * @param window               The window to clone from
         * @param destroy_on_unmanaged see destroy_on_unmanaged property
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

GreeterCompositorSafeWindowClone*
greeter_compositor_safe_window_clone_construct (GType object_type,
                                                MetaWindow* window,
                                                gboolean destroy_on_unmanaged)
{
	GreeterCompositorSafeWindowClone * self = NULL;
	MetaWindowActor* actor = NULL;
	GObject* _tmp0_;
	MetaWindowActor* _tmp1_;
	g_return_val_if_fail (window != NULL, NULL);
	_tmp0_ = meta_window_get_compositor_private (window);
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, meta_window_actor_get_type (), MetaWindowActor));
	actor = _tmp1_;
	self = (GreeterCompositorSafeWindowClone*) g_object_new (object_type, "window", window, "source", actor, "destroy-on-unmanaged", destroy_on_unmanaged, NULL);
	_g_object_unref0 (actor);
	return self;
}

GreeterCompositorSafeWindowClone*
greeter_compositor_safe_window_clone_new (MetaWindow* window,
                                          gboolean destroy_on_unmanaged)
{
	return greeter_compositor_safe_window_clone_construct (GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, window, destroy_on_unmanaged);
}

static void
greeter_compositor_safe_window_clone_reset_source (GreeterCompositorSafeWindowClone* self)
{
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	clutter_clone_set_source ((ClutterClone*) self, NULL);
	_tmp0_ = self->priv->_destroy_on_unmanaged;
	if (_tmp0_) {
		clutter_actor_destroy ((ClutterActor*) self);
	}
}

MetaWindow*
greeter_compositor_safe_window_clone_get_window (GreeterCompositorSafeWindowClone* self)
{
	MetaWindow* result;
	MetaWindow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_window;
	result = _tmp0_;
	return result;
}

static void
greeter_compositor_safe_window_clone_set_window (GreeterCompositorSafeWindowClone* self,
                                                 MetaWindow* value)
{
	MetaWindow* old_value;
	g_return_if_fail (self != NULL);
	old_value = greeter_compositor_safe_window_clone_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, greeter_compositor_safe_window_clone_properties[GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_WINDOW_PROPERTY]);
	}
}

gboolean
greeter_compositor_safe_window_clone_get_destroy_on_unmanaged (GreeterCompositorSafeWindowClone* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_destroy_on_unmanaged;
	return result;
}

void
greeter_compositor_safe_window_clone_set_destroy_on_unmanaged (GreeterCompositorSafeWindowClone* self,
                                                               gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = greeter_compositor_safe_window_clone_get_destroy_on_unmanaged (self);
	if (old_value != value) {
		self->priv->_destroy_on_unmanaged = value;
		g_object_notify_by_pspec ((GObject *) self, greeter_compositor_safe_window_clone_properties[GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY]);
	}
}

static GObject *
greeter_compositor_safe_window_clone_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GreeterCompositorSafeWindowClone * self;
	ClutterActor* _tmp0_;
	ClutterActor* _tmp1_;
	parent_class = G_OBJECT_CLASS (greeter_compositor_safe_window_clone_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowClone);
	_tmp0_ = clutter_clone_get_source ((ClutterClone*) self);
	_tmp1_ = _tmp0_;
	if (_tmp1_ != NULL) {
		MetaWindow* _tmp2_;
		_tmp2_ = self->priv->_window;
		g_signal_connect_object (_tmp2_, "unmanaged", (GCallback) _greeter_compositor_safe_window_clone_reset_source_meta_window_unmanaged, self, 0);
	}
	return obj;
}

static void
greeter_compositor_safe_window_clone_class_init (GreeterCompositorSafeWindowCloneClass * klass,
                                                 gpointer klass_data)
{
	greeter_compositor_safe_window_clone_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GreeterCompositorSafeWindowClone_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_greeter_compositor_safe_window_clone_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_greeter_compositor_safe_window_clone_set_property;
	G_OBJECT_CLASS (klass)->constructor = greeter_compositor_safe_window_clone_constructor;
	G_OBJECT_CLASS (klass)->finalize = greeter_compositor_safe_window_clone_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_WINDOW_PROPERTY, greeter_compositor_safe_window_clone_properties[GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_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));
	/**
	         * If set to true, the SafeWindowClone will destroy itself when the connected
	         * window is unmanaged
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY, greeter_compositor_safe_window_clone_properties[GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY] = g_param_spec_boolean ("destroy-on-unmanaged", "destroy-on-unmanaged", "destroy-on-unmanaged", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
greeter_compositor_safe_window_clone_instance_init (GreeterCompositorSafeWindowClone * self,
                                                    gpointer klass)
{
	self->priv = greeter_compositor_safe_window_clone_get_instance_private (self);
	self->priv->_destroy_on_unmanaged = FALSE;
}

static void
greeter_compositor_safe_window_clone_finalize (GObject * obj)
{
	GreeterCompositorSafeWindowClone * self;
	MetaWindow* _tmp0_;
	guint _tmp1_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowClone);
	_tmp0_ = self->priv->_window;
	g_signal_parse_name ("unmanaged", meta_window_get_type (), &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp0_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _greeter_compositor_safe_window_clone_reset_source_meta_window_unmanaged, self);
	_g_object_unref0 (self->priv->_window);
	G_OBJECT_CLASS (greeter_compositor_safe_window_clone_parent_class)->finalize (obj);
}

/**
     * A clone for a MetaWindowActor that will guard against the
     * meta_window_appears_focused crash by disabling painting the clone
     * as soon as it gets unavailable.
     */
static GType
greeter_compositor_safe_window_clone_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GreeterCompositorSafeWindowCloneClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) greeter_compositor_safe_window_clone_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GreeterCompositorSafeWindowClone), 0, (GInstanceInitFunc) greeter_compositor_safe_window_clone_instance_init, NULL };
	GType greeter_compositor_safe_window_clone_type_id;
	greeter_compositor_safe_window_clone_type_id = g_type_register_static (clutter_clone_get_type (), "GreeterCompositorSafeWindowClone", &g_define_type_info, 0);
	GreeterCompositorSafeWindowClone_private_offset = g_type_add_instance_private (greeter_compositor_safe_window_clone_type_id, sizeof (GreeterCompositorSafeWindowClonePrivate));
	return greeter_compositor_safe_window_clone_type_id;
}

GType
greeter_compositor_safe_window_clone_get_type (void)
{
	static volatile gsize greeter_compositor_safe_window_clone_type_id__once = 0;
	if (g_once_init_enter (&greeter_compositor_safe_window_clone_type_id__once)) {
		GType greeter_compositor_safe_window_clone_type_id;
		greeter_compositor_safe_window_clone_type_id = greeter_compositor_safe_window_clone_get_type_once ();
		g_once_init_leave (&greeter_compositor_safe_window_clone_type_id__once, greeter_compositor_safe_window_clone_type_id);
	}
	return greeter_compositor_safe_window_clone_type_id__once;
}

static void
_vala_greeter_compositor_safe_window_clone_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec)
{
	GreeterCompositorSafeWindowClone * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowClone);
	switch (property_id) {
		case GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_WINDOW_PROPERTY:
		g_value_set_object (value, greeter_compositor_safe_window_clone_get_window (self));
		break;
		case GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY:
		g_value_set_boolean (value, greeter_compositor_safe_window_clone_get_destroy_on_unmanaged (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_greeter_compositor_safe_window_clone_set_property (GObject * object,
                                                         guint property_id,
                                                         const GValue * value,
                                                         GParamSpec * pspec)
{
	GreeterCompositorSafeWindowClone * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GREETER_COMPOSITOR_TYPE_SAFE_WINDOW_CLONE, GreeterCompositorSafeWindowClone);
	switch (property_id) {
		case GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_WINDOW_PROPERTY:
		greeter_compositor_safe_window_clone_set_window (self, g_value_get_object (value));
		break;
		case GREETER_COMPOSITOR_SAFE_WINDOW_CLONE_DESTROY_ON_UNMANAGED_PROPERTY:
		greeter_compositor_safe_window_clone_set_destroy_on_unmanaged (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

