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

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "libkkc/libkkc.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.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

#define KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY (kkc_nicola_key_event_filter_timed_entry_get_type ())
#define KKC_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, KkcNicolaKeyEventFilterTimedEntry))
#define KKC_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, KkcNicolaKeyEventFilterTimedEntryClass))
#define KKC_NICOLA_KEY_EVENT_FILTER_IS_TIMED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY))
#define KKC_NICOLA_KEY_EVENT_FILTER_IS_TIMED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY))
#define KKC_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, KkcNicolaKeyEventFilterTimedEntryClass))

typedef struct _KkcNicolaKeyEventFilterTimedEntry KkcNicolaKeyEventFilterTimedEntry;
typedef struct _KkcNicolaKeyEventFilterTimedEntryClass KkcNicolaKeyEventFilterTimedEntryClass;
enum  {
	KKC_NICOLA_KEY_EVENT_FILTER_0_PROPERTY,
	KKC_NICOLA_KEY_EVENT_FILTER_NUM_PROPERTIES
};
static GParamSpec* kkc_nicola_key_event_filter_properties[KKC_NICOLA_KEY_EVENT_FILTER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _KkcNicolaKeyEventFilterTimedEntryPrivate KkcNicolaKeyEventFilterTimedEntryPrivate;
#define _kkc_nicola_key_event_filter_timed_entry_unref0(var) ((var == NULL) ? NULL : (var = (kkc_nicola_key_event_filter_timed_entry_unref (var), NULL)))
typedef struct _KkcNicolaKeyEventFilterParamSpecTimedEntry KkcNicolaKeyEventFilterParamSpecTimedEntry;

struct _KkcNicolaKeyEventFilterPrivate {
	GeeLinkedList* pending;
	guint timeout_id;
};

struct _KkcNicolaKeyEventFilterTimedEntry {
	GTypeInstance parent_instance;
	volatile int ref_count;
	KkcNicolaKeyEventFilterTimedEntryPrivate * priv;
	gpointer data;
	gint64 time;
};

struct _KkcNicolaKeyEventFilterTimedEntryClass {
	GTypeClass parent_class;
	void (*finalize) (KkcNicolaKeyEventFilterTimedEntry *self);
};

struct _KkcNicolaKeyEventFilterTimedEntryPrivate {
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
};

struct _KkcNicolaKeyEventFilterParamSpecTimedEntry {
	GParamSpec parent_instance;
};

static gint KkcNicolaKeyEventFilter_private_offset;
static gpointer kkc_nicola_key_event_filter_parent_class = NULL;
static gint KkcNicolaKeyEventFilterTimedEntry_private_offset;
static gpointer kkc_nicola_key_event_filter_timed_entry_parent_class = NULL;

static gpointer kkc_nicola_key_event_filter_timed_entry_ref (gpointer instance);
static void kkc_nicola_key_event_filter_timed_entry_unref (gpointer instance);
static GParamSpec* kkc_nicola_key_event_filter_param_spec_timed_entry (const gchar* name,
                                                                const gchar* nick,
                                                                const gchar* blurb,
                                                                GType object_type,
                                                                GParamFlags flags) G_GNUC_UNUSED ;
static void kkc_nicola_key_event_filter_value_set_timed_entry (GValue* value,
                                                        gpointer v_object) G_GNUC_UNUSED ;
static void kkc_nicola_key_event_filter_value_take_timed_entry (GValue* value,
                                                         gpointer v_object) G_GNUC_UNUSED ;
static gpointer kkc_nicola_key_event_filter_value_get_timed_entry (const GValue* value) G_GNUC_UNUSED ;
static GType kkc_nicola_key_event_filter_timed_entry_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static gint64 kkc_nicola_key_event_filter_get_time (void);
static gint64 _kkc_nicola_key_event_filter_get_time_kkc_get_time (gpointer self);
static gboolean kkc_nicola_key_event_filter_is_char (KkcKeyEvent* key);
static gboolean kkc_nicola_key_event_filter_is_lshift (KkcKeyEvent* key);
static gboolean kkc_nicola_key_event_filter_is_rshift (KkcKeyEvent* key);
static gboolean kkc_nicola_key_event_filter_is_shift (KkcKeyEvent* key);
static KkcKeyEvent* kkc_nicola_key_event_filter_queue (KkcNicolaKeyEventFilter* self,
                                                KkcKeyEvent* key,
                                                gint64 time,
                                                gint64* wait);
static gint64 kkc_nicola_key_event_filter_get_next_wait (KkcNicolaKeyEventFilter* self,
                                                  KkcKeyEvent* key,
                                                  gint64 time);
static KkcNicolaKeyEventFilterTimedEntry* kkc_nicola_key_event_filter_timed_entry_new (GType t_type,
                                                                                GBoxedCopyFunc t_dup_func,
                                                                                GDestroyNotify t_destroy_func,
                                                                                gconstpointer data,
                                                                                gint64 time);
static KkcNicolaKeyEventFilterTimedEntry* kkc_nicola_key_event_filter_timed_entry_construct (GType object_type,
                                                                                      GType t_type,
                                                                                      GBoxedCopyFunc t_dup_func,
                                                                                      GDestroyNotify t_destroy_func,
                                                                                      gconstpointer data,
                                                                                      gint64 time);
static KkcKeyEvent* kkc_nicola_key_event_filter_dispatch_single (KkcNicolaKeyEventFilter* self,
                                                          gint64 time);
static void kkc_nicola_key_event_filter_apply_shift (KkcNicolaKeyEventFilter* self,
                                              KkcKeyEvent* s,
                                              KkcKeyEvent* c);
static KkcKeyEvent* kkc_nicola_key_event_filter_dispatch (KkcNicolaKeyEventFilter* self,
                                                   gint64 time);
static KkcKeyEvent* kkc_nicola_key_event_filter_decompose_shifted (KkcNicolaKeyEventFilter* self,
                                                            KkcKeyEvent* key);
static gboolean kkc_nicola_key_event_filter_timeout_func (KkcNicolaKeyEventFilter* self);
static KkcKeyEvent* kkc_nicola_key_event_filter_real_filter_key_event (KkcKeyEventFilter* base,
                                                                KkcKeyEvent* key);
static gboolean _kkc_nicola_key_event_filter_timeout_func_gsource_func (gpointer self);
static void kkc_nicola_key_event_filter_real_reset (KkcKeyEventFilter* base);
static void kkc_nicola_key_event_filter_timed_entry_finalize (KkcNicolaKeyEventFilterTimedEntry * obj);
static GType kkc_nicola_key_event_filter_timed_entry_get_type_once (void);
static void kkc_nicola_key_event_filter_finalize (GObject * obj);
static GType kkc_nicola_key_event_filter_get_type_once (void);

static inline gpointer
kkc_nicola_key_event_filter_get_instance_private (KkcNicolaKeyEventFilter* self)
{
	return G_STRUCT_MEMBER_P (self, KkcNicolaKeyEventFilter_private_offset);
}

static gint64
_kkc_nicola_key_event_filter_get_time_kkc_get_time (gpointer self)
{
	gint64 result;
	result = kkc_nicola_key_event_filter_get_time ();
	return result;
}

static gint64
kkc_nicola_key_event_filter_get_time (void)
{
	GTimeVal tv = {0};
	GTimeVal _tmp0_;
	GTimeVal _tmp1_;
	gint64 result;
	g_get_current_time (&tv);
	_tmp0_ = tv;
	_tmp1_ = tv;
	result = (((gint64) _tmp0_.tv_sec) * 1000000) + _tmp1_.tv_usec;
	return result;
}

static gboolean
kkc_nicola_key_event_filter_is_char (KkcKeyEvent* key)
{
	gunichar _tmp0_;
	gunichar _tmp1_;
	gboolean result;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = kkc_key_event_get_unicode (key);
	_tmp1_ = _tmp0_;
	result = _tmp1_ != ((gunichar) 0);
	return result;
}

static gboolean
kkc_nicola_key_event_filter_is_lshift (KkcKeyEvent* key)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = kkc_key_event_get_name (key);
	_tmp1_ = _tmp0_;
	result = g_strcmp0 (_tmp1_, "Muhenkan") == 0;
	return result;
}

