/* GlobalTrigger.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from GlobalTrigger.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 "gala.h"
#include <glib.h>
#include <glib-object.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

enum  {
	GALA_GLOBAL_TRIGGER_0_PROPERTY,
	GALA_GLOBAL_TRIGGER_ACTION_PROPERTY,
	GALA_GLOBAL_TRIGGER_WM_PROPERTY,
	GALA_GLOBAL_TRIGGER_ACTION_INFO_PROPERTY,
	GALA_GLOBAL_TRIGGER_NUM_PROPERTIES
};
static GParamSpec* gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

#define GALA_TYPE_GESTURE (gala_gesture_get_type ())
#define GALA_GESTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_GESTURE, GalaGesture))
#define GALA_GESTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_GESTURE, GalaGestureClass))
#define GALA_IS_GESTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_GESTURE))
#define GALA_IS_GESTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_GESTURE))
#define GALA_GESTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_GESTURE, GalaGestureClass))

typedef struct _GalaGesture GalaGesture;
typedef struct _GalaGestureClass GalaGestureClass;
typedef enum  {
	GALA_TOUCHPAD_BACKEND_GROUP_NONE,
	GALA_TOUCHPAD_BACKEND_GROUP_MULTITASKING_VIEW
} GalaTouchpadBackendGroup;

#define GALA_TOUCHPAD_BACKEND_TYPE_GROUP (gala_touchpad_backend_group_get_type ())

#define GALA_TYPE_GESTURE_BACKEND (gala_gesture_backend_get_type ())
#define GALA_GESTURE_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_GESTURE_BACKEND, GalaGestureBackend))
#define GALA_IS_GESTURE_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_GESTURE_BACKEND))
#define GALA_GESTURE_BACKEND_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GALA_TYPE_GESTURE_BACKEND, GalaGestureBackendIface))

typedef struct _GalaGestureBackend GalaGestureBackend;
typedef struct _GalaGestureBackendIface GalaGestureBackendIface;

#define GALA_TYPE_TOUCHEGG_BACKEND (gala_touchegg_backend_get_type ())
#define GALA_TOUCHEGG_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_TOUCHEGG_BACKEND, GalaToucheggBackend))
#define GALA_TOUCHEGG_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_TOUCHEGG_BACKEND, GalaToucheggBackendClass))
#define GALA_IS_TOUCHEGG_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_TOUCHEGG_BACKEND))
#define GALA_IS_TOUCHEGG_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_TOUCHEGG_BACKEND))
#define GALA_TOUCHEGG_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_TOUCHEGG_BACKEND, GalaToucheggBackendClass))

typedef struct _GalaToucheggBackend GalaToucheggBackend;
typedef struct _GalaToucheggBackendClass GalaToucheggBackendClass;

#define GALA_TYPE_TOUCHPAD_BACKEND (gala_touchpad_backend_get_type ())
#define GALA_TOUCHPAD_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GALA_TYPE_TOUCHPAD_BACKEND, GalaTouchpadBackend))
#define GALA_TOUCHPAD_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GALA_TYPE_TOUCHPAD_BACKEND, GalaTouchpadBackendClass))
#define GALA_IS_TOUCHPAD_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GALA_TYPE_TOUCHPAD_BACKEND))
#define GALA_IS_TOUCHPAD_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GALA_TYPE_TOUCHPAD_BACKEND))
#define GALA_TOUCHPAD_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GALA_TYPE_TOUCHPAD_BACKEND, GalaTouchpadBackendClass))

typedef struct _GalaTouchpadBackend GalaTouchpadBackend;
typedef struct _GalaTouchpadBackendClass GalaTouchpadBackendClass;

struct _GalaGlobalTriggerPrivate {
	GalaGestureAction _action;
	GalaWindowManager* _wm;
	GVariant* _action_info;
};

struct _GalaGestureBackendIface {
	GTypeInterface parent_iface;
	void (*cancel_gesture) (GalaGestureBackend* self);
};

static gint GalaGlobalTrigger_private_offset;
static gpointer gala_global_trigger_parent_class = NULL;
static GalaGestureTriggerIface * gala_global_trigger_gala_gesture_trigger_parent_iface = NULL;

 G_GNUC_INTERNAL gpointer gala_gesture_ref (gpointer instance);
 G_GNUC_INTERNAL void gala_gesture_unref (gpointer instance);
 G_GNUC_INTERNAL GParamSpec* gala_param_spec_gesture (const gchar* name,
                                     const gchar* nick,
                                     const gchar* blurb,
                                     GType object_type,
                                     GParamFlags flags);
 G_GNUC_INTERNAL void gala_value_set_gesture (GValue* value,
                             gpointer v_object) G_GNUC_UNUSED ;
 G_GNUC_INTERNAL void gala_value_take_gesture (GValue* value,
                              gpointer v_object);
 G_GNUC_INTERNAL gpointer gala_value_get_gesture (const GValue* value) G_GNUC_UNUSED ;
 G_GNUC_INTERNAL GType gala_gesture_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gboolean gala_global_trigger_real_triggers (GalaGestureTrigger* base,
                                            GalaGesture* gesture);
 G_GNUC_INTERNAL GalaGestureAction gala_gesture_settings_get_action (GalaGesture* gesture,
                                                    GVariant** action_info);
static void gala_global_trigger_real_enable_backends (GalaGestureTrigger* base,
                                               GalaGestureController* controller);
 G_GNUC_INTERNAL GType gala_touchpad_backend_group_get_type (void) G_GNUC_CONST ;
 G_GNUC_INTERNAL GType gala_gesture_backend_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
 G_GNUC_INTERNAL void gala_gesture_controller_enable_backend (GalaGestureController* self,
                                             GalaGestureBackend* backend);
 G_GNUC_INTERNAL GType gala_touchegg_backend_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
 G_GNUC_INTERNAL GalaToucheggBackend* gala_touchegg_backend_get_default (void);
 G_GNUC_INTERNAL GalaTouchpadBackend* gala_touchpad_backend_new (ClutterActor* actor,
                                                GalaTouchpadBackendGroup group);
 G_GNUC_INTERNAL GalaTouchpadBackend* gala_touchpad_backend_construct (GType object_type,
                                                      ClutterActor* actor,
                                                      GalaTouchpadBackendGroup group);
 G_GNUC_INTERNAL GType gala_touchpad_backend_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
 G_GNUC_INTERNAL gboolean gala_gesture_trigger_triggers (GalaGestureTrigger* self,
                                        GalaGesture* gesture);
 G_GNUC_INTERNAL void gala_gesture_trigger_enable_backends (GalaGestureTrigger* self,
                                           GalaGestureController* controller);
static void gala_global_trigger_finalize (GObject * obj);
static GType gala_global_trigger_get_type_once (void);
static void _vala_gala_global_trigger_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_gala_global_trigger_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);

static inline gpointer
gala_global_trigger_get_instance_private (GalaGlobalTrigger* self)
{
	return G_STRUCT_MEMBER_P (self, GalaGlobalTrigger_private_offset);
}

GalaGlobalTrigger*
gala_global_trigger_construct (GType object_type,
                               GalaGestureAction action,
                               GalaWindowManager* wm)
{
	GalaGlobalTrigger * self = NULL;
	g_return_val_if_fail (wm != NULL, NULL);
	self = (GalaGlobalTrigger*) g_object_new (object_type, "action", action, "wm", wm, NULL);
	return self;
}

GalaGlobalTrigger*
gala_global_trigger_new (GalaGestureAction action,
                         GalaWindowManager* wm)
{
	return gala_global_trigger_construct (GALA_TYPE_GLOBAL_TRIGGER, action, wm);
}

static gboolean
gala_global_trigger_real_triggers (GalaGestureTrigger* base,
                                   GalaGesture* gesture)
{
	GalaGlobalTrigger * self;
	GalaGestureAction action = 0;
	GVariant* _tmp0_ = NULL;
	GalaGestureAction _tmp1_;
	gboolean _tmp2_ = FALSE;
	GalaWindowManager* _tmp3_;
	gboolean result;
	self = (GalaGlobalTrigger*) base;
	g_return_val_if_fail (gesture != NULL, FALSE);
	_tmp1_ = gala_gesture_settings_get_action (gesture, &_tmp0_);
	_g_variant_unref0 (self->priv->_action_info);
	self->priv->_action_info = _tmp0_;
	action = _tmp1_;
	_tmp3_ = self->priv->_wm;
	if (!gala_window_manager_filter_action (_tmp3_, gala_gesture_action_to_modal_action (action))) {
		GalaGestureAction _tmp4_;
		_tmp4_ = self->priv->_action;
		_tmp2_ = _tmp4_ == action;
	} else {
		_tmp2_ = FALSE;
	}
	result = _tmp2_;
	return result;
}

static void
gala_global_trigger_real_enable_backends (GalaGestureTrigger* base,
                                          GalaGestureController* controller)
{
	GalaGlobalTrigger * self;
	GalaTouchpadBackendGroup _tmp0_ = 0;
	gboolean _tmp1_ = FALSE;
	GalaGestureAction _tmp2_;
	GalaTouchpadBackendGroup group = 0;
	GalaToucheggBackend* _tmp4_;
	GalaWindowManager* _tmp5_;
	ClutterStage* _tmp6_;
	ClutterStage* _tmp7_;
	GalaTouchpadBackend* _tmp8_;
	GalaTouchpadBackend* _tmp9_;
	self = (GalaGlobalTrigger*) base;
	g_return_if_fail (controller != NULL);
	_tmp2_ = self->priv->_action;
	if (_tmp2_ == GALA_GESTURE_ACTION_MULTITASKING_VIEW) {
		_tmp1_ = TRUE;
	} else {
		GalaGestureAction _tmp3_;
		_tmp3_ = self->priv->_action;
		_tmp1_ = _tmp3_ == GALA_GESTURE_ACTION_SWITCH_WORKSPACE;
	}
	if (_tmp1_) {
		_tmp0_ = GALA_TOUCHPAD_BACKEND_GROUP_MULTITASKING_VIEW;
	} else {
		_tmp0_ = GALA_TOUCHPAD_BACKEND_GROUP_NONE;
	}
	group = _tmp0_;
	_tmp4_ = gala_touchegg_backend_get_default ();
	gala_gesture_controller_enable_backend (controller, (GalaGestureBackend*) _tmp4_);
	_tmp5_ = self->priv->_wm;
	_tmp6_ = gala_window_manager_get_stage (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gala_touchpad_backend_new ((ClutterActor*) _tmp7_, group);
	_tmp9_ = _tmp8_;
	gala_gesture_controller_enable_backend (controller, (GalaGestureBackend*) _tmp9_);
	_g_object_unref0 (_tmp9_);
}

GalaGestureAction
gala_global_trigger_get_action (GalaGlobalTrigger* self)
{
	GalaGestureAction result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_action;
	return result;
}

static void
gala_global_trigger_set_action (GalaGlobalTrigger* self,
                                GalaGestureAction value)
{
	GalaGestureAction old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_global_trigger_get_action (self);
	if (old_value != value) {
		self->priv->_action = value;
		g_object_notify_by_pspec ((GObject *) self, gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_ACTION_PROPERTY]);
	}
}

GalaWindowManager*
gala_global_trigger_get_wm (GalaGlobalTrigger* self)
{
	GalaWindowManager* result;
	GalaWindowManager* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_wm;
	result = _tmp0_;
	return result;
}

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

static void
gala_global_trigger_set_wm (GalaGlobalTrigger* self,
                            GalaWindowManager* value)
{
	GalaWindowManager* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_global_trigger_get_wm (self);
	if (old_value != value) {
		GalaWindowManager* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_wm);
		self->priv->_wm = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_WM_PROPERTY]);
	}
}

GVariant*
gala_global_trigger_get_action_info (GalaGlobalTrigger* self)
{
	GVariant* result;
	GVariant* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_action_info;
	result = _tmp0_;
	return result;
}

static void
gala_global_trigger_class_init (GalaGlobalTriggerClass * klass,
                                gpointer klass_data)
{
	gala_global_trigger_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaGlobalTrigger_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_global_trigger_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_global_trigger_set_property;
	G_OBJECT_CLASS (klass)->finalize = gala_global_trigger_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_GLOBAL_TRIGGER_ACTION_PROPERTY, gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_ACTION_PROPERTY] = g_param_spec_enum ("action", "action", "action", GALA_TYPE_GESTURE_ACTION, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_GLOBAL_TRIGGER_WM_PROPERTY, gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_WM_PROPERTY] = g_param_spec_object ("wm", "wm", "wm", GALA_TYPE_WINDOW_MANAGER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_GLOBAL_TRIGGER_ACTION_INFO_PROPERTY, gala_global_trigger_properties[GALA_GLOBAL_TRIGGER_ACTION_INFO_PROPERTY] = g_param_spec_variant ("action-info", "action-info", "action-info", G_VARIANT_TYPE_ANY, NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gala_global_trigger_gala_gesture_trigger_interface_init (GalaGestureTriggerIface * iface,
                                                         gpointer iface_data)
{
	gala_global_trigger_gala_gesture_trigger_parent_iface = g_type_interface_peek_parent (iface);
	iface->triggers = (gboolean (*) (GalaGestureTrigger*, GalaGesture*)) gala_global_trigger_real_triggers;
	iface->enable_backends = (void (*) (GalaGestureTrigger*, GalaGestureController*)) gala_global_trigger_real_enable_backends;
}

static void
gala_global_trigger_instance_init (GalaGlobalTrigger * self,
                                   gpointer klass)
{
	self->priv = gala_global_trigger_get_instance_private (self);
}

static void
gala_global_trigger_finalize (GObject * obj)
{
	GalaGlobalTrigger * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_GLOBAL_TRIGGER, GalaGlobalTrigger);
	_g_object_unref0 (self->priv->_wm);
	_g_variant_unref0 (self->priv->_action_info);
	G_OBJECT_CLASS (gala_global_trigger_parent_class)->finalize (obj);
}

/**
 * A trigger that triggers when a globally configured gesture has been recognized.
 * These are the typical three or four finger multi touch gestures configurable in the settings.
 * It enables touchpad and touchscreen backends for the whole stage.
 */
 G_GNUC_NO_INLINE static GType
