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

/*
 * Copyright (c) 2013-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_ui.h"
#include <glib.h>
#include <gdk/gdk.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.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 _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))

static gchar** ft_accelerator_get_labels (FtAccelerator *self,
                                   gint* result_length1);
static void _vala_array_add4 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add5 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add6 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add7 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add8 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add9 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void _vala_array_add10 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add11 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add12 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add13 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add14 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add15 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add16 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add17 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add18 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add19 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add20 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static const guint FT_ACCELERATOR_FORBIDDEN_KEYVALS[15] = {GDK_KEY_Home, GDK_KEY_Left, GDK_KEY_Up, GDK_KEY_Right, GDK_KEY_Down, GDK_KEY_Page_Up, GDK_KEY_Page_Down, GDK_KEY_End, GDK_KEY_Tab, GDK_KEY_Escape, GDK_KEY_KP_Enter, GDK_KEY_Return, GDK_KEY_space, GDK_KEY_BackSpace, GDK_KEY_Mode_switch};

void
ft_accelerator_empty (FtAccelerator* result)
{
	FtAccelerator _tmp0_ = {0};
	memset (&_tmp0_, 0, sizeof (FtAccelerator));
	_tmp0_.keycode = (guint) 0;
	_tmp0_.keyval = (guint) 0;
	_tmp0_.modifiers = GDK_NO_MODIFIER_MASK;
	*result = _tmp0_;
	return;
}

void
ft_accelerator_from_keycode (guint keycode,
                             GdkModifierType modifiers,
                             guint group,
                             FtAccelerator* result)
{
	FtAccelerator accelerator = {0};
	FtAccelerator _tmp0_ = {0};
	FtAccelerator _tmp1_ = {0};
	memset (&_tmp0_, 0, sizeof (FtAccelerator));
	_tmp0_.keycode = keycode;
	_tmp0_.keyval = (guint) 0;
	_tmp0_.modifiers = modifiers;
	accelerator = _tmp0_;
	ft_accelerator_normalize (&accelerator, group, &_tmp1_);
	*result = _tmp1_;
	return;
}

static gboolean
string_get_next_char (const gchar* self,
                      gint* index,
                      gunichar* c)
{
	gunichar _vala_c = 0U;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_vala_c = g_utf8_get_char (((gchar*) self) + (*index));
	if (_vala_c != ((gunichar) 0)) {
		gchar* _tmp0_;
		_tmp0_ = g_utf8_next_char (((gchar*) self) + (*index));
		*index = (gint) (_tmp0_ - ((gchar*) self));
		result = TRUE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	} else {
		result = FALSE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	}
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

void
ft_accelerator_from_string (const gchar* accelerator_string,
                            FtAccelerator* result)
{
	gint index = 0;
	gint modifier_position = 0;
	gint keyval_position = 0;
	gunichar chr = 0U;
	GdkModifierType modifiers = 0U;
	guint _tmp11_ = 0U;
	guint keyval = 0U;
	FtAccelerator _tmp14_ = {0};
	g_return_if_fail (accelerator_string != NULL);
	index = 0;
	modifier_position = -1;
	keyval_position = 0;
	modifiers = GDK_NO_MODIFIER_MASK;
	while (TRUE) {
		gunichar _tmp0_ = 0U;
		gboolean _tmp1_;
		gboolean _tmp2_ = FALSE;
		_tmp1_ = string_get_next_char (accelerator_string, &index, &_tmp0_);
		chr = _tmp0_;
		if (!_tmp1_) {
			break;
		}
		if (chr == ((gunichar) '<')) {
			_tmp2_ = modifier_position == -1;
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			modifier_position = index;
		} else {
			gboolean _tmp3_ = FALSE;
			if (chr == ((gunichar) '>')) {
				_tmp3_ = modifier_position >= 0;
			} else {
				_tmp3_ = FALSE;
			}
			if (_tmp3_) {
				gchar* modifier_name = NULL;
				gchar* _tmp4_;
				const gchar* _tmp5_;
				gchar* _tmp6_;
				gchar* _tmp7_;
				GQuark _tmp9_ = 0U;
				static GQuark _tmp8_label0 = 0;
				static GQuark _tmp8_label1 = 0;
				static GQuark _tmp8_label2 = 0;
				static GQuark _tmp8_label3 = 0;
				static GQuark _tmp8_label4 = 0;
				static GQuark _tmp8_label5 = 0;
				static GQuark _tmp8_label6 = 0;
				static GQuark _tmp8_label7 = 0;
				_tmp4_ = string_slice (accelerator_string, (glong) modifier_position, (glong) (index - 1));
				modifier_name = _tmp4_;
				_tmp5_ = modifier_name;
				_tmp6_ = g_utf8_strdown (_tmp5_, (gssize) -1);
				_tmp7_ = _tmp6_;
				_tmp9_ = (NULL == _tmp7_) ? 0 : g_quark_from_string (_tmp7_);
				g_free (_tmp7_);
				if ((_tmp9_ == ((0 != _tmp8_label0) ? _tmp8_label0 : (_tmp8_label0 = g_quark_from_static_string ("ctrl")))) || (_tmp9_ == ((0 != _tmp8_label1) ? _tmp8_label1 : (_tmp8_label1 = g_quark_from_static_string ("control"))))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_CONTROL_MASK;
							break;
						}
					}
				} else if ((_tmp9_ == ((0 != _tmp8_label2) ? _tmp8_label2 : (_tmp8_label2 = g_quark_from_static_string ("⌘")))) || (_tmp9_ == ((0 != _tmp8_label3) ? _tmp8_label3 : (_tmp8_label3 = g_quark_from_static_string ("meta"))))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_META_MASK;
							break;
						}
					}
				} else if (_tmp9_ == ((0 != _tmp8_label4) ? _tmp8_label4 : (_tmp8_label4 = g_quark_from_static_string ("alt")))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_ALT_MASK;
							break;
						}
					}
				} else if (_tmp9_ == ((0 != _tmp8_label5) ? _tmp8_label5 : (_tmp8_label5 = g_quark_from_static_string ("shift")))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_SHIFT_MASK;
							break;
						}
					}
				} else if (_tmp9_ == ((0 != _tmp8_label6) ? _tmp8_label6 : (_tmp8_label6 = g_quark_from_static_string ("super")))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_SUPER_MASK;
							break;
						}
					}
				} else if (_tmp9_ == ((0 != _tmp8_label7) ? _tmp8_label7 : (_tmp8_label7 = g_quark_from_static_string ("hyper")))) {
					switch (0) {
						default:
						{
							modifiers |= GDK_HYPER_MASK;
							break;
						}
					}
				} else {
					switch (0) {
						default:
						{
							const gchar* _tmp10_;
							_tmp10_ = modifier_name;
							g_warning ("accelerator.vala:105: Unknown modifier name: '%s'", _tmp10_);
							break;
						}
					}
				}
				modifier_position = -1;
				keyval_position = index;
				_g_free0 (modifier_name);
			}
		}
	}
	if (index > keyval_position) {
		gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp12_ = string_slice (accelerator_string, (glong) keyval_position, (glong) index);
		_tmp13_ = _tmp12_;
		_tmp11_ = gdk_keyval_from_name (_tmp13_);
		_g_free0 (_tmp13_);
	} else {
		_tmp11_ = (guint) 0;
	}
	keyval = _tmp11_;
	memset (&_tmp14_, 0, sizeof (FtAccelerator));
	_tmp14_.keycode = (guint) 0;
	_tmp14_.keyval = keyval;
	_tmp14_.modifiers = modifiers;
	*result = _tmp14_;
	return;
}

gboolean
ft_accelerator_is_empty (FtAccelerator *self)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	if ((*self).keycode == ((guint) 0)) {
		_tmp0_ = (*self).keyval == ((guint) 0);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

gboolean
ft_accelerator_is_valid (FtAccelerator *self)
{
	guint keyval = 0U;
	GdkModifierType modifiers = 0U;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	keyval = (*self).keyval;
	modifiers = (*self).modifiers;
	if (ft_accelerator_is_empty (&(*self))) {
		result = TRUE;
		return result;
	}
	if (modifiers == GDK_NO_MODIFIER_MASK) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = modifiers == GDK_SHIFT_MASK;
	}
	if (_tmp0_) {
		gboolean _tmp1_ = FALSE;
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		gboolean _tmp5_ = FALSE;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_ = FALSE;
		gboolean _tmp9_ = FALSE;
		gboolean _tmp10_ = FALSE;
		if (keyval >= GDK_KEY_a) {
			_tmp10_ = keyval <= GDK_KEY_z;
		} else {
			_tmp10_ = FALSE;
		}
		if (_tmp10_) {
			_tmp9_ = TRUE;
		} else {
			gboolean _tmp11_ = FALSE;
			if (keyval >= GDK_KEY_A) {
				_tmp11_ = keyval <= GDK_KEY_Z;
			} else {
				_tmp11_ = FALSE;
			}
			_tmp9_ = _tmp11_;
		}
		if (_tmp9_) {
			_tmp8_ = TRUE;
		} else {
			gboolean _tmp12_ = FALSE;
			if (keyval >= GDK_KEY_0) {
				_tmp12_ = keyval <= GDK_KEY_9;
			} else {
				_tmp12_ = FALSE;
			}
			_tmp8_ = _tmp12_;
		}
		if (_tmp8_) {
			_tmp7_ = TRUE;
		} else {
			gboolean _tmp13_ = FALSE;
			if (keyval >= GDK_KEY_kana_fullstop) {
				_tmp13_ = keyval <= GDK_KEY_semivoicedsound;
			} else {
				_tmp13_ = FALSE;
			}
			_tmp7_ = _tmp13_;
		}
		if (_tmp7_) {
			_tmp6_ = TRUE;
		} else {
			gboolean _tmp14_ = FALSE;
			if (keyval >= GDK_KEY_Arabic_comma) {
				_tmp14_ = keyval <= GDK_KEY_Arabic_sukun;
			} else {
				_tmp14_ = FALSE;
			}
			_tmp6_ = _tmp14_;
		}
		if (_tmp6_) {
			_tmp5_ = TRUE;
		} else {
			gboolean _tmp15_ = FALSE;
			if (keyval >= GDK_KEY_Serbian_dje) {
				_tmp15_ = keyval <= GDK_KEY_Cyrillic_HARDSIGN;
			} else {
				_tmp15_ = FALSE;
			}
			_tmp5_ = _tmp15_;
		}
		if (_tmp5_) {
			_tmp4_ = TRUE;
		} else {
			gboolean _tmp16_ = FALSE;
			if (keyval >= GDK_KEY_Greek_ALPHAaccent) {
				_tmp16_ = keyval <= GDK_KEY_Greek_omega;
			} else {
				_tmp16_ = FALSE;
			}
			_tmp4_ = _tmp16_;
		}
		if (_tmp4_) {
			_tmp3_ = TRUE;
		} else {
			gboolean _tmp17_ = FALSE;
			if (keyval >= GDK_KEY_hebrew_doublelowline) {
				_tmp17_ = keyval <= GDK_KEY_hebrew_taf;
			} else {
				_tmp17_ = FALSE;
			}
			_tmp3_ = _tmp17_;
		}
		if (_tmp3_) {
			_tmp2_ = TRUE;
		} else {
			gboolean _tmp18_ = FALSE;
			if (keyval >= GDK_KEY_Thai_kokai) {
				_tmp18_ = keyval <= GDK_KEY_Thai_lekkao;
			} else {
				_tmp18_ = FALSE;
			}
			_tmp2_ = _tmp18_;
		}
		if (_tmp2_) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp19_ = FALSE;
			if (keyval >= GDK_KEY_Hangul_Kiyeog) {
				_tmp19_ = keyval <= GDK_KEY_Hangul_J_YeorinHieuh;
			} else {
				_tmp19_ = FALSE;
			}
			_tmp1_ = _tmp19_;
		}
		if (_tmp1_) {
			result = FALSE;
			return result;
		}
		{
			gint index = 0;
			index = 0;
			{
				gboolean _tmp20_ = FALSE;
				_tmp20_ = TRUE;
				while (TRUE) {
					guint _tmp22_;
					if (!_tmp20_) {
						gint _tmp21_;
						_tmp21_ = index;
						index = _tmp21_ + 1;
					}
					_tmp20_ = FALSE;
					if (!(index < G_N_ELEMENTS (FT_ACCELERATOR_FORBIDDEN_KEYVALS))) {
						break;
					}
					_tmp22_ = FT_ACCELERATOR_FORBIDDEN_KEYVALS[index];
					if (keyval == _tmp22_) {
						result = FALSE;
						return result;
					}
				}
			}
		}
	}
	result = gtk_accelerator_valid (keyval, modifiers);
	return result;
}

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

void
ft_accelerator_normalize (FtAccelerator *self,
                          guint group,
                          FtAccelerator* result)
{
	guint unmodified_keyval = 0U;
	guint shifted_keyval = 0U;
	GdkModifierType explicit_modifiers = 0U;
	GdkModifierType used_modifiers = 0U;
	GdkDisplay* display = NULL;
	GdkDisplay* _tmp0_;
	GdkDisplay* _tmp1_;
	GdkDisplay* _tmp2_;
	guint _tmp3_ = 0U;
	GdkDisplay* _tmp4_;
	guint _tmp5_ = 0U;
	gboolean _tmp6_ = FALSE;
	FtAccelerator _tmp7_ = {0};
	explicit_modifiers = GDK_SHIFT_MASK | gtk_accelerator_get_default_mod_mask ();
	used_modifiers = (*self).modifiers & explicit_modifiers;
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	display = _tmp1_;
	_tmp2_ = display;
	gdk_display_translate_key (_tmp2_, (*self).keycode, (*self).modifiers & (~explicit_modifiers), (gint) group, &_tmp3_, NULL, NULL, NULL);
	unmodified_keyval = _tmp3_;
	_tmp4_ = display;
	gdk_display_translate_key (_tmp4_, (*self).keycode, GDK_SHIFT_MASK | ((*self).modifiers & (~explicit_modifiers)), (gint) group, &_tmp5_, NULL, NULL, NULL);
	shifted_keyval = _tmp5_;
	if (shifted_keyval >= GDK_KEY_0) {
		_tmp6_ = shifted_keyval <= GDK_KEY_9;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		unmodified_keyval = shifted_keyval;
	}
	if (unmodified_keyval == GDK_KEY_ISO_Left_Tab) {
		unmodified_keyval = GDK_KEY_Tab;
	}
	used_modifiers &= ~GDK_LOCK_MASK;
	memset (&_tmp7_, 0, sizeof (FtAccelerator));
	_tmp7_.keycode = (guint) 0;
	_tmp7_.keyval = unmodified_keyval;
	_tmp7_.modifiers = used_modifiers;
	*result = _tmp7_;
	_g_object_unref0 (display);
	return;
}

/**
         * Intention here is to match the behaviour somewhat of `GtkShortcutLabel` which we use
         * in the edit dialog.
         */
