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

/*
 * Copyright 2026 elementary, Inc. (https://elementary.io)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authored by: Leonhard Kargl <leo.kargl@proton.me>
 */

#include <glib-object.h>
#include <meta/display.h>
#include <gio/gio.h>
#include <glib.h>
#include <ibus.h>
#include <clutter/clutter.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 GALA_TYPE_OSK_RECEIVER (gala_osk_receiver_get_type ())
#define GALA_OSK_RECEIVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_OSK_RECEIVER, GalaOSKReceiver))
#define GALA_OSK_RECEIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_OSK_RECEIVER, GalaOSKReceiverClass))
#define GALA_IS_OSK_RECEIVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_OSK_RECEIVER))
#define GALA_IS_OSK_RECEIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_OSK_RECEIVER))
#define GALA_OSK_RECEIVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_OSK_RECEIVER, GalaOSKReceiverClass))

typedef struct _GalaOSKReceiver GalaOSKReceiver;
typedef struct _GalaOSKReceiverClass GalaOSKReceiverClass;
typedef struct _GalaOSKReceiverPrivate GalaOSKReceiverPrivate;

#define GALA_TYPE_OSK_PROXY (gala_osk_proxy_get_type ())
#define GALA_OSK_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_OSK_PROXY, GalaOSKProxy))
#define GALA_IS_OSK_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_OSK_PROXY))
#define GALA_OSK_PROXY_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GALA_TYPE_OSK_PROXY, GalaOSKProxyIface))

typedef struct _GalaOSKProxy GalaOSKProxy;
typedef struct _GalaOSKProxyIface GalaOSKProxyIface;

#define GALA_TYPE_OSK_PROXY_PROXY (gala_osk_proxy_proxy_get_type ())
enum  {
	GALA_OSK_RECEIVER_0_PROPERTY,
	GALA_OSK_RECEIVER_DISPLAY_PROPERTY,
	GALA_OSK_RECEIVER_OSK_PROPERTY,
	GALA_OSK_RECEIVER_NUM_PROPERTIES
};
static GParamSpec* gala_osk_receiver_properties[GALA_OSK_RECEIVER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GalaOSKReceiver {
	GObject parent_instance;
	GalaOSKReceiverPrivate * priv;
};

struct _GalaOSKReceiverClass {
	GObjectClass parent_class;
};

struct _GalaOSKProxyIface {
	GTypeInterface parent_iface;
	void (*set_enabled) (GalaOSKProxy* self, gboolean enabled, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*set_enabled_finish) (GalaOSKProxy* self, GAsyncResult* _res_, GError** error);
	void (*reset) (GalaOSKProxy* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*reset_finish) (GalaOSKProxy* self, GAsyncResult* _res_, GError** error);
	void (*set_input_purpose) (GalaOSKProxy* self, IBusInputPurpose input_purpose, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*set_input_purpose_finish) (GalaOSKProxy* self, GAsyncResult* _res_, GError** error);
};

struct _GalaOSKReceiverPrivate {
	MetaDisplay* _display;
	GalaOSKProxy* _osk;
	ClutterVirtualInputDevice* virtual_device;
};

static gint GalaOSKReceiver_private_offset;
static gpointer gala_osk_receiver_parent_class = NULL;

VALA_EXTERN GType gala_osk_receiver_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaOSKReceiver, g_object_unref)
VALA_EXTERN GType gala_osk_proxy_proxy_get_type (void) G_GNUC_CONST ;
VALA_EXTERN guint gala_osk_proxy_register_object (void* object,
                                      GDBusConnection* connection,
                                      const gchar* path,
                                      GError** error);
VALA_EXTERN GType gala_osk_proxy_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GalaOSKProxy, g_object_unref)
VALA_EXTERN GalaOSKReceiver* gala_osk_receiver_new (MetaDisplay* display,
                                        GalaOSKProxy* osk);
VALA_EXTERN GalaOSKReceiver* gala_osk_receiver_construct (GType object_type,
                                              MetaDisplay* display,
                                              GalaOSKProxy* osk);
static void gala_osk_receiver_on_keyval_pressed (GalaOSKReceiver* self,
                                          guint keyval);
static void gala_osk_receiver_on_keyval_released (GalaOSKReceiver* self,
                                           guint keyval);
static MetaDisplay* gala_osk_receiver_get_display (GalaOSKReceiver* self);
static void gala_osk_receiver_set_display (GalaOSKReceiver* self,
                                    MetaDisplay* value);
static GalaOSKProxy* gala_osk_receiver_get_osk (GalaOSKReceiver* self);
static void gala_osk_receiver_set_osk (GalaOSKReceiver* self,
                                GalaOSKProxy* value);