static gboolean
kkc_nicola_key_event_filter_is_rshift (KkcKeyEvent* key)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = kkc_key_event_get_name (key);
	_tmp1_ = _tmp0_;
	result = g_strcmp0 (_tmp1_, "Henkan") == 0;
	return result;
}

static gboolean
kkc_nicola_key_event_filter_is_shift (KkcKeyEvent* key)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (key != NULL, FALSE);
	if (kkc_nicola_key_event_filter_is_lshift (key)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = kkc_nicola_key_event_filter_is_rshift (key);
	}
	result = _tmp0_;
	return result;
}

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

static KkcKeyEvent*
kkc_nicola_key_event_filter_queue (KkcNicolaKeyEventFilter* self,
                                   KkcKeyEvent* key,
                                   gint64 time,
                                   gint64* wait)
{
	gint64 _vala_wait = 0LL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	KkcModifierType _tmp2_;
	KkcModifierType _tmp3_;
	gboolean _tmp21_ = FALSE;
	GeeLinkedList* _tmp22_;
	gint _tmp23_;
	gint _tmp24_;
	GeeLinkedList* _tmp37_;
	gint _tmp38_;
	gint _tmp39_;
	GeeLinkedList* _tmp50_;
	KkcNicolaKeyEventFilterTimedEntry* _tmp51_;
	KkcNicolaKeyEventFilterTimedEntry* _tmp52_;
	KkcKeyEvent* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp2_ = kkc_key_event_get_modifiers (key);
	_tmp3_ = _tmp2_;
	if ((_tmp3_ & KKC_MODIFIER_TYPE_RELEASE_MASK) != 0) {
		GeeLinkedList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		_tmp4_ = self->priv->pending;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp1_ = _tmp6_ > 0;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GeeLinkedList* _tmp7_;
		gpointer _tmp8_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp9_;
		gconstpointer _tmp10_;
		guint _tmp11_;
		guint _tmp12_;
		guint _tmp13_;
		guint _tmp14_;
		_tmp7_ = self->priv->pending;
		_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, 0);
		_tmp9_ = (KkcNicolaKeyEventFilterTimedEntry*) _tmp8_;
		_tmp10_ = _tmp9_->data;
		_tmp11_ = kkc_key_event_get_keyval ((KkcKeyEvent*) _tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = kkc_key_event_get_keyval (key);
		_tmp14_ = _tmp13_;
		_tmp0_ = _tmp12_ == _tmp14_;
		_kkc_nicola_key_event_filter_timed_entry_unref0 (_tmp9_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		KkcNicolaKeyEventFilterTimedEntry* entry = NULL;
		GeeLinkedList* _tmp15_;
		gpointer _tmp16_;
		GeeLinkedList* _tmp17_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp18_;
		gconstpointer _tmp19_;
		KkcKeyEvent* _tmp20_;
		_tmp15_ = self->priv->pending;
		_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, 0);
		entry = (KkcNicolaKeyEventFilterTimedEntry*) _tmp16_;
		_vala_wait = kkc_nicola_key_event_filter_get_next_wait (self, key, time);
		_tmp17_ = self->priv->pending;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp17_);
		_tmp18_ = entry;
		_tmp19_ = _tmp18_->data;
		_tmp20_ = _g_object_ref0 ((KkcKeyEvent*) _tmp19_);
		result = _tmp20_;
		_kkc_nicola_key_event_filter_timed_entry_unref0 (entry);
		if (wait) {
			*wait = _vala_wait;
		}
		return result;
	}
	_tmp22_ = self->priv->pending;
	_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp22_);
	_tmp24_ = _tmp23_;
	if (_tmp24_ > 0) {
		GeeLinkedList* _tmp25_;
		gpointer _tmp26_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp27_;
		gconstpointer _tmp28_;
		guint _tmp29_;
		guint _tmp30_;
		guint _tmp31_;
		guint _tmp32_;
		_tmp25_ = self->priv->pending;
		_tmp26_ = gee_abstract_list_get ((GeeAbstractList*) _tmp25_, 0);
		_tmp27_ = (KkcNicolaKeyEventFilterTimedEntry*) _tmp26_;
		_tmp28_ = _tmp27_->data;
		_tmp29_ = kkc_key_event_get_keyval ((KkcKeyEvent*) _tmp28_);
		_tmp30_ = _tmp29_;
		_tmp31_ = kkc_key_event_get_keyval (key);
		_tmp32_ = _tmp31_;
		_tmp21_ = _tmp30_ == _tmp32_;
		_kkc_nicola_key_event_filter_timed_entry_unref0 (_tmp27_);
	} else {
		_tmp21_ = FALSE;
	}
	if (_tmp21_) {
		GeeLinkedList* _tmp33_;
		gpointer _tmp34_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp35_;
		KkcKeyEvent* _tmp36_;
		_tmp33_ = self->priv->pending;
		_tmp34_ = gee_abstract_list_get ((GeeAbstractList*) _tmp33_, 0);
		_tmp35_ = (KkcNicolaKeyEventFilterTimedEntry*) _tmp34_;
		_tmp35_->time = time;
		_kkc_nicola_key_event_filter_timed_entry_unref0 (_tmp35_);
		_vala_wait = kkc_nicola_key_event_filter_get_next_wait (self, key, time);
		_tmp36_ = _g_object_ref0 (key);
		result = _tmp36_;
		if (wait) {
			*wait = _vala_wait;
		}
		return result;
	}
	_tmp37_ = self->priv->pending;
	_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
	_tmp39_ = _tmp38_;
	if (_tmp39_ > 2) {
		GeeBidirListIterator* iter = NULL;
		GeeLinkedList* _tmp40_;
		GeeBidirListIterator* _tmp41_;
		GeeBidirListIterator* _tmp42_;
		_tmp40_ = self->priv->pending;
		_tmp41_ = gee_abstract_bidir_list_bidir_list_iterator ((GeeAbstractBidirList*) _tmp40_);
		iter = _tmp41_;
		_tmp42_ = iter;
		gee_bidir_iterator_last ((GeeBidirIterator*) _tmp42_);
		{
			gboolean _tmp43_ = FALSE;
			_tmp43_ = TRUE;
			while (TRUE) {
				GeeBidirListIterator* _tmp49_;
				if (!_tmp43_) {
					gboolean _tmp44_ = FALSE;
					GeeLinkedList* _tmp45_;
					gint _tmp46_;
					gint _tmp47_;
					_tmp45_ = self->priv->pending;
					_tmp46_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp45_);
					_tmp47_ = _tmp46_;
					if (_tmp47_ > 2) {
						GeeBidirListIterator* _tmp48_;
						_tmp48_ = iter;
						_tmp44_ = gee_bidir_iterator_previous ((GeeBidirIterator*) _tmp48_);
					} else {
						_tmp44_ = FALSE;
					}
					if (!_tmp44_) {
						break;
					}
				}
				_tmp43_ = FALSE;
				_tmp49_ = iter;
				gee_iterator_remove ((GeeIterator*) _tmp49_);
			}
		}
		_g_object_unref0 (iter);
	}
	_tmp50_ = self->priv->pending;
	_tmp51_ = kkc_nicola_key_event_filter_timed_entry_new (KKC_TYPE_KEY_EVENT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, key, time);
	_tmp52_ = _tmp51_;
	gee_abstract_list_insert ((GeeAbstractList*) _tmp50_, 0, _tmp52_);
	_kkc_nicola_key_event_filter_timed_entry_unref0 (_tmp52_);
	_vala_wait = self->timeout;
	result = NULL;
	if (wait) {
		*wait = _vala_wait;
	}
	return result;
}