static void
_vala_array_add4 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add5 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add6 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add7 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add8 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add9 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add10 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

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

static void
_vala_array_add11 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add12 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add13 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add14 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add15 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add16 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add17 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add18 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add19 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static void
_vala_array_add20 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gchar**
ft_accelerator_get_labels (FtAccelerator *self,
                           gint* result_length1)
{
	gchar** labels = NULL;
	gchar** _tmp0_;
	gint labels_length1;
	gint _labels_size_;
	gunichar chr = 0U;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp8_ = FALSE;
	gchar** _tmp24_;
	gint _tmp24__length1;
	gchar** result;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	labels = _tmp0_;
	labels_length1 = 0;
	_labels_size_ = labels_length1;
	if (((*self).modifiers & GDK_SHIFT_MASK) == GDK_SHIFT_MASK) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("Shift");
		_vala_array_add4 (&labels, &labels_length1, &_labels_size_, _tmp1_);
	}
	if (((*self).modifiers & GDK_CONTROL_MASK) == GDK_CONTROL_MASK) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("Ctrl");
		_vala_array_add5 (&labels, &labels_length1, &_labels_size_, _tmp2_);
	}
	if (((*self).modifiers & GDK_META_MASK) == GDK_META_MASK) {
		gchar* _tmp3_;
		_tmp3_ = g_strdup ("⌘");
		_vala_array_add6 (&labels, &labels_length1, &_labels_size_, _tmp3_);
	}
	if (((*self).modifiers & GDK_ALT_MASK) == GDK_ALT_MASK) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("Alt");
		_vala_array_add7 (&labels, &labels_length1, &_labels_size_, _tmp4_);
	}
	if (((*self).modifiers & GDK_SUPER_MASK) == GDK_SUPER_MASK) {
		gchar* _tmp5_;
		_tmp5_ = g_strdup ("Super");
		_vala_array_add8 (&labels, &labels_length1, &_labels_size_, _tmp5_);
	}
	if (((*self).modifiers & GDK_HYPER_MASK) == GDK_HYPER_MASK) {
		gchar* _tmp6_;
		_tmp6_ = g_strdup ("Hyper");
		_vala_array_add9 (&labels, &labels_length1, &_labels_size_, _tmp6_);
	}
	chr = (gunichar) gdk_keyval_to_unicode ((*self).keyval);
	if (chr != ((gunichar) '\x00')) {
		_tmp8_ = chr < ((gunichar) '\x80');
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		_tmp7_ = g_unichar_isgraph (chr);
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		switch (chr) {
			case '\\':
			{
				gchar* _tmp9_;
				_tmp9_ = g_strdup ("Backslash");
				_vala_array_add10 (&labels, &labels_length1, &_labels_size_, _tmp9_);
				break;
			}
			default:
			{
				gchar* _tmp10_;
				_tmp10_ = g_unichar_to_string (g_unichar_toupper (chr));
				_vala_array_add11 (&labels, &labels_length1, &_labels_size_, _tmp10_);
				break;
			}
		}
	} else {
		switch ((*self).keyval) {
			case GDK_KEY_Left:
			{
				gchar* _tmp11_;
				_tmp11_ = g_strdup ("\xe2\x86\x90");
				_vala_array_add12 (&labels, &labels_length1, &_labels_size_, _tmp11_);
				break;
			}
			case GDK_KEY_Up:
			{
				gchar* _tmp12_;
				_tmp12_ = g_strdup ("\xe2\x86\x91");
				_vala_array_add13 (&labels, &labels_length1, &_labels_size_, _tmp12_);
				break;
			}
			case GDK_KEY_Right:
			{
				gchar* _tmp13_;
				_tmp13_ = g_strdup ("\xe2\x86\x92");
				_vala_array_add14 (&labels, &labels_length1, &_labels_size_, _tmp13_);
				break;
			}
			case GDK_KEY_Down:
			{
				gchar* _tmp14_;
				_tmp14_ = g_strdup ("\xe2\x86\x93");
				_vala_array_add15 (&labels, &labels_length1, &_labels_size_, _tmp14_);
				break;
			}
			case GDK_KEY_space:
			{
				gchar* _tmp15_;
				_tmp15_ = g_strdup ("Space");
				_vala_array_add16 (&labels, &labels_length1, &_labels_size_, _tmp15_);
				break;
			}
			case GDK_KEY_Return:
			{
				gchar* _tmp16_;
				_tmp16_ = g_strdup ("Return");
				_vala_array_add17 (&labels, &labels_length1, &_labels_size_, _tmp16_);
				break;
			}
			case GDK_KEY_Page_Up:
			{
				gchar* _tmp17_;
				_tmp17_ = g_strdup ("Page Up");
				_vala_array_add18 (&labels, &labels_length1, &_labels_size_, _tmp17_);
				break;
			}
			case GDK_KEY_Page_Down:
			{
				gchar* _tmp18_;
				_tmp18_ = g_strdup ("Page Down");
				_vala_array_add19 (&labels, &labels_length1, &_labels_size_, _tmp18_);
				break;
			}
			default:
			{
				gchar* keyval_name = NULL;
				const gchar* _tmp19_;
				gchar* _tmp20_;
				const gchar* _tmp21_;
				_tmp19_ = gdk_keyval_name ((*self).keyval);
				_tmp20_ = g_strdup (_tmp19_);
				keyval_name = _tmp20_;
				_tmp21_ = keyval_name;
				if (_tmp21_ != NULL) {
					const gchar* _tmp22_;
					gchar* _tmp23_;
					_tmp22_ = keyval_name;
					_tmp23_ = string_replace (_tmp22_, "_", " ");
					_vala_array_add20 (&labels, &labels_length1, &_labels_size_, _tmp23_);
				}
				_g_free0 (keyval_name);
				break;
			}
		}
	}
	_tmp24_ = labels;
	_tmp24__length1 = labels_length1;
	if (result_length1) {
		*result_length1 = _tmp24__length1;
	}
	result = _tmp24_;
	return result;
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