static GObject * gala_osk_receiver_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void _gala_osk_receiver_on_keyval_pressed_gala_osk_proxy_keyval_pressed (GalaOSKProxy* _sender,
                                                                         guint keyval,
                                                                         gpointer self);
static void _gala_osk_receiver_on_keyval_released_gala_osk_proxy_keyval_released (GalaOSKProxy* _sender,
                                                                           guint keyval,
                                                                           gpointer self);
static void gala_osk_receiver_finalize (GObject * obj);
static GType gala_osk_receiver_get_type_once (void);
static void _vala_gala_osk_receiver_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_gala_osk_receiver_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
gala_osk_receiver_get_instance_private (GalaOSKReceiver* self)
{
	return G_STRUCT_MEMBER_P (self, GalaOSKReceiver_private_offset);
}

GalaOSKReceiver*
gala_osk_receiver_construct (GType object_type,
                             MetaDisplay* display,
                             GalaOSKProxy* osk)
{
	GalaOSKReceiver * self = NULL;
	g_return_val_if_fail (display != NULL, NULL);
	g_return_val_if_fail (osk != NULL, NULL);
	self = (GalaOSKReceiver*) g_object_new (object_type, "display", display, "osk", osk, NULL);
	return self;
}

GalaOSKReceiver*
gala_osk_receiver_new (MetaDisplay* display,
                       GalaOSKProxy* osk)
{
	return gala_osk_receiver_construct (GALA_TYPE_OSK_RECEIVER, display, osk);
}

static void
gala_osk_receiver_on_keyval_pressed (GalaOSKReceiver* self,
                                     guint keyval)
{
	ClutterVirtualInputDevice* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->virtual_device;
	clutter_virtual_input_device_notify_keyval (_tmp0_, (guint64) (clutter_get_current_event_time () * 1000), (guint32) keyval, CLUTTER_KEY_STATE_PRESSED);
}

static void
gala_osk_receiver_on_keyval_released (GalaOSKReceiver* self,
                                      guint keyval)
{
	ClutterVirtualInputDevice* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->virtual_device;
	clutter_virtual_input_device_notify_keyval (_tmp0_, (guint64) (clutter_get_current_event_time () * 1000), (guint32) keyval, CLUTTER_KEY_STATE_RELEASED);
}

static MetaDisplay*
gala_osk_receiver_get_display (GalaOSKReceiver* self)
{
	MetaDisplay* result;
	MetaDisplay* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_display;
	result = _tmp0_;
	return result;
}

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

static void
gala_osk_receiver_set_display (GalaOSKReceiver* self,
                               MetaDisplay* value)
{
	MetaDisplay* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_osk_receiver_get_display (self);
	if (old_value != value) {
		MetaDisplay* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_display);
		self->priv->_display = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_osk_receiver_properties[GALA_OSK_RECEIVER_DISPLAY_PROPERTY]);
	}
}

static GalaOSKProxy*
gala_osk_receiver_get_osk (GalaOSKReceiver* self)
{
	GalaOSKProxy* result;
	GalaOSKProxy* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_osk;
	result = _tmp0_;
	return result;
}

static void
gala_osk_receiver_set_osk (GalaOSKReceiver* self,
                           GalaOSKProxy* value)
{
	GalaOSKProxy* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_osk_receiver_get_osk (self);
	if (old_value != value) {
		GalaOSKProxy* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_osk);
		self->priv->_osk = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_osk_receiver_properties[GALA_OSK_RECEIVER_OSK_PROPERTY]);
	}
}

static void
_gala_osk_receiver_on_keyval_pressed_gala_osk_proxy_keyval_pressed (GalaOSKProxy* _sender,
                                                                    guint keyval,
                                                                    gpointer self)
{
	gala_osk_receiver_on_keyval_pressed ((GalaOSKReceiver*) self, keyval);
}

static void
_gala_osk_receiver_on_keyval_released_gala_osk_proxy_keyval_released (GalaOSKProxy* _sender,
                                                                      guint keyval,
                                                                      gpointer self)
{
	gala_osk_receiver_on_keyval_released ((GalaOSKReceiver*) self, keyval);
}