static gint64
kkc_nicola_key_event_filter_get_next_wait (KkcNicolaKeyEventFilter* self,
                                           KkcKeyEvent* key,
                                           gint64 time)
{
	GeeLinkedList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeLinkedList* _tmp12_;
	gint _tmp13_;
	gint _tmp14_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	g_return_val_if_fail (key != NULL, -1LL);
	_tmp0_ = self->priv->pending;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ > 0) {
		GeeBidirListIterator* iter = NULL;
		GeeLinkedList* _tmp3_;
		GeeBidirListIterator* _tmp4_;
		GeeBidirListIterator* _tmp5_;
		_tmp3_ = self->priv->pending;
		_tmp4_ = gee_abstract_bidir_list_bidir_list_iterator ((GeeAbstractBidirList*) _tmp3_);
		iter = _tmp4_;
		_tmp5_ = iter;
		gee_bidir_iterator_last ((GeeBidirIterator*) _tmp5_);
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				KkcNicolaKeyEventFilterTimedEntry* entry = NULL;
				GeeBidirListIterator* _tmp8_;
				gpointer _tmp9_;
				KkcNicolaKeyEventFilterTimedEntry* _tmp10_;
				if (!_tmp6_) {
					GeeBidirListIterator* _tmp7_;
					_tmp7_ = iter;
					if (!gee_bidir_iterator_previous ((GeeBidirIterator*) _tmp7_)) {
						break;
					}
				}
				_tmp6_ = FALSE;
				_tmp8_ = iter;
				_tmp9_ = gee_iterator_get ((GeeIterator*) _tmp8_);
				entry = (KkcNicolaKeyEventFilterTimedEntry*) _tmp9_;
				_tmp10_ = entry;
				if ((time - _tmp10_->time) > self->timeout) {
					GeeBidirListIterator* _tmp11_;
					_tmp11_ = iter;
					gee_iterator_remove ((GeeIterator*) _tmp11_);
				}
				_kkc_nicola_key_event_filter_timed_entry_unref0 (entry);
			}
		}
		_g_object_unref0 (iter);
	}
	_tmp12_ = self->priv->pending;
	_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
	_tmp14_ = _tmp13_;
	if (_tmp14_ > 0) {
		GeeLinkedList* _tmp15_;
		gpointer _tmp16_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp17_;
		gint64 _tmp18_;
		_tmp15_ = self->priv->pending;
		_tmp16_ = gee_linked_list_last (_tmp15_);
		_tmp17_ = (KkcNicolaKeyEventFilterTimedEntry*) _tmp16_;
		_tmp18_ = self->timeout - (time - _tmp17_->time);
		_kkc_nicola_key_event_filter_timed_entry_unref0 (_tmp17_);
		result = _tmp18_;
		return result;
	} else {
		result = self->maxwait;
		return result;
	}
}

static KkcKeyEvent*
kkc_nicola_key_event_filter_dispatch_single (KkcNicolaKeyEventFilter* self,
                                             gint64 time)
{
	KkcNicolaKeyEventFilterTimedEntry* entry = NULL;
	GeeLinkedList* _tmp0_;
	gpointer _tmp1_;
	KkcNicolaKeyEventFilterTimedEntry* _tmp2_;
	KkcKeyEvent* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->pending;
	_tmp1_ = gee_queue_peek ((GeeQueue*) _tmp0_);
	entry = (KkcNicolaKeyEventFilterTimedEntry*) _tmp1_;
	_tmp2_ = entry;
	if ((time - _tmp2_->time) > self->timeout) {
		GeeLinkedList* _tmp3_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp4_;
		gconstpointer _tmp5_;
		KkcKeyEvent* _tmp6_;
		_tmp3_ = self->priv->pending;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp3_);
		_tmp4_ = entry;
		_tmp5_ = _tmp4_->data;
		_tmp6_ = _g_object_ref0 ((KkcKeyEvent*) _tmp5_);
		result = _tmp6_;
		_kkc_nicola_key_event_filter_timed_entry_unref0 (entry);
		return result;
	}
	result = NULL;
	_kkc_nicola_key_event_filter_timed_entry_unref0 (entry);
	return result;
}

