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

/*
 * Copyright (C) 2011-2018 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2018 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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gobject/gvaluecollector.h>


#define SKK_TYPE_KEY_EVENT_FILTER (skk_key_event_filter_get_type ())
#define SKK_KEY_EVENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SKK_TYPE_KEY_EVENT_FILTER, SkkKeyEventFilter))
#define SKK_KEY_EVENT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SKK_TYPE_KEY_EVENT_FILTER, SkkKeyEventFilterClass))
#define SKK_IS_KEY_EVENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SKK_TYPE_KEY_EVENT_FILTER))
#define SKK_IS_KEY_EVENT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SKK_TYPE_KEY_EVENT_FILTER))
#define SKK_KEY_EVENT_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SKK_TYPE_KEY_EVENT_FILTER, SkkKeyEventFilterClass))

typedef struct _SkkKeyEventFilter SkkKeyEventFilter;
typedef struct _SkkKeyEventFilterClass SkkKeyEventFilterClass;
typedef struct _SkkKeyEventFilterPrivate SkkKeyEventFilterPrivate;

#define SKK_TYPE_KEY_EVENT (skk_key_event_get_type ())
#define SKK_KEY_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SKK_TYPE_KEY_EVENT, SkkKeyEvent))
#define SKK_KEY_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SKK_TYPE_KEY_EVENT, SkkKeyEventClass))
#define SKK_IS_KEY_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SKK_TYPE_KEY_EVENT))
#define SKK_IS_KEY_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SKK_TYPE_KEY_EVENT))
#define SKK_KEY_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SKK_TYPE_KEY_EVENT, SkkKeyEventClass))

typedef struct _SkkKeyEvent SkkKeyEvent;
typedef struct _SkkKeyEventClass SkkKeyEventClass;

#define SKK_TYPE_NICOLA_KEY_EVENT_FILTER (skk_nicola_key_event_filter_get_type ())
#define SKK_NICOLA_KEY_EVENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilter))
#define SKK_NICOLA_KEY_EVENT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilterClass))
#define SKK_IS_NICOLA_KEY_EVENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SKK_TYPE_NICOLA_KEY_EVENT_FILTER))
#define SKK_IS_NICOLA_KEY_EVENT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SKK_TYPE_NICOLA_KEY_EVENT_FILTER))
#define SKK_NICOLA_KEY_EVENT_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilterClass))

typedef struct _SkkNicolaKeyEventFilter SkkNicolaKeyEventFilter;
typedef struct _SkkNicolaKeyEventFilterClass SkkNicolaKeyEventFilterClass;
typedef struct _SkkNicolaKeyEventFilterPrivate SkkNicolaKeyEventFilterPrivate;

#define SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY (skk_nicola_key_event_filter_timed_entry_get_type ())
#define SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, SkkNicolaKeyEventFilterTimedEntry))
#define SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, SkkNicolaKeyEventFilterTimedEntryClass))
#define SKK_NICOLA_KEY_EVENT_FILTER_IS_TIMED_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY))
#define SKK_NICOLA_KEY_EVENT_FILTER_IS_TIMED_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY))
#define SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, SkkNicolaKeyEventFilterTimedEntryClass))

typedef struct _SkkNicolaKeyEventFilterTimedEntry SkkNicolaKeyEventFilterTimedEntry;
typedef struct _SkkNicolaKeyEventFilterTimedEntryClass SkkNicolaKeyEventFilterTimedEntryClass;
enum  {
	SKK_NICOLA_KEY_EVENT_FILTER_0_PROPERTY,
	SKK_NICOLA_KEY_EVENT_FILTER_NUM_PROPERTIES
};
static GParamSpec* skk_nicola_key_event_filter_properties[SKK_NICOLA_KEY_EVENT_FILTER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define SKK_TYPE_MODIFIER_TYPE (skk_modifier_type_get_type ())
typedef struct _SkkNicolaKeyEventFilterTimedEntryPrivate SkkNicolaKeyEventFilterTimedEntryPrivate;
#define _skk_nicola_key_event_filter_timed_entry_unref0(var) ((var == NULL) ? NULL : (var = (skk_nicola_key_event_filter_timed_entry_unref (var), NULL)))
#define _t_destroy_func0(var) (((var == NULL) || (t_destroy_func == NULL)) ? NULL : (var = (t_destroy_func (var), NULL)))
typedef struct _SkkNicolaKeyEventFilterParamSpecTimedEntry SkkNicolaKeyEventFilterParamSpecTimedEntry;

typedef gint64 (*SkkGetTime) (gpointer user_data);
struct _SkkKeyEventFilter {
	GObject parent_instance;
	SkkKeyEventFilterPrivate * priv;
};

struct _SkkKeyEventFilterClass {
	GObjectClass parent_class;
	SkkKeyEvent* (*filter_key_event) (SkkKeyEventFilter* self, SkkKeyEvent* key);
	void (*reset) (SkkKeyEventFilter* self);
};

struct _SkkNicolaKeyEventFilter {
	SkkKeyEventFilter parent_instance;
	SkkNicolaKeyEventFilterPrivate * priv;
	SkkGetTime get_time_func;
	gpointer get_time_func_target;
	GDestroyNotify get_time_func_target_destroy_notify;
	gint64 timeout;
	gint64 overlap;
	gint64 maxwait;
	gchar** special_doubles;
	gint special_doubles_length1;
};

struct _SkkNicolaKeyEventFilterClass {
	SkkKeyEventFilterClass parent_class;
};

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

typedef enum  {
	SKK_MODIFIER_TYPE_NONE = 0,
	SKK_MODIFIER_TYPE_SHIFT_MASK = 1 << 0,
	SKK_MODIFIER_TYPE_LOCK_MASK = 1 << 1,
	SKK_MODIFIER_TYPE_CONTROL_MASK = 1 << 2,
	SKK_MODIFIER_TYPE_MOD1_MASK = 1 << 3,
	SKK_MODIFIER_TYPE_MOD2_MASK = 1 << 4,
	SKK_MODIFIER_TYPE_MOD3_MASK = 1 << 5,
	SKK_MODIFIER_TYPE_MOD4_MASK = 1 << 6,
	SKK_MODIFIER_TYPE_MOD5_MASK = 1 << 7,
	SKK_MODIFIER_TYPE_LSHIFT_MASK = 1 << 22,
	SKK_MODIFIER_TYPE_RSHIFT_MASK = 1 << 23,
	SKK_MODIFIER_TYPE_USLEEP_MASK = 1 << 24,
	SKK_MODIFIER_TYPE_SUPER_MASK = 1 << 26,
	SKK_MODIFIER_TYPE_HYPER_MASK = 1 << 27,
	SKK_MODIFIER_TYPE_META_MASK = 1 << 28,
	SKK_MODIFIER_TYPE_RELEASE_MASK = 1 << 30
} SkkModifierType;

struct _SkkNicolaKeyEventFilterTimedEntry {
	GTypeInstance parent_instance;
	volatile int ref_count;
	SkkNicolaKeyEventFilterTimedEntryPrivate * priv;
	gpointer data;
	gint64 time;
};

struct _SkkNicolaKeyEventFilterTimedEntryClass {
	GTypeClass parent_class;
	void (*finalize) (SkkNicolaKeyEventFilterTimedEntry *self);
};

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

struct _SkkNicolaKeyEventFilterParamSpecTimedEntry {
	GParamSpec parent_instance;
};


static gpointer skk_nicola_key_event_filter_parent_class = NULL;
static gpointer skk_nicola_key_event_filter_timed_entry_parent_class = NULL;

GType skk_key_event_filter_get_type (void) G_GNUC_CONST;
GType skk_key_event_get_type (void) G_GNUC_CONST;
GType skk_nicola_key_event_filter_get_type (void) G_GNUC_CONST;
static gpointer skk_nicola_key_event_filter_timed_entry_ref (gpointer instance);
static void skk_nicola_key_event_filter_timed_entry_unref (gpointer instance);
static GParamSpec* skk_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 skk_nicola_key_event_filter_value_set_timed_entry (GValue* value,
                                                        gpointer v_object) G_GNUC_UNUSED;
static void skk_nicola_key_event_filter_value_take_timed_entry (GValue* value,
                                                         gpointer v_object) G_GNUC_UNUSED;
static gpointer skk_nicola_key_event_filter_value_get_timed_entry (const GValue* value) G_GNUC_UNUSED;
static GType skk_nicola_key_event_filter_timed_entry_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
#define SKK_NICOLA_KEY_EVENT_FILTER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilterPrivate))
static gint64 skk_nicola_key_event_filter_get_time (void);
static gint64 _skk_nicola_key_event_filter_get_time_skk_get_time (gpointer self);
static gboolean skk_nicola_key_event_filter_is_char (SkkKeyEvent* key);
gunichar skk_key_event_get_code (SkkKeyEvent* self);
static gboolean skk_nicola_key_event_filter_is_lshift (SkkKeyEvent* key);
const gchar* skk_key_event_get_name (SkkKeyEvent* self);
static gboolean skk_nicola_key_event_filter_is_rshift (SkkKeyEvent* key);
static gboolean skk_nicola_key_event_filter_is_shift (SkkKeyEvent* key);
static gchar* skk_nicola_key_event_filter_get_special_double_name (SkkKeyEvent* a,
                                                            SkkKeyEvent* b);
static SkkKeyEvent* skk_nicola_key_event_filter_queue (SkkNicolaKeyEventFilter* self,
                                                SkkKeyEvent* key,
                                                gint64 time,
                                                gint64* wait);
GType skk_modifier_type_get_type (void) G_GNUC_CONST;
SkkModifierType skk_key_event_get_modifiers (SkkKeyEvent* self);
gboolean skk_key_event_base_equal (SkkKeyEvent* self,
                                   SkkKeyEvent* key);
static gint64 skk_nicola_key_event_filter_get_next_wait (SkkNicolaKeyEventFilter* self,
                                                  SkkKeyEvent* key,
                                                  gint64 time);
static SkkNicolaKeyEventFilterTimedEntry* skk_nicola_key_event_filter_timed_entry_new (GType t_type,
                                                                                GBoxedCopyFunc t_dup_func,
                                                                                GDestroyNotify t_destroy_func,
                                                                                gconstpointer data,
                                                                                gint64 time);
static SkkNicolaKeyEventFilterTimedEntry* skk_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 SkkKeyEvent* skk_nicola_key_event_filter_dispatch_single (SkkNicolaKeyEventFilter* self,
                                                          gint64 time);
static void skk_nicola_key_event_filter_apply_shift (SkkNicolaKeyEventFilter* self,
                                              SkkKeyEvent* s,
                                              SkkKeyEvent* c);
void skk_key_event_set_modifiers (SkkKeyEvent* self,
                                  SkkModifierType value);
static SkkKeyEvent* skk_nicola_key_event_filter_dispatch (SkkNicolaKeyEventFilter* self,
                                                   gint64 time);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      int stack_length,
                                      gchar* needle);
SkkKeyEvent* skk_key_event_new (const gchar* name,
                                gunichar code,
                                SkkModifierType modifiers);
SkkKeyEvent* skk_key_event_construct (GType object_type,
                                      const gchar* name,
                                      gunichar code,
                                      SkkModifierType modifiers);
static gboolean skk_nicola_key_event_filter_timeout_func (SkkNicolaKeyEventFilter* self);
static SkkKeyEvent* skk_nicola_key_event_filter_real_filter_key_event (SkkKeyEventFilter* base,
                                                                SkkKeyEvent* key);
static gboolean _skk_nicola_key_event_filter_timeout_func_gsource_func (gpointer self);
static void skk_nicola_key_event_filter_real_reset (SkkKeyEventFilter* base);
SkkNicolaKeyEventFilter* skk_nicola_key_event_filter_new (void);
SkkNicolaKeyEventFilter* skk_nicola_key_event_filter_construct (GType object_type);
SkkKeyEventFilter* skk_key_event_filter_construct (GType object_type);
static GObject * skk_nicola_key_event_filter_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static gchar** _vala_array_dup6 (gchar** self,
                          int length);
#define SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, SkkNicolaKeyEventFilterTimedEntryPrivate))
static void skk_nicola_key_event_filter_timed_entry_finalize (SkkNicolaKeyEventFilterTimedEntry * obj);
static void skk_nicola_key_event_filter_finalize (GObject * obj);
static void _vala_array_destroy (gpointer array,
                          gint array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gint array_length,
                       GDestroyNotify destroy_func);

static const gchar* SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES[4] = {"[fj]", "[gh]", "[dk]", "[LR]"};

static gint64
_skk_nicola_key_event_filter_get_time_skk_get_time (gpointer self)
{
	gint64 result;
	result = skk_nicola_key_event_filter_get_time ();
	return result;
}


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


static gboolean
skk_nicola_key_event_filter_is_char (SkkKeyEvent* key)
{
	gboolean result = FALSE;
	gunichar _tmp0_;
	gunichar _tmp1_;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp0_ = skk_key_event_get_code (key);
	_tmp1_ = _tmp0_;
	result = _tmp1_ != ((gunichar) 0);
	return result;
}


static gboolean
skk_nicola_key_event_filter_is_lshift (SkkKeyEvent* key)
{
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp1_ = skk_key_event_get_name (key);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "lshift") == 0) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = skk_key_event_get_name (key);
		_tmp4_ = _tmp3_;
		_tmp0_ = g_strcmp0 (_tmp4_, "Muhenkan") == 0;
	}
	result = _tmp0_;
	return result;
}


static gboolean
skk_nicola_key_event_filter_is_rshift (SkkKeyEvent* key)
{
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_val_if_fail (key != NULL, FALSE);
	_tmp1_ = skk_key_event_get_name (key);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "rshift") == 0) {
		_tmp0_ = TRUE;
	} else {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		_tmp3_ = skk_key_event_get_name (key);
		_tmp4_ = _tmp3_;
		_tmp0_ = g_strcmp0 (_tmp4_, "Henkan") == 0;
	}
	result = _tmp0_;
	return result;
}


static gboolean
skk_nicola_key_event_filter_is_shift (SkkKeyEvent* key)
{
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	g_return_val_if_fail (key != NULL, FALSE);
	if (skk_nicola_key_event_filter_is_lshift (key)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = skk_nicola_key_event_filter_is_rshift (key);
	}
	result = _tmp0_;
	return result;
}


static gchar*
g_unichar_to_string (gunichar self)
{
	gchar* result = NULL;
	gchar* str = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	_tmp0_ = g_new0 (gchar, 7);
	str = (gchar*) _tmp0_;
	_tmp1_ = str;
	g_unichar_to_utf8 (self, _tmp1_);
	result = str;
	return result;
}


static gchar*
skk_nicola_key_event_filter_get_special_double_name (SkkKeyEvent* a,
                                                     SkkKeyEvent* b)
{
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	g_return_val_if_fail (a != NULL, NULL);
	g_return_val_if_fail (b != NULL, NULL);
	if (skk_nicola_key_event_filter_is_shift (a)) {
		_tmp0_ = skk_nicola_key_event_filter_is_shift (b);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("[LR]");
		result = _tmp1_;
		return result;
	} else {
		gboolean _tmp2_ = FALSE;
		if (skk_nicola_key_event_filter_is_char (a)) {
			_tmp2_ = skk_nicola_key_event_filter_is_char (b);
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			gunichar ac = 0U;
			gunichar bc = 0U;
			gunichar _tmp3_;
			gunichar _tmp4_;
			gunichar _tmp5_;
			gunichar _tmp6_;
			gunichar _tmp15_;
			gchar* _tmp16_;
			gchar* _tmp17_;
			gunichar _tmp18_;
			gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			gchar* _tmp22_;
			_tmp3_ = skk_key_event_get_code (a);
			_tmp4_ = _tmp3_;
			_tmp5_ = skk_key_event_get_code (b);
			_tmp6_ = _tmp5_;
			if (_tmp4_ < _tmp6_) {
				gunichar _tmp7_;
				gunichar _tmp8_;
				gunichar _tmp9_;
				gunichar _tmp10_;
				_tmp7_ = skk_key_event_get_code (a);
				_tmp8_ = _tmp7_;
				ac = _tmp8_;
				_tmp9_ = skk_key_event_get_code (b);
				_tmp10_ = _tmp9_;
				bc = _tmp10_;
			} else {
				gunichar _tmp11_;
				gunichar _tmp12_;
				gunichar _tmp13_;
				gunichar _tmp14_;
				_tmp11_ = skk_key_event_get_code (b);
				_tmp12_ = _tmp11_;
				ac = _tmp12_;
				_tmp13_ = skk_key_event_get_code (a);
				_tmp14_ = _tmp13_;
				bc = _tmp14_;
			}
			_tmp15_ = ac;
			_tmp16_ = g_unichar_to_string (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = bc;
			_tmp19_ = g_unichar_to_string (_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_strconcat ("[", _tmp17_, _tmp20_, "]", NULL);
			_tmp22_ = _tmp21_;
			_g_free0 (_tmp20_);
			_g_free0 (_tmp17_);
			result = _tmp22_;
			return result;
		} else {
			g_return_val_if_reached (NULL);
		}
	}
}


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


static SkkKeyEvent*
skk_nicola_key_event_filter_queue (SkkNicolaKeyEventFilter* self,
                                   SkkKeyEvent* key,
                                   gint64 time,
                                   gint64* wait)
{
	gint64 _vala_wait = 0LL;
	SkkKeyEvent* result = NULL;
	SkkModifierType _tmp0_;
	SkkModifierType _tmp1_;
	gint64 _tmp44_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = skk_key_event_get_modifiers (key);
	_tmp1_ = _tmp0_;
	if ((_tmp1_ & SKK_MODIFIER_TYPE_RELEASE_MASK) != 0) {
		gboolean _tmp2_ = FALSE;
		GeeLinkedList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = self->priv->pending;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		if (_tmp5_ > 0) {
			GeeLinkedList* _tmp6_;
			gpointer _tmp7_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp8_;
			gconstpointer _tmp9_;
			_tmp6_ = self->priv->pending;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, 0);
			_tmp8_ = (SkkNicolaKeyEventFilterTimedEntry*) _tmp7_;
			_tmp9_ = _tmp8_->data;
			_tmp2_ = skk_key_event_base_equal ((SkkKeyEvent*) _tmp9_, key);
			_skk_nicola_key_event_filter_timed_entry_unref0 (_tmp8_);
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			SkkNicolaKeyEventFilterTimedEntry* entry = NULL;
			GeeLinkedList* _tmp10_;
			gpointer _tmp11_;
			GeeLinkedList* _tmp12_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp13_;
			gconstpointer _tmp14_;
			SkkKeyEvent* _tmp15_;
			_tmp10_ = self->priv->pending;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, 0);
			entry = (SkkNicolaKeyEventFilterTimedEntry*) _tmp11_;
			_vala_wait = skk_nicola_key_event_filter_get_next_wait (self, key, time);
			_tmp12_ = self->priv->pending;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp12_);
			_tmp13_ = entry;
			_tmp14_ = _tmp13_->data;
			_tmp15_ = _g_object_ref0 ((SkkKeyEvent*) _tmp14_);
			result = _tmp15_;
			_skk_nicola_key_event_filter_timed_entry_unref0 (entry);
			if (wait) {
				*wait = _vala_wait;
			}
			return result;
		}
	} else {
		gboolean _tmp16_ = FALSE;
		GeeLinkedList* _tmp17_;
		gint _tmp18_;
		gint _tmp19_;
		_tmp17_ = self->priv->pending;
		_tmp18_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp17_);
		_tmp19_ = _tmp18_;
		if (_tmp19_ > 0) {
			GeeLinkedList* _tmp20_;
			gpointer _tmp21_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp22_;
			gconstpointer _tmp23_;
			_tmp20_ = self->priv->pending;
			_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp20_, 0);
			_tmp22_ = (SkkNicolaKeyEventFilterTimedEntry*) _tmp21_;
			_tmp23_ = _tmp22_->data;
			_tmp16_ = skk_key_event_base_equal ((SkkKeyEvent*) _tmp23_, key);
			_skk_nicola_key_event_filter_timed_entry_unref0 (_tmp22_);
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			GeeLinkedList* _tmp24_;
			gpointer _tmp25_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp26_;
			SkkKeyEvent* _tmp27_;
			_tmp24_ = self->priv->pending;
			_tmp25_ = gee_abstract_list_get ((GeeAbstractList*) _tmp24_, 0);
			_tmp26_ = (SkkNicolaKeyEventFilterTimedEntry*) _tmp25_;
			_tmp26_->time = time;
			_skk_nicola_key_event_filter_timed_entry_unref0 (_tmp26_);
			_vala_wait = skk_nicola_key_event_filter_get_next_wait (self, key, time);
			_tmp27_ = _g_object_ref0 (key);
			result = _tmp27_;
			if (wait) {
				*wait = _vala_wait;
			}
			return result;
		} else {
			GeeLinkedList* _tmp28_;
			gint _tmp29_;
			gint _tmp30_;
			GeeLinkedList* _tmp41_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp42_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp43_;
			_tmp28_ = self->priv->pending;
			_tmp29_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp28_);
			_tmp30_ = _tmp29_;
			if (_tmp30_ > 2) {
				GeeBidirListIterator* iter = NULL;
				GeeLinkedList* _tmp31_;
				GeeBidirListIterator* _tmp32_;
				GeeBidirListIterator* _tmp33_;
				_tmp31_ = self->priv->pending;
				_tmp32_ = gee_abstract_bidir_list_bidir_list_iterator ((GeeAbstractBidirList*) _tmp31_);
				iter = _tmp32_;
				_tmp33_ = iter;
				gee_bidir_iterator_last ((GeeBidirIterator*) _tmp33_);
				{
					gboolean _tmp34_ = FALSE;
					_tmp34_ = TRUE;
					while (TRUE) {
						GeeBidirListIterator* _tmp40_;
						if (!_tmp34_) {
							gboolean _tmp35_ = FALSE;
							GeeLinkedList* _tmp36_;
							gint _tmp37_;
							gint _tmp38_;
							_tmp36_ = self->priv->pending;
							_tmp37_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp36_);
							_tmp38_ = _tmp37_;
							if (_tmp38_ > 2) {
								GeeBidirListIterator* _tmp39_;
								_tmp39_ = iter;
								_tmp35_ = gee_bidir_iterator_previous ((GeeBidirIterator*) _tmp39_);
							} else {
								_tmp35_ = FALSE;
							}
							if (!_tmp35_) {
								break;
							}
						}
						_tmp34_ = FALSE;
						_tmp40_ = iter;
						gee_iterator_remove ((GeeIterator*) _tmp40_);
					}
				}
				_g_object_unref0 (iter);
			}
			_tmp41_ = self->priv->pending;
			_tmp42_ = skk_nicola_key_event_filter_timed_entry_new (SKK_TYPE_KEY_EVENT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, key, time);
			_tmp43_ = _tmp42_;
			gee_abstract_list_insert ((GeeAbstractList*) _tmp41_, 0, _tmp43_);
			_skk_nicola_key_event_filter_timed_entry_unref0 (_tmp43_);
		}
	}
	_tmp44_ = self->maxwait;
	_vala_wait = _tmp44_;
	result = NULL;
	if (wait) {
		*wait = _vala_wait;
	}
	return result;
}


static gint64
skk_nicola_key_event_filter_get_next_wait (SkkNicolaKeyEventFilter* self,
                                           SkkKeyEvent* key,
                                           gint64 time)
{
	gint64 result = 0LL;
	GeeLinkedList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeLinkedList* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	g_return_val_if_fail (self != NULL, 0LL);
	g_return_val_if_fail (key != NULL, 0LL);
	_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) {
				SkkNicolaKeyEventFilterTimedEntry* entry = NULL;
				GeeBidirListIterator* _tmp8_;
				gpointer _tmp9_;
				SkkNicolaKeyEventFilterTimedEntry* _tmp10_;
				gint64 _tmp11_;
				gint64 _tmp12_;
				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 = (SkkNicolaKeyEventFilterTimedEntry*) _tmp9_;
				_tmp10_ = entry;
				_tmp11_ = _tmp10_->time;
				_tmp12_ = self->timeout;
				if ((time - _tmp11_) > _tmp12_) {
					GeeBidirListIterator* _tmp13_;
					_tmp13_ = iter;
					gee_iterator_remove ((GeeIterator*) _tmp13_);
				}
				_skk_nicola_key_event_filter_timed_entry_unref0 (entry);
			}
		}
		_g_object_unref0 (iter);
	}
	_tmp14_ = self->priv->pending;
	_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
	_tmp16_ = _tmp15_;
	if (_tmp16_ > 0) {
		gint64 _tmp17_;
		GeeLinkedList* _tmp18_;
		gpointer _tmp19_;
		SkkNicolaKeyEventFilterTimedEntry* _tmp20_;
		gint64 _tmp21_;
		gint64 _tmp22_;
		_tmp17_ = self->timeout;
		_tmp18_ = self->priv->pending;
		_tmp19_ = gee_linked_list_last (_tmp18_);
		_tmp20_ = (SkkNicolaKeyEventFilterTimedEntry*) _tmp19_;
		_tmp21_ = _tmp20_->time;
		_tmp22_ = _tmp17_ - (time - _tmp21_);
		_skk_nicola_key_event_filter_timed_entry_unref0 (_tmp20_);
		result = _tmp22_;
		return result;
	} else {
		gint64 _tmp23_;
		_tmp23_ = self->maxwait;
		result = _tmp23_;
		return result;
	}
}


static SkkKeyEvent*
skk_nicola_key_event_filter_dispatch_single (SkkNicolaKeyEventFilter* self,
                                             gint64 time)
{
	SkkKeyEvent* result = NULL;
	SkkNicolaKeyEventFilterTimedEntry* entry = NULL;
	GeeLinkedList* _tmp0_;
	gpointer _tmp1_;
	SkkNicolaKeyEventFilterTimedEntry* _tmp2_;
	gint64 _tmp3_;
	gint64 _tmp4_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->pending;
	_tmp1_ = gee_queue_peek ((GeeQueue*) _tmp0_);
	entry = (SkkNicolaKeyEventFilterTimedEntry*) _tmp1_;
	_tmp2_ = entry;
	_tmp3_ = _tmp2_->time;
	_tmp4_ = self->timeout;
	if ((time - _tmp3_) > _tmp4_) {
		GeeLinkedList* _tmp5_;
		SkkNicolaKeyEventFilterTimedEntry* _tmp6_;
		gconstpointer _tmp7_;
		SkkKeyEvent* _tmp8_;
		_tmp5_ = self->priv->pending;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp5_);
		_tmp6_ = entry;
		_tmp7_ = _tmp6_->data;
		_tmp8_ = _g_object_ref0 ((SkkKeyEvent*) _tmp7_);
		result = _tmp8_;
		_skk_nicola_key_event_filter_timed_entry_unref0 (entry);
		return result;
	}
	result = NULL;
	_skk_nicola_key_event_filter_timed_entry_unref0 (entry);
	return result;
}


static void
skk_nicola_key_event_filter_apply_shift (SkkNicolaKeyEventFilter* self,
                                         SkkKeyEvent* s,
                                         SkkKeyEvent* c)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (s != NULL);
	g_return_if_fail (c != NULL);
	if (skk_nicola_key_event_filter_is_lshift (s)) {
		SkkModifierType _tmp0_;
		SkkModifierType _tmp1_;
		_tmp0_ = skk_key_event_get_modifiers (c);
		_tmp1_ = _tmp0_;
		skk_key_event_set_modifiers (c, _tmp1_ | SKK_MODIFIER_TYPE_LSHIFT_MASK);
	} else {
		if (skk_nicola_key_event_filter_is_rshift (s)) {
			SkkModifierType _tmp2_;
			SkkModifierType _tmp3_;
			_tmp2_ = skk_key_event_get_modifiers (c);
			_tmp3_ = _tmp2_;
			skk_key_event_set_modifiers (c, _tmp3_ | SKK_MODIFIER_TYPE_RSHIFT_MASK);
		}
	}
}


static gboolean
_vala_string_array_contains (gchar* * stack,
                             int stack_length,
                             gchar* needle)
{
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


static SkkKeyEvent*
skk_nicola_key_event_filter_dispatch (SkkNicolaKeyEventFilter* self,
                                      gint64 time)
{
	SkkKeyEvent* result = NULL;
	GeeLinkedList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	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) {
		SkkNicolaKeyEventFilterTimedEntry* b = NULL;
		GeeLinkedList* _tmp3_;
		gpointer _tmp4_;
		SkkNicolaKeyEventFilterTimedEntry* s = NULL;
		GeeLinkedList* _tmp5_;
		gpointer _tmp6_;
		SkkNicolaKeyEventFilterTimedEntry* a = NULL;
		GeeLinkedList* _tmp7_;
		gpointer _tmp8_;
		gint64 t1 = 0LL;
		SkkNicolaKeyEventFilterTimedEntry* _tmp9_;
		gint64 _tmp10_;
		SkkNicolaKeyEventFilterTimedEntry* _tmp11_;
		gint64 _tmp12_;
		gint64 t2 = 0LL;
		SkkNicolaKeyEventFilterTimedEntry* _tmp13_;
		gint64 _tmp14_;
		SkkNicolaKeyEventFilterTimedEntry* _tmp15_;
		gint64 _tmp16_;
		gint64 _tmp17_;
		gint64 _tmp18_;
		_tmp3_ = self->priv->pending;
		_tmp4_ = gee_abstract_list_get ((GeeAbstractList*) _tmp3_, 0);
		b = (SkkNicolaKeyEventFilterTimedEntry*) _tmp4_;
		_tmp5_ = self->priv->pending;
		_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, 1);
		s = (SkkNicolaKeyEventFilterTimedEntry*) _tmp6_;
		_tmp7_ = self->priv->pending;
		_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, 2);
		a = (SkkNicolaKeyEventFilterTimedEntry*) _tmp8_;
		_tmp9_ = s;
		_tmp10_ = _tmp9_->time;
		_tmp11_ = a;
		_tmp12_ = _tmp11_->time;
		t1 = _tmp10_ - _tmp12_;
		_tmp13_ = b;
		_tmp14_ = _tmp13_->time;
		_tmp15_ = s;
		_tmp16_ = _tmp15_->time;
		t2 = _tmp14_ - _tmp16_;
		_tmp17_ = t1;
		_tmp18_ = t2;
		if (_tmp17_ <= _tmp18_) {
			GeeLinkedList* _tmp19_;
			GeeLinkedList* _tmp20_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp21_;
			SkkKeyEvent* r = NULL;
			SkkKeyEvent* _tmp22_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp23_;
			gconstpointer _tmp24_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp25_;
			gconstpointer _tmp26_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp27_;
			gconstpointer _tmp28_;
			_tmp19_ = self->priv->pending;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp19_);
			_tmp20_ = self->priv->pending;
			_tmp21_ = b;
			gee_deque_offer_head ((GeeDeque*) _tmp20_, _tmp21_);
			_tmp22_ = skk_nicola_key_event_filter_dispatch_single (self, time);
			r = _tmp22_;
			_tmp23_ = s;
			_tmp24_ = _tmp23_->data;
			_tmp25_ = a;
			_tmp26_ = _tmp25_->data;
			skk_nicola_key_event_filter_apply_shift (self, (SkkKeyEvent*) _tmp24_, (SkkKeyEvent*) _tmp26_);
			_tmp27_ = a;
			_tmp28_ = _tmp27_->data;
			g_signal_emit_by_name ((SkkKeyEventFilter*) self, "forwarded", (SkkKeyEvent*) _tmp28_);
			result = r;
			_skk_nicola_key_event_filter_timed_entry_unref0 (a);
			_skk_nicola_key_event_filter_timed_entry_unref0 (s);
			_skk_nicola_key_event_filter_timed_entry_unref0 (b);
			return result;
		} else {
			GeeLinkedList* _tmp29_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp30_;
			gconstpointer _tmp31_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp32_;
			gconstpointer _tmp33_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp34_;
			gconstpointer _tmp35_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp36_;
			gconstpointer _tmp37_;
			SkkKeyEvent* _tmp38_;
			_tmp29_ = self->priv->pending;
			gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp29_);
			_tmp30_ = s;
			_tmp31_ = _tmp30_->data;
			_tmp32_ = b;
			_tmp33_ = _tmp32_->data;
			skk_nicola_key_event_filter_apply_shift (self, (SkkKeyEvent*) _tmp31_, (SkkKeyEvent*) _tmp33_);
			_tmp34_ = a;
			_tmp35_ = _tmp34_->data;
			g_signal_emit_by_name ((SkkKeyEventFilter*) self, "forwarded", (SkkKeyEvent*) _tmp35_);
			_tmp36_ = b;
			_tmp37_ = _tmp36_->data;
			_tmp38_ = _g_object_ref0 ((SkkKeyEvent*) _tmp37_);
			result = _tmp38_;
			_skk_nicola_key_event_filter_timed_entry_unref0 (a);
			_skk_nicola_key_event_filter_timed_entry_unref0 (s);
			_skk_nicola_key_event_filter_timed_entry_unref0 (b);
			return result;
		}
		_skk_nicola_key_event_filter_timed_entry_unref0 (a);
		_skk_nicola_key_event_filter_timed_entry_unref0 (s);
		_skk_nicola_key_event_filter_timed_entry_unref0 (b);
	} else {
		GeeLinkedList* _tmp39_;
		gint _tmp40_;
		gint _tmp41_;
		_tmp39_ = self->priv->pending;
		_tmp40_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp39_);
		_tmp41_ = _tmp40_;
		if (_tmp41_ == 2) {
			SkkNicolaKeyEventFilterTimedEntry* b = NULL;
			GeeLinkedList* _tmp42_;
			gpointer _tmp43_;
			SkkNicolaKeyEventFilterTimedEntry* a = NULL;
			GeeLinkedList* _tmp44_;
			gpointer _tmp45_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp46_;
			gint64 _tmp47_;
			SkkNicolaKeyEventFilterTimedEntry* _tmp48_;
			gint64 _tmp49_;
			gint64 _tmp50_;
			_tmp42_ = self->priv->pending;
			_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, 0);
			b = (SkkNicolaKeyEventFilterTimedEntry*) _tmp43_;
			_tmp44_ = self->priv->pending;
			_tmp45_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, 1);
			a = (SkkNicolaKeyEventFilterTimedEntry*) _tmp45_;
			_tmp46_ = b;
			_tmp47_ = _tmp46_->time;
			_tmp48_ = a;
			_tmp49_ = _tmp48_->time;
			_tmp50_ = self->overlap;
			if ((_tmp47_ - _tmp49_) > _tmp50_) {
				GeeLinkedList* _tmp51_;
				GeeLinkedList* _tmp52_;
				SkkNicolaKeyEventFilterTimedEntry* _tmp53_;
				SkkKeyEvent* r = NULL;
				SkkKeyEvent* _tmp54_;
				SkkNicolaKeyEventFilterTimedEntry* _tmp55_;
				gconstpointer _tmp56_;
				_tmp51_ = self->priv->pending;
				gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp51_);
				_tmp52_ = self->priv->pending;
				_tmp53_ = b;
				gee_deque_offer_head ((GeeDeque*) _tmp52_, _tmp53_);
				_tmp54_ = skk_nicola_key_event_filter_dispatch_single (self, time);
				r = _tmp54_;
				_tmp55_ = a;
				_tmp56_ = _tmp55_->data;
				g_signal_emit_by_name ((SkkKeyEventFilter*) self, "forwarded", (SkkKeyEvent*) _tmp56_);
				result = r;
				_skk_nicola_key_event_filter_timed_entry_unref0 (a);
				_skk_nicola_key_event_filter_timed_entry_unref0 (b);
				return result;
			} else {
				gboolean _tmp57_ = FALSE;
				gboolean _tmp58_ = FALSE;
				SkkNicolaKeyEventFilterTimedEntry* _tmp59_;
				gconstpointer _tmp60_;
				_tmp59_ = a;
				_tmp60_ = _tmp59_->data;
				if (skk_nicola_key_event_filter_is_char ((SkkKeyEvent*) _tmp60_)) {
					SkkNicolaKeyEventFilterTimedEntry* _tmp61_;
					gconstpointer _tmp62_;
					_tmp61_ = b;
					_tmp62_ = _tmp61_->data;
					_tmp58_ = skk_nicola_key_event_filter_is_char ((SkkKeyEvent*) _tmp62_);
				} else {
					_tmp58_ = FALSE;
				}
				if (_tmp58_) {
					_tmp57_ = TRUE;
				} else {
					gboolean _tmp63_ = FALSE;
					SkkNicolaKeyEventFilterTimedEntry* _tmp64_;
					gconstpointer _tmp65_;
					_tmp64_ = a;
					_tmp65_ = _tmp64_->data;
					if (skk_nicola_key_event_filter_is_shift ((SkkKeyEvent*) _tmp65_)) {
						SkkNicolaKeyEventFilterTimedEntry* _tmp66_;
						gconstpointer _tmp67_;
						_tmp66_ = b;
						_tmp67_ = _tmp66_->data;
						_tmp63_ = skk_nicola_key_event_filter_is_shift ((SkkKeyEvent*) _tmp67_);
					} else {
						_tmp63_ = FALSE;
					}
					_tmp57_ = _tmp63_;
				}
				if (_tmp57_) {
					gchar* name = NULL;
					SkkNicolaKeyEventFilterTimedEntry* _tmp68_;
					gconstpointer _tmp69_;
					SkkNicolaKeyEventFilterTimedEntry* _tmp70_;
					gconstpointer _tmp71_;
					gchar* _tmp72_;
					const gchar* _tmp73_;
					gchar** _tmp74_;
					gint _tmp74__length1;
					_tmp68_ = b;
					_tmp69_ = _tmp68_->data;
					_tmp70_ = a;
					_tmp71_ = _tmp70_->data;
					_tmp72_ = skk_nicola_key_event_filter_get_special_double_name ((SkkKeyEvent*) _tmp69_, (SkkKeyEvent*) _tmp71_);
					name = _tmp72_;
					_tmp73_ = name;
					_tmp74_ = self->special_doubles;
					_tmp74__length1 = self->special_doubles_length1;
					if (_vala_string_array_contains (_tmp74_, _tmp74__length1, _tmp73_)) {
						GeeLinkedList* _tmp75_;
						const gchar* _tmp76_;
						SkkKeyEvent* _tmp77_;
						_tmp75_ = self->priv->pending;
						gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp75_);
						_tmp76_ = name;
						_tmp77_ = skk_key_event_new (_tmp76_, (gunichar) 0, SKK_MODIFIER_TYPE_NONE);
						result = _tmp77_;
						_g_free0 (name);
						_skk_nicola_key_event_filter_timed_entry_unref0 (a);
						_skk_nicola_key_event_filter_timed_entry_unref0 (b);
						return result;
					} else {
						GeeLinkedList* _tmp78_;
						GeeLinkedList* _tmp79_;
						SkkNicolaKeyEventFilterTimedEntry* _tmp80_;
						SkkKeyEvent* r = NULL;
						SkkKeyEvent* _tmp81_;
						SkkNicolaKeyEventFilterTimedEntry* _tmp82_;
						gconstpointer _tmp83_;
						_tmp78_ = self->priv->pending;
						gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp78_);
						_tmp79_ = self->priv->pending;
						_tmp80_ = b;
						gee_deque_offer_head ((GeeDeque*) _tmp79_, _tmp80_);
						_tmp81_ = skk_nicola_key_event_filter_dispatch_single (self, time);
						r = _tmp81_;
						_tmp82_ = a;
						_tmp83_ = _tmp82_->data;
						g_signal_emit_by_name ((SkkKeyEventFilter*) self, "forwarded", (SkkKeyEvent*) _tmp83_);
						result = r;
						_g_free0 (name);
						_skk_nicola_key_event_filter_timed_entry_unref0 (a);
						_skk_nicola_key_event_filter_timed_entry_unref0 (b);
						return result;
					}
					_g_free0 (name);
				} else {
					SkkNicolaKeyEventFilterTimedEntry* _tmp84_;
					gint64 _tmp85_;
					gint64 _tmp86_;
					_tmp84_ = a;
					_tmp85_ = _tmp84_->time;
					_tmp86_ = self->timeout;
					if ((time - _tmp85_) > _tmp86_) {
						GeeLinkedList* _tmp87_;
						SkkNicolaKeyEventFilterTimedEntry* _tmp88_;
						gconstpointer _tmp89_;
						_tmp87_ = self->priv->pending;
						gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp87_);
						_tmp88_ = b;
						_tmp89_ = _tmp88_->data;
						if (skk_nicola_key_event_filter_is_shift ((SkkKeyEvent*) _tmp89_)) {
							SkkNicolaKeyEventFilterTimedEntry* _tmp90_;
							gconstpointer _tmp91_;
							SkkNicolaKeyEventFilterTimedEntry* _tmp92_;
							gconstpointer _tmp93_;
							SkkNicolaKeyEventFilterTimedEntry* _tmp94_;
							gconstpointer _tmp95_;
							SkkKeyEvent* _tmp96_;
							_tmp90_ = b;
							_tmp91_ = _tmp90_->data;
							_tmp92_ = a;
							_tmp93_ = _tmp92_->data;
							skk_nicola_key_event_filter_apply_shift (self, (SkkKeyEvent*) _tmp91_, (SkkKeyEvent*) _tmp93_);
							_tmp94_ = a;
							_tmp95_ = _tmp94_->data;
							_tmp96_ = _g_object_ref0 ((SkkKeyEvent*) _tmp95_);
							result = _tmp96_;
							_skk_nicola_key_event_filter_timed_entry_unref0 (a);
							_skk_nicola_key_event_filter_timed_entry_unref0 (b);
							return result;
						} else {
							SkkNicolaKeyEventFilterTimedEntry* _tmp97_;
							gconstpointer _tmp98_;
							SkkNicolaKeyEventFilterTimedEntry* _tmp99_;
							gconstpointer _tmp100_;
							SkkNicolaKeyEventFilterTimedEntry* _tmp101_;
							gconstpointer _tmp102_;
							SkkKeyEvent* _tmp103_;
							_tmp97_ = a;
							_tmp98_ = _tmp97_->data;
							_tmp99_ = b;
							_tmp100_ = _tmp99_->data;
							skk_nicola_key_event_filter_apply_shift (self, (SkkKeyEvent*) _tmp98_, (SkkKeyEvent*) _tmp100_);
							_tmp101_ = b;
							_tmp102_ = _tmp101_->data;
							_tmp103_ = _g_object_ref0 ((SkkKeyEvent*) _tmp102_);
							result = _tmp103_;
							_skk_nicola_key_event_filter_timed_entry_unref0 (a);
							_skk_nicola_key_event_filter_timed_entry_unref0 (b);
							return result;
						}
					}
				}
			}
			_skk_nicola_key_event_filter_timed_entry_unref0 (a);
			_skk_nicola_key_event_filter_timed_entry_unref0 (b);
		} else {
			GeeLinkedList* _tmp104_;
			gint _tmp105_;
			gint _tmp106_;
			_tmp104_ = self->priv->pending;
			_tmp105_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp104_);
			_tmp106_ = _tmp105_;
			if (_tmp106_ == 1) {
				SkkKeyEvent* _tmp107_;
				_tmp107_ = skk_nicola_key_event_filter_dispatch_single (self, time);
				result = _tmp107_;
				return result;
			}
		}
	}
	result = NULL;
	return result;
}


static gboolean
skk_nicola_key_event_filter_timeout_func (SkkNicolaKeyEventFilter* self)
{
	gboolean result = FALSE;
	gint64 time = 0LL;
	SkkGetTime _tmp0_;
	void* _tmp0__target;
	SkkKeyEvent* r = NULL;
	gint64 _tmp1_;
	SkkKeyEvent* _tmp2_;
	SkkKeyEvent* _tmp3_;
	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_ = time;
	_tmp2_ = skk_nicola_key_event_filter_dispatch (self, _tmp1_);
	r = _tmp2_;
	_tmp3_ = r;
	if (_tmp3_ != NULL) {
		SkkKeyEvent* _tmp4_;
		_tmp4_ = r;
		g_signal_emit_by_name ((SkkKeyEventFilter*) self, "forwarded", _tmp4_);
	}
	result = FALSE;
	_g_object_unref0 (r);
	return result;
}


/**
         * {@inheritDoc}
         */