static GObject *
gala_osk_receiver_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GalaOSKReceiver * self;
	ClutterSeat* seat = NULL;
	ClutterBackend* _tmp0_;
	ClutterSeat* _tmp1_;
	ClutterSeat* _tmp2_;
	ClutterSeat* _tmp3_;
	ClutterVirtualInputDevice* _tmp4_;
	GalaOSKProxy* _tmp5_;
	GalaOSKProxy* _tmp6_;
	parent_class = G_OBJECT_CLASS (gala_osk_receiver_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_OSK_RECEIVER, GalaOSKReceiver);
	_tmp0_ = clutter_get_default_backend ();
	_tmp1_ = clutter_backend_get_default_seat (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	seat = _tmp2_;
	_tmp3_ = seat;
	_tmp4_ = clutter_seat_create_virtual_device (_tmp3_, CLUTTER_KEYBOARD_DEVICE);
	_g_object_unref0 (self->priv->virtual_device);
	self->priv->virtual_device = _tmp4_;
	_tmp5_ = self->priv->_osk;
	g_signal_connect_object (_tmp5_, "keyval-pressed", (GCallback) _gala_osk_receiver_on_keyval_pressed_gala_osk_proxy_keyval_pressed, self, 0);
	_tmp6_ = self->priv->_osk;
	g_signal_connect_object (_tmp6_, "keyval-released", (GCallback) _gala_osk_receiver_on_keyval_released_gala_osk_proxy_keyval_released, self, 0);
	_g_object_unref0 (seat);
	return obj;
}

static void
gala_osk_receiver_class_init (GalaOSKReceiverClass * klass,
                              gpointer klass_data)
{
	gala_osk_receiver_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaOSKReceiver_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_osk_receiver_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_osk_receiver_set_property;
	G_OBJECT_CLASS (klass)->constructor = gala_osk_receiver_constructor;
	G_OBJECT_CLASS (klass)->finalize = gala_osk_receiver_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_OSK_RECEIVER_DISPLAY_PROPERTY, gala_osk_receiver_properties[GALA_OSK_RECEIVER_DISPLAY_PROPERTY] = g_param_spec_object ("display", "display", "display", meta_display_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_OSK_RECEIVER_OSK_PROPERTY, gala_osk_receiver_properties[GALA_OSK_RECEIVER_OSK_PROPERTY] = g_param_spec_object ("osk", "osk", "osk", GALA_TYPE_OSK_PROXY, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
gala_osk_receiver_instance_init (GalaOSKReceiver * self,
                                 gpointer klass)
{
	self->priv = gala_osk_receiver_get_instance_private (self);
}

static void
gala_osk_receiver_finalize (GObject * obj)
{
	GalaOSKReceiver * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_OSK_RECEIVER, GalaOSKReceiver);
	_g_object_unref0 (self->priv->_display);
	_g_object_unref0 (self->priv->_osk);
	_g_object_unref0 (self->priv->virtual_device);
	G_OBJECT_CLASS (gala_osk_receiver_parent_class)->finalize (obj);
}

/**
 * Once the OSK is enabled the Manager creates a receiver which handles the input received from
 * the OSK and forwards it.
 */
 G_GNUC_NO_INLINE static GType
gala_osk_receiver_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaOSKReceiverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_osk_receiver_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaOSKReceiver), 0, (GInstanceInitFunc) gala_osk_receiver_instance_init, NULL };
	GType gala_osk_receiver_type_id;
	gala_osk_receiver_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaOSKReceiver", &g_define_type_info, G_TYPE_FLAG_NONE);
	GalaOSKReceiver_private_offset = g_type_add_instance_private (gala_osk_receiver_type_id, sizeof (GalaOSKReceiverPrivate));
	return gala_osk_receiver_type_id;
}

GType
gala_osk_receiver_get_type (void)
{
	static gsize gala_osk_receiver_type_id__once = 0;
	if (g_once_init_enter (&gala_osk_receiver_type_id__once)) {
		GType gala_osk_receiver_type_id;
		gala_osk_receiver_type_id = gala_osk_receiver_get_type_once ();
		g_once_init_leave (&gala_osk_receiver_type_id__once, gala_osk_receiver_type_id);
	}
	return gala_osk_receiver_type_id__once;
}

static void
_vala_gala_osk_receiver_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	GalaOSKReceiver * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_OSK_RECEIVER, GalaOSKReceiver);
	switch (property_id) {
		case GALA_OSK_RECEIVER_DISPLAY_PROPERTY:
		g_value_set_object (value, gala_osk_receiver_get_display (self));
		break;
		case GALA_OSK_RECEIVER_OSK_PROPERTY:
		g_value_set_object (value, gala_osk_receiver_get_osk (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_osk_receiver_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	GalaOSKReceiver * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_OSK_RECEIVER, GalaOSKReceiver);
	switch (property_id) {
		case GALA_OSK_RECEIVER_DISPLAY_PROPERTY:
		gala_osk_receiver_set_display (self, g_value_get_object (value));
		break;
		case GALA_OSK_RECEIVER_OSK_PROPERTY:
		gala_osk_receiver_set_osk (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