static void
kkc_nicola_key_event_filter_apply_shift (KkcNicolaKeyEventFilter* self,
                                         KkcKeyEvent* s,
                                         KkcKeyEvent* c)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (s != NULL);
	g_return_if_fail (c != NULL);
	if (kkc_nicola_key_event_filter_is_lshift (s)) {
		KkcModifierType _tmp0_;
		KkcModifierType _tmp1_;
		_tmp0_ = kkc_key_event_get_modifiers (c);
		_tmp1_ = _tmp0_;
		kkc_key_event_set_modifiers (c, _tmp1_ | KKC_MODIFIER_TYPE_LSHIFT_MASK);
	} else {
		if (kkc_nicola_key_event_filter_is_rshift (s)) {
			KkcModifierType _tmp2_;
			KkcModifierType _tmp3_;
			_tmp2_ = kkc_key_event_get_modifiers (c);
			_tmp3_ = _tmp2_;
			kkc_key_event_set_modifiers (c, _tmp3_ | KKC_MODIFIER_TYPE_RSHIFT_MASK);
		}
	}
}

static KkcKeyEvent*
kkc_nicola_key_event_filter_dispatch (KkcNicolaKeyEventFilter* self,
                                      gint64 time)
{
	GeeLinkedList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	KkcKeyEvent* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->pending;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 3) {
		KkcNicolaKeyEventFilterTimedEntry* b = NULL;
		GeeLinkedList* _tmp3_;
		gpointer _tmp4_;
		KkcNicolaKeyEventFilterTimedEntry* s = NULL;
		GeeLinkedList* _tmp5_;
		gpointer _tmp6_;
		KkcNicolaKeyEventFilterTimedEntry* a = NULL;
		GeeLinkedList* _tmp7_;
		gpointer _tmp8_;
		gint64 t1 = 0LL;
		KkcNicolaKeyEventFilterTimedEntry* _tmp9_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp10_;
		gint64 t2 = 0LL;
		KkcNicolaKeyEventFilterTimedEntry* _tmp11_;
		KkcNicolaKeyEventFilterTimedEntry* _tmp12_;
		_tmp3_ = self->priv->pending;
		_tmp4_ = gee_abstract_list_get ((GeeAbstractList*) _tmp3_, 0);
		b = (KkcNicolaKeyEventFilterTimedEntry*) _tmp4_;
		_tmp5_ = self->priv->pending;
		_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, 1);
		s = (KkcNicolaKeyEventFilterTimedEntry*) _tmp6_;
		_tmp7_ = self->priv->pending;
		_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, 2);
		a = (KkcNicolaKeyEventFilterTimedEntry*) _tmp8_;
		_tmp9_ = s;
		_tmp10_ = a;
		t1 = _tmp9_->time - _tmp10_->time;
		_tmp11_ = b;
		_tmp12_ = s;
		t2 = _tmp11_->time - _tmp12_->time;
		if (t1 <= t2) {
			GeeLinkedList* _tmp13_;
			GeeLinkedList* _tmp14_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp15_;
			KkcKeyEvent* r = NULL;
			KkcKeyEvent* _tmp16_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp17_;
			gconstpointer _tmp18_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp19_;
			gconstpointer _tmp20_;
			KkcKeyEvent* output = NULL;
			KkcNicolaKeyEventFilterTimedEntry* _tmp21_;
			gconstpointer _tmp22_;
			KkcKeyEvent* _tmp23_;
			KkcKeyEvent* _tmp24_;
			_tmp13_ = self->priv->pending;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp13_);
			_tmp14_ = self->priv->pending;
			_tmp15_ = b;
			gee_deque_offer_head ((GeeDeque*) _tmp14_, _tmp15_);
			_tmp16_ = kkc_nicola_key_event_filter_dispatch_single (self, time);
			r = _tmp16_;
			_tmp17_ = s;
			_tmp18_ = _tmp17_->data;
			_tmp19_ = a;
			_tmp20_ = _tmp19_->data;
			kkc_nicola_key_event_filter_apply_shift (self, (KkcKeyEvent*) _tmp18_, (KkcKeyEvent*) _tmp20_);
			_tmp21_ = a;
			_tmp22_ = _tmp21_->data;
			_tmp23_ = kkc_nicola_key_event_filter_decompose_shifted (self, (KkcKeyEvent*) _tmp22_);
			output = _tmp23_;
			_tmp24_ = output;
			g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp24_);
			result = r;
			_g_object_unref0 (output);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (s);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
			return result;
		} else {
			GeeLinkedList* _tmp25_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp26_;
			gconstpointer _tmp27_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp28_;
			gconstpointer _tmp29_;
			KkcKeyEvent* output = NULL;
			KkcNicolaKeyEventFilterTimedEntry* _tmp30_;
			gconstpointer _tmp31_;
			KkcKeyEvent* _tmp32_;
			KkcKeyEvent* _tmp33_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp34_;
			gconstpointer _tmp35_;
			KkcKeyEvent* _tmp36_;
			_tmp25_ = self->priv->pending;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp25_);
			_tmp26_ = s;
			_tmp27_ = _tmp26_->data;
			_tmp28_ = b;
			_tmp29_ = _tmp28_->data;
			kkc_nicola_key_event_filter_apply_shift (self, (KkcKeyEvent*) _tmp27_, (KkcKeyEvent*) _tmp29_);
			_tmp30_ = a;
			_tmp31_ = _tmp30_->data;
			_tmp32_ = kkc_nicola_key_event_filter_decompose_shifted (self, (KkcKeyEvent*) _tmp31_);
			output = _tmp32_;
			_tmp33_ = output;
			g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp33_);
			_tmp34_ = b;
			_tmp35_ = _tmp34_->data;
			_tmp36_ = _g_object_ref0 ((KkcKeyEvent*) _tmp35_);
			result = _tmp36_;
			_g_object_unref0 (output);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (s);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
			return result;
		}
		_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
		_kkc_nicola_key_event_filter_timed_entry_unref0 (s);
		_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
	} else {
		GeeLinkedList* _tmp37_;
		gint _tmp38_;
		gint _tmp39_;
		_tmp37_ = self->priv->pending;
		_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
		_tmp39_ = _tmp38_;
		if (_tmp39_ == 2) {
			KkcNicolaKeyEventFilterTimedEntry* b = NULL;
			GeeLinkedList* _tmp40_;
			gpointer _tmp41_;
			KkcNicolaKeyEventFilterTimedEntry* a = NULL;
			GeeLinkedList* _tmp42_;
			gpointer _tmp43_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp44_;
			KkcNicolaKeyEventFilterTimedEntry* _tmp45_;
			_tmp40_ = self->priv->pending;
			_tmp41_ = gee_abstract_list_get ((GeeAbstractList*) _tmp40_, 0);
			b = (KkcNicolaKeyEventFilterTimedEntry*) _tmp41_;
			_tmp42_ = self->priv->pending;
			_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, 1);
			a = (KkcNicolaKeyEventFilterTimedEntry*) _tmp43_;
			_tmp44_ = b;
			_tmp45_ = a;
			if ((_tmp44_->time - _tmp45_->time) > self->overlap) {
				GeeLinkedList* _tmp46_;
				GeeLinkedList* _tmp47_;
				KkcNicolaKeyEventFilterTimedEntry* _tmp48_;
				KkcKeyEvent* r = NULL;
				KkcKeyEvent* _tmp49_;
				KkcKeyEvent* output = NULL;
				KkcNicolaKeyEventFilterTimedEntry* _tmp50_;
				gconstpointer _tmp51_;
				KkcKeyEvent* _tmp52_;
				KkcKeyEvent* _tmp53_;
				_tmp46_ = self->priv->pending;
				gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp46_);
				_tmp47_ = self->priv->pending;
				_tmp48_ = b;
				gee_deque_offer_head ((GeeDeque*) _tmp47_, _tmp48_);
				_tmp49_ = kkc_nicola_key_event_filter_dispatch_single (self, time);
				r = _tmp49_;
				_tmp50_ = a;
				_tmp51_ = _tmp50_->data;
				_tmp52_ = kkc_nicola_key_event_filter_decompose_shifted (self, (KkcKeyEvent*) _tmp51_);
				output = _tmp52_;
				_tmp53_ = output;
				g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp53_);
				result = r;
				_g_object_unref0 (output);
				_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
				_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
				return result;
			} else {
				gboolean _tmp54_ = FALSE;
				gboolean _tmp55_ = FALSE;
				KkcNicolaKeyEventFilterTimedEntry* _tmp56_;
				gconstpointer _tmp57_;
				_tmp56_ = a;
				_tmp57_ = _tmp56_->data;
				if (kkc_nicola_key_event_filter_is_char ((KkcKeyEvent*) _tmp57_)) {
					KkcNicolaKeyEventFilterTimedEntry* _tmp58_;
					gconstpointer _tmp59_;
					_tmp58_ = b;
					_tmp59_ = _tmp58_->data;
					_tmp55_ = kkc_nicola_key_event_filter_is_char ((KkcKeyEvent*) _tmp59_);
				} else {
					_tmp55_ = FALSE;
				}
				if (_tmp55_) {
					_tmp54_ = TRUE;
				} else {
					gboolean _tmp60_ = FALSE;
					KkcNicolaKeyEventFilterTimedEntry* _tmp61_;
					gconstpointer _tmp62_;
					_tmp61_ = a;
					_tmp62_ = _tmp61_->data;
					if (kkc_nicola_key_event_filter_is_shift ((KkcKeyEvent*) _tmp62_)) {
						KkcNicolaKeyEventFilterTimedEntry* _tmp63_;
						gconstpointer _tmp64_;
						_tmp63_ = b;
						_tmp64_ = _tmp63_->data;
						_tmp60_ = kkc_nicola_key_event_filter_is_shift ((KkcKeyEvent*) _tmp64_);
					} else {
						_tmp60_ = FALSE;
					}
					_tmp54_ = _tmp60_;
				}
				if (_tmp54_) {
					GeeLinkedList* _tmp65_;
					GeeLinkedList* _tmp66_;
					KkcNicolaKeyEventFilterTimedEntry* _tmp67_;
					KkcKeyEvent* r = NULL;
					KkcKeyEvent* _tmp68_;
					KkcKeyEvent* output = NULL;
					KkcNicolaKeyEventFilterTimedEntry* _tmp69_;
					gconstpointer _tmp70_;
					KkcKeyEvent* _tmp71_;
					KkcKeyEvent* _tmp72_;
					_tmp65_ = self->priv->pending;
					gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp65_);
					_tmp66_ = self->priv->pending;
					_tmp67_ = b;
					gee_deque_offer_head ((GeeDeque*) _tmp66_, _tmp67_);
					_tmp68_ = kkc_nicola_key_event_filter_dispatch_single (self, time);
					r = _tmp68_;
					_tmp69_ = a;
					_tmp70_ = _tmp69_->data;
					_tmp71_ = kkc_nicola_key_event_filter_decompose_shifted (self, (KkcKeyEvent*) _tmp70_);
					output = _tmp71_;
					_tmp72_ = output;
					g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp72_);
					result = r;
					_g_object_unref0 (output);
					_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
					_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
					return result;
				} else {
					KkcNicolaKeyEventFilterTimedEntry* _tmp73_;
					_tmp73_ = a;
					if ((time - _tmp73_->time) > self->timeout) {
						GeeLinkedList* _tmp74_;
						KkcNicolaKeyEventFilterTimedEntry* _tmp75_;
						gconstpointer _tmp76_;
						_tmp74_ = self->priv->pending;
						gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp74_);
						_tmp75_ = b;
						_tmp76_ = _tmp75_->data;
						if (kkc_nicola_key_event_filter_is_shift ((KkcKeyEvent*) _tmp76_)) {
							KkcNicolaKeyEventFilterTimedEntry* _tmp77_;
							gconstpointer _tmp78_;
							KkcNicolaKeyEventFilterTimedEntry* _tmp79_;
							gconstpointer _tmp80_;
							KkcNicolaKeyEventFilterTimedEntry* _tmp81_;
							gconstpointer _tmp82_;
							KkcKeyEvent* _tmp83_;
							_tmp77_ = b;
							_tmp78_ = _tmp77_->data;
							_tmp79_ = a;
							_tmp80_ = _tmp79_->data;
							kkc_nicola_key_event_filter_apply_shift (self, (KkcKeyEvent*) _tmp78_, (KkcKeyEvent*) _tmp80_);
							_tmp81_ = a;
							_tmp82_ = _tmp81_->data;
							_tmp83_ = _g_object_ref0 ((KkcKeyEvent*) _tmp82_);
							result = _tmp83_;
							_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
							_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
							return result;
						} else {
							KkcNicolaKeyEventFilterTimedEntry* _tmp84_;
							gconstpointer _tmp85_;
							KkcNicolaKeyEventFilterTimedEntry* _tmp86_;
							gconstpointer _tmp87_;
							KkcNicolaKeyEventFilterTimedEntry* _tmp88_;
							gconstpointer _tmp89_;
							KkcKeyEvent* _tmp90_;
							_tmp84_ = a;
							_tmp85_ = _tmp84_->data;
							_tmp86_ = b;
							_tmp87_ = _tmp86_->data;
							kkc_nicola_key_event_filter_apply_shift (self, (KkcKeyEvent*) _tmp85_, (KkcKeyEvent*) _tmp87_);
							_tmp88_ = b;
							_tmp89_ = _tmp88_->data;
							_tmp90_ = _g_object_ref0 ((KkcKeyEvent*) _tmp89_);
							result = _tmp90_;
							_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
							_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
							return result;
						}
					}
				}
			}
			_kkc_nicola_key_event_filter_timed_entry_unref0 (a);
			_kkc_nicola_key_event_filter_timed_entry_unref0 (b);
		} else {
			GeeLinkedList* _tmp91_;
			gint _tmp92_;
			gint _tmp93_;
			_tmp91_ = self->priv->pending;
			_tmp92_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp91_);
			_tmp93_ = _tmp92_;
			if (_tmp93_ == 1) {
				KkcKeyEvent* _tmp94_;
				_tmp94_ = kkc_nicola_key_event_filter_dispatch_single (self, time);
				result = _tmp94_;
				return result;
			}
		}
	}
	result = NULL;
	return result;
}