static gboolean
_skk_nicola_key_event_filter_timeout_func_gsource_func (gpointer self)
{
	gboolean result;
	result = skk_nicola_key_event_filter_timeout_func ((SkkNicolaKeyEventFilter*) self);
	return result;
}


static SkkKeyEvent*
skk_nicola_key_event_filter_real_filter_key_event (SkkKeyEventFilter* base,
                                                   SkkKeyEvent* key)
{
	SkkNicolaKeyEventFilter * self;
	SkkKeyEvent* result = NULL;
	SkkModifierType _tmp0_;
	SkkModifierType _tmp1_;
	SkkKeyEvent* output = NULL;
	gint64 time = 0LL;
	SkkModifierType _tmp2_;
	SkkModifierType _tmp3_;
	SkkKeyEvent* _tmp27_;
	self = (SkkNicolaKeyEventFilter*) base;
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = skk_key_event_get_modifiers (key);
	_tmp1_ = _tmp0_;
	skk_key_event_set_modifiers (key, _tmp1_ & (~SKK_MODIFIER_TYPE_SHIFT_MASK));
	output = NULL;
	_tmp2_ = skk_key_event_get_modifiers (key);
	_tmp3_ = _tmp2_;
	if ((_tmp3_ & SKK_MODIFIER_TYPE_USLEEP_MASK) != 0) {
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		SkkGetTime _tmp6_;
		void* _tmp6__target;
		_tmp4_ = skk_key_event_get_name (key);
		_tmp5_ = _tmp4_;
		g_usleep ((gulong) ((glong) atoi (_tmp5_)));
		_tmp6_ = self->get_time_func;
		_tmp6__target = self->get_time_func_target;
		time = _tmp6_ (_tmp6__target);
	} else {
		gboolean _tmp7_ = FALSE;
		SkkModifierType _tmp8_;
		SkkModifierType _tmp9_;
		_tmp8_ = skk_key_event_get_modifiers (key);
		_tmp9_ = _tmp8_;
		if ((_tmp9_ & (~SKK_MODIFIER_TYPE_RELEASE_MASK)) == 0) {
			gboolean _tmp10_ = FALSE;
			if (skk_nicola_key_event_filter_is_shift (key)) {
				_tmp10_ = TRUE;
			} else {
				gboolean _tmp11_ = FALSE;
				gunichar _tmp12_;
				gunichar _tmp13_;
				_tmp12_ = skk_key_event_get_code (key);
				_tmp13_ = _tmp12_;
				if (((gunichar) 0x20) <= _tmp13_) {
					gunichar _tmp14_;
					gunichar _tmp15_;
					_tmp14_ = skk_key_event_get_code (key);
					_tmp15_ = _tmp14_;
					_tmp11_ = _tmp15_ <= ((gunichar) 0x7E);
				} else {
					_tmp11_ = FALSE;
				}
				_tmp10_ = _tmp11_;
			}
			_tmp7_ = _tmp10_;
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			SkkGetTime _tmp16_;
			void* _tmp16__target;
			gint64 wait = 0LL;
			gint64 _tmp17_;
			gint64 _tmp18_ = 0LL;
			SkkKeyEvent* _tmp19_;
			gint64 _tmp20_;
			_tmp16_ = self->get_time_func;
			_tmp16__target = self->get_time_func_target;
			time = _tmp16_ (_tmp16__target);
			_tmp17_ = time;
			_tmp19_ = skk_nicola_key_event_filter_queue (self, key, _tmp17_, &_tmp18_);
			wait = _tmp18_;
			_g_object_unref0 (output);
			output = _tmp19_;
			_tmp20_ = wait;
			if (_tmp20_ > ((gint64) 0)) {
				guint _tmp21_;
				gint64 _tmp23_;
				_tmp21_ = self->priv->timeout_id;
				if (_tmp21_ > ((guint) 0)) {
					guint _tmp22_;
					_tmp22_ = self->priv->timeout_id;
					g_source_remove (_tmp22_);
				}
				_tmp23_ = wait;
				self->priv->timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) _tmp23_, _skk_nicola_key_event_filter_timeout_func_gsource_func, g_object_ref (self), g_object_unref);
			}
		} else {
			SkkModifierType _tmp24_;
			SkkModifierType _tmp25_;
			_tmp24_ = skk_key_event_get_modifiers (key);
			_tmp25_ = _tmp24_;
			if ((_tmp25_ & SKK_MODIFIER_TYPE_RELEASE_MASK) == 0) {
				SkkKeyEvent* _tmp26_;
				_tmp26_ = _g_object_ref0 (key);
				result = _tmp26_;
				_g_object_unref0 (output);
				return result;
			}
			result = NULL;
			_g_object_unref0 (output);
			return result;
		}
	}
	_tmp27_ = output;
	if (_tmp27_ == NULL) {
		gint64 _tmp28_;
		SkkKeyEvent* _tmp29_;
		_tmp28_ = time;
		_tmp29_ = skk_nicola_key_event_filter_dispatch (self, _tmp28_);
		_g_object_unref0 (output);
		output = _tmp29_;
	}
	result = output;
	return result;
}


