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

#include <glib-object.h>
#include "xdg-activation-v1-client-protocol.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client.h>
#include <gtk/gtk.h>
#include <gdk/gdk.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 TYPE_XDG_ACTIVATION_HELPER (xdg_activation_helper_get_type ())
#define XDG_ACTIVATION_HELPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_XDG_ACTIVATION_HELPER, XdgActivationHelper))
#define XDG_ACTIVATION_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_XDG_ACTIVATION_HELPER, XdgActivationHelperClass))
#define IS_XDG_ACTIVATION_HELPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_XDG_ACTIVATION_HELPER))
#define IS_XDG_ACTIVATION_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_XDG_ACTIVATION_HELPER))
#define XDG_ACTIVATION_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_XDG_ACTIVATION_HELPER, XdgActivationHelperClass))

typedef struct _XdgActivationHelper XdgActivationHelper;
typedef struct _XdgActivationHelperClass XdgActivationHelperClass;
typedef struct _XdgActivationHelperPrivate XdgActivationHelperPrivate;
enum  {
	XDG_ACTIVATION_HELPER_0_PROPERTY,
	XDG_ACTIVATION_HELPER_NUM_PROPERTIES
};
static GParamSpec* xdg_activation_helper_properties[XDG_ACTIVATION_HELPER_NUM_PROPERTIES];
typedef void (*XDGActivationTokenListenerDone) (void* data, struct xdg_activation_token_v1* activation_token, const gchar* token);
typedef void (*wl_RegistryListenerGlobal) (void* data, struct wl_registry* wl_registry, guint32 name, const gchar* interface, guint32 version);
#define _wl_registry_destroy0(var) ((var == NULL) ? NULL : (var = (wl_registry_destroy (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _XdgActivationHelper {
	GObject parent_instance;
	XdgActivationHelperPrivate * priv;
};

struct _XdgActivationHelperClass {
	GObjectClass parent_class;
};

struct _XdgActivationHelperPrivate {
	struct xdg_activation_v1* xdg_activation;
};

static gint XdgActivationHelper_private_offset;
static gpointer xdg_activation_helper_parent_class = NULL;
static struct wl_registry_listener xdg_activation_helper_registry_listener;
static struct wl_registry_listener xdg_activation_helper_registry_listener = {0};

VALA_EXTERN GType xdg_activation_helper_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (XdgActivationHelper, g_object_unref)
static void xdg_activation_helper_handle_done (void* data,
                                        struct xdg_activation_token_v1* activation_token,
                                        const gchar* token);
static void _xdg_activation_helper_handle_done_xdg_activation_token_listener_done (void* data,
                                                                            struct xdg_activation_token_v1* activation_token,
                                                                            const gchar* token);
static void xdg_activation_helper_registry_handle_global (XdgActivationHelper* self,
                                                   struct wl_registry* wl_registry,
                                                   guint32 name,
                                                   const gchar* interface,
                                                   guint32 version);
static void _xdg_activation_helper_registry_handle_global_wl_registrylistenerglobal (void* data,
                                                                              struct wl_registry* wl_registry,
                                                                              guint32 name,
                                                                              const gchar* interface,
                                                                              guint32 version);
VALA_EXTERN XdgActivationHelper* xdg_activation_helper_new (void);
VALA_EXTERN XdgActivationHelper* xdg_activation_helper_construct (GType object_type);
VALA_EXTERN struct wl_display* sway_notification_center_functions_get_wl_display (void);
VALA_EXTERN gchar* xdg_activation_helper_get_token (XdgActivationHelper* self,
                                        GtkWidget* widget);
VALA_EXTERN struct wl_surface* sway_notification_center_functions_get_wl_surface (GdkSurface* surface);
static void xdg_activation_helper_finalize (GObject * obj);
static GType xdg_activation_helper_get_type_once (void);

static const struct xdg_activation_token_v1_listener XDG_ACTIVATION_HELPER_TOKEN_LISTENER = {_xdg_activation_helper_handle_done_xdg_activation_token_listener_done};

static inline gpointer
xdg_activation_helper_get_instance_private (XdgActivationHelper* self)
{
	return G_STRUCT_MEMBER_P (self, XdgActivationHelper_private_offset);
}

static void
_xdg_activation_helper_handle_done_xdg_activation_token_listener_done (void* data,
                                                                       struct xdg_activation_token_v1* activation_token,
                                                                       const gchar* token)
{
	xdg_activation_helper_handle_done (data, activation_token, token);
}

static void
_xdg_activation_helper_registry_handle_global_wl_registrylistenerglobal (void* data,
                                                                         struct wl_registry* wl_registry,
                                                                         guint32 name,
                                                                         const gchar* interface,
                                                                         guint32 version)
{
	xdg_activation_helper_registry_handle_global (data, wl_registry, name, interface, version);
}