static gboolean
kkc_nicola_key_event_filter_timeout_func (KkcNicolaKeyEventFilter* self)
{
	gint64 time = 0LL;
	KkcGetTime _tmp0_;
	gpointer _tmp0__target;
	KkcKeyEvent* r = NULL;
	KkcKeyEvent* _tmp1_;
	KkcKeyEvent* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->get_time_func;
	_tmp0__target = self->get_time_func_target;
	time = _tmp0_ (_tmp0__target);
	_tmp1_ = kkc_nicola_key_event_filter_dispatch (self, time);
	r = _tmp1_;
	_tmp2_ = r;
	if (_tmp2_ != NULL) {
		KkcKeyEvent* output = NULL;
		KkcKeyEvent* _tmp3_;
		KkcKeyEvent* _tmp4_;
		KkcKeyEvent* _tmp5_;
		_tmp3_ = r;
		_tmp4_ = kkc_nicola_key_event_filter_decompose_shifted (self, _tmp3_);
		output = _tmp4_;
		_tmp5_ = output;
		g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp5_);
		_g_object_unref0 (output);
	}
	self->priv->timeout_id = (guint) 0;
	result = FALSE;
	_g_object_unref0 (r);
	return result;
}

static KkcKeyEvent*
kkc_nicola_key_event_filter_decompose_shifted (KkcNicolaKeyEventFilter* self,
                                               KkcKeyEvent* key)
{
	KkcModifierType _tmp0_;
	KkcModifierType _tmp1_;
	KkcModifierType _tmp7_;
	KkcModifierType _tmp8_;
	KkcKeyEvent* _tmp14_;
	KkcKeyEvent* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = kkc_key_event_get_modifiers (key);
	_tmp1_ = _tmp0_;
	if ((_tmp1_ & KKC_MODIFIER_TYPE_LSHIFT_MASK) != 0) {
		KkcKeyEvent* _tmp2_;
		KkcKeyEvent* _tmp3_;
		KkcModifierType _tmp4_;
		KkcModifierType _tmp5_;
		KkcKeyEvent* _tmp6_;
		_tmp2_ = kkc_key_event_new_from_x_event ((guint) 0x4c, (guint) 0, 0);
		_tmp3_ = _tmp2_;
		g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp3_);
		_g_object_unref0 (_tmp3_);
		_tmp4_ = kkc_key_event_get_modifiers (key);
		_tmp5_ = _tmp4_;
		kkc_key_event_set_modifiers (key, _tmp5_ & (~KKC_MODIFIER_TYPE_LSHIFT_MASK));
		_tmp6_ = _g_object_ref0 (key);
		result = _tmp6_;
		return result;
	}
	_tmp7_ = kkc_key_event_get_modifiers (key);
	_tmp8_ = _tmp7_;
	if ((_tmp8_ & KKC_MODIFIER_TYPE_RSHIFT_MASK) != 0) {
		KkcKeyEvent* _tmp9_;
		KkcKeyEvent* _tmp10_;
		KkcModifierType _tmp11_;
		KkcModifierType _tmp12_;
		KkcKeyEvent* _tmp13_;
		_tmp9_ = kkc_key_event_new_from_x_event ((guint) 0x52, (guint) 0, 0);
		_tmp10_ = _tmp9_;
		g_signal_emit_by_name ((KkcKeyEventFilter*) self, "forwarded", _tmp10_);
		_g_object_unref0 (_tmp10_);
		_tmp11_ = kkc_key_event_get_modifiers (key);
		_tmp12_ = _tmp11_;
		kkc_key_event_set_modifiers (key, _tmp12_ & (~KKC_MODIFIER_TYPE_RSHIFT_MASK));
		_tmp13_ = _g_object_ref0 (key);
		result = _tmp13_;
		return result;
	}
	_tmp14_ = _g_object_ref0 (key);
	result = _tmp14_;
	return result;
}