/**
         * {@inheritDoc}
         */
static void
skk_nicola_key_event_filter_real_reset (SkkKeyEventFilter* base)
{
	SkkNicolaKeyEventFilter * self;
	GeeLinkedList* _tmp0_;
	self = (SkkNicolaKeyEventFilter*) base;
	_tmp0_ = self->priv->pending;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
}


SkkNicolaKeyEventFilter*
skk_nicola_key_event_filter_construct (GType object_type)
{
	SkkNicolaKeyEventFilter * self = NULL;
	self = (SkkNicolaKeyEventFilter*) skk_key_event_filter_construct (object_type);
	return self;
}


SkkNicolaKeyEventFilter*
skk_nicola_key_event_filter_new (void)
{
	return skk_nicola_key_event_filter_construct (SKK_TYPE_NICOLA_KEY_EVENT_FILTER);
}


static gchar**
_vala_array_dup6 (gchar** self,
                  int length)
{
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


static GObject *
skk_nicola_key_event_filter_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SkkNicolaKeyEventFilter * self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	parent_class = G_OBJECT_CLASS (skk_nicola_key_event_filter_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilter);
	_tmp0_ = (SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES != NULL) ? _vala_array_dup6 (SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES, G_N_ELEMENTS (SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES)) : ((gpointer) SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES);
	_tmp0__length1 = G_N_ELEMENTS (SKK_NICOLA_KEY_EVENT_FILTER_SPECIAL_DOUBLES);
	self->special_doubles = (_vala_array_free (self->special_doubles, self->special_doubles_length1, (GDestroyNotify) g_free), NULL);
	self->special_doubles = _tmp0_;
	self->special_doubles_length1 = _tmp0__length1;
	return obj;
}