gchar*
ft_accelerator_get_label (FtAccelerator *self)
{
	gint _tmp0_ = 0;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp1_ = ft_accelerator_get_labels (&(*self), &_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp0_;
	_tmp3_ = _vala_g_strjoinv (" + ", _tmp2_, (gint) _tmp0_);
	_tmp4_ = _tmp3_;
	_tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL);
	result = _tmp4_;
	return result;
}

gchar*
ft_accelerator_to_string (FtAccelerator *self)
{
	gchar* _tmp0_ = NULL;
	gchar* _tmp3_;
	gchar* result;
	if (!ft_accelerator_is_empty (&(*self))) {
		gchar* _tmp1_;
		_tmp1_ = gtk_accelerator_name ((*self).keyval, (*self).modifiers);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp1_;
	} else {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_free0 (_tmp0_);
	return result;
}

FtAccelerator*
ft_accelerator_dup (const FtAccelerator* self)
{
	FtAccelerator* dup;
	dup = g_new0 (FtAccelerator, 1);
	memcpy (dup, self, sizeof (FtAccelerator));
	return dup;
}

void
ft_accelerator_free (FtAccelerator* self)
{
	g_free (self);
}

static GType
ft_accelerator_get_type_once (void)
{
	GType ft_accelerator_type_id;
	ft_accelerator_type_id = g_boxed_type_register_static ("FtAccelerator", (GBoxedCopyFunc) ft_accelerator_dup, (GBoxedFreeFunc) ft_accelerator_free);
	return ft_accelerator_type_id;
}

GType
ft_accelerator_get_type (void)
{
	static volatile gsize ft_accelerator_type_id__once = 0;
	if (g_once_init_enter (&ft_accelerator_type_id__once)) {
		GType ft_accelerator_type_id;
		ft_accelerator_type_id = ft_accelerator_get_type_once ();
		g_once_init_leave (&ft_accelerator_type_id__once, ft_accelerator_type_id);
	}
	return ft_accelerator_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