/**
         * {@inheritDoc}
         */
static gboolean
_kkc_nicola_key_event_filter_timeout_func_gsource_func (gpointer self)
{
	gboolean result;
	result = kkc_nicola_key_event_filter_timeout_func ((KkcNicolaKeyEventFilter*) self);
	return result;
}

static KkcKeyEvent*
kkc_nicola_key_event_filter_real_filter_key_event (KkcKeyEventFilter* base,
                                                   KkcKeyEvent* key)
{
	KkcNicolaKeyEventFilter * self;
	gint64 time = 0LL;
	KkcGetTime _tmp0_;
	gpointer _tmp0__target;
	gint64 wait = 0LL;
	KkcKeyEvent* output = NULL;
	gint64 _tmp1_ = 0LL;
	KkcKeyEvent* _tmp2_;
	KkcKeyEvent* _tmp3_;
	KkcKeyEvent* _tmp5_;
	KkcKeyEvent* _tmp6_;
	KkcKeyEvent* _tmp7_;
	KkcKeyEvent* result;
	self = (KkcNicolaKeyEventFilter*) base;
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = self->get_time_func;
	_tmp0__target = self->get_time_func_target;
	time = _tmp0_ (_tmp0__target);
	_tmp2_ = kkc_nicola_key_event_filter_queue (self, key, time, &_tmp1_);
	wait = _tmp1_;
	output = _tmp2_;
	if (wait > ((gint64) 0)) {
		if (self->priv->timeout_id > ((guint) 0)) {
			g_source_remove (self->priv->timeout_id);
		}
		self->priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) (wait / 1000), _kkc_nicola_key_event_filter_timeout_func_gsource_func, g_object_ref (self), g_object_unref);
	}
	_tmp3_ = output;
	if (_tmp3_ == NULL) {
		KkcKeyEvent* _tmp4_;
		_tmp4_ = kkc_nicola_key_event_filter_dispatch (self, time);
		_g_object_unref0 (output);
		output = _tmp4_;
	}
	_tmp5_ = output;
	if (_tmp5_ == NULL) {
		result = NULL;
		_g_object_unref0 (output);
		return result;
	}
	_tmp6_ = output;
	_tmp7_ = kkc_nicola_key_event_filter_decompose_shifted (self, _tmp6_);
	result = _tmp7_;
	_g_object_unref0 (output);
	return result;
}

