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

/**/
/*  Copyright (C) 2013 Tom Beckmann, Rico Tzschichholz*/
/**/
/*  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 <meta/meta-background-group.h>
#include <glib-object.h>
#include <meta/display.h>
#include <meta/meta-monitor-manager.h>
#include <glib.h>
#include <clutter/clutter.h>
#include <gdk/gdk.h>
#include <string.h>

#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_BACKGROUND_CONTAINER (gala_background_container_get_type ())
#define GALA_BACKGROUND_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer))
#define GALA_BACKGROUND_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainerClass))
#define GALA_IS_BACKGROUND_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_BACKGROUND_CONTAINER))
#define GALA_IS_BACKGROUND_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_BACKGROUND_CONTAINER))
#define GALA_BACKGROUND_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainerClass))

typedef struct _GalaBackgroundContainer GalaBackgroundContainer;
typedef struct _GalaBackgroundContainerClass GalaBackgroundContainerClass;
typedef struct _GalaBackgroundContainerPrivate GalaBackgroundContainerPrivate;
enum  {
	GALA_BACKGROUND_CONTAINER_0_PROPERTY,
	GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY,
	GALA_BACKGROUND_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* gala_background_container_properties[GALA_BACKGROUND_CONTAINER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_TYPE_BACKGROUND_MANAGER (gala_background_manager_get_type ())
#define GALA_BACKGROUND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManager))
#define GALA_BACKGROUND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManagerClass))
#define GALA_IS_BACKGROUND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_BACKGROUND_MANAGER))
#define GALA_IS_BACKGROUND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_BACKGROUND_MANAGER))
#define GALA_BACKGROUND_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_BACKGROUND_MANAGER, GalaBackgroundManagerClass))

typedef struct _GalaBackgroundManager GalaBackgroundManager;
typedef struct _GalaBackgroundManagerClass GalaBackgroundManagerClass;
enum  {
	GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL,
	GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL,
	GALA_BACKGROUND_CONTAINER_NUM_SIGNALS
};
static guint gala_background_container_signals[GALA_BACKGROUND_CONTAINER_NUM_SIGNALS] = {0};

struct _GalaBackgroundContainer {
	MetaBackgroundGroup parent_instance;
	GalaBackgroundContainerPrivate * priv;
};

struct _GalaBackgroundContainerClass {
	MetaBackgroundGroupClass parent_class;
};

struct _GalaBackgroundContainerPrivate {
	MetaDisplay* _display;
};

static gint GalaBackgroundContainer_private_offset;
static gpointer gala_background_container_parent_class = NULL;

VALA_EXTERN GType gala_background_container_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaBackgroundContainer, g_object_unref)
static void gala_background_container_update (GalaBackgroundContainer* self);
static void _gala_background_container_update_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                              gpointer self);
VALA_EXTERN GalaBackgroundContainer* gala_background_container_new (MetaDisplay* display);
VALA_EXTERN GalaBackgroundContainer* gala_background_container_construct (GType object_type,
                                                              MetaDisplay* display);
VALA_EXTERN GType gala_background_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaBackgroundManager, g_object_unref)
static void gala_background_container_background_changed (GalaBackgroundContainer* self);
static void _gala_background_container_background_changed_gala_background_manager_changed (GalaBackgroundManager* _sender,
                                                                                    gpointer self);
VALA_EXTERN MetaDisplay* gala_background_container_get_display (GalaBackgroundContainer* self);
VALA_EXTERN GalaBackgroundManager* gala_background_manager_new (MetaDisplay* display,
                                                    gint monitor_index,
                                                    gboolean control_position);
VALA_EXTERN GalaBackgroundManager* gala_background_manager_construct (GType object_type,
                                                          MetaDisplay* display,
                                                          gint monitor_index,
                                                          gboolean control_position);
static void gala_background_container_set_display (GalaBackgroundContainer* self,
                                            MetaDisplay* value);
static void g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data);
static GObject * gala_background_container_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static gboolean _gala_background_container___lambda63_ (GalaBackgroundContainer* self,
                                                 ClutterButtonEvent* event);
static gboolean __gala_background_container___lambda63__clutter_actor_button_release_event (ClutterActor* _sender,
                                                                                     ClutterButtonEvent* event,
                                                                                     gpointer self);
static void gala_background_container_finalize (GObject * obj);
static GType gala_background_container_get_type_once (void);
static void _vala_gala_background_container_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gala_background_container_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
gala_background_container_get_instance_private (GalaBackgroundContainer* self)
{
	return G_STRUCT_MEMBER_P (self, GalaBackgroundContainer_private_offset);
}

static void
_gala_background_container_update_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                         gpointer self)
{
	gala_background_container_update ((GalaBackgroundContainer*) self);
}

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

GalaBackgroundContainer*
gala_background_container_new (MetaDisplay* display)
{
	return gala_background_container_construct (GALA_TYPE_BACKGROUND_CONTAINER, display);
}

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

static void
_gala_background_container_background_changed_gala_background_manager_changed (GalaBackgroundManager* _sender,
                                                                               gpointer self)
{
	gala_background_container_background_changed ((GalaBackgroundContainer*) self);
}

static void
gala_background_container_update (GalaBackgroundContainer* self)
{
	GalaBackgroundManager* reference_child = NULL;
	ClutterActor* _tmp0_;
	GalaBackgroundManager* _tmp1_;
	GalaBackgroundManager* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = clutter_actor_get_child_at_index ((ClutterActor*) self, 0);
	_tmp1_ = _g_object_ref0 (GALA_IS_BACKGROUND_MANAGER (_tmp0_) ? ((GalaBackgroundManager*) _tmp0_) : NULL);
	reference_child = _tmp1_;
	_tmp2_ = reference_child;
	if (_tmp2_ != NULL) {
		GalaBackgroundManager* _tmp3_;
		guint _tmp4_;
		_tmp3_ = reference_child;
		g_signal_parse_name ("changed", GALA_TYPE_BACKGROUND_MANAGER, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _gala_background_container_background_changed_gala_background_manager_changed, self);
	}
	clutter_actor_destroy_all_children ((ClutterActor*) self);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				MetaDisplay* _tmp7_;
				GalaBackgroundManager* background = NULL;
				MetaDisplay* _tmp8_;
				GalaBackgroundManager* _tmp9_;
				GalaBackgroundManager* _tmp10_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				_tmp7_ = self->priv->_display;
				if (!(i < meta_display_get_n_monitors (_tmp7_))) {
					break;
				}
				_tmp8_ = self->priv->_display;
				_tmp9_ = gala_background_manager_new (_tmp8_, i, TRUE);
				g_object_ref_sink (_tmp9_);
				background = _tmp9_;
				_tmp10_ = background;
				clutter_actor_add_child ((ClutterActor*) self, (ClutterActor*) _tmp10_);
				if (i == 0) {
					GalaBackgroundManager* _tmp11_;
					_tmp11_ = background;
					g_signal_connect_object (_tmp11_, "changed", (GCallback) _gala_background_container_background_changed_gala_background_manager_changed, self, 0);
				}
				_g_object_unref0 (background);
			}
		}
	}
	_g_object_unref0 (reference_child);
}

static void
gala_background_container_background_changed (GalaBackgroundContainer* self)
{
	g_return_if_fail (self != NULL);
	g_signal_emit (self, gala_background_container_signals[GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL], 0);
}

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

static void
gala_background_container_set_display (GalaBackgroundContainer* self,
                                       MetaDisplay* value)
{
	MetaDisplay* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_background_container_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_background_container_properties[GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure,
                                       GValue * return_value,
                                       guint n_param_values,
                                       const GValue * param_values,
                                       gpointer invocation_hint,
                                       gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1, gint arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), data2);
}

static gboolean
_gala_background_container___lambda63_ (GalaBackgroundContainer* self,
                                        ClutterButtonEvent* event)
{
	g_return_val_if_fail (event != NULL, FALSE);
	if (event->button == ((guint32) GDK_BUTTON_SECONDARY)) {
		g_signal_emit (self, gala_background_container_signals[GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL], 0, (gint) event->x, (gint) event->y);
	}
}

static gboolean
__gala_background_container___lambda63__clutter_actor_button_release_event (ClutterActor* _sender,
                                                                            ClutterButtonEvent* event,
                                                                            gpointer self)
{
	gboolean result;
	result = _gala_background_container___lambda63_ ((GalaBackgroundContainer*) self, event);
	return result;
}

static GObject *
gala_background_container_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaBackgroundContainer * self;
	MetaMonitorManager* _tmp0_;
	parent_class = G_OBJECT_CLASS (gala_background_container_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	_tmp0_ = meta_monitor_manager_get ();
	g_signal_connect_object (_tmp0_, "monitors-changed", (GCallback) _gala_background_container_update_meta_monitor_manager_monitors_changed, self, 0);
	clutter_actor_set_reactive ((ClutterActor*) self, TRUE);
	g_signal_connect_object ((ClutterActor*) self, "button-release-event", (GCallback) __gala_background_container___lambda63__clutter_actor_button_release_event, self, 0);
	gala_background_container_update (self);
	return obj;
}

static void
gala_background_container_class_init (GalaBackgroundContainerClass * klass,
                                      gpointer klass_data)
{
	gala_background_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaBackgroundContainer_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_background_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_background_container_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_background_container_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_background_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY, gala_background_container_properties[GALA_BACKGROUND_CONTAINER_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));
	gala_background_container_signals[GALA_BACKGROUND_CONTAINER_CHANGED_SIGNAL] = g_signal_new ("changed", GALA_TYPE_BACKGROUND_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	gala_background_container_signals[GALA_BACKGROUND_CONTAINER_SHOW_BACKGROUND_MENU_SIGNAL] = g_signal_new ("show-background-menu", GALA_TYPE_BACKGROUND_CONTAINER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
}

static void
gala_background_container_instance_init (GalaBackgroundContainer * self,
                                         gpointer klass)
{
	self->priv = gala_background_container_get_instance_private (self);
}

static void
gala_background_container_finalize (GObject * obj)
{
	GalaBackgroundContainer * self;
	MetaMonitorManager* _tmp0_;
	guint _tmp1_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	_tmp0_ = meta_monitor_manager_get ();
	g_signal_parse_name ("monitors-changed", meta_monitor_manager_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) _gala_background_container_update_meta_monitor_manager_monitors_changed, self);
	_g_object_unref0 (self->priv->_display);
	G_OBJECT_CLASS (gala_background_container_parent_class)->finalize (obj);
}

static GType
gala_background_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaBackgroundContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_background_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaBackgroundContainer), 0, (GInstanceInitFunc) gala_background_container_instance_init, NULL };
	GType gala_background_container_type_id;
	gala_background_container_type_id = g_type_register_static (meta_background_group_get_type (), "GalaBackgroundContainer", &g_define_type_info, 0);
	GalaBackgroundContainer_private_offset = g_type_add_instance_private (gala_background_container_type_id, sizeof (GalaBackgroundContainerPrivate));
	return gala_background_container_type_id;
}

GType
gala_background_container_get_type (void)
{
	static volatile gsize gala_background_container_type_id__once = 0;
	if (g_once_init_enter (&gala_background_container_type_id__once)) {
		GType gala_background_container_type_id;
		gala_background_container_type_id = gala_background_container_get_type_once ();
		g_once_init_leave (&gala_background_container_type_id__once, gala_background_container_type_id);
	}
	return gala_background_container_type_id__once;
}

static void
_vala_gala_background_container_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GalaBackgroundContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	switch (property_id) {
		case GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY:
		g_value_set_object (value, gala_background_container_get_display (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_background_container_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GalaBackgroundContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_BACKGROUND_CONTAINER, GalaBackgroundContainer);
	switch (property_id) {
		case GALA_BACKGROUND_CONTAINER_DISPLAY_PROPERTY:
		gala_background_container_set_display (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