static SkkNicolaKeyEventFilterTimedEntry*
skk_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)
{
	SkkNicolaKeyEventFilterTimedEntry* self = NULL;
	gpointer _tmp0_;
	self = (SkkNicolaKeyEventFilterTimedEntry*) 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);
	_t_destroy_func0 (self->data);
	self->data = _tmp0_;
	self->time = time;
	return self;
}


static SkkNicolaKeyEventFilterTimedEntry*
skk_nicola_key_event_filter_timed_entry_new (GType t_type,
                                             GBoxedCopyFunc t_dup_func,
                                             GDestroyNotify t_destroy_func,
                                             gconstpointer data,
                                             gint64 time)
{
	return skk_nicola_key_event_filter_timed_entry_construct (SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, t_type, t_dup_func, t_destroy_func, data, time);
}


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


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


static void
skk_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 = skk_nicola_key_event_filter_timed_entry_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


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


static gchar*
skk_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) {
		SkkNicolaKeyEventFilterTimedEntry * 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 = skk_nicola_key_event_filter_timed_entry_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar*
skk_nicola_key_event_filter_value_timed_entry_lcopy_value (const GValue* value,
                                                           guint n_collect_values,
                                                           GTypeCValue* collect_values,
                                                           guint collect_flags)
{
	SkkNicolaKeyEventFilterTimedEntry ** 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 = skk_nicola_key_event_filter_timed_entry_ref (value->data[0].v_pointer);
	}
	return NULL;
}