gala_global_trigger_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaGlobalTriggerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_global_trigger_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaGlobalTrigger), 0, (GInstanceInitFunc) gala_global_trigger_instance_init, NULL };
	static const GInterfaceInfo gala_gesture_trigger_info = { (GInterfaceInitFunc) gala_global_trigger_gala_gesture_trigger_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gala_global_trigger_type_id;
	gala_global_trigger_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaGlobalTrigger", &g_define_type_info, 0);
	g_type_add_interface_static (gala_global_trigger_type_id, GALA_TYPE_GESTURE_TRIGGER, &gala_gesture_trigger_info);
	GalaGlobalTrigger_private_offset = g_type_add_instance_private (gala_global_trigger_type_id, sizeof (GalaGlobalTriggerPrivate));
	return gala_global_trigger_type_id;
}

GType
gala_global_trigger_get_type (void)
{
	static gsize gala_global_trigger_type_id__once = 0;
	if (g_once_init_enter (&gala_global_trigger_type_id__once)) {
		GType gala_global_trigger_type_id;
		gala_global_trigger_type_id = gala_global_trigger_get_type_once ();
		g_once_init_leave (&gala_global_trigger_type_id__once, gala_global_trigger_type_id);
	}
	return gala_global_trigger_type_id__once;
}

static void
_vala_gala_global_trigger_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	GalaGlobalTrigger * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_GLOBAL_TRIGGER, GalaGlobalTrigger);
	switch (property_id) {
		case GALA_GLOBAL_TRIGGER_ACTION_PROPERTY:
		g_value_set_enum (value, gala_global_trigger_get_action (self));
		break;
		case GALA_GLOBAL_TRIGGER_WM_PROPERTY:
		g_value_set_object (value, gala_global_trigger_get_wm (self));
		break;
		case GALA_GLOBAL_TRIGGER_ACTION_INFO_PROPERTY:
		g_value_set_variant (value, gala_global_trigger_get_action_info (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_global_trigger_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	GalaGlobalTrigger * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_GLOBAL_TRIGGER, GalaGlobalTrigger);
	switch (property_id) {
		case GALA_GLOBAL_TRIGGER_ACTION_PROPERTY:
		gala_global_trigger_set_action (self, g_value_get_enum (value));
		break;
		case GALA_GLOBAL_TRIGGER_WM_PROPERTY:
		gala_global_trigger_set_wm (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

