/* theme-manager.c generated by valac 0.56.19, the Vala compiler
 * generated from theme-manager.vala, do not modify */

#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <adwaita.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>

#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 PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER (proton_plus_widgets_theme_manager_get_type ())
#define PROTON_PLUS_WIDGETS_THEME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER, ProtonPlusWidgetsThemeManager))
#define PROTON_PLUS_WIDGETS_THEME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER, ProtonPlusWidgetsThemeManagerClass))
#define PROTON_PLUS_WIDGETS_IS_THEME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER))
#define PROTON_PLUS_WIDGETS_IS_THEME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER))
#define PROTON_PLUS_WIDGETS_THEME_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER, ProtonPlusWidgetsThemeManagerClass))

typedef struct _ProtonPlusWidgetsThemeManager ProtonPlusWidgetsThemeManager;
typedef struct _ProtonPlusWidgetsThemeManagerClass ProtonPlusWidgetsThemeManagerClass;
typedef struct _ProtonPlusWidgetsThemeManagerPrivate ProtonPlusWidgetsThemeManagerPrivate;
enum  {
	PROTON_PLUS_WIDGETS_THEME_MANAGER_0_PROPERTY,
	PROTON_PLUS_WIDGETS_THEME_MANAGER_NUM_PROPERTIES
};
static GParamSpec* proton_plus_widgets_theme_manager_properties[PROTON_PLUS_WIDGETS_THEME_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ProtonPlusWidgetsThemeManager {
	GObject parent_instance;
	ProtonPlusWidgetsThemeManagerPrivate * priv;
};

struct _ProtonPlusWidgetsThemeManagerClass {
	GObjectClass parent_class;
};

static gpointer proton_plus_widgets_theme_manager_parent_class = NULL;
static ProtonPlusWidgetsThemeManager* proton_plus_widgets_theme_manager__instance;
static ProtonPlusWidgetsThemeManager* proton_plus_widgets_theme_manager__instance = NULL;
VALA_EXTERN GSettings* proton_plus_globals_SETTINGS;

VALA_EXTERN GType proton_plus_widgets_theme_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProtonPlusWidgetsThemeManager, g_object_unref)
VALA_EXTERN ProtonPlusWidgetsThemeManager* proton_plus_widgets_theme_manager_get_default (void);
VALA_EXTERN ProtonPlusWidgetsThemeManager* proton_plus_widgets_theme_manager_new (void);
VALA_EXTERN ProtonPlusWidgetsThemeManager* proton_plus_widgets_theme_manager_construct (GType object_type);
VALA_EXTERN void proton_plus_widgets_theme_manager_apply_theme (ProtonPlusWidgetsThemeManager* self);
VALA_EXTERN void proton_plus_widgets_theme_manager_apply_to_window (ProtonPlusWidgetsThemeManager* self,
                                                        GtkWindow* window);
static GObject * proton_plus_widgets_theme_manager_constructor (GType type,
                                                         guint n_construct_properties,
                                                         GObjectConstructParam * construct_properties);
static void _proton_plus_widgets_theme_manager_apply_to_window_gtk_application_window_added (GtkApplication* _sender,
                                                                                      GtkWindow* window,
                                                                                      gpointer self);
static void _proton_plus_widgets_theme_manager____lambda65_ (ProtonPlusWidgetsThemeManager* self);
static void __proton_plus_widgets_theme_manager____lambda65__g_settings_changed (GSettings* _sender,
                                                                          const gchar* key,
                                                                          gpointer self);
static void proton_plus_widgets_theme_manager_finalize (GObject * obj);
static GType proton_plus_widgets_theme_manager_get_type_once (void);

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