static GParamSpec*
skk_nicola_key_event_filter_param_spec_timed_entry (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags)
{
	SkkNicolaKeyEventFilterParamSpecTimedEntry* spec;
	g_return_val_if_fail (g_type_is_a (object_type, SKK_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
skk_nicola_key_event_filter_value_get_timed_entry (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY), NULL);
	return value->data[0].v_pointer;
}


static void
skk_nicola_key_event_filter_value_set_timed_entry (GValue* value,
                                                   gpointer v_object)
{
	SkkNicolaKeyEventFilterTimedEntry * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SKK_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, SKK_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;
		skk_nicola_key_event_filter_timed_entry_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		skk_nicola_key_event_filter_timed_entry_unref (old);
	}
}


static void
skk_nicola_key_event_filter_value_take_timed_entry (GValue* value,
                                                    gpointer v_object)
{
	SkkNicolaKeyEventFilterTimedEntry * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SKK_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, SKK_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) {
		skk_nicola_key_event_filter_timed_entry_unref (old);
	}
}


static void
skk_nicola_key_event_filter_timed_entry_class_init (SkkNicolaKeyEventFilterTimedEntryClass * klass)
{
	skk_nicola_key_event_filter_timed_entry_parent_class = g_type_class_peek_parent (klass);
	((SkkNicolaKeyEventFilterTimedEntryClass *) klass)->finalize = skk_nicola_key_event_filter_timed_entry_finalize;
	g_type_class_add_private (klass, sizeof (SkkNicolaKeyEventFilterTimedEntryPrivate));
}


