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

/*
 * Copyright (c) 2026 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_plugin_gnome.h"
#include "ft_core.h"
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include "ft_ui.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

enum  {
	GNOME_APPLICATION_EXTENSION_0_PROPERTY,
	GNOME_APPLICATION_EXTENSION_NUM_PROPERTIES
};
static GParamSpec* gnome_application_extension_properties[GNOME_APPLICATION_EXTENSION_NUM_PROPERTIES];
#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)))

struct _GnomeApplicationExtensionPrivate {
	FtBackgroundManager* background_manager;
	FtNotificationManager* notification_manager;
	GnomeShell* shell_proxy;
	GnomeShellExtension* shell_extension;
	gboolean shell_extension_enabled;
	guint shell_watcher_id;
	guint background_hold_id;
};

static gint GnomeApplicationExtension_private_offset;
static gpointer gnome_application_extension_parent_class = NULL;
static GType gnome_application_extension_type_id = 0;

static void gnome_application_extension_update (GnomeApplicationExtension* self);
static void gnome_application_extension_on_shell_name_appeared (GnomeApplicationExtension* self,
                                                         GDBusConnection* connection,
                                                         const gchar* name,
                                                         const gchar* name_owner);
static void gnome_application_extension_on_shell_name_vanished (GnomeApplicationExtension* self,
                                                         GDBusConnection* connection,
                                                         const gchar* name);
static void gnome_application_extension_on_shell_extension_notify_enabled (GnomeApplicationExtension* self,
                                                                    GObject* object,
                                                                    GParamSpec* pspec);
static void gnome_application_extension_on_screen_overlay_opened (GnomeApplicationExtension* self);
static void gnome_application_extension_real_dispose (GObject* base);
static void _gnome_application_extension_on_screen_overlay_opened_ft_notification_manager_screen_overlay_opened (FtNotificationManager* _sender,
                                                                                                          gpointer self);
static GObject * gnome_application_extension_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _gnome_application_extension_on_shell_extension_notify_enabled_g_object_notify (GObject* _sender,
                                                                                     GParamSpec* pspec,
                                                                                     gpointer self);
static void _gnome_application_extension_on_shell_name_appeared_gbus_name_appeared_callback (GDBusConnection* connection,
                                                                                      const gchar* name,
                                                                                      const gchar* name_owner,
                                                                                      gpointer self);
static void _gnome_application_extension_on_shell_name_vanished_gbus_name_vanished_callback (GDBusConnection* connection,
                                                                                      const gchar* name,
                                                                                      gpointer self);
static void gnome_application_extension_finalize (GObject * obj);

static inline gpointer
gnome_application_extension_get_instance_private (GnomeApplicationExtension* self)
{
	return G_STRUCT_MEMBER_P (self, GnomeApplicationExtension_private_offset);
}

static void
gnome_application_extension_update (GnomeApplicationExtension* self)
{
	FtNotificationManager* notification_manager = NULL;
	FtNotificationManager* _tmp0_;
	gboolean shell_extension_enabled = FALSE;
	GnomeShellExtension* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ft_notification_manager_new ();
	notification_manager = _tmp0_;
	_tmp1_ = self->priv->shell_extension;
	_tmp2_ = gnome_shell_extension_get_enabled (_tmp1_);
	_tmp3_ = _tmp2_;
	shell_extension_enabled = _tmp3_;
	if (self->priv->shell_extension_enabled == shell_extension_enabled) {
		_g_object_unref0 (notification_manager);
		return;
	}
	self->priv->shell_extension_enabled = shell_extension_enabled;
	if (shell_extension_enabled) {
		FtNotificationManager* _tmp5_;
		if (self->priv->background_hold_id == 0U) {
			FtBackgroundManager* _tmp4_;
			_tmp4_ = self->priv->background_manager;
			self->priv->background_hold_id = ft_background_manager_hold_sync (_tmp4_, "");
		}
		_tmp5_ = notification_manager;
		ft_notification_manager_inhibit (_tmp5_);
	} else {
		FtNotificationManager* _tmp7_;
		if (self->priv->background_hold_id != 0U) {
			FtBackgroundManager* _tmp6_;
			_tmp6_ = self->priv->background_manager;
			ft_background_manager_release (_tmp6_, self->priv->background_hold_id);
			self->priv->background_hold_id = 0U;
		}
		_tmp7_ = notification_manager;
		ft_notification_manager_uninhibit (_tmp7_, TRUE);
	}
	_g_object_unref0 (notification_manager);
}

static void
gnome_application_extension_on_shell_name_appeared (GnomeApplicationExtension* self,
                                                    GDBusConnection* connection,
                                                    const gchar* name,
                                                    const gchar* name_owner)
{
	GnomeShell* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (connection != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (name_owner != NULL);
	_tmp0_ = self->priv->shell_proxy;
	if (_tmp0_ != NULL) {
		return;
	}
	{
		GnomeShell* _tmp1_ = NULL;
		GnomeShell* _tmp2_;
		GnomeShell* _tmp3_;
		_tmp2_ = (GnomeShell*) g_initable_new (GNOME_TYPE_SHELL_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, "g-name", "org.gnome.Shell", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/gnome/Shell", "g-interface-name", "org.gnome.Shell", NULL);
		_tmp1_ = (GnomeShell*) _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp3_ = _tmp1_;
		_tmp1_ = NULL;
		_g_object_unref0 (self->priv->shell_proxy);
		self->priv->shell_proxy = _tmp3_;
		_g_object_unref0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp4_;
		const gchar* _tmp5_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = _error_;
		_tmp5_ = _tmp4_->message;
		g_warning ("application-extension.vala:86: Error while initializing shell proxy: %" \
"s", _tmp5_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != 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;
	}
}

static void
gnome_application_extension_on_shell_name_vanished (GnomeApplicationExtension* self,
                                                    GDBusConnection* connection,
                                                    const gchar* name)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_g_object_unref0 (self->priv->shell_proxy);
	self->priv->shell_proxy = NULL;
}

static void
gnome_application_extension_on_shell_extension_notify_enabled (GnomeApplicationExtension* self,
                                                               GObject* object,
                                                               GParamSpec* pspec)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	gnome_application_extension_update (self);
}

static void
gnome_application_extension_on_screen_overlay_opened (GnomeApplicationExtension* self)
{
	gboolean _tmp0_ = FALSE;
	GnomeShell* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->shell_proxy;
	if (_tmp1_ != NULL) {
		GnomeShell* _tmp2_;
		gboolean _tmp3_;
		gboolean _tmp4_;
		_tmp2_ = self->priv->shell_proxy;
		_tmp3_ = gnome_shell_get_overview_active (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GnomeShell* _tmp5_;
		_tmp5_ = self->priv->shell_proxy;
		gnome_shell_set_overview_active (_tmp5_, FALSE);
	}
}

static void
_gnome_application_extension_on_screen_overlay_opened_ft_notification_manager_screen_overlay_opened (FtNotificationManager* _sender,
                                                                                                     gpointer self)
{
	gnome_application_extension_on_screen_overlay_opened ((GnomeApplicationExtension*) self);
}

static void
gnome_application_extension_real_dispose (GObject* base)
{
	GnomeApplicationExtension * self;
	FtNotificationManager* _tmp1_;
	self = (GnomeApplicationExtension*) base;
	if (self->priv->shell_watcher_id != ((guint) 0)) {
		g_bus_unwatch_name (self->priv->shell_watcher_id);
		self->priv->shell_watcher_id = (guint) 0;
	}
	if (self->priv->background_hold_id != 0U) {
		FtBackgroundManager* _tmp0_;
		_tmp0_ = self->priv->background_manager;
		ft_background_manager_release (_tmp0_, self->priv->background_hold_id);
		self->priv->background_hold_id = 0U;
	}
	_tmp1_ = self->priv->notification_manager;
	if (_tmp1_ != NULL) {
		FtNotificationManager* _tmp2_;
		guint _tmp3_;
		_tmp2_ = self->priv->notification_manager;
		g_signal_parse_name ("screen-overlay-opened", FT_TYPE_NOTIFICATION_MANAGER, &_tmp3_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp2_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp3_, 0, NULL, (GCallback) _gnome_application_extension_on_screen_overlay_opened_ft_notification_manager_screen_overlay_opened, self);
		_g_object_unref0 (self->priv->notification_manager);
		self->priv->notification_manager = NULL;
	}
	_g_object_unref0 (self->priv->shell_extension);
	self->priv->shell_extension = NULL;
	_g_object_unref0 (self->priv->shell_proxy);
	self->priv->shell_proxy = NULL;
	_g_object_unref0 (self->priv->background_manager);
	self->priv->background_manager = NULL;
	G_OBJECT_CLASS (gnome_application_extension_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, FT_TYPE_APPLICATION_EXTENSION, FtApplicationExtension));
}

GnomeApplicationExtension*
gnome_application_extension_construct (GType object_type)
{
	GnomeApplicationExtension * self = NULL;
	self = (GnomeApplicationExtension*) ft_application_extension_construct (object_type);
	return self;
}

GnomeApplicationExtension*
gnome_application_extension_new (void)
{
	return gnome_application_extension_construct (GNOME_TYPE_APPLICATION_EXTENSION);
}

static void
_gnome_application_extension_on_shell_extension_notify_enabled_g_object_notify (GObject* _sender,
                                                                                GParamSpec* pspec,
                                                                                gpointer self)
{
	gnome_application_extension_on_shell_extension_notify_enabled ((GnomeApplicationExtension*) self, _sender, pspec);
}

static void
_gnome_application_extension_on_shell_name_appeared_gbus_name_appeared_callback (GDBusConnection* connection,
                                                                                 const gchar* name,
                                                                                 const gchar* name_owner,
                                                                                 gpointer self)
{
	gnome_application_extension_on_shell_name_appeared ((GnomeApplicationExtension*) self, connection, name, name_owner);
}

static void
_gnome_application_extension_on_shell_name_vanished_gbus_name_vanished_callback (GDBusConnection* connection,
                                                                                 const gchar* name,
                                                                                 gpointer self)
{
	gnome_application_extension_on_shell_name_vanished ((GnomeApplicationExtension*) self, connection, name);
}

static GObject *
gnome_application_extension_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GnomeApplicationExtension * self;
	FtBackgroundManager* _tmp0_;
	FtNotificationManager* _tmp1_;
	FtNotificationManager* _tmp2_;
	GnomeShellExtension* _tmp3_;
	GnomeShellExtension* _tmp4_;
	parent_class = G_OBJECT_CLASS (gnome_application_extension_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_APPLICATION_EXTENSION, GnomeApplicationExtension);
	_tmp0_ = ft_background_manager_new ();
	_g_object_unref0 (self->priv->background_manager);
	self->priv->background_manager = _tmp0_;
	_tmp1_ = ft_notification_manager_new ();
	_g_object_unref0 (self->priv->notification_manager);
	self->priv->notification_manager = _tmp1_;
	_tmp2_ = self->priv->notification_manager;
	g_signal_connect_object (_tmp2_, "screen-overlay-opened", (GCallback) _gnome_application_extension_on_screen_overlay_opened_ft_notification_manager_screen_overlay_opened, self, 0);
	_tmp3_ = gnome_shell_extension_new ();
	_g_object_unref0 (self->priv->shell_extension);
	self->priv->shell_extension = _tmp3_;
	_tmp4_ = self->priv->shell_extension;
	g_signal_connect_object ((GObject*) _tmp4_, "notify::enabled", (GCallback) _gnome_application_extension_on_shell_extension_notify_enabled_g_object_notify, self, 0);
	self->priv->shell_watcher_id = g_bus_watch_name_with_closures (G_BUS_TYPE_SESSION, "org.gnome.Shell", G_BUS_NAME_WATCHER_FLAGS_NONE, (GClosure*) ((_gnome_application_extension_on_shell_name_appeared_gbus_name_appeared_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _gnome_application_extension_on_shell_name_appeared_gbus_name_appeared_callback, g_object_ref (self), (GClosureNotify) g_object_unref)), (GClosure*) ((_gnome_application_extension_on_shell_name_vanished_gbus_name_vanished_callback == NULL) ? NULL : g_cclosure_new ((GCallback) _gnome_application_extension_on_shell_name_vanished_gbus_name_vanished_callback, g_object_ref (self), (GClosureNotify) g_object_unref)));
	gnome_application_extension_update (self);
	return obj;
}

static void
gnome_application_extension_class_init (GnomeApplicationExtensionClass * klass,
                                        gpointer klass_data)
{
	gnome_application_extension_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomeApplicationExtension_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) gnome_application_extension_real_dispose;
	G_OBJECT_CLASS (klass)->constructor = gnome_application_extension_constructor;
	G_OBJECT_CLASS (klass)->finalize = gnome_application_extension_finalize;
}

static void
gnome_application_extension_instance_init (GnomeApplicationExtension * self,
                                           gpointer klass)
{
	self->priv = gnome_application_extension_get_instance_private (self);
	self->priv->background_manager = NULL;
	self->priv->notification_manager = NULL;
	self->priv->shell_proxy = NULL;
	self->priv->shell_extension = NULL;
	self->priv->shell_extension_enabled = FALSE;
	self->priv->shell_watcher_id = (guint) 0;
	self->priv->background_hold_id = 0U;
}

static void
gnome_application_extension_finalize (GObject * obj)
{
	GnomeApplicationExtension * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_TYPE_APPLICATION_EXTENSION, GnomeApplicationExtension);
	_g_object_unref0 (self->priv->background_manager);
	_g_object_unref0 (self->priv->notification_manager);
	_g_object_unref0 (self->priv->shell_proxy);
	_g_object_unref0 (self->priv->shell_extension);
	G_OBJECT_CLASS (gnome_application_extension_parent_class)->finalize (obj);
}

GType
gnome_application_extension_get_type (void)
{
	return gnome_application_extension_type_id;
}

GType
gnome_application_extension_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomeApplicationExtensionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_application_extension_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomeApplicationExtension), 0, (GInstanceInitFunc) gnome_application_extension_instance_init, NULL };
	gnome_application_extension_type_id = g_type_module_register_type (module, FT_TYPE_APPLICATION_EXTENSION, "GnomeApplicationExtension", &g_define_type_info, 0);
	GnomeApplicationExtension_private_offset = sizeof (GnomeApplicationExtensionPrivate);
	return gnome_application_extension_type_id;
}