ProtonPlusWidgetsThemeManager*
proton_plus_widgets_theme_manager_get_default (void)
{
	ProtonPlusWidgetsThemeManager* _tmp0_;
	ProtonPlusWidgetsThemeManager* _tmp2_;
	ProtonPlusWidgetsThemeManager* _tmp3_;
	ProtonPlusWidgetsThemeManager* result;
	_tmp0_ = proton_plus_widgets_theme_manager__instance;
	if (_tmp0_ == NULL) {
		ProtonPlusWidgetsThemeManager* _tmp1_;
		_tmp1_ = proton_plus_widgets_theme_manager_new ();
		_g_object_unref0 (proton_plus_widgets_theme_manager__instance);
		proton_plus_widgets_theme_manager__instance = _tmp1_;
	}
	_tmp2_ = proton_plus_widgets_theme_manager__instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

void
proton_plus_widgets_theme_manager_apply_theme (ProtonPlusWidgetsThemeManager* self)
{
	GSettings* _tmp0_;
	gint theme = 0;
	GSettings* _tmp1_;
	AdwStyleManager* style_manager = NULL;
	AdwStyleManager* _tmp2_;
	AdwStyleManager* _tmp3_;
	AdwColorScheme _tmp4_ = 0;
	gboolean _tmp5_ = FALSE;
	AdwStyleManager* _tmp6_;
	AdwApplication* application = NULL;
	GApplication* _tmp7_;
	AdwApplication* _tmp8_;
	AdwApplication* _tmp9_;
	GList* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = proton_plus_globals_SETTINGS;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = proton_plus_globals_SETTINGS;
	theme = g_settings_get_enum (_tmp1_, "theme");
	_tmp2_ = adw_style_manager_get_default ();
	_tmp3_ = _g_object_ref0 (_tmp2_);
	style_manager = _tmp3_;
	if (theme == 5) {
		_tmp5_ = TRUE;
	} else {
		_tmp5_ = theme == 6;
	}
	if (_tmp5_) {
		_tmp4_ = ADW_COLOR_SCHEME_FORCE_DARK;
	} else {
		_tmp4_ = (AdwColorScheme) theme;
	}
	_tmp6_ = style_manager;
	adw_style_manager_set_color_scheme (_tmp6_, _tmp4_);
	_tmp7_ = g_application_get_default ();
	_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, adw_application_get_type (), AdwApplication));
	application = _tmp8_;
	_tmp9_ = application;
	_tmp10_ = gtk_application_get_windows ((GtkApplication*) _tmp9_);
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp10_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			GtkWindow* _tmp11_;
			GtkWindow* window = NULL;
			_tmp11_ = _g_object_ref0 ((GtkWindow*) window_it->data);
			window = _tmp11_;
			{
				GtkWindow* _tmp12_;
				_tmp12_ = window;
				proton_plus_widgets_theme_manager_apply_to_window (self, _tmp12_);
				_g_object_unref0 (window);
			}
		}
	}
	_g_object_unref0 (application);
	_g_object_unref0 (style_manager);
}

void
proton_plus_widgets_theme_manager_apply_to_window (ProtonPlusWidgetsThemeManager* self,
                                                   GtkWindow* window)
{
	GSettings* _tmp0_;
	gint theme = 0;
	GSettings* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	_tmp0_ = proton_plus_globals_SETTINGS;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = proton_plus_globals_SETTINGS;
	theme = g_settings_get_enum (_tmp1_, "theme");
	if (theme == 5) {
		gtk_widget_add_css_class ((GtkWidget*) window, "steamos");
		gtk_widget_remove_css_class ((GtkWidget*) window, "oled");
	} else {
		if (theme == 6) {
			gtk_widget_remove_css_class ((GtkWidget*) window, "steamos");
			gtk_widget_add_css_class ((GtkWidget*) window, "oled");
		} else {
			gtk_widget_remove_css_class ((GtkWidget*) window, "steamos");
			gtk_widget_remove_css_class ((GtkWidget*) window, "oled");
		}
	}
}

ProtonPlusWidgetsThemeManager*
proton_plus_widgets_theme_manager_construct (GType object_type)
{
	ProtonPlusWidgetsThemeManager * self = NULL;
	self = (ProtonPlusWidgetsThemeManager*) g_object_new (object_type, NULL);
	return self;
}