XdgActivationHelper*
xdg_activation_helper_construct (GType object_type)
{
	XdgActivationHelper * self = NULL;
	struct wl_display* wl_display = NULL;
	struct wl_display* _tmp0_;
	struct wl_registry* wl_registry = NULL;
	struct wl_display* _tmp1_;
	struct wl_registry* _tmp2_;
	struct wl_registry* _tmp3_;
	struct wl_registry_listener _tmp4_;
	struct wl_display* _tmp5_;
	self = (XdgActivationHelper*) g_object_new (object_type, NULL);
	_tmp0_ = sway_notification_center_functions_get_wl_display ();
	wl_display = _tmp0_;
	_tmp1_ = wl_display;
	_tmp2_ = wl_display_get_registry (_tmp1_);
	wl_registry = _tmp2_;
	_tmp3_ = wl_registry;
	_tmp4_ = xdg_activation_helper_registry_listener;
	wl_registry_add_listener (_tmp3_, &_tmp4_, self);
	_tmp5_ = wl_display;
	if (wl_display_roundtrip (_tmp5_) < 0) {
		_wl_registry_destroy0 (wl_registry);
		return self;
	}
	_wl_registry_destroy0 (wl_registry);
	return self;
}

XdgActivationHelper*
xdg_activation_helper_new (void)
{
	return xdg_activation_helper_construct (TYPE_XDG_ACTIVATION_HELPER);
}

static void
xdg_activation_helper_registry_handle_global (XdgActivationHelper* self,
                                              struct wl_registry* wl_registry,
                                              guint32 name,
                                              const gchar* interface,
                                              guint32 version)
{
	g_return_if_fail (IS_XDG_ACTIVATION_HELPER (self));
	g_return_if_fail (wl_registry != NULL);
	g_return_if_fail (interface != NULL);
	if (g_strcmp0 (interface, "xdg_activation_v1") == 0) {
		gpointer _tmp0_;
		struct xdg_activation_v1* _tmp1_;
		_tmp0_ = wl_registry_bind (wl_registry, name, &xdg_activation_v1_interface, version);
		self->priv->xdg_activation = (struct xdg_activation_v1*) _tmp0_;
		_tmp1_ = self->priv->xdg_activation;
		if (_tmp1_ == NULL) {
			g_warning ("xdg_activation.vala:31: Could not bind to xdg_activation_v1 iface!");
		}
	}
}

static void
xdg_activation_helper_handle_done (void* data,
                                   struct xdg_activation_token_v1* activation_token,
                                   const gchar* token)
{
	GValue* value = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (activation_token != NULL);
	g_return_if_fail (token != NULL);
	value = (GValue*) data;
	_tmp0_ = g_strdup (token);
	_tmp1_ = _tmp0_;
	g_value_set_string (value, _tmp1_);
	_g_free0 (_tmp1_);
}