static void
skk_nicola_key_event_filter_timed_entry_instance_init (SkkNicolaKeyEventFilterTimedEntry * self)
{
	self->priv = SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void
skk_nicola_key_event_filter_timed_entry_finalize (SkkNicolaKeyEventFilterTimedEntry * obj)
{
	SkkNicolaKeyEventFilterTimedEntry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, SkkNicolaKeyEventFilterTimedEntry);
	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
skk_nicola_key_event_filter_timed_entry_get_type (void)
{
	static volatile gsize skk_nicola_key_event_filter_timed_entry_type_id__volatile = 0;
	if (g_once_init_enter (&skk_nicola_key_event_filter_timed_entry_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { skk_nicola_key_event_filter_value_timed_entry_init, skk_nicola_key_event_filter_value_timed_entry_free_value, skk_nicola_key_event_filter_value_timed_entry_copy_value, skk_nicola_key_event_filter_value_timed_entry_peek_pointer, "p", skk_nicola_key_event_filter_value_timed_entry_collect_value, "p", skk_nicola_key_event_filter_value_timed_entry_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (SkkNicolaKeyEventFilterTimedEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) skk_nicola_key_event_filter_timed_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SkkNicolaKeyEventFilterTimedEntry), 0, (GInstanceInitFunc) skk_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 skk_nicola_key_event_filter_timed_entry_type_id;
		skk_nicola_key_event_filter_timed_entry_type_id = g_type_register_fundamental (g_type_fundamental_next (), "SkkNicolaKeyEventFilterTimedEntry", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&skk_nicola_key_event_filter_timed_entry_type_id__volatile, skk_nicola_key_event_filter_timed_entry_type_id);
	}
	return skk_nicola_key_event_filter_timed_entry_type_id__volatile;
}


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


static void
skk_nicola_key_event_filter_timed_entry_unref (gpointer instance)
{
	SkkNicolaKeyEventFilterTimedEntry * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		SKK_NICOLA_KEY_EVENT_FILTER_TIMED_ENTRY_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void
skk_nicola_key_event_filter_class_init (SkkNicolaKeyEventFilterClass * klass)
{
	skk_nicola_key_event_filter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (SkkNicolaKeyEventFilterPrivate));
	((SkkKeyEventFilterClass *) klass)->filter_key_event = (SkkKeyEvent* (*) (SkkKeyEventFilter *, SkkKeyEvent*)) skk_nicola_key_event_filter_real_filter_key_event;
	((SkkKeyEventFilterClass *) klass)->reset = (void (*) (SkkKeyEventFilter *)) skk_nicola_key_event_filter_real_reset;
	G_OBJECT_CLASS (klass)->constructor = skk_nicola_key_event_filter_constructor;
	G_OBJECT_CLASS (klass)->finalize = skk_nicola_key_event_filter_finalize;
}


static void
skk_nicola_key_event_filter_instance_init (SkkNicolaKeyEventFilter * self)
{
	GeeLinkedList* _tmp0_;
	self->priv = SKK_NICOLA_KEY_EVENT_FILTER_GET_PRIVATE (self);
	self->get_time_func = _skk_nicola_key_event_filter_get_time_skk_get_time;
	self->get_time_func_target = self;
	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 (SKK_NICOLA_KEY_EVENT_FILTER_TYPE_TIMED_ENTRY, (GBoxedCopyFunc) skk_nicola_key_event_filter_timed_entry_ref, (GDestroyNotify) skk_nicola_key_event_filter_timed_entry_unref, NULL, NULL, NULL);
	self->priv->pending = _tmp0_;
	self->priv->timeout_id = (guint) 0;
}


static void
skk_nicola_key_event_filter_finalize (GObject * obj)
{
	SkkNicolaKeyEventFilter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SKK_TYPE_NICOLA_KEY_EVENT_FILTER, SkkNicolaKeyEventFilter);
	(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;
	self->special_doubles = (_vala_array_free (self->special_doubles, self->special_doubles_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->pending);
	G_OBJECT_CLASS (skk_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
     */
GType
skk_nicola_key_event_filter_get_type (void)
{
	static volatile gsize skk_nicola_key_event_filter_type_id__volatile = 0;
	if (g_once_init_enter (&skk_nicola_key_event_filter_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SkkNicolaKeyEventFilterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) skk_nicola_key_event_filter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SkkNicolaKeyEventFilter), 0, (GInstanceInitFunc) skk_nicola_key_event_filter_instance_init, NULL };
		GType skk_nicola_key_event_filter_type_id;
		skk_nicola_key_event_filter_type_id = g_type_register_static (SKK_TYPE_KEY_EVENT_FILTER, "SkkNicolaKeyEventFilter", &g_define_type_info, 0);
		g_once_init_leave (&skk_nicola_key_event_filter_type_id__volatile, skk_nicola_key_event_filter_type_id);
	}
	return skk_nicola_key_event_filter_type_id__volatile;
}


static void
_vala_array_destroy (gpointer array,
                     gint array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void
_vala_array_free (gpointer array,
                  gint array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



