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

/*
 * Copyright 2024 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <granite.h>
#include <gdk/gdk.h>
#include <locale.h>
#include <glib/gi18n-lib.h>

#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

#define GALA_DAEMON_TYPE_APPLICATION (gala_daemon_application_get_type ())
#define GALA_DAEMON_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_APPLICATION, GalaDaemonApplication))
#define GALA_DAEMON_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_APPLICATION, GalaDaemonApplicationClass))
#define GALA_DAEMON_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_APPLICATION))
#define GALA_DAEMON_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_APPLICATION))
#define GALA_DAEMON_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_APPLICATION, GalaDaemonApplicationClass))

typedef struct _GalaDaemonApplication GalaDaemonApplication;
typedef struct _GalaDaemonApplicationClass GalaDaemonApplicationClass;
typedef struct _GalaDaemonApplicationPrivate GalaDaemonApplicationPrivate;
enum  {
	GALA_DAEMON_APPLICATION_0_PROPERTY,
	GALA_DAEMON_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* gala_daemon_application_properties[GALA_DAEMON_APPLICATION_NUM_PROPERTIES];
typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GALA_DAEMON_TYPE_DBUS (gala_daemon_dbus_get_type ())
#define GALA_DAEMON_DBUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_DAEMON_TYPE_DBUS, GalaDaemonDBus))
#define GALA_DAEMON_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_DAEMON_TYPE_DBUS, GalaDaemonDBusClass))
#define GALA_DAEMON_IS_DBUS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_DAEMON_TYPE_DBUS))
#define GALA_DAEMON_IS_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_DAEMON_TYPE_DBUS))
#define GALA_DAEMON_DBUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_DAEMON_TYPE_DBUS, GalaDaemonDBusClass))

typedef struct _GalaDaemonDBus GalaDaemonDBus;
typedef struct _GalaDaemonDBusClass GalaDaemonDBusClass;

struct _GalaDaemonApplication {
	GtkApplication parent_instance;
	GalaDaemonApplicationPrivate * priv;
};

struct _GalaDaemonApplicationClass {
	GtkApplicationClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	GalaDaemonApplication* self;
	GraniteSettings* granite_settings;
	GtkSettings* gtk_settings;
};

static gpointer gala_daemon_application_parent_class = NULL;

VALA_EXTERN GType gala_daemon_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonApplication, g_object_unref)
VALA_EXTERN GalaDaemonApplication* gala_daemon_application_new (void);
VALA_EXTERN GalaDaemonApplication* gala_daemon_application_construct (GType object_type);
static void gala_daemon_application_real_startup (GApplication* base);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda4_ (Block1Data* _data1_);
static void ___lambda4__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void gala_daemon_application_real_activate (GApplication* base);
static gboolean gala_daemon_application_real_dbus_register (GApplication* base,
                                                     GDBusConnection* connection,
                                                     const gchar* object_path,
                                                     GError** error);
VALA_EXTERN GalaDaemonDBus* gala_daemon_dbus_new (void);
VALA_EXTERN GalaDaemonDBus* gala_daemon_dbus_construct (GType object_type);
VALA_EXTERN GType gala_daemon_dbus_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaDaemonDBus, g_object_unref)
VALA_EXTERN guint gala_daemon_dbus_register_object (void* object,
                                        GDBusConnection* connection,
                                        const gchar* path,
                                        GError** error);
static GType gala_daemon_application_get_type_once (void);
static gint _vala_main (gchar** args,
                 gint args_length1);

GalaDaemonApplication*
gala_daemon_application_construct (GType object_type)
{
	GalaDaemonApplication * self = NULL;
	self = (GalaDaemonApplication*) g_object_new (object_type, "application-id", "org.pantheon.gala.daemon", NULL);
	return self;
}

GalaDaemonApplication*
gala_daemon_application_new (void)
{
	return gala_daemon_application_construct (GALA_DAEMON_TYPE_APPLICATION);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		GalaDaemonApplication* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->gtk_settings);
		_g_object_unref0 (_data1_->granite_settings);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
__lambda4_ (Block1Data* _data1_)
{
	GalaDaemonApplication* self;
	GraniteSettingsColorScheme _tmp0_;
	GraniteSettingsColorScheme _tmp1_;
	self = _data1_->self;
	_tmp0_ = granite_settings_get_prefers_color_scheme (_data1_->granite_settings);
	_tmp1_ = _tmp0_;
	g_object_set (_data1_->gtk_settings, "gtk-application-prefer-dark-theme", _tmp1_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
}

static void
___lambda4__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda4_ (self);
}

static void
gala_daemon_application_real_startup (GApplication* base)
{
	GalaDaemonApplication * self;
	Block1Data* _data1_;
	GraniteSettings* _tmp0_;
	GraniteSettings* _tmp1_;
	GtkSettings* _tmp2_;
	GtkSettings* _tmp3_;
	GraniteSettingsColorScheme _tmp4_;
	GraniteSettingsColorScheme _tmp5_;
	GtkCssProvider* app_provider = NULL;
	GtkCssProvider* _tmp6_;
	GdkScreen* _tmp7_;
	self = (GalaDaemonApplication*) base;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	G_APPLICATION_CLASS (gala_daemon_application_parent_class)->startup ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication));
	_tmp0_ = granite_settings_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_data1_->granite_settings = _tmp1_;
	_tmp2_ = gtk_settings_get_default ();
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_data1_->gtk_settings = _tmp3_;
	_tmp4_ = granite_settings_get_prefers_color_scheme (_data1_->granite_settings);
	_tmp5_ = _tmp4_;
	g_object_set (_data1_->gtk_settings, "gtk-application-prefer-dark-theme", _tmp5_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
	g_signal_connect_data ((GObject*) _data1_->granite_settings, "notify::prefers-color-scheme", (GCallback) ___lambda4__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp6_ = gtk_css_provider_new ();
	app_provider = _tmp6_;
	gtk_css_provider_load_from_resource (app_provider, "io/elementary/desktop/gala-daemon/gala-daemon.css");
	_tmp7_ = gdk_screen_get_default ();
	gtk_style_context_add_provider_for_screen (_tmp7_, (GtkStyleProvider*) app_provider, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_g_object_unref0 (app_provider);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
gala_daemon_application_real_activate (GApplication* base)
{
	GalaDaemonApplication * self;
	self = (GalaDaemonApplication*) base;
	g_application_hold ((GApplication*) self);
}

static gboolean
gala_daemon_application_real_dbus_register (GApplication* base,
                                            GDBusConnection* connection,
                                            const gchar* object_path,
                                            GError** error)
{
	GalaDaemonApplication * self;
	GalaDaemonDBus* _tmp1_;
	GalaDaemonDBus* _tmp2_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	self = (GalaDaemonApplication*) base;
	g_return_val_if_fail (connection != NULL, FALSE);
	g_return_val_if_fail (object_path != NULL, FALSE);
	G_APPLICATION_CLASS (gala_daemon_application_parent_class)->dbus_register ((GApplication*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_get_type (), GtkApplication), connection, object_path, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp0_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp0_;
	}
	_tmp1_ = gala_daemon_dbus_new ();
	_tmp2_ = _tmp1_;
	gala_daemon_dbus_register_object (_tmp2_, connection, object_path, &_inner_error0_);
	_g_object_unref0 (_tmp2_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp3_ = FALSE;
		g_propagate_error (error, _inner_error0_);
		return _tmp3_;
	}
	result = TRUE;
	return result;
}

static void
gala_daemon_application_class_init (GalaDaemonApplicationClass * klass,
                                    gpointer klass_data)
{
	gala_daemon_application_parent_class = g_type_class_peek_parent (klass);
	((GApplicationClass *) klass)->startup = (void (*) (GApplication*)) gala_daemon_application_real_startup;
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) gala_daemon_application_real_activate;
	((GApplicationClass *) klass)->dbus_register = (gboolean (*) (GApplication*, GDBusConnection*, const gchar*, GError**)) gala_daemon_application_real_dbus_register;
}

static void
gala_daemon_application_instance_init (GalaDaemonApplication * self,
                                       gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
gala_daemon_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaDaemonApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_daemon_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaDaemonApplication), 0, (GInstanceInitFunc) gala_daemon_application_instance_init, NULL };
	GType gala_daemon_application_type_id;
	gala_daemon_application_type_id = g_type_register_static (gtk_application_get_type (), "GalaDaemonApplication", &g_define_type_info, 0);
	return gala_daemon_application_type_id;
}

GType
gala_daemon_application_get_type (void)
{
	static gsize gala_daemon_application_type_id__once = 0;
	if (g_once_init_enter (&gala_daemon_application_type_id__once)) {
		GType gala_daemon_application_type_id;
		gala_daemon_application_type_id = gala_daemon_application_get_type_once ();
		g_once_init_leave (&gala_daemon_application_type_id__once, gala_daemon_application_type_id);
	}
	return gala_daemon_application_type_id__once;
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GalaDaemonApplication* app = NULL;
	GalaDaemonApplication* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (CONFIG_GETTEXT_PACKAGE, CONFIG_LOCALEDIR);
	bind_textdomain_codeset (CONFIG_GETTEXT_PACKAGE, "UTF-8");
	textdomain (CONFIG_GETTEXT_PACKAGE);
	_tmp0_ = gala_daemon_application_new ();
	app = _tmp0_;
	result = g_application_run ((GApplication*) app, (gint) 0, NULL);
	_g_object_unref0 (app);
	return result;
}

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

