/* Main.c generated by valac 0.56.18-dirty, 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 <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"
#include <meta/meta-enums.h>

#define CONFIG_VERSION "8.4.1"
#define CONFIG_GETTEXT_PACKAGE "gala"
#define CONFIG_LOCALEDIR "/usr/share/locale"
#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

typedef struct _Block6Data Block6Data;
#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 _Block6Data {
	int _ref_count_;
	MetaContext* ctx;
};

 G_GNUC_INTERNAL void gala_print_version (void);
static gint gala_main (gchar** args,
                gint args_length1);
static Block6Data* block6_data_ref (Block6Data* _data6_);
static void block6_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 __lambda175_ (Block6Data* _data6_);
static gboolean ___lambda175__gsource_func (gpointer self);
VALA_EXTERN void gala_init_pantheon_shell (MetaContext* context);
VALA_EXTERN void gala_window_state_saver_on_shutdown (void);

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", CONFIG_VERSION);
	meta_exit (META_EXIT_SUCCESS);
}

static Block6Data*
block6_data_ref (Block6Data* _data6_)
{
	g_atomic_int_inc (&_data6_->_ref_count_);
	return _data6_;
}

static void
block6_data_unref (void * _userdata_)
{
	Block6Data* _data6_;
	_data6_ = (Block6Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data6_->_ref_count_)) {
		_g_object_unref0 (_data6_->ctx);
		g_slice_free (Block6Data, _data6_);
	}
}

static gboolean
__lambda175_ (Block6Data* _data6_)
{
	MetaContext* _tmp0_;
	gboolean result;
	_tmp0_ = _data6_->ctx;
	meta_context_terminate (_tmp0_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda175__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda175_ (self);
	return result;
}

static gint
gala_main (gchar** args,
           gint args_length1)
{
	Block6Data* _data6_;
	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;
	_data6_ = g_slice_new0 (Block6Data);
	_data6_->_ref_count_ = 1;
	setlocale (LC_ALL, "");
	bindtextdomain (CONFIG_GETTEXT_PACKAGE, CONFIG_LOCALEDIR);
	bind_textdomain_codeset (CONFIG_GETTEXT_PACKAGE, "UTF-8");
	textdomain (CONFIG_GETTEXT_PACKAGE);
	_tmp0_ = meta_create_context ("Mutter(Gala)");
	_data6_->ctx = _tmp0_;
	_tmp1_ = _data6_->ctx;
	meta_context_add_option_entries (_tmp1_, GALA_OPTIONS, CONFIG_GETTEXT_PACKAGE);
	{
		MetaContext* _tmp2_;
		_tmp2_ = _data6_->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);
		block6_data_unref (_data6_);
		_data6_ = NULL;
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp6_ = -1;
		block6_data_unref (_data6_);
		_data6_ = 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_ = _data6_->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 ((gint) SIGPIPE, &_tmp12_, NULL) < 0) {
		const gchar* _tmp13_;
		_tmp13_ = g_strerror (errno);
		g_warning ("Main.vala:54: Failed to register SIGPIPE handler: %s", _tmp13_);
	}
	_tmp14_ = act;
	if (sigaction ((gint) SIGXFSZ, &_tmp14_, NULL) < 0) {
		const gchar* _tmp15_;
		_tmp15_ = g_strerror (errno);
		g_warning ("Main.vala:58: Failed to register SIGXFSZ handler: %s", _tmp15_);
	}
	g_unix_signal_add_full (G_PRIORITY_DEFAULT, (gint) SIGTERM, ___lambda175__gsource_func, block6_data_ref (_data6_), block6_data_unref);
	{
		MetaContext* _tmp16_;
		_tmp16_ = _data6_->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);
		block6_data_unref (_data6_);
		_data6_ = NULL;
		return result;
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp20_ = -1;
		block6_data_unref (_data6_);
		_data6_ = 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_;
		MetaContext* _tmp24_;
		_tmp23_ = _data6_->ctx;
		meta_context_start (_tmp23_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch2_g_error;
		}
		_tmp24_ = _data6_->ctx;
		if (meta_context_get_compositor_type (_tmp24_) == META_COMPOSITOR_TYPE_WAYLAND) {
			MetaContext* _tmp25_;
			_tmp25_ = _data6_->ctx;
			gala_init_pantheon_shell (_tmp25_);
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		FILE* _tmp26_;
		GError* _tmp27_;
		const gchar* _tmp28_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp26_ = stderr;
		_tmp27_ = e;
		_tmp28_ = _tmp27_->message;
		fprintf (_tmp26_, "Failed to start: %s\n", _tmp28_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block6_data_unref (_data6_);
		_data6_ = NULL;
		return result;
	}
	__finally2:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp29_ = -1;
		block6_data_unref (_data6_);
		_data6_ = 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 _tmp29_;
	}
	{
		MetaContext* _tmp30_;
		_tmp30_ = _data6_->ctx;
		meta_context_run_main_loop (_tmp30_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch3_g_error;
		}
	}
	goto __finally3;
	__catch3_g_error:
	{
		GError* e = NULL;
		FILE* _tmp31_;
		GError* _tmp32_;
		const gchar* _tmp33_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp31_ = stderr;
		_tmp32_ = e;
		_tmp33_ = _tmp32_->message;
		fprintf (_tmp31_, "Gala terminated with a failure: %s\n", _tmp33_);
		result = EXIT_FAILURE;
		_g_error_free0 (e);
		block6_data_unref (_data6_);
		_data6_ = NULL;
		return result;
	}
	__finally3:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp34_ = -1;
		block6_data_unref (_data6_);
		_data6_ = 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 _tmp34_;
	}
	gala_window_state_saver_on_shutdown ();
	result = EXIT_SUCCESS;
	block6_data_unref (_data6_);
	_data6_ = NULL;
	return result;
}

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

