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

/*
 * This file is part of budgie-desktop
 *
 * Copyright © 2015-2022 Budgie Desktop Developers
 *
 * 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 2 of the License, or
 * (at your option) any later version.
 */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <meta/meta-context.h>
#include <meta/main.h>
#include <glib-object.h>
#include <meta/meta-plugin.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 _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 BUDGIE_TYPE_BUDGIE_WM (budgie_budgie_wm_get_type ())
#define BUDGIE_BUDGIE_WM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_BUDGIE_WM, BudgieBudgieWM))
#define BUDGIE_BUDGIE_WM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_BUDGIE_WM, BudgieBudgieWMClass))
#define BUDGIE_IS_BUDGIE_WM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_BUDGIE_WM))
#define BUDGIE_IS_BUDGIE_WM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_BUDGIE_WM))
#define BUDGIE_BUDGIE_WM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_BUDGIE_WM, BudgieBudgieWMClass))

typedef struct _BudgieBudgieWM BudgieBudgieWM;
typedef struct _BudgieBudgieWMClass BudgieBudgieWMClass;

VALA_EXTERN gchar** budgie_budgie_wm_old_args;
VALA_EXTERN gint budgie_budgie_wm_old_args_length1;

static gint _vala_main (gchar** args,
                 gint args_length1);
static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
VALA_EXTERN GType budgie_budgie_wm_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieBudgieWM, g_object_unref)
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 gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	MetaContext* ctx = NULL;
	MetaContext* _tmp1_;
	MetaContext* _tmp8_;
	MetaContext* _tmp9_;
	GError* _inner_error0_ = NULL;
	gint result;
	_tmp0_ = (args != NULL) ? _vala_array_dup1 (args, args_length1) : args;
	_tmp0__length1 = args_length1;
	budgie_budgie_wm_old_args = (_vala_array_free (budgie_budgie_wm_old_args, budgie_budgie_wm_old_args_length1, (GDestroyNotify) g_free), NULL);
	budgie_budgie_wm_old_args = _tmp0_;
	budgie_budgie_wm_old_args_length1 = _tmp0__length1;
	_tmp1_ = meta_create_context ("Mutter(Budgie)");
	ctx = _tmp1_;
	{
		gboolean _tmp2_ = FALSE;
		MetaContext* _tmp3_;
		gboolean _tmp4_;
		_tmp3_ = ctx;
		_tmp4_ = meta_context_configure (_tmp3_, (gint*) (&args_length1), &args, &_inner_error0_);
		_tmp2_ = _tmp4_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (!_tmp2_) {
			result = (gint) META_EXIT_ERROR;
			_g_object_unref0 (ctx);
			return result;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		g_message ("main.vala:22: Configuration failed: %s", _tmp6_);
		result = (gint) META_EXIT_ERROR;
		_g_error_free0 (e);
		_g_object_unref0 (ctx);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp7_ = -1;
		_g_object_unref0 (ctx);
		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 _tmp7_;
	}
	_tmp8_ = ctx;
	meta_context_set_plugin_gtype (_tmp8_, BUDGIE_TYPE_BUDGIE_WM);
	_tmp9_ = ctx;
	meta_context_set_gnome_wm_keybindings (_tmp9_, "Mutter,GNOME Shell");
	g_setenv ("NO_GAIL", "1", TRUE);
	g_setenv ("NO_AT_BRIDGE", "1", TRUE);
	{
		MetaContext* _tmp10_;
		MetaContext* _tmp11_;
		MetaContext* _tmp12_;
		MetaContext* _tmp13_;
		_tmp10_ = ctx;
		meta_context_setup (_tmp10_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp11_ = ctx;
		meta_context_start (_tmp11_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp12_ = ctx;
		meta_context_notify_ready (_tmp12_);
		_tmp13_ = ctx;
		meta_context_run_main_loop (_tmp13_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp14_;
		const gchar* _tmp15_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp14_ = e;
		_tmp15_ = _tmp14_->message;
		g_message ("main.vala:39: Error running WM: %s", _tmp15_);
		_g_error_free0 (e);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp16_ = -1;
		_g_object_unref0 (ctx);
		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 _tmp16_;
	}
	result = (gint) META_EXIT_SUCCESS;
	_g_object_unref0 (ctx);
	return result;
}

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

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);
}

