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

/**/
/*  Copyright (C) 2012 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/>.*/
/**/

#define _GNU_SOURCE

#include <glib.h>
#include <stdio.h>
#include "config.h"
#include <meta/main.h>
#include <meta/meta-context.h>
#include <locale.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <glib-object.h>
#include <meta/meta-plugin.h>
#include <sys/select.h>
#include <signal.h>
#include <errno.h>
#include <glib-unix.h>
#include "gala.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

typedef struct _Block3Data Block3Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

#define GALA_TYPE_WINDOW_MANAGER_GALA (gala_window_manager_gala_get_type ())
#define GALA_WINDOW_MANAGER_GALA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_WINDOW_MANAGER_GALA, GalaWindowManagerGala))
#define GALA_WINDOW_MANAGER_GALA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_WINDOW_MANAGER_GALA, GalaWindowManagerGalaClass))
#define GALA_IS_WINDOW_MANAGER_GALA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_WINDOW_MANAGER_GALA))
#define GALA_IS_WINDOW_MANAGER_GALA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_WINDOW_MANAGER_GALA))
#define GALA_WINDOW_MANAGER_GALA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_WINDOW_MANAGER_GALA, GalaWindowManagerGalaClass))

typedef struct _GalaWindowManagerGala GalaWindowManagerGala;
typedef struct _GalaWindowManagerGalaClass GalaWindowManagerGalaClass;
#define _g_type_class_unref0(var) ((var == NULL) ? NULL : (var = (g_type_class_unref (var), NULL)))

struct _Block3Data {
	int _ref_count_;
	MetaContext* ctx;
};

 G_GNUC_INTERNAL void gala_print_version (void);
static gint gala_main (gchar** args,
                gint args_length1);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
VALA_EXTERN GType gala_window_manager_gala_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaWindowManagerGala, g_object_unref)
static gboolean __lambda191_ (Block3Data* _data3_);
static gboolean ___lambda191__gsource_func (gpointer self);

const GOptionEntry GALA_OPTIONS[2] = {{"version", (gchar) 0, (gint) G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (void*) gala_print_version, "Print version", NULL}, {NULL}};

 G_GNUC_INTERNAL void
gala_print_version (void)
{
	FILE* _tmp0_;
	_tmp0_ = stdout;
	fprintf (_tmp0_, "Gala %s\n", VERSION);
	meta_exit (META_EXIT_SUCCESS);
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		_g_object_unref0 (_data3_->ctx);
		g_slice_free (Block3Data, _data3_);
	}
}