/**
         * {@inheritDoc}
         */
static void
kkc_nicola_key_event_filter_real_reset (KkcKeyEventFilter* base)
{
	KkcNicolaKeyEventFilter * self;
	GeeLinkedList* _tmp0_;
	self = (KkcNicolaKeyEventFilter*) base;
	_tmp0_ = self->priv->pending;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
}

KkcNicolaKeyEventFilter*
kkc_nicola_key_event_filter_construct (GType object_type)
{
	KkcNicolaKeyEventFilter * self = NULL;
	self = (KkcNicolaKeyEventFilter*) kkc_key_event_filter_construct (object_type);
	return self;
}

KkcNicolaKeyEventFilter*
kkc_nicola_key_event_filter_new (void)
{
	return kkc_nicola_key_event_filter_construct (KKC_TYPE_NICOLA_KEY_EVENT_FILTER);
}

static inline gpointer
kkc_nicola_key_event_filter_timed_entry_get_instance_private (KkcNicolaKeyEventFilterTimedEntry* self)
{
	return G_STRUCT_MEMBER_P (self, KkcNicolaKeyEventFilterTimedEntry_private_offset);
}

static KkcNicolaKeyEventFilterTimedEntry*
kkc_nicola_key_event_filter_timed_entry_construct (GType object_type,
                                                   GType t_type,
                                                   GBoxedCopyFunc t_dup_func,
                                                   GDestroyNotify t_destroy_func,
                                                   gconstpointer data,
                                                   gint64 time)
{
	KkcNicolaKeyEventFilterTimedEntry* self = NULL;
	gpointer _tmp0_;
	self = (KkcNicolaKeyEventFilterTimedEntry*) g_type_create_instance (object_type);
	self->priv->t_type = t_type;
	self->priv->t_dup_func = t_dup_func;
	self->priv->t_destroy_func = t_destroy_func;
	_tmp0_ = ((data != NULL) && (t_dup_func != NULL)) ? t_dup_func ((gpointer) data) : ((gpointer) data);
	((self->data == NULL) || (t_destroy_func == NULL)) ? NULL : (self->data = (t_destroy_func (self->data), NULL));
	self->data = _tmp0_;
	self->time = time;
	return self;
}

static KkcNicolaKeyEventFilterTimedEntry*
kkc_nicola_key_event_filter_timed_entry_new (GType t_type,
                                             GBoxedCopyFunc t_dup_func,
                                             GDestroyNotify t_destroy_func,
                                             gconstpointer data,
                                             gint64 time)
{
	return kkc_nicola_key_event_filter_timed_entry_construct (KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, t_type, t_dup_func, t_destroy_func, data, time);
}

static void
kkc_nicola_key_event_filter_value_timed_entry_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
kkc_nicola_key_event_filter_value_timed_entry_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		kkc_nicola_key_event_filter_timed_entry_unref (value->data[0].v_pointer);
	}
}