ProtonPlusWidgetsThemeManager*
proton_plus_widgets_theme_manager_new (void)
{
	return proton_plus_widgets_theme_manager_construct (PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER);
}

static void
_proton_plus_widgets_theme_manager_apply_to_window_gtk_application_window_added (GtkApplication* _sender,
                                                                                 GtkWindow* window,
                                                                                 gpointer self)
{
	proton_plus_widgets_theme_manager_apply_to_window ((ProtonPlusWidgetsThemeManager*) self, window);
}

static void
_proton_plus_widgets_theme_manager____lambda65_ (ProtonPlusWidgetsThemeManager* self)
{
	proton_plus_widgets_theme_manager_apply_theme (self);
}

static void
__proton_plus_widgets_theme_manager____lambda65__g_settings_changed (GSettings* _sender,
                                                                     const gchar* key,
                                                                     gpointer self)
{
	_proton_plus_widgets_theme_manager____lambda65_ ((ProtonPlusWidgetsThemeManager*) self);
}

static GObject *
proton_plus_widgets_theme_manager_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	ProtonPlusWidgetsThemeManager * self;
	AdwApplication* application = NULL;
	GApplication* _tmp0_;
	AdwApplication* _tmp1_;
	AdwApplication* _tmp2_;
	GSettings* _tmp3_;
	parent_class = G_OBJECT_CLASS (proton_plus_widgets_theme_manager_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER, ProtonPlusWidgetsThemeManager);
	_tmp0_ = g_application_get_default ();
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, adw_application_get_type (), AdwApplication));
	application = _tmp1_;
	_tmp2_ = application;
	g_signal_connect_object ((GtkApplication*) _tmp2_, "window-added", (GCallback) _proton_plus_widgets_theme_manager_apply_to_window_gtk_application_window_added, self, 0);
	_tmp3_ = proton_plus_globals_SETTINGS;
	if (_tmp3_ != NULL) {
		GSettings* _tmp4_;
		_tmp4_ = proton_plus_globals_SETTINGS;
		g_signal_connect_object (_tmp4_, "changed::theme", (GCallback) __proton_plus_widgets_theme_manager____lambda65__g_settings_changed, self, 0);
	}
	_g_object_unref0 (application);
	return obj;
}

static void
proton_plus_widgets_theme_manager_class_init (ProtonPlusWidgetsThemeManagerClass * klass,
                                              gpointer klass_data)
{
	proton_plus_widgets_theme_manager_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->constructor = proton_plus_widgets_theme_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = proton_plus_widgets_theme_manager_finalize;
}

static void
proton_plus_widgets_theme_manager_instance_init (ProtonPlusWidgetsThemeManager * self,
                                                 gpointer klass)
{
}

static void
proton_plus_widgets_theme_manager_finalize (GObject * obj)
{
	ProtonPlusWidgetsThemeManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_WIDGETS_TYPE_THEME_MANAGER, ProtonPlusWidgetsThemeManager);
	G_OBJECT_CLASS (proton_plus_widgets_theme_manager_parent_class)->finalize (obj);
}

static GType
proton_plus_widgets_theme_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusWidgetsThemeManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_widgets_theme_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusWidgetsThemeManager), 0, (GInstanceInitFunc) proton_plus_widgets_theme_manager_instance_init, NULL };
	GType proton_plus_widgets_theme_manager_type_id;
	proton_plus_widgets_theme_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "ProtonPlusWidgetsThemeManager", &g_define_type_info, 0);
	return proton_plus_widgets_theme_manager_type_id;
}

GType
proton_plus_widgets_theme_manager_get_type (void)
{
	static volatile gsize proton_plus_widgets_theme_manager_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_widgets_theme_manager_type_id__once)) {
		GType proton_plus_widgets_theme_manager_type_id;
		proton_plus_widgets_theme_manager_type_id = proton_plus_widgets_theme_manager_get_type_once ();
		g_once_init_leave (&proton_plus_widgets_theme_manager_type_id__once, proton_plus_widgets_theme_manager_type_id);
	}
	return proton_plus_widgets_theme_manager_type_id__once;
}

