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

/*
 * This file is part of budgie-desktop
 * 
 * Copyright (C) 2015-2016 Ikey Doherty <ikey@solus-project.com>
 * 
 * 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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <meta/main.h>
#include <gtk/gtk.h>
#include <meta/meta-plugin.h>

#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;


extern gchar** budgie_budgie_wm_old_args;
extern gint budgie_budgie_wm_old_args_length1;
extern gboolean budgie_budgie_wm_gtk_available;
extern gboolean budgie_budgie_wm_wayland;

gint _vala_main (gchar** args, int args_length1);
static gchar** _vala_array_dup1 (gchar** self, int length);
static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle);
GType budgie_budgie_wm_get_type (void) G_GNUC_CONST;
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static gchar** _vala_array_dup1 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_ = NULL;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle) {
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GOptionContext* ctx = NULL;
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gchar** _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	GOptionContext* _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	gint _tmp10_ = 0;
	GError * _inner_error_ = NULL;
	ctx = NULL;
	_tmp0_ = args;
	_tmp0__length1 = args_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__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 = _tmp1_;
	budgie_budgie_wm_old_args_length1 = _tmp1__length1;
	_tmp2_ = meta_get_option_context ();
	ctx = _tmp2_;
	_tmp3_ = args;
	_tmp3__length1 = args_length1;
	if (_vala_string_array_contains (_tmp3_, _tmp3__length1, "--wayland")) {
		g_warning ("main.vala:21: Running under Wayland, GTK+ functionality not available");
		budgie_budgie_wm_gtk_available = FALSE;
		budgie_budgie_wm_wayland = TRUE;
	} else {
		gboolean _tmp4_ = FALSE;
		_tmp4_ = gtk_init_check (&args_length1, &args);
		if (!_tmp4_) {
			g_warning ("main.vala:25: GTK+ functionality not available");
			budgie_budgie_wm_gtk_available = FALSE;
		}
	}
	{
		gboolean _tmp5_ = FALSE;
		GOptionContext* _tmp6_ = NULL;
		gboolean _tmp7_ = FALSE;
		_tmp6_ = ctx;
		_tmp7_ = g_option_context_parse (_tmp6_, &args_length1, &args, &_inner_error_);
		_tmp5_ = _tmp7_;
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch0_g_option_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		if (!_tmp5_) {
			result = (gint) META_EXIT_ERROR;
			return result;
		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{
		GError* e = NULL;
		GError* _tmp8_ = NULL;
		const gchar* _tmp9_ = NULL;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_message ("main.vala:34: Unknown option: %s", _tmp9_);
		result = (gint) META_EXIT_ERROR;
		_g_error_free0 (e);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	meta_plugin_manager_set_plugin_type (BUDGIE_TYPE_BUDGIE_WM);
	meta_set_gnome_wm_keybindings ("Mutter,GNOME Shell");
	meta_set_wm_name ("Mutter(Budgie)");
	g_setenv ("NO_GAIL", "1", TRUE);
	g_setenv ("NO_AT_BRIDGE", "1", TRUE);
	meta_init ();
	meta_register_with_session ();
	_tmp10_ = meta_run ();
	result = _tmp10_;
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return _vala_main (argv, argc);
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