static gboolean
__lambda191_ (Block3Data* _data3_)
{
	MetaContext* _tmp0_;
	gboolean result;
	_tmp0_ = _data3_->ctx;
	meta_context_terminate (_tmp0_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda191__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda191_ (self);
	return result;
}

static gint
gala_main (gchar** args,
           gint args_length1)
{
	Block3Data* _data3_;
	MetaContext* _tmp0_;
	MetaContext* _tmp1_;
	MetaContext* _tmp7_;
	sigset_t empty_mask = {0};
	sigset_t _tmp8_ = {0};
	struct sigaction act = {0};
	struct sigaction _tmp9_ = {0};
	sighandler_t _tmp10_;
	sigset_t _tmp11_;
	struct sigaction _tmp12_;
	struct sigaction _tmp14_;
	GTypeClass* _tmp21_;
	GTypeClass* _tmp22_;
	GError* _inner_error0_ = NULL;
	gint result;
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = meta_create_context ("Mutter(Gala)");
	_data3_->ctx = _tmp0_;
	_tmp1_ = _data3_->ctx;
	meta_context_add_option_entries (_tmp1_, GALA_OPTIONS, GETTEXT_PACKAGE);
	{
		MetaContext* _tmp2_;
		_tmp2_ = _data3_->ctx;
		meta_context_configure (_tmp2_, (gint*) (&args_length1), &args, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp3_;
		GError* _tmp4_;
		const gchar* _tmp5_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = stderr;
		_tmp4_ = e;
		_tmp5_ = _tmp4_->message;
		fprintf (_tmp3_, "Error initializing: %s\n", _tmp5_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block3_data_unref (_data3_);
		_data3_ = NULL;
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp6_ = -1;
		block3_data_unref (_data3_);
		_data3_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp6_;
	}
	_tmp7_ = _data3_->ctx;
	meta_context_set_plugin_gtype (_tmp7_, GALA_TYPE_WINDOW_MANAGER_GALA);
	sigemptyset (&_tmp8_);
	empty_mask = _tmp8_;
	act = _tmp9_;
	_tmp10_ = SIG_IGN;
	act.sa_handler = _tmp10_;
	_tmp11_ = empty_mask;
	act.sa_mask = _tmp11_;
	act.sa_flags = 0;
	_tmp12_ = act;
	if (sigaction (SIGPIPE, &_tmp12_, NULL) < 0) {
		const gchar* _tmp13_;
		_tmp13_ = g_strerror (errno);
		g_warning ("Main.vala:55: Failed to register SIGPIPE handler: %s", _tmp13_);
	}
	_tmp14_ = act;
	if (sigaction (SIGXFSZ, &_tmp14_, NULL) < 0) {
		const gchar* _tmp15_;
		_tmp15_ = g_strerror (errno);
		g_warning ("Main.vala:59: Failed to register SIGXFSZ handler: %s", _tmp15_);
	}
	g_unix_signal_add_full (G_PRIORITY_DEFAULT, SIGTERM, ___lambda191__gsource_func, block3_data_ref (_data3_), block3_data_unref);
	{
		MetaContext* _tmp16_;
		_tmp16_ = _data3_->ctx;
		meta_context_setup (_tmp16_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		FILE* _tmp17_;
		GError* _tmp18_;
		const gchar* _tmp19_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp17_ = stderr;
		_tmp18_ = e;
		_tmp19_ = _tmp18_->message;
		fprintf (_tmp17_, "Failed to setup: %s\n", _tmp19_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block3_data_unref (_data3_);
		_data3_ = NULL;
		return result;
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp20_ = -1;
		block3_data_unref (_data3_);
		_data3_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp20_;
	}
	_tmp21_ = g_type_class_ref (GALA_TYPE_UTILS);
	_tmp22_ = _tmp21_;
	_g_type_class_unref0 (_tmp22_);
	{
		MetaContext* _tmp23_;
		_tmp23_ = _data3_->ctx;
		meta_context_start (_tmp23_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		FILE* _tmp24_;
		GError* _tmp25_;
		const gchar* _tmp26_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp24_ = stderr;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->message;
		fprintf (_tmp24_, "Failed to start: %s\n", _tmp26_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block3_data_unref (_data3_);
		_data3_ = NULL;
		return result;
	}
	__finally2:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp27_ = -1;
		block3_data_unref (_data3_);
		_data3_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp27_;
	}
	{
		MetaContext* _tmp28_;
		_tmp28_ = _data3_->ctx;
		meta_context_run_main_loop (_tmp28_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch3_g_error;
		}
	}
	goto __finally3;
	__catch3_g_error:
	{
		GError* e = NULL;
		FILE* _tmp29_;
		GError* _tmp30_;
		const gchar* _tmp31_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp29_ = stderr;
		_tmp30_ = e;
		_tmp31_ = _tmp30_->message;
		fprintf (_tmp29_, "Gala terminated with a failure: %s\n", _tmp31_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block3_data_unref (_data3_);
		_data3_ = NULL;
		return result;
	}
	__finally3:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp32_ = -1;
		block3_data_unref (_data3_);
		_data3_ = NULL;
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp32_;
	}
	result = EXIT_SUCCESS;
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return result;
}

int
main (int argc,
      char ** argv)
{
	return gala_main (argv, argc);
}