gchar*
xdg_activation_helper_get_token (XdgActivationHelper* self,
                                 GtkWidget* widget)
{
	struct xdg_activation_v1* _tmp0_;
	struct wl_display* wl_display = NULL;
	struct wl_display* _tmp1_;
	GtkRoot* root = NULL;
	GtkRoot* _tmp2_;
	GtkRoot* _tmp3_;
	struct wl_surface* wl_surface = NULL;
	GtkRoot* _tmp4_;
	GdkSurface* _tmp5_;
	struct wl_surface* _tmp6_;
	GValue token_value = {0};
	GValue _tmp7_ = {0};
	struct xdg_activation_token_v1* token = NULL;
	struct xdg_activation_v1* _tmp8_;
	struct xdg_activation_token_v1* _tmp9_;
	struct xdg_activation_token_v1* _tmp10_;
	struct xdg_activation_token_v1* _tmp11_;
	struct wl_surface* _tmp12_;
	struct xdg_activation_token_v1* _tmp13_;
	struct xdg_activation_token_v1* _tmp17_;
	const gchar* token_str = NULL;
	const gchar* _tmp18_;
	gboolean _tmp19_ = FALSE;
	const gchar* _tmp20_;
	gchar* result;
	g_return_val_if_fail (IS_XDG_ACTIVATION_HELPER (self), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (widget, gtk_widget_get_type ()), NULL);
	_tmp0_ = self->priv->xdg_activation;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = sway_notification_center_functions_get_wl_display ();
	wl_display = _tmp1_;
	_tmp2_ = gtk_widget_get_root (widget);
	root = _tmp2_;
	_tmp3_ = root;
	if (_tmp3_ == NULL) {
		g_warning ("xdg_activation.vala:54: GDK Window is null");
		result = NULL;
		return result;
	}
	_tmp4_ = root;
	_tmp5_ = gtk_native_get_surface (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, gtk_native_get_type (), GtkNative));
	_tmp6_ = sway_notification_center_functions_get_wl_surface (_tmp5_);
	wl_surface = _tmp6_;
	g_value_init (&_tmp7_, G_TYPE_STRING);
	token_value = _tmp7_;
	g_value_set_string (&token_value, NULL);
	_tmp8_ = self->priv->xdg_activation;
	_tmp9_ = xdg_activation_v1_get_activation_token (_tmp8_);
	token = _tmp9_;
	_tmp10_ = token;
	xdg_activation_token_v1_add_listener (_tmp10_, &XDG_ACTIVATION_HELPER_TOKEN_LISTENER, &token_value);
	_tmp11_ = token;
	_tmp12_ = wl_surface;
	xdg_activation_token_v1_set_surface (_tmp11_, _tmp12_);
	_tmp13_ = token;
	xdg_activation_token_v1_commit (_tmp13_);
	while (TRUE) {
		gboolean _tmp14_ = FALSE;
		struct wl_display* _tmp15_;
		_tmp15_ = wl_display;
		if (wl_display_dispatch (_tmp15_) >= 0) {
			const gchar* _tmp16_;
			_tmp16_ = g_value_get_string (&token_value);
			_tmp14_ = _tmp16_ == NULL;
		} else {
			_tmp14_ = FALSE;
		}
		if (!_tmp14_) {
			break;
		}
	}
	_tmp17_ = token;
	xdg_activation_token_v1_destroy (_tmp17_);
	_tmp18_ = g_value_get_string (&token_value);
	token_str = _tmp18_;
	_tmp20_ = token_str;
	if (_tmp20_ != NULL) {
		const gchar* _tmp21_;
		gint _tmp22_;
		gint _tmp23_;
		_tmp21_ = token_str;
		_tmp22_ = strlen (_tmp21_);
		_tmp23_ = _tmp22_;
		_tmp19_ = _tmp23_ > 0;
	} else {
		_tmp19_ = FALSE;
	}
	if (_tmp19_) {
		const gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp24_ = token_str;
		_tmp25_ = g_strdup (_tmp24_);
		result = _tmp25_;
		G_IS_VALUE (&token_value) ? (g_value_unset (&token_value), NULL) : NULL;
		return result;
	}
	result = NULL;
	G_IS_VALUE (&token_value) ? (g_value_unset (&token_value), NULL) : NULL;
	return result;
}

static void
xdg_activation_helper_class_init (XdgActivationHelperClass * klass,
                                  gpointer klass_data)
{
	struct wl_registry_listener _tmp0_ = {0};
	xdg_activation_helper_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XdgActivationHelper_private_offset);
	G_OBJECT_CLASS (klass)->finalize = xdg_activation_helper_finalize;
	memset (&_tmp0_, 0, sizeof (struct wl_registry_listener));
	_tmp0_.global = _xdg_activation_helper_registry_handle_global_wl_registrylistenerglobal;
	xdg_activation_helper_registry_listener = _tmp0_;
}

static void
xdg_activation_helper_instance_init (XdgActivationHelper * self,
                                     gpointer klass)
{
	self->priv = xdg_activation_helper_get_instance_private (self);
	self->priv->xdg_activation = NULL;
}

static void
xdg_activation_helper_finalize (GObject * obj)
{
	XdgActivationHelper * self;
	struct xdg_activation_v1* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_XDG_ACTIVATION_HELPER, XdgActivationHelper);
	_tmp0_ = self->priv->xdg_activation;
	if (_tmp0_ != NULL) {
		struct xdg_activation_v1* _tmp1_;
		_tmp1_ = self->priv->xdg_activation;
		xdg_activation_v1_destroy (_tmp1_);
	}
	G_OBJECT_CLASS (xdg_activation_helper_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
xdg_activation_helper_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XdgActivationHelperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xdg_activation_helper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XdgActivationHelper), 0, (GInstanceInitFunc) xdg_activation_helper_instance_init, NULL };
	GType xdg_activation_helper_type_id;
	xdg_activation_helper_type_id = g_type_register_static (G_TYPE_OBJECT, "XdgActivationHelper", &g_define_type_info, 0);
	XdgActivationHelper_private_offset = g_type_add_instance_private (xdg_activation_helper_type_id, sizeof (XdgActivationHelperPrivate));
	return xdg_activation_helper_type_id;
}

GType
xdg_activation_helper_get_type (void)
{
	static gsize xdg_activation_helper_type_id__once = 0;
	if (g_once_init_enter (&xdg_activation_helper_type_id__once)) {
		GType xdg_activation_helper_type_id;
		xdg_activation_helper_type_id = xdg_activation_helper_get_type_once ();
		g_once_init_leave (&xdg_activation_helper_type_id__once, xdg_activation_helper_type_id);
	}
	return xdg_activation_helper_type_id__once;
}