static void
kkc_nicola_key_event_filter_value_timed_entry_copy_value (const GValue* src_value,
                                                          GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = kkc_nicola_key_event_filter_timed_entry_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
kkc_nicola_key_event_filter_value_timed_entry_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
kkc_nicola_key_event_filter_value_timed_entry_collect_value (GValue* value,
                                                             guint n_collect_values,
                                                             GTypeCValue* collect_values,
                                                             guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		KkcNicolaKeyEventFilterTimedEntry * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = kkc_nicola_key_event_filter_timed_entry_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
kkc_nicola_key_event_filter_value_timed_entry_lcopy_value (const GValue* value,
                                                           guint n_collect_values,
                                                           GTypeCValue* collect_values,
                                                           guint collect_flags)
{
	KkcNicolaKeyEventFilterTimedEntry ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = kkc_nicola_key_event_filter_timed_entry_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
kkc_nicola_key_event_filter_param_spec_timed_entry (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags)
{
	KkcNicolaKeyEventFilterParamSpecTimedEntry* spec;
	g_return_val_if_fail (g_type_is_a (object_type, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
kkc_nicola_key_event_filter_value_get_timed_entry (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY), NULL);
	return value->data[0].v_pointer;
}

static void
kkc_nicola_key_event_filter_value_set_timed_entry (GValue* value,
                                                   gpointer v_object)
{
	KkcNicolaKeyEventFilterTimedEntry * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		kkc_nicola_key_event_filter_timed_entry_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		kkc_nicola_key_event_filter_timed_entry_unref (old);
	}
}

static void
kkc_nicola_key_event_filter_value_take_timed_entry (GValue* value,
                                                    gpointer v_object)
{
	KkcNicolaKeyEventFilterTimedEntry * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		kkc_nicola_key_event_filter_timed_entry_unref (old);
	}
}

static void
kkc_nicola_key_event_filter_timed_entry_class_init (KkcNicolaKeyEventFilterTimedEntryClass * klass,
                                                    gpointer klass_data)
{
	kkc_nicola_key_event_filter_timed_entry_parent_class = g_type_class_peek_parent (klass);
	((KkcNicolaKeyEventFilterTimedEntryClass *) klass)->finalize = kkc_nicola_key_event_filter_timed_entry_finalize;
	g_type_class_adjust_private_offset (klass, &KkcNicolaKeyEventFilterTimedEntry_private_offset);
}

static void
kkc_nicola_key_event_filter_timed_entry_instance_init (KkcNicolaKeyEventFilterTimedEntry * self,
                                                       gpointer klass)
{
	self->priv = kkc_nicola_key_event_filter_timed_entry_get_instance_private (self);
	self->ref_count = 1;
}

static void
kkc_nicola_key_event_filter_timed_entry_finalize (KkcNicolaKeyEventFilterTimedEntry * obj)
{
	KkcNicolaKeyEventFilterTimedEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, KkcNicolaKeyEventFilterTimedEntry);
	g_signal_handlers_destroy (self);
	((self->data == NULL) || (self->priv->t_destroy_func == NULL)) ? NULL : (self->data = (self->priv->t_destroy_func (self->data), NULL));
}

static GType
kkc_nicola_key_event_filter_timed_entry_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { kkc_nicola_key_event_filter_value_timed_entry_init, kkc_nicola_key_event_filter_value_timed_entry_free_value, kkc_nicola_key_event_filter_value_timed_entry_copy_value, kkc_nicola_key_event_filter_value_timed_entry_peek_pointer, "p", kkc_nicola_key_event_filter_value_timed_entry_collect_value, "p", kkc_nicola_key_event_filter_value_timed_entry_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (KkcNicolaKeyEventFilterTimedEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_nicola_key_event_filter_timed_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcNicolaKeyEventFilterTimedEntry), 0, (GInstanceInitFunc) kkc_nicola_key_event_filter_timed_entry_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType kkc_nicola_key_event_filter_timed_entry_type_id;
	kkc_nicola_key_event_filter_timed_entry_type_id = g_type_register_fundamental (g_type_fundamental_next (), "KkcNicolaKeyEventFilterTimedEntry", &g_define_type_info, &g_define_type_fundamental_info, 0);
	KkcNicolaKeyEventFilterTimedEntry_private_offset = g_type_add_instance_private (kkc_nicola_key_event_filter_timed_entry_type_id, sizeof (KkcNicolaKeyEventFilterTimedEntryPrivate));
	return kkc_nicola_key_event_filter_timed_entry_type_id;
}

static GType
kkc_nicola_key_event_filter_timed_entry_get_type (void)
{
	static volatile gsize kkc_nicola_key_event_filter_timed_entry_type_id__once = 0;
	if (g_once_init_enter (&kkc_nicola_key_event_filter_timed_entry_type_id__once)) {
		GType kkc_nicola_key_event_filter_timed_entry_type_id;
		kkc_nicola_key_event_filter_timed_entry_type_id = kkc_nicola_key_event_filter_timed_entry_get_type_once ();
		g_once_init_leave (&kkc_nicola_key_event_filter_timed_entry_type_id__once, kkc_nicola_key_event_filter_timed_entry_type_id);
	}
	return kkc_nicola_key_event_filter_timed_entry_type_id__once;
}

static gpointer
kkc_nicola_key_event_filter_timed_entry_ref (gpointer instance)
{
	KkcNicolaKeyEventFilterTimedEntry * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
kkc_nicola_key_event_filter_timed_entry_unref (gpointer instance)
{
	KkcNicolaKeyEventFilterTimedEntry * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		KKC_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
kkc_nicola_key_event_filter_class_init (KkcNicolaKeyEventFilterClass * klass,
                                        gpointer klass_data)
{
	kkc_nicola_key_event_filter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcNicolaKeyEventFilter_private_offset);
	((KkcKeyEventFilterClass *) klass)->filter_key_event = (KkcKeyEvent* (*) (KkcKeyEventFilter*, KkcKeyEvent*)) kkc_nicola_key_event_filter_real_filter_key_event;
	((KkcKeyEventFilterClass *) klass)->reset = (void (*) (KkcKeyEventFilter*)) kkc_nicola_key_event_filter_real_reset;
	G_OBJECT_CLASS (klass)->finalize = kkc_nicola_key_event_filter_finalize;
}

static void
kkc_nicola_key_event_filter_instance_init (KkcNicolaKeyEventFilter * self,
                                           gpointer klass)
{
	GeeLinkedList* _tmp0_;
	self->priv = kkc_nicola_key_event_filter_get_instance_private (self);
	self->get_time_func = _kkc_nicola_key_event_filter_get_time_kkc_get_time;
	self->get_time_func_target = NULL;
	self->get_time_func_target_destroy_notify = NULL;
	self->timeout = (gint64) 100000;
	self->overlap = (gint64) 50000;
	self->maxwait = (gint64) 10000000;
	_tmp0_ = gee_linked_list_new (KKC_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, (GBoxedCopyFunc) kkc_nicola_key_event_filter_timed_entry_ref, (GDestroyNotify) kkc_nicola_key_event_filter_timed_entry_unref, NULL, NULL, NULL);
	self->priv->pending = _tmp0_;
	self->priv->timeout_id = (guint) 0;
}

static void
kkc_nicola_key_event_filter_finalize (GObject * obj)
{
	KkcNicolaKeyEventFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_NICOLA_KEY_EVENT_FILTER, KkcNicolaKeyEventFilter);
	(self->get_time_func_target_destroy_notify == NULL) ? NULL : (self->get_time_func_target_destroy_notify (self->get_time_func_target), NULL);
	self->get_time_func = NULL;
	self->get_time_func_target = NULL;
	self->get_time_func_target_destroy_notify = NULL;
	_g_object_unref0 (self->priv->pending);
	G_OBJECT_CLASS (kkc_nicola_key_event_filter_parent_class)->finalize (obj);
}

/**
     * Key event filter implementing NICOLA (thumb shift) input
     *
     * This class is rarely used in programs but specified as "filter"
     * property in rule metadata.
     *
     * @see Rule
     */
static GType
kkc_nicola_key_event_filter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcNicolaKeyEventFilterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_nicola_key_event_filter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcNicolaKeyEventFilter), 0, (GInstanceInitFunc) kkc_nicola_key_event_filter_instance_init, NULL };
	GType kkc_nicola_key_event_filter_type_id;
	kkc_nicola_key_event_filter_type_id = g_type_register_static (KKC_TYPE_KEY_EVENT_FILTER, "KkcNicolaKeyEventFilter", &g_define_type_info, 0);
	KkcNicolaKeyEventFilter_private_offset = g_type_add_instance_private (kkc_nicola_key_event_filter_type_id, sizeof (KkcNicolaKeyEventFilterPrivate));
	return kkc_nicola_key_event_filter_type_id;
}

GType
kkc_nicola_key_event_filter_get_type (void)
{
	static volatile gsize kkc_nicola_key_event_filter_type_id__once = 0;
	if (g_once_init_enter (&kkc_nicola_key_event_filter_type_id__once)) {
		GType kkc_nicola_key_event_filter_type_id;
		kkc_nicola_key_event_filter_type_id = kkc_nicola_key_event_filter_get_type_once ();
		g_once_init_leave (&kkc_nicola_key_event_filter_type_id__once, kkc_nicola_key_event_filter_type_id);
	}
	return kkc_nicola_key_event_filter_type_id__once;
}

