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

/*
 * Copyright 2021 elementary, Inc (https://elementary.io)
 *           2015 Rory J Sanderson
 *
 * 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 "gala-maskcorners.h"
#include "gala.h"
#include <gio/gio.h>
#include <glib.h>
#include <clutter/clutter.h>
#include <meta/display.h>
#include <meta/meta-plugin.h>
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <meta/meta-monitor-manager.h>
#include <meta/boxes.h>
#include <cairo-gobject.h>
#include <float.h>
#include <math.h>
#include <glib-object.h>

#define GALA_PLUGINS_MASK_CORNERS_MAIN_DEFAULT_CORNER_RADIUS 6

enum  {
	GALA_PLUGINS_MASK_CORNERS_MAIN_0_PROPERTY,
	GALA_PLUGINS_MASK_CORNERS_MAIN_NUM_PROPERTIES
};
static GParamSpec* gala_plugins_mask_corners_main_properties[GALA_PLUGINS_MASK_CORNERS_MAIN_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GalaPluginsMaskCornersMainPrivate {
	GalaWindowManager* wm;
	GSettings* settings;
	gint corner_radius;
	GList** cornermasks;
	gint cornermasks_length1;
	gint _cornermasks_size_;
	MetaDisplay* display;
};

static gint GalaPluginsMaskCornersMain_private_offset;
static gpointer gala_plugins_mask_corners_main_parent_class = NULL;

static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static void gala_plugins_mask_corners_main_real_initialize (GalaPlugin* base,
                                                     GalaWindowManager* wm);
static void gala_plugins_mask_corners_main_setup_cornermasks (GalaPluginsMaskCornersMain* self);
static void gala_plugins_mask_corners_main_resetup_cornermasks (GalaPluginsMaskCornersMain* self);
static void _gala_plugins_mask_corners_main_resetup_cornermasks_g_settings_changed (GSettings* _sender,
                                                                             const gchar* key,
                                                                             gpointer self);
static void gala_plugins_mask_corners_main_real_destroy (GalaPlugin* base);
static void gala_plugins_mask_corners_main_destroy_cornermasks (GalaPluginsMaskCornersMain* self);
static void gala_plugins_mask_corners_main_add_cornermasks (GalaPluginsMaskCornersMain* self,
                                                     gint monitor_no);
static void gala_plugins_mask_corners_main_fullscreen_changed (GalaPluginsMaskCornersMain* self);
static void _gala_plugins_mask_corners_main_fullscreen_changed_meta_display_in_fullscreen_changed (MetaDisplay* _sender,
                                                                                            gpointer self);
static void _gala_plugins_mask_corners_main_resetup_cornermasks_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                                                gpointer self);
static void _gala_plugins_mask_corners_main_resetup_cornermasks_meta_display_gl_video_memory_purged (MetaDisplay* _sender,
                                                                                              gpointer self);
static gboolean gala_plugins_mask_corners_main_draw_cornermask (GalaPluginsMaskCornersMain* self,
                                                         cairo_t* context);
static gboolean _gala_plugins_mask_corners_main_draw_cornermask_clutter_canvas_draw (ClutterCanvas* _sender,
                                                                              cairo_t* cr,
                                                                              gint width,
                                                                              gint height,
                                                                              gpointer self);
static void gala_plugins_mask_corners_main_finalize (GObject * obj);
static GType gala_plugins_mask_corners_main_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
gala_plugins_mask_corners_main_get_instance_private (GalaPluginsMaskCornersMain* self)
{
	return G_STRUCT_MEMBER_P (self, GalaPluginsMaskCornersMain_private_offset);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

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

static void
_gala_plugins_mask_corners_main_resetup_cornermasks_g_settings_changed (GSettings* _sender,
                                                                        const gchar* key,
                                                                        gpointer self)
{
	gala_plugins_mask_corners_main_resetup_cornermasks ((GalaPluginsMaskCornersMain*) self);
}

static void
gala_plugins_mask_corners_main_real_initialize (GalaPlugin* base,
                                                GalaWindowManager* wm)
{
	GalaPluginsMaskCornersMain * self;
	GalaWindowManager* _tmp0_;
	MetaDisplay* _tmp1_;
	MetaDisplay* _tmp2_;
	GSettings* _tmp3_;
	GSettings* _tmp4_;
	self = (GalaPluginsMaskCornersMain*) base;
	g_return_if_fail (wm != NULL);
	_tmp0_ = _g_object_ref0 (wm);
	_g_object_unref0 (self->priv->wm);
	self->priv->wm = _tmp0_;
	_tmp1_ = meta_plugin_get_display ((MetaPlugin*) wm);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_g_object_unref0 (self->priv->display);
	self->priv->display = _tmp2_;
	_tmp3_ = g_settings_new (SCHEMA ".mask-corners");
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp3_;
	gala_plugins_mask_corners_main_setup_cornermasks (self);
	_tmp4_ = self->priv->settings;
	g_signal_connect_object (_tmp4_, "changed", (GCallback) _gala_plugins_mask_corners_main_resetup_cornermasks_g_settings_changed, self, 0);
}

static void
gala_plugins_mask_corners_main_real_destroy (GalaPlugin* base)
{
	GalaPluginsMaskCornersMain * self;
	self = (GalaPluginsMaskCornersMain*) base;
	gala_plugins_mask_corners_main_destroy_cornermasks (self);
}

static void
_gala_plugins_mask_corners_main_fullscreen_changed_meta_display_in_fullscreen_changed (MetaDisplay* _sender,
                                                                                       gpointer self)
{
	gala_plugins_mask_corners_main_fullscreen_changed ((GalaPluginsMaskCornersMain*) self);
}

static void
_gala_plugins_mask_corners_main_resetup_cornermasks_meta_monitor_manager_monitors_changed (MetaMonitorManager* _sender,
                                                                                           gpointer self)
{
	gala_plugins_mask_corners_main_resetup_cornermasks ((GalaPluginsMaskCornersMain*) self);
}

static void
_gala_plugins_mask_corners_main_resetup_cornermasks_meta_display_gl_video_memory_purged (MetaDisplay* _sender,
                                                                                         gpointer self)
{
	gala_plugins_mask_corners_main_resetup_cornermasks ((GalaPluginsMaskCornersMain*) self);
}

static void
gala_plugins_mask_corners_main_setup_cornermasks (GalaPluginsMaskCornersMain* self)
{
	GSettings* _tmp0_;
	gint scale = 0;
	gint n_monitors = 0;
	MetaDisplay* _tmp1_;
	GList** _tmp2_;
	GSettings* _tmp3_;
	GSettings* _tmp7_;
	MetaMonitorManager* monitor_manager = NULL;
	MetaMonitorManager* _tmp9_;
	MetaMonitorManager* _tmp10_;
	MetaDisplay* _tmp11_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->settings;
	if (!g_settings_get_boolean (_tmp0_, "enable")) {
		return;
	}
	scale = gala_utils_get_ui_scaling_factor ();
	_tmp1_ = self->priv->display;
	n_monitors = meta_display_get_n_monitors (_tmp1_);
	_tmp2_ = g_new0 (GList*, n_monitors + 1);
	self->priv->cornermasks = (_vala_array_free (self->priv->cornermasks, self->priv->cornermasks_length1, (GDestroyNotify) _g_list_free__g_object_unref0_), NULL);
	self->priv->cornermasks = _tmp2_;
	self->priv->cornermasks_length1 = n_monitors;
	self->priv->_cornermasks_size_ = self->priv->cornermasks_length1;
	self->priv->corner_radius = GALA_PLUGINS_MASK_CORNERS_MAIN_DEFAULT_CORNER_RADIUS * scale;
	_tmp3_ = self->priv->settings;
	if (g_settings_get_boolean (_tmp3_, "only-on-primary")) {
		MetaDisplay* _tmp4_;
		_tmp4_ = self->priv->display;
		gala_plugins_mask_corners_main_add_cornermasks (self, meta_display_get_primary_monitor (_tmp4_));
	} else {
		{
			gint m = 0;
			m = 0;
			{
				gboolean _tmp5_ = FALSE;
				_tmp5_ = TRUE;
				while (TRUE) {
					if (!_tmp5_) {
						gint _tmp6_;
						_tmp6_ = m;
						m = _tmp6_ + 1;
					}
					_tmp5_ = FALSE;
					if (!(m < n_monitors)) {
						break;
					}
					gala_plugins_mask_corners_main_add_cornermasks (self, m);
				}
			}
		}
	}
	_tmp7_ = self->priv->settings;
	if (g_settings_get_boolean (_tmp7_, "disable-on-fullscreen")) {
		MetaDisplay* _tmp8_;
		_tmp8_ = self->priv->display;
		g_signal_connect_object (_tmp8_, "in-fullscreen-changed", (GCallback) _gala_plugins_mask_corners_main_fullscreen_changed_meta_display_in_fullscreen_changed, self, 0);
	}
	_tmp9_ = meta_monitor_manager_get ();
	monitor_manager = _tmp9_;
	_tmp10_ = monitor_manager;
	g_signal_connect_object (_tmp10_, "monitors-changed", (GCallback) _gala_plugins_mask_corners_main_resetup_cornermasks_meta_monitor_manager_monitors_changed, self, 0);
	_tmp11_ = self->priv->display;
	g_signal_connect_object (_tmp11_, "gl-video-memory-purged", (GCallback) _gala_plugins_mask_corners_main_resetup_cornermasks_meta_display_gl_video_memory_purged, self, 0);
}

static void
gala_plugins_mask_corners_main_destroy_cornermasks (GalaPluginsMaskCornersMain* self)
{
	MetaDisplay* _tmp0_;
	guint _tmp1_;
	MetaMonitorManager* monitor_manager = NULL;
	MetaMonitorManager* _tmp2_;
	MetaMonitorManager* _tmp3_;
	guint _tmp4_;
	MetaDisplay* _tmp5_;
	guint _tmp6_;
	GList** _tmp7_;
	gint _tmp7__length1;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->display;
	g_signal_parse_name ("gl-video-memory-purged", meta_display_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_plugins_mask_corners_main_resetup_cornermasks_meta_display_gl_video_memory_purged, self);
	_tmp2_ = meta_monitor_manager_get ();
	monitor_manager = _tmp2_;
	_tmp3_ = monitor_manager;
	g_signal_parse_name ("monitors-changed", meta_monitor_manager_get_type (), &_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_plugins_mask_corners_main_resetup_cornermasks_meta_monitor_manager_monitors_changed, self);
	_tmp5_ = self->priv->display;
	g_signal_parse_name ("in-fullscreen-changed", meta_display_get_type (), &_tmp6_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp5_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, 0, NULL, (GCallback) _gala_plugins_mask_corners_main_fullscreen_changed_meta_display_in_fullscreen_changed, self);
	_tmp7_ = self->priv->cornermasks;
	_tmp7__length1 = self->priv->cornermasks_length1;
	{
		GList** list_collection = NULL;
		gint list_collection_length1 = 0;
		gint _list_collection_size_ = 0;
		gint list_it = 0;
		list_collection = _tmp7_;
		list_collection_length1 = _tmp7__length1;
		for (list_it = 0; list_it < list_collection_length1; list_it = list_it + 1) {
			GList* list = NULL;
			list = list_collection[list_it];
			{
				GList* _tmp8_;
				_tmp8_ = list;
				{
					GList* actor_collection = NULL;
					GList* actor_it = NULL;
					actor_collection = _tmp8_;
					for (actor_it = actor_collection; actor_it != NULL; actor_it = actor_it->next) {
						ClutterActor* _tmp9_;
						ClutterActor* actor = NULL;
						_tmp9_ = _g_object_ref0 ((ClutterActor*) actor_it->data);
						actor = _tmp9_;
						{
							ClutterActor* _tmp10_;
							_tmp10_ = actor;
							clutter_actor_destroy (_tmp10_);
							_g_object_unref0 (actor);
						}
					}
				}
			}
		}
	}
}

static void
gala_plugins_mask_corners_main_resetup_cornermasks (GalaPluginsMaskCornersMain* self)
{
	g_return_if_fail (self != NULL);
	gala_plugins_mask_corners_main_destroy_cornermasks (self);
	gala_plugins_mask_corners_main_setup_cornermasks (self);
}

static void
gala_plugins_mask_corners_main_fullscreen_changed (GalaPluginsMaskCornersMain* self)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				MetaDisplay* _tmp2_;
				GList** _tmp3_;
				gint _tmp3__length1;
				GList* _tmp4_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->display;
				if (!(i < meta_display_get_n_monitors (_tmp2_))) {
					break;
				}
				_tmp3_ = self->priv->cornermasks;
				_tmp3__length1 = self->priv->cornermasks_length1;
				_tmp4_ = _tmp3_[i];
				{
					GList* actor_collection = NULL;
					GList* actor_it = NULL;
					actor_collection = _tmp4_;
					for (actor_it = actor_collection; actor_it != NULL; actor_it = actor_it->next) {
						ClutterActor* _tmp5_;
						ClutterActor* actor = NULL;
						_tmp5_ = _g_object_ref0 ((ClutterActor*) actor_it->data);
						actor = _tmp5_;
						{
							MetaDisplay* _tmp6_;
							_tmp6_ = self->priv->display;
							if (meta_display_get_monitor_in_fullscreen (_tmp6_, i)) {
								ClutterActor* _tmp7_;
								_tmp7_ = actor;
								clutter_actor_hide (_tmp7_);
							} else {
								ClutterActor* _tmp8_;
								_tmp8_ = actor;
								clutter_actor_show (_tmp8_);
							}
							_g_object_unref0 (actor);
						}
					}
				}
			}
		}
	}
}

static gboolean
_gala_plugins_mask_corners_main_draw_cornermask_clutter_canvas_draw (ClutterCanvas* _sender,
                                                                     cairo_t* cr,
                                                                     gint width,
                                                                     gint height,
                                                                     gpointer self)
{
	gboolean result;
	result = gala_plugins_mask_corners_main_draw_cornermask ((GalaPluginsMaskCornersMain*) self, cr);
	return result;
}

static void
gala_plugins_mask_corners_main_add_cornermasks (GalaPluginsMaskCornersMain* self,
                                                gint monitor_no)
{
	MetaRectangle monitor_geometry = {0};
	MetaDisplay* _tmp0_;
	MetaRectangle _tmp1_ = {0};
	ClutterCanvas* canvas = NULL;
	ClutterCanvas* _tmp2_;
	ClutterCanvas* _tmp3_;
	ClutterCanvas* _tmp4_;
	ClutterCanvas* _tmp5_;
	ClutterActor* actor = NULL;
	ClutterActor* _tmp6_;
	ClutterActor* _tmp7_;
	ClutterCanvas* _tmp8_;
	ClutterActor* _tmp9_;
	ClutterActor* _tmp10_;
	MetaRectangle _tmp11_;
	MetaRectangle _tmp12_;
	ClutterActor* _tmp13_;
	GList** _tmp14_;
	gint _tmp14__length1;
	ClutterActor* _tmp15_;
	ClutterActor* _tmp16_;
	GalaWindowManager* _tmp17_;
	ClutterStage* _tmp18_;
	ClutterStage* _tmp19_;
	ClutterActor* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->display;
	meta_display_get_monitor_geometry (_tmp0_, monitor_no, &_tmp1_);
	monitor_geometry = _tmp1_;
	_tmp2_ = (ClutterCanvas*) clutter_canvas_new ();
	canvas = _tmp2_;
	_tmp3_ = canvas;
	clutter_canvas_set_size (_tmp3_, self->priv->corner_radius, self->priv->corner_radius);
	_tmp4_ = canvas;
	g_signal_connect_object (_tmp4_, "draw", (GCallback) _gala_plugins_mask_corners_main_draw_cornermask_clutter_canvas_draw, self, 0);
	_tmp5_ = canvas;
	clutter_content_invalidate ((ClutterContent*) _tmp5_);
	_tmp6_ = clutter_actor_new ();
	g_object_ref_sink (_tmp6_);
	actor = _tmp6_;
	_tmp7_ = actor;
	_tmp8_ = canvas;
	clutter_actor_set_content (_tmp7_, (ClutterContent*) _tmp8_);
	_tmp9_ = actor;
	clutter_actor_set_size (_tmp9_, (gfloat) self->priv->corner_radius, (gfloat) self->priv->corner_radius);
	_tmp10_ = actor;
	_tmp11_ = monitor_geometry;
	_tmp12_ = monitor_geometry;
	clutter_actor_set_position (_tmp10_, (gfloat) _tmp11_.x, (gfloat) _tmp12_.y);
	_tmp13_ = actor;
	clutter_actor_set_pivot_point (_tmp13_, (gfloat) 0.5, (gfloat) 0.5);
	_tmp14_ = self->priv->cornermasks;
	_tmp14__length1 = self->priv->cornermasks_length1;
	_tmp15_ = actor;
	_tmp16_ = _g_object_ref0 (_tmp15_);
	_tmp14_[monitor_no] = g_list_append (_tmp14_[monitor_no], _tmp16_);
	_tmp17_ = self->priv->wm;
	_tmp18_ = gala_window_manager_get_stage (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = actor;
	clutter_actor_add_child ((ClutterActor*) _tmp19_, _tmp20_);
	{
		gint p = 0;
		p = 1;
		{
			gboolean _tmp21_ = FALSE;
			_tmp21_ = TRUE;
			while (TRUE) {
				ClutterClone* clone = NULL;
				ClutterActor* _tmp23_;
				ClutterClone* _tmp24_;
				ClutterClone* _tmp25_;
				GList** _tmp39_;
				gint _tmp39__length1;
				ClutterClone* _tmp40_;
				ClutterActor* _tmp41_;
				GalaWindowManager* _tmp42_;
				ClutterStage* _tmp43_;
				ClutterStage* _tmp44_;
				ClutterClone* _tmp45_;
				if (!_tmp21_) {
					gint _tmp22_;
					_tmp22_ = p;
					p = _tmp22_ + 1;
				}
				_tmp21_ = FALSE;
				if (!(p < 4)) {
					break;
				}
				_tmp23_ = actor;
				_tmp24_ = (ClutterClone*) clutter_clone_new (_tmp23_);
				g_object_ref_sink (_tmp24_);
				clone = _tmp24_;
				_tmp25_ = clone;
				g_object_set ((ClutterActor*) _tmp25_, "rotation-angle-z", (gdouble) (p * 90), NULL);
				switch (p) {
					case 1:
					{
						ClutterClone* _tmp26_;
						MetaRectangle _tmp27_;
						MetaRectangle _tmp28_;
						MetaRectangle _tmp29_;
						_tmp26_ = clone;
						_tmp27_ = monitor_geometry;
						_tmp28_ = monitor_geometry;
						_tmp29_ = monitor_geometry;
						clutter_actor_set_position ((ClutterActor*) _tmp26_, (gfloat) (_tmp27_.x + _tmp28_.width), (gfloat) _tmp29_.y);
						break;
					}
					case 2:
					{
						ClutterClone* _tmp30_;
						MetaRectangle _tmp31_;
						MetaRectangle _tmp32_;
						MetaRectangle _tmp33_;
						MetaRectangle _tmp34_;
						_tmp30_ = clone;
						_tmp31_ = monitor_geometry;
						_tmp32_ = monitor_geometry;
						_tmp33_ = monitor_geometry;
						_tmp34_ = monitor_geometry;
						clutter_actor_set_position ((ClutterActor*) _tmp30_, (gfloat) (_tmp31_.x + _tmp32_.width), (gfloat) (_tmp33_.y + _tmp34_.height));
						break;
					}
					case 3:
					{
						ClutterClone* _tmp35_;
						MetaRectangle _tmp36_;
						MetaRectangle _tmp37_;
						MetaRectangle _tmp38_;
						_tmp35_ = clone;
						_tmp36_ = monitor_geometry;
						_tmp37_ = monitor_geometry;
						_tmp38_ = monitor_geometry;
						clutter_actor_set_position ((ClutterActor*) _tmp35_, (gfloat) _tmp36_.x, (gfloat) (_tmp37_.y + _tmp38_.height));
						break;
					}
					default:
					break;
				}
				_tmp39_ = self->priv->cornermasks;
				_tmp39__length1 = self->priv->cornermasks_length1;
				_tmp40_ = clone;
				_tmp41_ = _g_object_ref0 ((ClutterActor*) _tmp40_);
				_tmp39_[monitor_no] = g_list_append (_tmp39_[monitor_no], _tmp41_);
				_tmp42_ = self->priv->wm;
				_tmp43_ = gala_window_manager_get_stage (_tmp42_);
				_tmp44_ = _tmp43_;
				_tmp45_ = clone;
				clutter_actor_add_child ((ClutterActor*) _tmp44_, (ClutterActor*) _tmp45_);
				_g_object_unref0 (clone);
			}
		}
	}
	_g_object_unref0 (actor);
	_g_object_unref0 (canvas);
}

static gpointer
_cairo_reference0 (gpointer self)
{
	return self ? cairo_reference (self) : NULL;
}

static gboolean
gala_plugins_mask_corners_main_draw_cornermask (GalaPluginsMaskCornersMain* self,
                                                cairo_t* context)
{
	GalaDrawingBufferSurface* buffer = NULL;
	GalaDrawingBufferSurface* _tmp0_;
	cairo_t* buffer_context = NULL;
	cairo_t* _tmp1_;
	cairo_t* _tmp2_;
	cairo_t* _tmp3_;
	cairo_surface_t* _tmp4_;
	cairo_surface_t* _tmp5_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (context != NULL, FALSE);
	_tmp0_ = gala_drawing_buffer_surface_new (self->priv->corner_radius, self->priv->corner_radius);
	buffer = _tmp0_;
	_tmp1_ = gala_drawing_buffer_surface_get_context (buffer);
	_tmp2_ = _tmp1_;
	_tmp3_ = _cairo_reference0 (_tmp2_);
	buffer_context = _tmp3_;
	cairo_arc (buffer_context, (gdouble) self->priv->corner_radius, (gdouble) self->priv->corner_radius, (gdouble) self->priv->corner_radius, G_PI, 1.5 * G_PI);
	cairo_line_to (buffer_context, (gdouble) 0, (gdouble) 0);
	cairo_line_to (buffer_context, (gdouble) 0, (gdouble) self->priv->corner_radius);
	cairo_set_source_rgb (buffer_context, (gdouble) 0, (gdouble) 0, (gdouble) 0);
	cairo_fill (buffer_context);
	cairo_set_operator (context, CAIRO_OPERATOR_CLEAR);
	cairo_paint (context);
	cairo_set_operator (context, CAIRO_OPERATOR_OVER);
	_tmp4_ = gala_drawing_buffer_surface_get_surface (buffer);
	_tmp5_ = _tmp4_;
	cairo_set_source_surface (context, _tmp5_, (gdouble) 0, (gdouble) 0);
	cairo_paint (context);
	result = TRUE;
	_cairo_destroy0 (buffer_context);
	_g_object_unref0 (buffer);
	return result;
}

GalaPluginsMaskCornersMain*
gala_plugins_mask_corners_main_construct (GType object_type)
{
	GalaPluginsMaskCornersMain * self = NULL;
	self = (GalaPluginsMaskCornersMain*) gala_plugin_construct (object_type);
	return self;
}

GalaPluginsMaskCornersMain*
gala_plugins_mask_corners_main_new (void)
{
	return gala_plugins_mask_corners_main_construct (GALA_PLUGINS_MASK_CORNERS_TYPE_MAIN);
}

static void
gala_plugins_mask_corners_main_class_init (GalaPluginsMaskCornersMainClass * klass,
                                           gpointer klass_data)
{
	gala_plugins_mask_corners_main_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaPluginsMaskCornersMain_private_offset);
	((GalaPluginClass *) klass)->initialize = (void (*) (GalaPlugin*, GalaWindowManager*)) gala_plugins_mask_corners_main_real_initialize;
	((GalaPluginClass *) klass)->destroy = (void (*) (GalaPlugin*)) gala_plugins_mask_corners_main_real_destroy;
	G_OBJECT_CLASS (klass)->finalize = gala_plugins_mask_corners_main_finalize;
}

static void
gala_plugins_mask_corners_main_instance_init (GalaPluginsMaskCornersMain * self,
                                              gpointer klass)
{
	self->priv = gala_plugins_mask_corners_main_get_instance_private (self);
	self->priv->wm = NULL;
	self->priv->corner_radius = GALA_PLUGINS_MASK_CORNERS_MAIN_DEFAULT_CORNER_RADIUS;
}

static void
gala_plugins_mask_corners_main_finalize (GObject * obj)
{
	GalaPluginsMaskCornersMain * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_PLUGINS_MASK_CORNERS_TYPE_MAIN, GalaPluginsMaskCornersMain);
	_g_object_unref0 (self->priv->wm);
	_g_object_unref0 (self->priv->settings);
	self->priv->cornermasks = (_vala_array_free (self->priv->cornermasks, self->priv->cornermasks_length1, (GDestroyNotify) _g_list_free__g_object_unref0_), NULL);
	_g_object_unref0 (self->priv->display);
	G_OBJECT_CLASS (gala_plugins_mask_corners_main_parent_class)->finalize (obj);
}

static GType
gala_plugins_mask_corners_main_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaPluginsMaskCornersMainClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_plugins_mask_corners_main_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaPluginsMaskCornersMain), 0, (GInstanceInitFunc) gala_plugins_mask_corners_main_instance_init, NULL };
	GType gala_plugins_mask_corners_main_type_id;
	gala_plugins_mask_corners_main_type_id = g_type_register_static (GALA_TYPE_PLUGIN, "GalaPluginsMaskCornersMain", &g_define_type_info, 0);
	GalaPluginsMaskCornersMain_private_offset = g_type_add_instance_private (gala_plugins_mask_corners_main_type_id, sizeof (GalaPluginsMaskCornersMainPrivate));
	return gala_plugins_mask_corners_main_type_id;
}

GType
gala_plugins_mask_corners_main_get_type (void)
{
	static volatile gsize gala_plugins_mask_corners_main_type_id__once = 0;
	if (g_once_init_enter (&gala_plugins_mask_corners_main_type_id__once)) {
		GType gala_plugins_mask_corners_main_type_id;
		gala_plugins_mask_corners_main_type_id = gala_plugins_mask_corners_main_get_type_once ();
		g_once_init_leave (&gala_plugins_mask_corners_main_type_id__once, gala_plugins_mask_corners_main_type_id);
	}
	return gala_plugins_mask_corners_main_type_id__once;
}

void
register_plugin (GalaPluginInfo* result)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	GalaPluginInfo _tmp2_ = {0};
	_tmp0_ = g_strdup ("Mask Corners");
	_tmp1_ = g_strdup ("Gala Developers");
	_g_free0 (_tmp2_.name);
	_tmp2_.name = _tmp0_;
	_g_free0 (_tmp2_.author);
	_tmp2_.author = _tmp1_;
	_tmp2_.plugin_type = GALA_PLUGINS_MASK_CORNERS_TYPE_MAIN;
	_tmp2_.provides = GALA_PLUGIN_FUNCTION_ADDITION;
	_tmp2_.load_priority = GALA_LOAD_PRIORITY_IMMEDIATE;
	*result = _tmp2_;
	return;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

