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

#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <pango/pango.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib/gstdio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_SETTINGS_WINDOW (settings_window_get_type ())
#define SETTINGS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SETTINGS_WINDOW, SettingsWindow))
#define SETTINGS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SETTINGS_WINDOW, SettingsWindowClass))
#define IS_SETTINGS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SETTINGS_WINDOW))
#define IS_SETTINGS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SETTINGS_WINDOW))
#define SETTINGS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SETTINGS_WINDOW, SettingsWindowClass))

typedef struct _SettingsWindow SettingsWindow;
typedef struct _SettingsWindowClass SettingsWindowClass;
typedef struct _SettingsWindowPrivate SettingsWindowPrivate;

#define TYPE_SETTINGS_STATE_SNAPSHOT (settings_state_snapshot_get_type ())
#define SETTINGS_STATE_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_SETTINGS_STATE_SNAPSHOT, SettingsStateSnapshot))
#define SETTINGS_STATE_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_SETTINGS_STATE_SNAPSHOT, SettingsStateSnapshotClass))
#define IS_SETTINGS_STATE_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_SETTINGS_STATE_SNAPSHOT))
#define IS_SETTINGS_STATE_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_SETTINGS_STATE_SNAPSHOT))
#define SETTINGS_STATE_SNAPSHOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_SETTINGS_STATE_SNAPSHOT, SettingsStateSnapshotClass))

typedef struct _SettingsStateSnapshot SettingsStateSnapshot;
typedef struct _SettingsStateSnapshotClass SettingsStateSnapshotClass;
typedef enum  {
	WM_DETECTOR_WAYLAND_WM_LABWC,
	WM_DETECTOR_WAYLAND_WM_SWAY,
	WM_DETECTOR_WAYLAND_WM_WAYFIRE,
	WM_DETECTOR_WAYLAND_WM_RIVER,
	WM_DETECTOR_WAYLAND_WM_HYPRLAND,
	WM_DETECTOR_WAYLAND_WM_UNKNOWN
} WMDetectorWaylandWM;

#define WM_DETECTOR_TYPE_WAYLAND_WM (wm_detector_wayland_wm_get_type ())
enum  {
	SETTINGS_WINDOW_0_PROPERTY,
	SETTINGS_WINDOW_NUM_PROPERTIES
};
static GParamSpec* settings_window_properties[SETTINGS_WINDOW_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))
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _Block2Data Block2Data;
#define _g_key_file_unref0(var) ((var == NULL) ? NULL : (var = (g_key_file_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define __vala_GtkTreePath_free0(var) ((var == NULL) ? NULL : (var = (_vala_GtkTreePath_free (var), NULL)))

#define WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG (wm_config_modifier_xkb_config_get_type ())
#define WM_CONFIG_MODIFIER_XKB_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG, WMConfigModifierXKBConfig))
#define WM_CONFIG_MODIFIER_XKB_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG, WMConfigModifierXKBConfigClass))
#define WM_CONFIG_MODIFIER_IS_XKB_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG))
#define WM_CONFIG_MODIFIER_IS_XKB_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG))
#define WM_CONFIG_MODIFIER_XKB_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WM_CONFIG_MODIFIER_TYPE_XKB_CONFIG, WMConfigModifierXKBConfigClass))

typedef struct _WMConfigModifierXKBConfig WMConfigModifierXKBConfig;
typedef struct _WMConfigModifierXKBConfigClass WMConfigModifierXKBConfigClass;
#define _wm_config_modifier_xkb_config_unref0(var) ((var == NULL) ? NULL : (var = (wm_config_modifier_xkb_config_unref (var), NULL)))

struct _SettingsWindow {
	GtkApplicationWindow parent_instance;
	SettingsWindowPrivate * priv;
};

struct _SettingsWindowClass {
	GtkApplicationWindowClass parent_class;
};

struct _SettingsWindowPrivate {
	GtkListStore* layout_store;
	GtkTreeView* layout_view;
	GtkComboBoxText* shortcut_combo;
	GtkEntry* custom_option_entry;
	GtkLabel* preview_layout_label;
	GtkLabel* preview_option_label;
	GtkButton* remove_button;
	GtkButton* up_button;
	GtkButton* down_button;
	GtkButton* apply_wm_button;
	GtkLabel* status_label;
	SettingsStateSnapshot* initial_snapshot;
	gchar* env_file_path;
	gchar* flag_dir_path;
	gchar* layouts_config_path;
	WMDetectorWaylandWM detected_wm;
};

struct _Block1Data {
	int _ref_count_;
	SettingsWindow* self;
	GtkButton* add_button;
};

struct _Block2Data {
	int _ref_count_;
	SettingsWindow* self;
	GtkDialog* dialog;
	GtkSearchEntry* search_entry;
	GtkTreeModelFilter* filter_model;
	GtkTreeView* tree_view;
};

static gint SettingsWindow_private_offset;
static gpointer settings_window_parent_class = NULL;

VALA_EXTERN GType settings_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SettingsWindow, g_object_unref)
VALA_EXTERN GType settings_state_snapshot_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SettingsStateSnapshot, g_object_unref)
VALA_EXTERN GType wm_detector_wayland_wm_get_type (void) G_GNUC_CONST ;
static GtkButton* settings_window_create_icon_button (SettingsWindow* self,
                                               const gchar* icon_name,
                                               const gchar* label_text);
static void settings_window_set_uniform_button_width (SettingsWindow* self,
                                               GtkButton* first,
                                               GtkButton* second,
                                               GtkButton* third,
                                               GtkButton* fourth);
VALA_EXTERN SettingsWindow* settings_window_new (GtkApplication* app);
VALA_EXTERN SettingsWindow* settings_window_construct (GType object_type,
                                           GtkApplication* app);
static gchar* settings_window_build_environment_path (SettingsWindow* self);
VALA_EXTERN gchar* flag_utils_build_flag_dir_path (void);
VALA_EXTERN gchar* flag_utils_build_layouts_config_path (void);
VALA_EXTERN WMDetectorWaylandWM wm_detector_detect (void);
VALA_EXTERN gchar* wm_detector_get_name (WMDetectorWaylandWM wm);
static GtkWidget* settings_window_build_layouts_frame (SettingsWindow* self);
static GtkWidget* settings_window_build_switching_frame (SettingsWindow* self);
static void __lambda15_ (SettingsWindow* self);
static void settings_window_restore_initial_state (SettingsWindow* self);
static void ___lambda15__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda16_ (SettingsWindow* self);
static void settings_window_apply_changes (SettingsWindow* self);
static void ___lambda16__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda18_ (SettingsWindow* self);
static void ___lambda18__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void ___lambda19_ (SettingsWindow* self);
static void settings_window_apply_to_wm (SettingsWindow* self);
static void ____lambda19__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static void settings_window_load_environment (SettingsWindow* self);
static SettingsStateSnapshot* settings_window_capture_current_state (SettingsWindow* self);
static void settings_window_update_preview (SettingsWindow* self);
static void settings_window_update_layout_buttons (SettingsWindow* self);
static void settings_window_update_custom_option_state (SettingsWindow* self);
static void settings_window_clear_status (SettingsWindow* self);
static gchar* settings_window_collect_layouts_csv (SettingsWindow* self);
static gchar* settings_window_get_effective_option (SettingsWindow* self);
VALA_EXTERN SettingsStateSnapshot* settings_state_snapshot_new (const gchar* layouts_csv,
                                                    const gchar* option);
VALA_EXTERN SettingsStateSnapshot* settings_state_snapshot_construct (GType object_type,
                                                          const gchar* layouts_csv,
                                                          const gchar* option);
static void settings_window_populate_layout_store (SettingsWindow* self,
                                            const gchar* layouts_csv);
VALA_EXTERN const gchar* settings_state_snapshot_get_layouts_csv (SettingsStateSnapshot* self);
static void settings_window_apply_option_to_controls (SettingsWindow* self,
                                               const gchar* option);
VALA_EXTERN const gchar* settings_state_snapshot_get_option (SettingsStateSnapshot* self);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static void __lambda4_ (SettingsWindow* self);
static void ___lambda4__gtk_tree_selection_changed (GtkTreeSelection* _sender,
                                             gpointer self);
static void __lambda5_ (SettingsWindow* self);
static void settings_window_add_layout_dialog (SettingsWindow* self);
static void ___lambda5__gtk_button_clicked (GtkButton* _sender,
                                     gpointer self);
static void __lambda9_ (SettingsWindow* self);
static void settings_window_remove_selected_layout (SettingsWindow* self);
static void ___lambda9__gtk_button_clicked (GtkButton* _sender,
                                     gpointer self);
static void __lambda10_ (SettingsWindow* self);
static void settings_window_move_selected_layout (SettingsWindow* self,
                                           gint direction);
static void ___lambda10__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda11_ (SettingsWindow* self);
static void ___lambda11__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static gboolean __lambda12_ (Block1Data* _data1_);
static gboolean ___lambda12__gsource_func (gpointer self);
static void __lambda13_ (SettingsWindow* self);
static void ___lambda13__gtk_combo_box_changed (GtkComboBox* _sender,
                                         gpointer self);
static void __lambda14_ (SettingsWindow* self);
static void ___lambda14__gtk_editable_changed (GtkEditable* _sender,
                                        gpointer self);
static GdkPixbuf* settings_window_load_flag_pixbuf (const gchar* flag_dir_path,
                                             const gchar* layout_code,
                                             gint size);
VALA_EXTERN gchar* flag_utils_get_layout_icon_code (const gchar* layout_code);
static void settings_window_ensure_environment_file (SettingsWindow* self);
static void settings_window_show_error_dialog (SettingsWindow* self,
                                        const gchar* title,
                                        const gchar* details);
static gchar* settings_window_read_env_key (SettingsWindow* self,
                                     const gchar* key);
static gchar* settings_window_shortcut_label_from_option (SettingsWindow* self,
                                                   const gchar* option);
static gchar* settings_window_option_from_shortcut_label (SettingsWindow* self,
                                                   const gchar* shortcut_label);
static gchar* settings_window_merge_grp_option (SettingsWindow* self,
                                         const gchar* existing_options,
                                         const gchar* new_grp);
static void _g_free0_ (gpointer var);
static void _vala_gchar_free_function_content_of (gpointer data);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static GtkTreeStore* settings_window_build_layout_catalog_store (SettingsWindow* self);
static gboolean __lambda6_ (Block2Data* _data2_,
                     GtkTreeModel* model,
                     GtkTreeIter* iter);
static gboolean settings_window_catalog_row_matches (SettingsWindow* self,
                                              GtkTreeModel* model,
                                              GtkTreeIter* iter,
                                              const gchar* needle);
static gboolean ___lambda6__gtk_tree_model_filter_visible_func (GtkTreeModel* model,
                                                         GtkTreeIter* iter,
                                                         gpointer self);
static void __lambda7_ (Block2Data* _data2_,
                 GtkTreePath* path,
                 GtkTreeViewColumn* column);
static void ___lambda7__gtk_tree_view_row_activated (GtkTreeView* _sender,
                                              GtkTreePath* path,
                                              GtkTreeViewColumn* column,
                                              gpointer self);
static void __lambda8_ (Block2Data* _data2_);
static void ___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                       gpointer self);
static gboolean settings_window_is_valid_layout_code (SettingsWindow* self,
                                               const gchar* code);
static gboolean settings_window_layout_exists (SettingsWindow* self,
                                        const gchar* code);
static gchar* settings_window_translate_xkeyboard_config (SettingsWindow* self,
                                                   const gchar* text);
static void settings_window_add_catalog_layout_row (SettingsWindow* self,
                                             GtkTreeStore* store,
                                             GHashTable* seen,
                                             const gchar* code,
                                             const gchar* description);
static void settings_window_add_catalog_variant_row (SettingsWindow* self,
                                              GtkTreeStore* store,
                                              GHashTable* seen,
                                              const gchar* layout,
                                              const gchar* code,
                                              const gchar* description);
static gboolean settings_window_find_catalog_parent_iter (SettingsWindow* self,
                                                   GtkTreeStore* store,
                                                   const gchar* layout,
                                                   GtkTreeIter* iter);
static gboolean settings_window_catalog_text_matches (SettingsWindow* self,
                                               const gchar* text,
                                               const gchar* needle);
static gint settings_window_get_selected_index (SettingsWindow* self,
                                         GtkTreeIter* selected_iter);
static void _vala_GtkTreePath_free (GtkTreePath* self);
static gint* _vala_array_dup2 (gint* self,
                        gssize length);
static gboolean settings_window_validate_form (SettingsWindow* self,
                                        gchar** message);
static gboolean settings_window_write_environment (SettingsWindow* self,
                                            const gchar* layouts_csv,
                                            const gchar* option,
                                            gchar** error_message);
static gboolean settings_window_reload_labwc (SettingsWindow* self,
                                       gchar** error_message);
static gboolean __lambda17_ (SettingsWindow* self);
static gboolean ___lambda17__gsource_func (gpointer self);
VALA_EXTERN gpointer wm_config_modifier_xkb_config_ref (gpointer instance);
VALA_EXTERN void wm_config_modifier_xkb_config_unref (gpointer instance);
VALA_EXTERN GParamSpec* wm_config_modifier_param_spec_xkb_config (const gchar* name,
                                                      const gchar* nick,
                                                      const gchar* blurb,
                                                      GType object_type,
                                                      GParamFlags flags);
VALA_EXTERN void wm_config_modifier_value_set_xkb_config (GValue* value,
                                              gpointer v_object);
VALA_EXTERN void wm_config_modifier_value_take_xkb_config (GValue* value,
                                               gpointer v_object);
VALA_EXTERN gpointer wm_config_modifier_value_get_xkb_config (const GValue* value);
VALA_EXTERN GType wm_config_modifier_xkb_config_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WMConfigModifierXKBConfig, wm_config_modifier_xkb_config_unref)
VALA_EXTERN WMConfigModifierXKBConfig* wm_config_modifier_read_from_wm (WMDetectorWaylandWM wm,
                                                            GError** error);
VALA_EXTERN WMConfigModifierXKBConfig* wm_config_modifier_xkb_config_new (void);
VALA_EXTERN WMConfigModifierXKBConfig* wm_config_modifier_xkb_config_construct (GType object_type);
VALA_EXTERN void wm_config_modifier_xkb_config_set_layout (WMConfigModifierXKBConfig* self,
                                               const gchar* value);
VALA_EXTERN const gchar* wm_config_modifier_xkb_config_get_options (WMConfigModifierXKBConfig* self);
VALA_EXTERN void wm_config_modifier_xkb_config_set_options (WMConfigModifierXKBConfig* self,
                                                const gchar* value);
VALA_EXTERN gchar* wm_detector_get_config_path (WMDetectorWaylandWM wm);
VALA_EXTERN gboolean wm_config_backup_create_backup (const gchar* config_path,
                                         const gchar* wm_name,
                                         GError** error);
VALA_EXTERN gboolean wm_config_modifier_apply_to_wm (WMDetectorWaylandWM wm,
                                         WMConfigModifierXKBConfig* config,
                                         GError** error);
static gboolean ___lambda20_ (SettingsWindow* self);
static gboolean ____lambda20__gsource_func (gpointer self);
static void settings_window_finalize (GObject * obj);
static GType settings_window_get_type_once (void);
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 gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
settings_window_get_instance_private (SettingsWindow* self)
{
	return G_STRUCT_MEMBER_P (self, SettingsWindow_private_offset);
}

static GtkButton*
settings_window_create_icon_button (SettingsWindow* self,
                                    const gchar* icon_name,
                                    const gchar* label_text)
{
	GtkButton* button = NULL;
	GtkButton* _tmp0_;
	GtkImage* image = NULL;
	GtkImage* _tmp1_;
	GtkLabel* label = NULL;
	GtkLabel* _tmp2_;
	GtkBox* row = NULL;
	GtkBox* _tmp3_;
	GtkButton* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (icon_name != NULL, NULL);
	g_return_val_if_fail (label_text != NULL, NULL);
	_tmp0_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp0_);
	button = _tmp0_;
	_tmp1_ = (GtkImage*) gtk_image_new_from_icon_name (icon_name, (GtkIconSize) GTK_ICON_SIZE_BUTTON);
	g_object_ref_sink (_tmp1_);
	image = _tmp1_;
	_tmp2_ = (GtkLabel*) gtk_label_new (label_text);
	g_object_ref_sink (_tmp2_);
	label = _tmp2_;
	gtk_widget_set_halign ((GtkWidget*) label, GTK_ALIGN_START);
	gtk_label_set_xalign (label, 0.0f);
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp3_);
	row = _tmp3_;
	gtk_widget_set_halign ((GtkWidget*) row, GTK_ALIGN_START);
	gtk_widget_set_margin_start ((GtkWidget*) row, 4);
	gtk_box_pack_start (row, (GtkWidget*) image, FALSE, FALSE, (guint) 0);
	gtk_box_pack_start (row, (GtkWidget*) label, FALSE, FALSE, (guint) 0);
	gtk_container_add ((GtkContainer*) button, (GtkWidget*) row);
	result = button;
	_g_object_unref0 (row);
	_g_object_unref0 (label);
	_g_object_unref0 (image);
	return result;
}

static void
settings_window_set_uniform_button_width (SettingsWindow* self,
                                          GtkButton* first,
                                          GtkButton* second,
                                          GtkButton* third,
                                          GtkButton* fourth)
{
	GtkRequisition nat_req = {0};
	gint max_width = 0;
	GtkRequisition _tmp0_ = {0};
	GtkRequisition _tmp1_;
	GtkRequisition _tmp2_ = {0};
	GtkRequisition _tmp3_;
	GtkRequisition _tmp4_ = {0};
	GtkRequisition _tmp5_;
	GtkRequisition _tmp6_ = {0};
	GtkRequisition _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (first != NULL);
	g_return_if_fail (second != NULL);
	g_return_if_fail (third != NULL);
	g_return_if_fail (fourth != NULL);
	max_width = 0;
	gtk_widget_get_preferred_size ((GtkWidget*) first, NULL, &_tmp0_);
	nat_req = _tmp0_;
	_tmp1_ = nat_req;
	max_width = MAX (max_width, _tmp1_.width);
	gtk_widget_get_preferred_size ((GtkWidget*) second, NULL, &_tmp2_);
	nat_req = _tmp2_;
	_tmp3_ = nat_req;
	max_width = MAX (max_width, _tmp3_.width);
	gtk_widget_get_preferred_size ((GtkWidget*) third, NULL, &_tmp4_);
	nat_req = _tmp4_;
	_tmp5_ = nat_req;
	max_width = MAX (max_width, _tmp5_.width);
	gtk_widget_get_preferred_size ((GtkWidget*) fourth, NULL, &_tmp6_);
	nat_req = _tmp6_;
	_tmp7_ = nat_req;
	max_width = MAX (max_width, _tmp7_.width);
	gtk_widget_set_size_request ((GtkWidget*) first, max_width, -1);
	gtk_widget_set_size_request ((GtkWidget*) second, max_width, -1);
	gtk_widget_set_size_request ((GtkWidget*) third, max_width, -1);
	gtk_widget_set_size_request ((GtkWidget*) fourth, max_width, -1);
}

static void
__lambda15_ (SettingsWindow* self)
{
	settings_window_restore_initial_state (self);
}

static void
___lambda15__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda15_ ((SettingsWindow*) self);
}

static void
__lambda16_ (SettingsWindow* self)
{
	settings_window_apply_changes (self);
}

static void
___lambda16__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda16_ ((SettingsWindow*) self);
}

static void
__lambda18_ (SettingsWindow* self)
{
	gtk_window_close ((GtkWindow*) self);
}

static void
___lambda18__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda18_ ((SettingsWindow*) self);
}

static void
___lambda19_ (SettingsWindow* self)
{
	settings_window_apply_to_wm (self);
}

static void
____lambda19__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	___lambda19_ ((SettingsWindow*) self);
}

SettingsWindow*
settings_window_construct (GType object_type,
                           GtkApplication* app)
{
	SettingsWindow * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GtkBox* root = NULL;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	GtkBox* _tmp5_;
	GtkBox* _tmp6_;
	GtkBox* _tmp7_;
	GtkBox* _tmp8_;
	gchar* wm_name = NULL;
	gchar* _tmp9_;
	GtkLabel* subtitle = NULL;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GtkLabel* _tmp13_;
	GtkLabel* _tmp14_;
	GtkLabel* _tmp15_;
	GtkBox* _tmp16_;
	GtkLabel* _tmp17_;
	GtkBox* _tmp18_;
	GtkWidget* _tmp19_;
	GtkWidget* _tmp20_;
	GtkBox* _tmp21_;
	GtkWidget* _tmp22_;
	GtkWidget* _tmp23_;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	GtkLabel* _tmp26_;
	GtkLabel* _tmp27_;
	GtkButtonBox* action_bar = NULL;
	GtkButtonBox* _tmp28_;
	GtkButtonBox* _tmp29_;
	GtkButtonBox* _tmp30_;
	GtkButton* cancel_btn = NULL;
	GtkButton* _tmp31_;
	GtkButton* _tmp32_;
	GtkButton* _tmp33_;
	GtkButtonBox* _tmp34_;
	GtkButton* _tmp35_;
	GtkButton* apply_btn = NULL;
	GtkButton* _tmp36_;
	GtkButton* _tmp37_;
	GtkButton* _tmp38_;
	GtkButtonBox* _tmp39_;
	GtkButton* _tmp40_;
	GtkButton* close_btn = NULL;
	GtkButton* _tmp41_;
	GtkButton* _tmp42_;
	GtkButton* _tmp43_;
	GtkButtonBox* _tmp44_;
	GtkButton* _tmp45_;
	gboolean _tmp46_ = FALSE;
	GtkBox* bottom_box = NULL;
	GtkBox* _tmp52_;
	GtkLabel* _tmp53_;
	GtkButtonBox* _tmp54_;
	GtkBox* _tmp55_;
	SettingsStateSnapshot* _tmp56_;
	g_return_val_if_fail (app != NULL, NULL);
	self = (SettingsWindow*) g_object_new (object_type, "application", app, "title", _ ("Keyboard Layout"), "resizable", TRUE, NULL);
	_tmp0_ = settings_window_build_environment_path (self);
	_g_free0 (self->priv->env_file_path);
	self->priv->env_file_path = _tmp0_;
	_tmp1_ = flag_utils_build_flag_dir_path ();
	_g_free0 (self->priv->flag_dir_path);
	self->priv->flag_dir_path = _tmp1_;
	_tmp2_ = flag_utils_build_layouts_config_path ();
	_g_free0 (self->priv->layouts_config_path);
	self->priv->layouts_config_path = _tmp2_;
	self->priv->detected_wm = wm_detector_detect ();
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp3_);
	root = _tmp3_;
	_tmp4_ = root;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp4_, 12);
	_tmp5_ = root;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp5_, 12);
	_tmp6_ = root;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp6_, 12);
	_tmp7_ = root;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp7_, 12);
	_tmp8_ = root;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp8_);
	_tmp9_ = wm_detector_get_name (self->priv->detected_wm);
	wm_name = _tmp9_;
	_tmp10_ = wm_name;
	_tmp11_ = g_strdup_printf (_ ("Configure layouts and switching for %s"), _tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = (GtkLabel*) gtk_label_new (_tmp12_);
	g_object_ref_sink (_tmp13_);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp12_);
	subtitle = _tmp14_;
	_tmp15_ = subtitle;
	gtk_widget_set_halign ((GtkWidget*) _tmp15_, GTK_ALIGN_START);
	_tmp16_ = root;
	_tmp17_ = subtitle;
	gtk_box_pack_start (_tmp16_, (GtkWidget*) _tmp17_, FALSE, FALSE, (guint) 0);
	_tmp18_ = root;
	_tmp19_ = settings_window_build_layouts_frame (self);
	_tmp20_ = _tmp19_;
	gtk_box_pack_start (_tmp18_, _tmp20_, FALSE, FALSE, (guint) 0);
	_g_object_unref0 (_tmp20_);
	_tmp21_ = root;
	_tmp22_ = settings_window_build_switching_frame (self);
	_tmp23_ = _tmp22_;
	gtk_box_pack_start (_tmp21_, _tmp23_, FALSE, FALSE, (guint) 0);
	_g_object_unref0 (_tmp23_);
	_tmp24_ = (GtkLabel*) gtk_label_new (" ");
	g_object_ref_sink (_tmp24_);
	_g_object_unref0 (self->priv->status_label);
	self->priv->status_label = _tmp24_;
	_tmp25_ = self->priv->status_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp25_, GTK_ALIGN_END);
	_tmp26_ = self->priv->status_label;
	gtk_label_set_single_line_mode (_tmp26_, TRUE);
	_tmp27_ = self->priv->status_label;
	gtk_label_set_ellipsize (_tmp27_, PANGO_ELLIPSIZE_END);
	_tmp28_ = (GtkButtonBox*) gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp28_);
	action_bar = _tmp28_;
	_tmp29_ = action_bar;
	g_object_set (_tmp29_, "layout-style", GTK_BUTTONBOX_END, NULL);
	_tmp30_ = action_bar;
	gtk_box_set_spacing ((GtkBox*) _tmp30_, 6);
	_tmp31_ = settings_window_create_icon_button (self, "window-close", _ ("Cancel"));
	cancel_btn = _tmp31_;
	_tmp32_ = cancel_btn;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp32_, _ ("Restore values from window open"));
	_tmp33_ = cancel_btn;
	g_signal_connect_object (_tmp33_, "clicked", (GCallback) ___lambda15__gtk_button_clicked, self, 0);
	_tmp34_ = action_bar;
	_tmp35_ = cancel_btn;
	gtk_container_add ((GtkContainer*) _tmp34_, (GtkWidget*) _tmp35_);
	_tmp36_ = settings_window_create_icon_button (self, "document-save", _ ("Apply"));
	apply_btn = _tmp36_;
	_tmp37_ = apply_btn;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp37_, _ ("Apply keyboard settings to WM config"));
	_tmp38_ = apply_btn;
	g_signal_connect_object (_tmp38_, "clicked", (GCallback) ___lambda16__gtk_button_clicked, self, 0);
	_tmp39_ = action_bar;
	_tmp40_ = apply_btn;
	gtk_container_add ((GtkContainer*) _tmp39_, (GtkWidget*) _tmp40_);
	_tmp41_ = settings_window_create_icon_button (self, "window-close", _ ("Close"));
	close_btn = _tmp41_;
	_tmp42_ = close_btn;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp42_, _ ("Close this window"));
	_tmp43_ = close_btn;
	g_signal_connect_object (_tmp43_, "clicked", (GCallback) ___lambda18__gtk_button_clicked, self, 0);
	_tmp44_ = action_bar;
	_tmp45_ = close_btn;
	gtk_container_add ((GtkContainer*) _tmp44_, (GtkWidget*) _tmp45_);
	if (self->priv->detected_wm != WM_DETECTOR_WAYLAND_WM_UNKNOWN) {
		_tmp46_ = self->priv->detected_wm != WM_DETECTOR_WAYLAND_WM_LABWC;
	} else {
		_tmp46_ = FALSE;
	}
	if (_tmp46_) {
		GtkButton* _tmp47_;
		GtkButton* _tmp48_;
		GtkButton* _tmp49_;
		GtkButtonBox* _tmp50_;
		GtkButton* _tmp51_;
		_tmp47_ = settings_window_create_icon_button (self, "document-save", _ ("Apply to WM"));
		_g_object_unref0 (self->priv->apply_wm_button);
		self->priv->apply_wm_button = _tmp47_;
		_tmp48_ = self->priv->apply_wm_button;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp48_, _ ("Apply current XKB settings to the detected window manager"));
		_tmp49_ = self->priv->apply_wm_button;
		g_signal_connect_object (_tmp49_, "clicked", (GCallback) ____lambda19__gtk_button_clicked, self, 0);
		_tmp50_ = action_bar;
		_tmp51_ = self->priv->apply_wm_button;
		gtk_container_add ((GtkContainer*) _tmp50_, (GtkWidget*) _tmp51_);
	}
	_tmp52_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 4);
	g_object_ref_sink (_tmp52_);
	bottom_box = _tmp52_;
	_tmp53_ = self->priv->status_label;
	gtk_box_pack_start (bottom_box, (GtkWidget*) _tmp53_, FALSE, FALSE, (guint) 0);
	_tmp54_ = action_bar;
	gtk_box_pack_start (bottom_box, (GtkWidget*) _tmp54_, FALSE, FALSE, (guint) 0);
	_tmp55_ = root;
	gtk_box_pack_end (_tmp55_, (GtkWidget*) bottom_box, FALSE, FALSE, (guint) 0);
	settings_window_load_environment (self);
	_tmp56_ = settings_window_capture_current_state (self);
	_g_object_unref0 (self->priv->initial_snapshot);
	self->priv->initial_snapshot = _tmp56_;
	settings_window_update_preview (self);
	settings_window_update_layout_buttons (self);
	settings_window_update_custom_option_state (self);
	gtk_widget_show_all ((GtkWidget*) self);
	_g_object_unref0 (bottom_box);
	_g_object_unref0 (close_btn);
	_g_object_unref0 (apply_btn);
	_g_object_unref0 (cancel_btn);
	_g_object_unref0 (action_bar);
	_g_object_unref0 (subtitle);
	_g_free0 (wm_name);
	_g_object_unref0 (root);
	return self;
}

SettingsWindow*
settings_window_new (GtkApplication* app)
{
	return settings_window_construct (TYPE_SETTINGS_WINDOW, app);
}

static void
settings_window_clear_status (SettingsWindow* self)
{
	GtkLabel* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->status_label;
	gtk_label_set_label (_tmp0_, " ");
}

static SettingsStateSnapshot*
settings_window_capture_current_state (SettingsWindow* self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	SettingsStateSnapshot* _tmp4_;
	SettingsStateSnapshot* _tmp5_;
	SettingsStateSnapshot* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = settings_window_collect_layouts_csv (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = settings_window_get_effective_option (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = settings_state_snapshot_new (_tmp1_, _tmp3_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp5_;
	return result;
}

static void
settings_window_restore_initial_state (SettingsWindow* self)
{
	SettingsStateSnapshot* _tmp0_;
	SettingsStateSnapshot* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	SettingsStateSnapshot* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->initial_snapshot;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->initial_snapshot;
	_tmp2_ = settings_state_snapshot_get_layouts_csv (_tmp1_);
	_tmp3_ = _tmp2_;
	settings_window_populate_layout_store (self, _tmp3_);
	_tmp4_ = self->priv->initial_snapshot;
	_tmp5_ = settings_state_snapshot_get_option (_tmp4_);
	_tmp6_ = _tmp5_;
	settings_window_apply_option_to_controls (self, _tmp6_);
	settings_window_update_custom_option_state (self);
	settings_window_update_preview (self);
	settings_window_update_layout_buttons (self);
	settings_window_clear_status (self);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		SettingsWindow* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->add_button);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

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

static void
__lambda4_ (SettingsWindow* self)
{
	settings_window_update_layout_buttons (self);
}

static void
___lambda4__gtk_tree_selection_changed (GtkTreeSelection* _sender,
                                        gpointer self)
{
	__lambda4_ ((SettingsWindow*) self);
}

static void
__lambda5_ (SettingsWindow* self)
{
	settings_window_add_layout_dialog (self);
}

static void
___lambda5__gtk_button_clicked (GtkButton* _sender,
                                gpointer self)
{
	__lambda5_ ((SettingsWindow*) self);
}

static void
__lambda9_ (SettingsWindow* self)
{
	settings_window_remove_selected_layout (self);
}

static void
___lambda9__gtk_button_clicked (GtkButton* _sender,
                                gpointer self)
{
	__lambda9_ ((SettingsWindow*) self);
}

static void
__lambda10_ (SettingsWindow* self)
{
	settings_window_move_selected_layout (self, -1);
}

static void
___lambda10__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda10_ ((SettingsWindow*) self);
}

static void
__lambda11_ (SettingsWindow* self)
{
	settings_window_move_selected_layout (self, 1);
}

static void
___lambda11__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda11_ ((SettingsWindow*) self);
}

static gboolean
__lambda12_ (Block1Data* _data1_)
{
	SettingsWindow* self;
	GtkButton* _tmp0_;
	GtkButton* _tmp1_;
	GtkButton* _tmp2_;
	gboolean result;
	self = _data1_->self;
	_tmp0_ = self->priv->remove_button;
	_tmp1_ = self->priv->up_button;
	_tmp2_ = self->priv->down_button;
	settings_window_set_uniform_button_width (self, _data1_->add_button, _tmp0_, _tmp1_, _tmp2_);
	result = FALSE;
	return result;
}

static gboolean
___lambda12__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda12_ (self);
	return result;
}

static GtkWidget*
settings_window_build_layouts_frame (SettingsWindow* self)
{
	Block1Data* _data1_;
	GtkFrame* frame = NULL;
	GtkFrame* _tmp0_;
	GtkLabel* title_label = NULL;
	GtkLabel* _tmp1_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp2_;
	GtkListStore* _tmp3_;
	GtkListStore* _tmp4_;
	GtkTreeView* _tmp5_;
	GtkTreeView* _tmp6_;
	GtkTreeView* _tmp7_;
	GtkCellRendererPixbuf* flag_renderer = NULL;
	GtkCellRendererPixbuf* _tmp8_;
	GtkTreeViewColumn* flag_column = NULL;
	GtkTreeViewColumn* _tmp9_;
	GtkTreeView* _tmp10_;
	GtkCellRendererText* renderer = NULL;
	GtkCellRendererText* _tmp11_;
	GtkTreeViewColumn* column = NULL;
	GtkTreeViewColumn* _tmp12_;
	GtkTreeView* _tmp13_;
	GtkTreeSelection* selection = NULL;
	GtkTreeView* _tmp14_;
	GtkTreeSelection* _tmp15_;
	GtkTreeSelection* _tmp16_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp17_;
	GtkTreeView* _tmp18_;
	GtkBox* controls = NULL;
	GtkBox* _tmp19_;
	GtkButton* _tmp20_;
	GtkButton* _tmp21_;
	GtkButton* _tmp22_;
	GtkButton* _tmp23_;
	GtkButton* _tmp24_;
	GtkButton* _tmp25_;
	GtkButton* _tmp26_;
	GtkButton* _tmp27_;
	GtkButton* _tmp28_;
	GtkButton* _tmp29_;
	GtkButton* _tmp30_;
	GtkButton* _tmp31_;
	GtkButton* _tmp32_;
	GtkButton* _tmp33_;
	GtkButton* _tmp34_;
	GtkButton* _tmp35_;
	GtkButton* _tmp36_;
	GtkButton* _tmp37_;
	GtkButton* _tmp38_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = (GtkFrame*) gtk_frame_new (NULL);
	g_object_ref_sink (_tmp0_);
	frame = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new (_ ("Configured layouts"));
	g_object_ref_sink (_tmp1_);
	title_label = _tmp1_;
	gtk_widget_set_halign ((GtkWidget*) title_label, GTK_ALIGN_START);
	gtk_frame_set_label_widget (frame, (GtkWidget*) title_label);
	_tmp2_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp2_);
	grid = _tmp2_;
	gtk_widget_set_margin_top ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_bottom ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_start ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_end ((GtkWidget*) grid, 8);
	gtk_grid_set_column_spacing (grid, 10);
	gtk_container_add ((GtkContainer*) frame, (GtkWidget*) grid);
	_tmp3_ = gtk_list_store_new (2, gdk_pixbuf_get_type (), G_TYPE_STRING, -1);
	_g_object_unref0 (self->priv->layout_store);
	self->priv->layout_store = _tmp3_;
	_tmp4_ = self->priv->layout_store;
	_tmp5_ = (GtkTreeView*) gtk_tree_view_new_with_model ((GtkTreeModel*) _tmp4_);
	g_object_ref_sink (_tmp5_);
	_g_object_unref0 (self->priv->layout_view);
	self->priv->layout_view = _tmp5_;
	_tmp6_ = self->priv->layout_view;
	gtk_tree_view_set_headers_visible (_tmp6_, FALSE);
	_tmp7_ = self->priv->layout_view;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp7_, _ ("Configured keyboard layouts"));
	_tmp8_ = (GtkCellRendererPixbuf*) gtk_cell_renderer_pixbuf_new ();
	g_object_ref_sink (_tmp8_);
	flag_renderer = _tmp8_;
	_tmp9_ = gtk_tree_view_column_new ();
	g_object_ref_sink (_tmp9_);
	flag_column = _tmp9_;
	gtk_cell_layout_pack_start ((GtkCellLayout*) flag_column, (GtkCellRenderer*) flag_renderer, FALSE);
	gtk_cell_layout_add_attribute ((GtkCellLayout*) flag_column, (GtkCellRenderer*) flag_renderer, "pixbuf", 0);
	_tmp10_ = self->priv->layout_view;
	gtk_tree_view_append_column (_tmp10_, flag_column);
	_tmp11_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp11_);
	renderer = _tmp11_;
	_tmp12_ = gtk_tree_view_column_new ();
	g_object_ref_sink (_tmp12_);
	column = _tmp12_;
	gtk_cell_layout_pack_start ((GtkCellLayout*) column, (GtkCellRenderer*) renderer, TRUE);
	gtk_cell_layout_add_attribute ((GtkCellLayout*) column, (GtkCellRenderer*) renderer, "text", 1);
	_tmp13_ = self->priv->layout_view;
	gtk_tree_view_append_column (_tmp13_, column);
	_tmp14_ = self->priv->layout_view;
	_tmp15_ = gtk_tree_view_get_selection (_tmp14_);
	_tmp16_ = _g_object_ref0 (_tmp15_);
	selection = _tmp16_;
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
	g_signal_connect_object (selection, "changed", (GCallback) ___lambda4__gtk_tree_selection_changed, self, 0);
	_tmp17_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp17_);
	scroll = _tmp17_;
	gtk_scrolled_window_set_policy (scroll, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_widget_set_size_request ((GtkWidget*) scroll, 260, -1);
	_tmp18_ = self->priv->layout_view;
	gtk_container_add ((GtkContainer*) scroll, (GtkWidget*) _tmp18_);
	gtk_grid_attach (grid, (GtkWidget*) scroll, 0, 0, 1, 1);
	_tmp19_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	g_object_ref_sink (_tmp19_);
	controls = _tmp19_;
	gtk_widget_set_halign ((GtkWidget*) controls, GTK_ALIGN_START);
	gtk_widget_set_valign ((GtkWidget*) controls, GTK_ALIGN_START);
	gtk_box_set_homogeneous (controls, TRUE);
	gtk_grid_attach (grid, (GtkWidget*) controls, 1, 0, 1, 1);
	_tmp20_ = settings_window_create_icon_button (self, "list-add", _ ("Add..."));
	_data1_->add_button = _tmp20_;
	gtk_widget_set_halign ((GtkWidget*) _data1_->add_button, GTK_ALIGN_START);
	gtk_widget_set_tooltip_text ((GtkWidget*) _data1_->add_button, _ ("Add new keyboard layout"));
	g_signal_connect_object (_data1_->add_button, "clicked", (GCallback) ___lambda5__gtk_button_clicked, self, 0);
	gtk_box_pack_start (controls, (GtkWidget*) _data1_->add_button, FALSE, FALSE, (guint) 0);
	_tmp21_ = settings_window_create_icon_button (self, "list-remove", _ ("Remove"));
	_g_object_unref0 (self->priv->remove_button);
	self->priv->remove_button = _tmp21_;
	_tmp22_ = self->priv->remove_button;
	gtk_widget_set_halign ((GtkWidget*) _tmp22_, GTK_ALIGN_START);
	_tmp23_ = self->priv->remove_button;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp23_, _ ("Remove selected layout"));
	_tmp24_ = self->priv->remove_button;
	g_signal_connect_object (_tmp24_, "clicked", (GCallback) ___lambda9__gtk_button_clicked, self, 0);
	_tmp25_ = self->priv->remove_button;
	gtk_box_pack_start (controls, (GtkWidget*) _tmp25_, FALSE, FALSE, (guint) 0);
	_tmp26_ = settings_window_create_icon_button (self, "go-up", _ ("Up"));
	_g_object_unref0 (self->priv->up_button);
	self->priv->up_button = _tmp26_;
	_tmp27_ = self->priv->up_button;
	gtk_widget_set_halign ((GtkWidget*) _tmp27_, GTK_ALIGN_START);
	_tmp28_ = self->priv->up_button;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp28_, _ ("Move selected layout up in priority"));
	_tmp29_ = self->priv->up_button;
	g_signal_connect_object (_tmp29_, "clicked", (GCallback) ___lambda10__gtk_button_clicked, self, 0);
	_tmp30_ = self->priv->up_button;
	gtk_box_pack_start (controls, (GtkWidget*) _tmp30_, FALSE, FALSE, (guint) 0);
	_tmp31_ = settings_window_create_icon_button (self, "go-down", _ ("Down"));
	_g_object_unref0 (self->priv->down_button);
	self->priv->down_button = _tmp31_;
	_tmp32_ = self->priv->down_button;
	gtk_widget_set_halign ((GtkWidget*) _tmp32_, GTK_ALIGN_START);
	_tmp33_ = self->priv->down_button;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp33_, _ ("Move selected layout down in priority"));
	_tmp34_ = self->priv->down_button;
	g_signal_connect_object (_tmp34_, "clicked", (GCallback) ___lambda11__gtk_button_clicked, self, 0);
	_tmp35_ = self->priv->down_button;
	gtk_box_pack_start (controls, (GtkWidget*) _tmp35_, FALSE, FALSE, (guint) 0);
	_tmp36_ = self->priv->remove_button;
	_tmp37_ = self->priv->up_button;
	_tmp38_ = self->priv->down_button;
	settings_window_set_uniform_button_width (self, _data1_->add_button, _tmp36_, _tmp37_, _tmp38_);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda12__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	result = (GtkWidget*) frame;
	_g_object_unref0 (controls);
	_g_object_unref0 (scroll);
	_g_object_unref0 (selection);
	_g_object_unref0 (column);
	_g_object_unref0 (renderer);
	_g_object_unref0 (flag_column);
	_g_object_unref0 (flag_renderer);
	_g_object_unref0 (grid);
	_g_object_unref0 (title_label);
	block1_data_unref (_data1_);
	_data1_ = NULL;
	return result;
}

static void
__lambda13_ (SettingsWindow* self)
{
	settings_window_update_custom_option_state (self);
	settings_window_update_preview (self);
}

static void
___lambda13__gtk_combo_box_changed (GtkComboBox* _sender,
                                    gpointer self)
{
	__lambda13_ ((SettingsWindow*) self);
}

static void
__lambda14_ (SettingsWindow* self)
{
	settings_window_update_preview (self);
}

static void
___lambda14__gtk_editable_changed (GtkEditable* _sender,
                                   gpointer self)
{
	__lambda14_ ((SettingsWindow*) self);
}

static GtkWidget*
settings_window_build_switching_frame (SettingsWindow* self)
{
	GtkFrame* frame = NULL;
	GtkFrame* _tmp0_;
	GtkLabel* title_label = NULL;
	GtkLabel* _tmp1_;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp2_;
	GtkLabel* shortcut_title = NULL;
	GtkLabel* _tmp3_;
	GtkComboBoxText* _tmp4_;
	GtkComboBoxText* _tmp5_;
	GtkComboBoxText* _tmp6_;
	GtkComboBoxText* _tmp7_;
	GtkComboBoxText* _tmp8_;
	GtkComboBoxText* _tmp9_;
	GtkComboBoxText* _tmp10_;
	GtkComboBoxText* _tmp11_;
	GtkComboBoxText* _tmp12_;
	GtkComboBoxText* _tmp13_;
	GtkComboBoxText* _tmp14_;
	GtkComboBoxText* _tmp15_;
	GtkLabel* custom_title = NULL;
	GtkLabel* _tmp16_;
	GtkEntry* _tmp17_;
	GtkEntry* _tmp18_;
	GtkEntry* _tmp19_;
	GtkComboBoxText* _tmp20_;
	GtkEntry* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	GtkLabel* _tmp24_;
	GtkLabel* _tmp25_;
	GtkLabel* _tmp26_;
	GtkLabel* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	GtkLabel* _tmp30_;
	GtkLabel* _tmp31_;
	GtkLabel* _tmp32_;
	GtkLabel* _tmp33_;
	GtkLabel* _tmp34_;
	GtkLabel* _tmp35_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = (GtkFrame*) gtk_frame_new (NULL);
	g_object_ref_sink (_tmp0_);
	frame = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new (_ ("Switching"));
	g_object_ref_sink (_tmp1_);
	title_label = _tmp1_;
	gtk_widget_set_halign ((GtkWidget*) title_label, GTK_ALIGN_START);
	gtk_frame_set_label_widget (frame, (GtkWidget*) title_label);
	_tmp2_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp2_);
	grid = _tmp2_;
	gtk_widget_set_margin_top ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_bottom ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_start ((GtkWidget*) grid, 8);
	gtk_widget_set_margin_end ((GtkWidget*) grid, 8);
	gtk_grid_set_row_spacing (grid, 6);
	gtk_grid_set_column_spacing (grid, 8);
	gtk_container_add ((GtkContainer*) frame, (GtkWidget*) grid);
	_tmp3_ = (GtkLabel*) gtk_label_new (_ ("Shortcut:"));
	g_object_ref_sink (_tmp3_);
	shortcut_title = _tmp3_;
	gtk_widget_set_halign ((GtkWidget*) shortcut_title, GTK_ALIGN_START);
	gtk_widget_set_tooltip_text ((GtkWidget*) shortcut_title, _ ("Keyboard shortcut to switch between layouts"));
	_tmp4_ = (GtkComboBoxText*) gtk_combo_box_text_new ();
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->shortcut_combo);
	self->priv->shortcut_combo = _tmp4_;
	_tmp5_ = self->priv->shortcut_combo;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp5_, _ ("Select keyboard layout switching shortcut"));
	_tmp6_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp6_, "grp:alt_shift_toggle", _ ("Alt+Shift"));
	_tmp7_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp7_, "grp:shifts_toggle", _ ("Both Shifts"));
	_tmp8_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp8_, "grp:ctrl_shift_toggle", _ ("Ctrl+Shift"));
	_tmp9_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp9_, "grp:caps_toggle", _ ("Caps Lock"));
	_tmp10_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp10_, "grp:win_space_toggle", _ ("Win+Space"));
	_tmp11_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp11_, "grp:menu_toggle", _ ("Menu key"));
	_tmp12_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp12_, "grp:lwin_toggle", _ ("Left Win"));
	_tmp13_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp13_, "grp:ralt_toggle", _ ("Right Alt"));
	_tmp14_ = self->priv->shortcut_combo;
	gtk_combo_box_text_append (_tmp14_, "", _ ("User-defined"));
	_tmp15_ = self->priv->shortcut_combo;
	g_signal_connect_object ((GtkComboBox*) _tmp15_, "changed", (GCallback) ___lambda13__gtk_combo_box_changed, self, 0);
	_tmp16_ = (GtkLabel*) gtk_label_new (_ ("Custom XKB option:"));
	g_object_ref_sink (_tmp16_);
	custom_title = _tmp16_;
	gtk_widget_set_halign ((GtkWidget*) custom_title, GTK_ALIGN_START);
	gtk_widget_set_tooltip_text ((GtkWidget*) custom_title, _ ("Custom XKB option for layout switching"));
	_tmp17_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp17_);
	_g_object_unref0 (self->priv->custom_option_entry);
	self->priv->custom_option_entry = _tmp17_;
	_tmp18_ = self->priv->custom_option_entry;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp18_, _ ("Custom XKB options (e.g., grp:ctrl_shift_toggle)"));
	_tmp19_ = self->priv->custom_option_entry;
	g_signal_connect_object ((GtkEditable*) _tmp19_, "changed", (GCallback) ___lambda14__gtk_editable_changed, self, 0);
	gtk_grid_attach (grid, (GtkWidget*) shortcut_title, 0, 0, 1, 1);
	_tmp20_ = self->priv->shortcut_combo;
	gtk_grid_attach (grid, (GtkWidget*) _tmp20_, 1, 0, 1, 1);
	gtk_grid_attach (grid, (GtkWidget*) custom_title, 0, 1, 1, 1);
	_tmp21_ = self->priv->custom_option_entry;
	gtk_grid_attach (grid, (GtkWidget*) _tmp21_, 1, 1, 1, 1);
	_tmp22_ = g_strconcat (_ ("XKB_DEFAULT_LAYOUT="), "us,ru", NULL);
	_tmp23_ = _tmp22_;
	_tmp24_ = (GtkLabel*) gtk_label_new (_tmp23_);
	g_object_ref_sink (_tmp24_);
	_g_object_unref0 (self->priv->preview_layout_label);
	self->priv->preview_layout_label = _tmp24_;
	_g_free0 (_tmp23_);
	_tmp25_ = self->priv->preview_layout_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp25_, GTK_ALIGN_START);
	_tmp26_ = self->priv->preview_layout_label;
	gtk_label_set_selectable (_tmp26_, TRUE);
	_tmp27_ = self->priv->preview_layout_label;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp27_, _ ("Preview of XKB_DEFAULT_LAYOUT environment variable"));
	_tmp28_ = g_strconcat (_ ("XKB_DEFAULT_OPTIONS="), "grp:alt_shift_toggle", NULL);
	_tmp29_ = _tmp28_;
	_tmp30_ = (GtkLabel*) gtk_label_new (_tmp29_);
	g_object_ref_sink (_tmp30_);
	_g_object_unref0 (self->priv->preview_option_label);
	self->priv->preview_option_label = _tmp30_;
	_g_free0 (_tmp29_);
	_tmp31_ = self->priv->preview_option_label;
	gtk_widget_set_halign ((GtkWidget*) _tmp31_, GTK_ALIGN_START);
	_tmp32_ = self->priv->preview_option_label;
	gtk_label_set_selectable (_tmp32_, TRUE);
	_tmp33_ = self->priv->preview_option_label;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp33_, _ ("Preview of XKB_DEFAULT_OPTIONS environment variable"));
	_tmp34_ = self->priv->preview_layout_label;
	gtk_grid_attach (grid, (GtkWidget*) _tmp34_, 0, 2, 2, 1);
	_tmp35_ = self->priv->preview_option_label;
	gtk_grid_attach (grid, (GtkWidget*) _tmp35_, 0, 3, 2, 1);
	result = (GtkWidget*) frame;
	_g_object_unref0 (custom_title);
	_g_object_unref0 (shortcut_title);
	_g_object_unref0 (grid);
	_g_object_unref0 (title_label);
	return result;
}

static gchar*
settings_window_build_environment_path (SettingsWindow* self)
{
	gchar* config_home = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_getenv ("XDG_CONFIG_HOME");
	_tmp1_ = g_strdup (_tmp0_);
	config_home = _tmp1_;
	_tmp3_ = config_home;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp4_;
		_tmp4_ = config_home;
		_tmp2_ = g_strcmp0 (_tmp4_, "") == 0;
	}
	if (_tmp2_) {
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = g_get_home_dir ();
		_tmp6_ = g_build_filename (_tmp5_, ".config", NULL);
		_g_free0 (config_home);
		config_home = _tmp6_;
	}
	_tmp7_ = config_home;
	_tmp8_ = g_build_filename (_tmp7_, "labwc", "environment", NULL);
	result = _tmp8_;
	_g_free0 (config_home);
	return result;
}

static GdkPixbuf*
settings_window_load_flag_pixbuf (const gchar* flag_dir_path,
                                  const gchar* layout_code,
                                  gint size)
{
	gchar* icon_code = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar** _tmp3_;
	GError* _inner_error0_ = NULL;
	GdkPixbuf* result;
	g_return_val_if_fail (flag_dir_path != NULL, NULL);
	g_return_val_if_fail (layout_code != NULL, NULL);
	_tmp0_ = flag_utils_get_layout_icon_code (layout_code);
	icon_code = _tmp0_;
	_tmp1_ = g_strdup (".svg");
	_tmp2_ = g_strdup (".png");
	_tmp3_ = g_new0 (gchar*, 2 + 1);
	_tmp3_[0] = _tmp1_;
	_tmp3_[1] = _tmp2_;
	{
		gchar** ext_collection = NULL;
		gint ext_collection_length1 = 0;
		gint _ext_collection_size_ = 0;
		gint ext_it = 0;
		ext_collection = _tmp3_;
		ext_collection_length1 = 2;
		for (ext_it = 0; ext_it < ext_collection_length1; ext_it = ext_it + 1) {
			gchar* _tmp4_;
			gchar* ext = NULL;
			_tmp4_ = g_strdup (ext_collection[ext_it]);
			ext = _tmp4_;
			{
				gchar* path = NULL;
				const gchar* _tmp5_;
				const gchar* _tmp6_;
				gchar* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				const gchar* _tmp11_;
				_tmp5_ = icon_code;
				_tmp6_ = ext;
				_tmp7_ = g_strconcat (_tmp5_, _tmp6_, NULL);
				_tmp8_ = _tmp7_;
				_tmp9_ = g_build_filename (flag_dir_path, _tmp8_, NULL);
				_tmp10_ = _tmp9_;
				_g_free0 (_tmp8_);
				path = _tmp10_;
				_tmp11_ = path;
				if (g_file_test (_tmp11_, G_FILE_TEST_EXISTS)) {
					{
						GdkPixbuf* _tmp12_ = NULL;
						const gchar* _tmp13_;
						GdkPixbuf* _tmp14_;
						GdkPixbuf* _tmp15_;
						_tmp13_ = path;
						_tmp14_ = gdk_pixbuf_new_from_file_at_scale (_tmp13_, size, size, TRUE, &_inner_error0_);
						_tmp12_ = _tmp14_;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							goto __catch0_g_error;
						}
						_tmp15_ = _tmp12_;
						_tmp12_ = NULL;
						result = _tmp15_;
						_g_object_unref0 (_tmp12_);
						_g_free0 (path);
						_g_free0 (ext);
						ext_collection = (_vala_array_free (ext_collection, ext_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (icon_code);
						return result;
					}
					goto __finally0;
					__catch0_g_error:
					{
						GError* e = NULL;
						const gchar* _tmp16_;
						GError* _tmp17_;
						const gchar* _tmp18_;
						e = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp16_ = path;
						_tmp17_ = e;
						_tmp18_ = _tmp17_->message;
						g_warning ("settings_window.vala:335: load_flag_pixbuf %s: %s", _tmp16_, _tmp18_);
						_g_error_free0 (e);
					}
					__finally0:
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (path);
						_g_free0 (ext);
						ext_collection = (_vala_array_free (ext_collection, ext_collection_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (icon_code);
						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;
					}
				}
				_g_free0 (path);
				_g_free0 (ext);
			}
		}
		ext_collection = (_vala_array_free (ext_collection, ext_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = NULL;
	_g_free0 (icon_code);
	return result;
}

static void
settings_window_ensure_environment_file (SettingsWindow* self)
{
	gchar* labwc_dir = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->env_file_path;
	_tmp1_ = g_path_get_dirname (_tmp0_);
	labwc_dir = _tmp1_;
	_tmp2_ = labwc_dir;
	g_mkdir_with_parents (_tmp2_, 0755);
	_tmp3_ = self->priv->env_file_path;
	if (!g_file_test (_tmp3_, G_FILE_TEST_EXISTS)) {
		gchar* defaults = NULL;
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("XKB_DEFAULT_LAYOUT=us,ru\nXKB_DEFAULT_OPTIONS=grp:alt_shift_toggle\n");
		defaults = _tmp4_;
		{
			const gchar* _tmp5_;
			const gchar* _tmp6_;
			_tmp5_ = self->priv->env_file_path;
			_tmp6_ = defaults;
			g_file_set_contents (_tmp5_, _tmp6_, (gssize) -1, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp7_;
			const gchar* _tmp8_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp7_ = e;
			_tmp8_ = _tmp7_->message;
			settings_window_show_error_dialog (self, _ ("Failed to initialize environment file"), _tmp8_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (defaults);
			_g_free0 (labwc_dir);
			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;
		}
		_g_free0 (defaults);
	}
	_g_free0 (labwc_dir);
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

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

static gchar*
settings_window_read_env_key (SettingsWindow* self,
                              const gchar* key)
{
	gchar* content = NULL;
	const gchar* _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gchar* _tmp21_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	{
		gboolean _tmp0_ = FALSE;
		const gchar* _tmp1_;
		gchar* _tmp2_ = NULL;
		gboolean _tmp3_;
		_tmp1_ = self->priv->env_file_path;
		_tmp3_ = g_file_get_contents (_tmp1_, &_tmp2_, NULL, &_inner_error0_);
		_g_free0 (content);
		content = _tmp2_;
		_tmp0_ = _tmp3_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (!_tmp0_) {
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("");
			result = _tmp4_;
			_g_free0 (content);
			return result;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		gchar* _tmp5_;
		g_clear_error (&_inner_error0_);
		_tmp5_ = g_strdup ("");
		result = _tmp5_;
		_g_free0 (content);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (content);
		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;
	}
	_tmp6_ = content;
	_tmp8_ = _tmp7_ = g_strsplit (_tmp6_, "\n", 0);
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp8_;
		line_collection_length1 = _vala_array_length (_tmp7_);
		for (line_it = 0; line_it < line_collection_length1; line_it = line_it + 1) {
			gchar* _tmp9_;
			gchar* line = NULL;
			_tmp9_ = g_strdup (line_collection[line_it]);
			line = _tmp9_;
			{
				const gchar* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				gboolean _tmp13_;
				_tmp10_ = line;
				_tmp11_ = g_strconcat (key, "=", NULL);
				_tmp12_ = _tmp11_;
				_tmp13_ = g_str_has_prefix (_tmp10_, _tmp12_);
				_g_free0 (_tmp12_);
				if (_tmp13_) {
					const gchar* _tmp14_;
					gchar* _tmp15_;
					gchar* _tmp16_;
					gint _tmp17_;
					gint _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					_tmp14_ = line;
					_tmp15_ = g_strconcat (key, "=", NULL);
					_tmp16_ = _tmp15_;
					_tmp17_ = strlen (_tmp16_);
					_tmp18_ = _tmp17_;
					_tmp19_ = string_substring (_tmp14_, (glong) _tmp18_, (glong) -1);
					_tmp20_ = _tmp19_;
					_g_free0 (_tmp16_);
					result = _tmp20_;
					_g_free0 (line);
					line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (content);
					return result;
				}
				_g_free0 (line);
			}
		}
		line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp21_ = g_strdup ("");
	result = _tmp21_;
	_g_free0 (content);
	return result;
}

static void
settings_window_load_environment (SettingsWindow* self)
{
	gchar* layouts = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* option = NULL;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	settings_window_ensure_environment_file (self);
	_tmp0_ = settings_window_read_env_key (self, "XKB_DEFAULT_LAYOUT");
	layouts = _tmp0_;
	_tmp1_ = layouts;
	if (g_strcmp0 (_tmp1_, "") == 0) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("us,ru");
		_g_free0 (layouts);
		layouts = _tmp2_;
	}
	_tmp3_ = settings_window_read_env_key (self, "XKB_DEFAULT_OPTIONS");
	option = _tmp3_;
	_tmp4_ = option;
	if (g_strcmp0 (_tmp4_, "") == 0) {
		gchar* _tmp5_;
		_tmp5_ = g_strdup ("grp:alt_shift_toggle");
		_g_free0 (option);
		option = _tmp5_;
	}
	_tmp6_ = layouts;
	settings_window_populate_layout_store (self, _tmp6_);
	_tmp7_ = option;
	settings_window_apply_option_to_controls (self, _tmp7_);
	_g_free0 (option);
	_g_free0 (layouts);
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

static void
settings_window_populate_layout_store (SettingsWindow* self,
                                       const gchar* layouts_csv)
{
	GtkListStore* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	GtkListStore* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (layouts_csv != NULL);
	_tmp0_ = self->priv->layout_store;
	gtk_list_store_clear (_tmp0_);
	_tmp2_ = _tmp1_ = g_strsplit (layouts_csv, ",", 0);
	{
		gchar** raw_collection = NULL;
		gint raw_collection_length1 = 0;
		gint _raw_collection_size_ = 0;
		gint raw_it = 0;
		raw_collection = _tmp2_;
		raw_collection_length1 = _vala_array_length (_tmp1_);
		for (raw_it = 0; raw_it < raw_collection_length1; raw_it = raw_it + 1) {
			gchar* _tmp3_;
			gchar* raw = NULL;
			_tmp3_ = g_strdup (raw_collection[raw_it]);
			raw = _tmp3_;
			{
				gchar* code = NULL;
				const gchar* _tmp4_;
				gchar* _tmp5_;
				const gchar* _tmp6_;
				GtkTreeIter iter = {0};
				GtkListStore* _tmp7_;
				GtkTreeIter _tmp8_ = {0};
				GtkListStore* _tmp9_;
				GtkTreeIter _tmp10_;
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				GdkPixbuf* _tmp13_;
				GdkPixbuf* _tmp14_;
				const gchar* _tmp15_;
				_tmp4_ = raw;
				_tmp5_ = string_strip (_tmp4_);
				code = _tmp5_;
				_tmp6_ = code;
				if (g_strcmp0 (_tmp6_, "") == 0) {
					_g_free0 (code);
					_g_free0 (raw);
					continue;
				}
				_tmp7_ = self->priv->layout_store;
				gtk_list_store_append (_tmp7_, &_tmp8_);
				iter = _tmp8_;
				_tmp9_ = self->priv->layout_store;
				_tmp10_ = iter;
				_tmp11_ = self->priv->flag_dir_path;
				_tmp12_ = code;
				_tmp13_ = settings_window_load_flag_pixbuf (_tmp11_, _tmp12_, 32);
				_tmp14_ = _tmp13_;
				_tmp15_ = code;
				gtk_list_store_set (_tmp9_, &_tmp10_, 0, _tmp14_, 1, _tmp15_, -1);
				_g_object_unref0 (_tmp14_);
				_g_free0 (code);
				_g_free0 (raw);
			}
		}
		raw_collection = (_vala_array_free (raw_collection, raw_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp16_ = self->priv->layout_store;
	if (gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp16_, NULL) > 0) {
		GtkTreeIter first = {0};
		GtkListStore* _tmp17_;
		GtkTreeIter _tmp18_ = {0};
		gboolean _tmp19_;
		_tmp17_ = self->priv->layout_store;
		_tmp19_ = gtk_tree_model_iter_nth_child ((GtkTreeModel*) _tmp17_, &_tmp18_, NULL, 0);
		first = _tmp18_;
		if (_tmp19_) {
			GtkTreeView* _tmp20_;
			GtkTreeSelection* _tmp21_;
			GtkTreeIter _tmp22_;
			_tmp20_ = self->priv->layout_view;
			_tmp21_ = gtk_tree_view_get_selection (_tmp20_);
			_tmp22_ = first;
			gtk_tree_selection_select_iter (_tmp21_, &_tmp22_);
		}
	}
}

static gchar*
settings_window_shortcut_label_from_option (SettingsWindow* self,
                                            const gchar* option)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (option != NULL, NULL);
	_tmp0_ = option;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("grp:alt_shift_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp3_;
				_tmp3_ = g_strdup (_ ("Alt+Shift"));
				result = _tmp3_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("grp:shift_caps_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp4_;
				_tmp4_ = g_strdup (_ ("Shift+Caps Lock"));
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("grp:ctrl_shift_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp5_;
				_tmp5_ = g_strdup (_ ("Ctrl+Shift"));
				result = _tmp5_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("grp:caps_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp6_;
				_tmp6_ = g_strdup (_ ("Caps Lock"));
				result = _tmp6_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("grp:win_space_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp7_;
				_tmp7_ = g_strdup (_ ("Win+Space"));
				result = _tmp7_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("grp:menu_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp8_;
				_tmp8_ = g_strdup (_ ("Menu"));
				result = _tmp8_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("grp:ralt_toggle")))) {
		switch (0) {
			default:
			{
				gchar* _tmp9_;
				_tmp9_ = g_strdup (_ ("Right Alt"));
				result = _tmp9_;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				gchar* _tmp10_;
				_tmp10_ = g_strdup (_ ("User-defined"));
				result = _tmp10_;
				return result;
			}
		}
	}
}

static gchar*
settings_window_option_from_shortcut_label (SettingsWindow* self,
                                            const gchar* shortcut_label)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (shortcut_label != NULL, NULL);
	_tmp0_ = shortcut_label;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("Alt+Shift")))) {
		switch (0) {
			default:
			{
				gchar* _tmp3_;
				_tmp3_ = g_strdup ("grp:alt_shift_toggle");
				result = _tmp3_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("Shift+Caps Lock")))) {
		switch (0) {
			default:
			{
				gchar* _tmp4_;
				_tmp4_ = g_strdup ("grp:shift_caps_toggle");
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("Ctrl+Shift")))) {
		switch (0) {
			default:
			{
				gchar* _tmp5_;
				_tmp5_ = g_strdup ("grp:ctrl_shift_toggle");
				result = _tmp5_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("Caps Lock")))) {
		switch (0) {
			default:
			{
				gchar* _tmp6_;
				_tmp6_ = g_strdup ("grp:caps_toggle");
				result = _tmp6_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("Win+Space")))) {
		switch (0) {
			default:
			{
				gchar* _tmp7_;
				_tmp7_ = g_strdup ("grp:win_space_toggle");
				result = _tmp7_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("Menu")))) {
		switch (0) {
			default:
			{
				gchar* _tmp8_;
				_tmp8_ = g_strdup ("grp:menu_toggle");
				result = _tmp8_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("Right Alt")))) {
		switch (0) {
			default:
			{
				gchar* _tmp9_;
				_tmp9_ = g_strdup ("grp:ralt_toggle");
				result = _tmp9_;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				gchar* _tmp10_;
				_tmp10_ = g_strdup ("");
				result = _tmp10_;
				return result;
			}
		}
	}
}

static void
settings_window_apply_option_to_controls (SettingsWindow* self,
                                          const gchar* option)
{
	gchar* current_grp_option = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	GtkComboBoxText* _tmp8_;
	const gchar* _tmp9_;
	GtkComboBoxText* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	GtkComboBoxText* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (option != NULL);
	_tmp0_ = g_strdup ("");
	current_grp_option = _tmp0_;
	_tmp2_ = _tmp1_ = g_strsplit (option, ",", 0);
	{
		gchar** p_collection = NULL;
		gint p_collection_length1 = 0;
		gint _p_collection_size_ = 0;
		gint p_it = 0;
		p_collection = _tmp2_;
		p_collection_length1 = _vala_array_length (_tmp1_);
		for (p_it = 0; p_it < p_collection_length1; p_it = p_it + 1) {
			const gchar* p = NULL;
			p = p_collection[p_it];
			{
				gchar* t = NULL;
				const gchar* _tmp3_;
				gchar* _tmp4_;
				const gchar* _tmp5_;
				_tmp3_ = p;
				_tmp4_ = string_strip (_tmp3_);
				t = _tmp4_;
				_tmp5_ = t;
				if (g_str_has_prefix (_tmp5_, "grp:")) {
					const gchar* _tmp6_;
					gchar* _tmp7_;
					_tmp6_ = t;
					_tmp7_ = g_strdup (_tmp6_);
					_g_free0 (current_grp_option);
					current_grp_option = _tmp7_;
					_g_free0 (t);
					break;
				}
				_g_free0 (t);
			}
		}
		p_collection = (_vala_array_free (p_collection, p_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp8_ = self->priv->shortcut_combo;
	_tmp9_ = current_grp_option;
	gtk_combo_box_set_active_id ((GtkComboBox*) _tmp8_, _tmp9_);
	_tmp10_ = self->priv->shortcut_combo;
	_tmp11_ = gtk_combo_box_get_active_id ((GtkComboBox*) _tmp10_);
	_tmp12_ = _tmp11_;
	if (_tmp12_ == NULL) {
		GtkComboBoxText* _tmp13_;
		_tmp13_ = self->priv->shortcut_combo;
		gtk_combo_box_set_active_id ((GtkComboBox*) _tmp13_, "");
	}
	_tmp14_ = self->priv->shortcut_combo;
	_tmp15_ = gtk_combo_box_get_active_id ((GtkComboBox*) _tmp14_);
	_tmp16_ = _tmp15_;
	if (g_strcmp0 (_tmp16_, "") == 0) {
		GtkEntry* _tmp17_;
		_tmp17_ = self->priv->custom_option_entry;
		gtk_entry_set_text (_tmp17_, option);
	} else {
		GtkEntry* _tmp18_;
		_tmp18_ = self->priv->custom_option_entry;
		gtk_entry_set_text (_tmp18_, "");
	}
	_g_free0 (current_grp_option);
}

static void
settings_window_update_custom_option_state (SettingsWindow* self)
{
	GtkEntry* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->custom_option_entry;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, TRUE);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static void
_vala_gchar_free_function_content_of (gpointer data)
{
	gchar* self;
	self = *((gchar**) data);
	_g_free0_ (self);
}

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;
	}
}

static gchar*
settings_window_merge_grp_option (SettingsWindow* self,
                                  const gchar* existing_options,
                                  const gchar* new_grp)
{
	GArray* parts = NULL;
	GArray* _tmp0_;
	GArray* _tmp13_;
	gpointer* _tmp14_;
	gint _tmp14__length1;
	gchar* _tmp15_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (existing_options != NULL, NULL);
	g_return_val_if_fail (new_grp != NULL, NULL);
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (gchar*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_gchar_free_function_content_of);
	parts = _tmp0_;
	if (g_strcmp0 (existing_options, "") != 0) {
		gchar** _tmp1_;
		gchar** _tmp2_;
		_tmp2_ = _tmp1_ = g_strsplit (existing_options, ",", 0);
		{
			gchar** p_collection = NULL;
			gint p_collection_length1 = 0;
			gint _p_collection_size_ = 0;
			gint p_it = 0;
			p_collection = _tmp2_;
			p_collection_length1 = _vala_array_length (_tmp1_);
			for (p_it = 0; p_it < p_collection_length1; p_it = p_it + 1) {
				const gchar* p = NULL;
				p = p_collection[p_it];
				{
					gchar* t = NULL;
					const gchar* _tmp3_;
					gchar* _tmp4_;
					gboolean _tmp5_ = FALSE;
					const gchar* _tmp6_;
					_tmp3_ = p;
					_tmp4_ = string_strip (_tmp3_);
					t = _tmp4_;
					_tmp6_ = t;
					if (g_strcmp0 (_tmp6_, "") != 0) {
						const gchar* _tmp7_;
						_tmp7_ = t;
						_tmp5_ = !g_str_has_prefix (_tmp7_, "grp:");
					} else {
						_tmp5_ = FALSE;
					}
					if (_tmp5_) {
						GArray* _tmp8_;
						const gchar* _tmp9_;
						gchar* _tmp10_;
						_tmp8_ = parts;
						_tmp9_ = t;
						_tmp10_ = g_strdup (_tmp9_);
						g_array_append_val (_tmp8_, _tmp10_);
					}
					_g_free0 (t);
				}
			}
			p_collection = (_vala_array_free (p_collection, p_collection_length1, (GDestroyNotify) g_free), NULL);
		}
	}
	if (g_strcmp0 (new_grp, "") != 0) {
		GArray* _tmp11_;
		gchar* _tmp12_;
		_tmp11_ = parts;
		_tmp12_ = g_strdup (new_grp);
		g_array_append_val (_tmp11_, _tmp12_);
	}
	_tmp13_ = parts;
	_tmp14_ = _tmp13_->data;
	_tmp14__length1 = _tmp13_->len;
	_tmp15_ = _vala_g_strjoinv (",", _tmp14_, (gint) _tmp14__length1);
	result = _tmp15_;
	_g_array_unref0 (parts);
	return result;
}

static gchar*
settings_window_collect_layouts_csv (SettingsWindow* self)
{
	GString* builder = NULL;
	GString* _tmp0_;
	GtkTreeIter iter = {0};
	gboolean valid = FALSE;
	GtkListStore* _tmp1_;
	GtkTreeIter _tmp2_ = {0};
	gboolean _tmp3_;
	gboolean first = FALSE;
	GString* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	_tmp1_ = self->priv->layout_store;
	_tmp3_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp1_, &_tmp2_);
	iter = _tmp2_;
	valid = _tmp3_;
	first = TRUE;
	while (TRUE) {
		gchar* code = NULL;
		GtkListStore* _tmp4_;
		GtkTreeIter _tmp5_;
		gchar* _tmp6_ = NULL;
		GString* _tmp8_;
		const gchar* _tmp9_;
		GtkListStore* _tmp10_;
		gboolean _tmp11_;
		if (!valid) {
			break;
		}
		_tmp4_ = self->priv->layout_store;
		_tmp5_ = iter;
		gtk_tree_model_get ((GtkTreeModel*) _tmp4_, &_tmp5_, 1, &_tmp6_, -1);
		_g_free0 (code);
		code = _tmp6_;
		if (!first) {
			GString* _tmp7_;
			_tmp7_ = builder;
			g_string_append (_tmp7_, ",");
		}
		_tmp8_ = builder;
		_tmp9_ = code;
		g_string_append (_tmp8_, _tmp9_);
		first = FALSE;
		_tmp10_ = self->priv->layout_store;
		_tmp11_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp10_, &iter);
		valid = _tmp11_;
		_g_free0 (code);
	}
	_tmp12_ = builder;
	_tmp13_ = _tmp12_->str;
	_tmp14_ = g_strdup (_tmp13_);
	result = _tmp14_;
	_g_string_free0 (builder);
	return result;
}

static gchar*
settings_window_get_effective_option (SettingsWindow* self)
{
	const gchar* _tmp0_ = NULL;
	GtkComboBoxText* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* selected = NULL;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gchar* custom = NULL;
	GtkEntry* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->shortcut_combo;
	_tmp2_ = gtk_combo_box_get_active_id ((GtkComboBox*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp0_ = _tmp3_;
	if (_tmp0_ == NULL) {
		_tmp0_ = "grp:alt_shift_toggle";
	}
	_tmp4_ = g_strdup (_tmp0_);
	selected = _tmp4_;
	_tmp5_ = selected;
	if (g_strcmp0 (_tmp5_, "") != 0) {
		result = selected;
		return result;
	}
	_tmp6_ = self->priv->custom_option_entry;
	_tmp7_ = gtk_entry_get_text (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = string_strip (_tmp8_);
	custom = _tmp9_;
	_tmp10_ = custom;
	if (g_strcmp0 (_tmp10_, "") == 0) {
		gchar* _tmp11_;
		_tmp11_ = g_strdup ("");
		result = _tmp11_;
		_g_free0 (custom);
		_g_free0 (selected);
		return result;
	}
	_tmp12_ = custom;
	if (g_str_has_prefix (_tmp12_, "grp:")) {
		result = custom;
		_g_free0 (selected);
		return result;
	}
	_tmp13_ = custom;
	_tmp14_ = g_strconcat ("grp:", _tmp13_, NULL);
	result = _tmp14_;
	_g_free0 (custom);
	_g_free0 (selected);
	return result;
}

static void
settings_window_update_preview (SettingsWindow* self)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GtkLabel* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->preview_layout_label;
	_tmp1_ = settings_window_collect_layouts_csv (self);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_ ("XKB_DEFAULT_LAYOUT="), _tmp2_, NULL);
	_tmp4_ = _tmp3_;
	gtk_label_set_label (_tmp0_, _tmp4_);
	_g_free0 (_tmp4_);
	_g_free0 (_tmp2_);
	_tmp5_ = self->priv->preview_option_label;
	_tmp6_ = settings_window_get_effective_option (self);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strconcat (_ ("XKB_DEFAULT_OPTIONS="), _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	gtk_label_set_label (_tmp5_, _tmp9_);
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
}

static Block2Data*
block2_data_ref (Block2Data* _data2_)
{
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}

static void
block2_data_unref (void * _userdata_)
{
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		SettingsWindow* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->tree_view);
		_g_object_unref0 (_data2_->filter_model);
		_g_object_unref0 (_data2_->search_entry);
		_g_object_unref0 (_data2_->dialog);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static gboolean
__lambda6_ (Block2Data* _data2_,
            GtkTreeModel* model,
            GtkTreeIter* iter)
{
	SettingsWindow* self;
	gchar* text = NULL;
	GtkSearchEntry* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	const gchar* _tmp4_;
	GtkTreeIter _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gboolean _tmp9_;
	gboolean result;
	self = _data2_->self;
	g_return_val_if_fail (model != NULL, FALSE);
	g_return_val_if_fail (iter != NULL, FALSE);
	_tmp0_ = _data2_->search_entry;
	_tmp1_ = gtk_entry_get_text ((GtkEntry*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	text = _tmp3_;
	_tmp4_ = text;
	if (g_strcmp0 (_tmp4_, "") == 0) {
		result = TRUE;
		_g_free0 (text);
		return result;
	}
	_tmp5_ = *iter;
	_tmp6_ = text;
	_tmp7_ = g_utf8_strdown (_tmp6_, (gssize) -1);
	_tmp8_ = _tmp7_;
	_tmp9_ = settings_window_catalog_row_matches (self, model, &_tmp5_, _tmp8_);
	_g_free0 (_tmp8_);
	result = _tmp9_;
	_g_free0 (text);
	return result;
}

static gboolean
___lambda6__gtk_tree_model_filter_visible_func (GtkTreeModel* model,
                                                GtkTreeIter* iter,
                                                gpointer self)
{
	gboolean result;
	result = __lambda6_ (self, model, iter);
	return result;
}

static void
__lambda7_ (Block2Data* _data2_,
            GtkTreePath* path,
            GtkTreeViewColumn* column)
{
	SettingsWindow* self;
	GtkDialog* _tmp0_;
	self = _data2_->self;
	g_return_if_fail (path != NULL);
	g_return_if_fail (column != NULL);
	_tmp0_ = _data2_->dialog;
	gtk_dialog_response (_tmp0_, (gint) GTK_RESPONSE_OK);
}

static void
___lambda7__gtk_tree_view_row_activated (GtkTreeView* _sender,
                                         GtkTreePath* path,
                                         GtkTreeViewColumn* column,
                                         gpointer self)
{
	__lambda7_ (self, path, column);
}

static void
__lambda8_ (Block2Data* _data2_)
{
	SettingsWindow* self;
	GtkTreeModelFilter* _tmp0_;
	GtkTreeView* _tmp1_;
	self = _data2_->self;
	_tmp0_ = _data2_->filter_model;
	gtk_tree_model_filter_refilter (_tmp0_);
	_tmp1_ = _data2_->tree_view;
	gtk_tree_view_collapse_all (_tmp1_);
}

static void
___lambda8__gtk_editable_changed (GtkEditable* _sender,
                                  gpointer self)
{
	__lambda8_ (self);
}

static void
settings_window_add_layout_dialog (SettingsWindow* self)
{
	Block2Data* _data2_;
	GtkTreeStore* catalog_store = NULL;
	GtkTreeStore* _tmp0_;
	GtkTreeStore* _tmp1_;
	GtkDialog* _tmp2_;
	GtkDialog* _tmp3_;
	GtkButton* cancel_button = NULL;
	GtkDialog* _tmp4_;
	GtkWidget* _tmp5_;
	GtkButton* _tmp6_;
	GtkButton* _tmp7_;
	GtkButton* add_dialog_button = NULL;
	GtkDialog* _tmp14_;
	GtkWidget* _tmp15_;
	GtkButton* _tmp16_;
	GtkButton* _tmp17_;
	GtkBox* content = NULL;
	GtkDialog* _tmp24_;
	GtkBox* _tmp25_;
	GtkBox* _tmp26_;
	GtkBox* box = NULL;
	GtkBox* _tmp27_;
	GtkBox* _tmp28_;
	GtkBox* _tmp29_;
	GtkBox* _tmp30_;
	GtkBox* _tmp31_;
	GtkBox* _tmp32_;
	GtkBox* _tmp33_;
	GtkLabel* hint = NULL;
	GtkLabel* _tmp34_;
	GtkLabel* _tmp35_;
	GtkLabel* _tmp36_;
	GtkBox* _tmp37_;
	GtkLabel* _tmp38_;
	GtkSearchEntry* _tmp39_;
	GtkSearchEntry* _tmp40_;
	GtkSearchEntry* _tmp41_;
	GtkBox* _tmp42_;
	GtkSearchEntry* _tmp43_;
	GtkTreeStore* _tmp44_;
	GtkTreeModelFilter* _tmp45_;
	GtkTreeModelFilter* _tmp46_;
	GtkTreeModelSort* sort_model = NULL;
	GtkTreeModelFilter* _tmp47_;
	GtkTreeModelSort* _tmp48_;
	GtkTreeModelSort* _tmp49_;
	GtkTreeView* _tmp50_;
	GtkTreeView* _tmp51_;
	GtkTreeView* _tmp52_;
	GtkTreeView* _tmp53_;
	GtkTreeSelection* _tmp54_;
	GtkTreeView* _tmp55_;
	GtkSearchEntry* _tmp56_;
	GtkCellRendererPixbuf* flag_renderer = NULL;
	GtkCellRendererPixbuf* _tmp57_;
	GtkTreeViewColumn* flag_column = NULL;
	GtkTreeViewColumn* _tmp58_;
	GtkTreeViewColumn* _tmp59_;
	GtkTreeViewColumn* _tmp60_;
	GtkCellRendererPixbuf* _tmp61_;
	GtkTreeViewColumn* _tmp62_;
	GtkCellRendererPixbuf* _tmp63_;
	GtkTreeView* _tmp64_;
	GtkTreeViewColumn* _tmp65_;
	GtkCellRendererText* code_renderer = NULL;
	GtkCellRendererText* _tmp66_;
	GtkTreeViewColumn* code_column = NULL;
	GtkTreeViewColumn* _tmp67_;
	GtkTreeViewColumn* _tmp68_;
	GtkTreeViewColumn* _tmp69_;
	GtkCellRendererText* _tmp70_;
	GtkTreeViewColumn* _tmp71_;
	GtkCellRendererText* _tmp72_;
	GtkTreeViewColumn* _tmp73_;
	GtkTreeView* _tmp74_;
	GtkTreeViewColumn* _tmp75_;
	GtkCellRendererText* desc_renderer = NULL;
	GtkCellRendererText* _tmp76_;
	GtkTreeViewColumn* desc_column = NULL;
	GtkTreeViewColumn* _tmp77_;
	GtkTreeViewColumn* _tmp78_;
	GtkTreeViewColumn* _tmp79_;
	GtkCellRendererText* _tmp80_;
	GtkTreeViewColumn* _tmp81_;
	GtkCellRendererText* _tmp82_;
	GtkTreeViewColumn* _tmp83_;
	GtkTreeView* _tmp84_;
	GtkTreeViewColumn* _tmp85_;
	GtkTreeView* _tmp86_;
	GtkTreeView* _tmp87_;
	GtkTreeModelSort* _tmp88_;
	GtkScrolledWindow* scroll = NULL;
	GtkScrolledWindow* _tmp89_;
	GtkScrolledWindow* _tmp90_;
	GtkScrolledWindow* _tmp91_;
	GtkTreeView* _tmp92_;
	GtkBox* _tmp93_;
	GtkScrolledWindow* _tmp94_;
	GtkLabel* manual_title = NULL;
	GtkLabel* _tmp95_;
	GtkLabel* _tmp96_;
	GtkLabel* _tmp97_;
	GtkBox* _tmp98_;
	GtkLabel* _tmp99_;
	GtkEntry* manual_entry = NULL;
	GtkEntry* _tmp100_;
	GtkEntry* _tmp101_;
	GtkEntry* _tmp102_;
	GtkBox* _tmp103_;
	GtkEntry* _tmp104_;
	GtkDialog* _tmp105_;
	GtkDialog* _tmp106_;
	GtkTreeView* _tmp107_;
	GtkSearchEntry* _tmp108_;
	GtkDialog* _tmp109_;
	GtkDialog* _tmp147_;
	g_return_if_fail (self != NULL);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_tmp0_ = settings_window_build_layout_catalog_store (self);
	catalog_store = _tmp0_;
	_tmp1_ = catalog_store;
	if (gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp1_, NULL) == 0) {
		settings_window_show_error_dialog (self, _ ("No layouts found"), _ ("Unable to read bundled keyboard layouts catalog"));
		_g_object_unref0 (catalog_store);
		block2_data_unref (_data2_);
		_data2_ = NULL;
		return;
	}
	_tmp2_ = (GtkDialog*) gtk_dialog_new_with_buttons (_ ("Add Layout"), (GtkWindow*) self, GTK_DIALOG_MODAL, _ ("Cancel"), GTK_RESPONSE_CANCEL, _ ("Add"), GTK_RESPONSE_OK, NULL);
	g_object_ref_sink (_tmp2_);
	_data2_->dialog = _tmp2_;
	_tmp3_ = _data2_->dialog;
	gtk_window_set_default_size ((GtkWindow*) _tmp3_, 640, 480);
	_tmp4_ = _data2_->dialog;
	_tmp5_ = gtk_dialog_get_widget_for_response (_tmp4_, (gint) GTK_RESPONSE_CANCEL);
	_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp5_, gtk_button_get_type ()) ? ((GtkButton*) _tmp5_) : NULL);
	cancel_button = _tmp6_;
	_tmp7_ = cancel_button;
	if (_tmp7_ != NULL) {
		GtkButton* _tmp8_;
		GtkButton* _tmp9_;
		GtkButton* _tmp10_;
		GtkImage* _tmp11_;
		GtkImage* _tmp12_;
		GtkButton* _tmp13_;
		_tmp8_ = cancel_button;
		gtk_button_set_label (_tmp8_, _ ("Cancel"));
		_tmp9_ = cancel_button;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp9_, _ ("Cancel and close dialog"));
		_tmp10_ = cancel_button;
		_tmp11_ = (GtkImage*) gtk_image_new_from_icon_name ("window-close", (GtkIconSize) GTK_ICON_SIZE_BUTTON);
		g_object_ref_sink (_tmp11_);
		_tmp12_ = _tmp11_;
		gtk_button_set_image (_tmp10_, (GtkWidget*) _tmp12_);
		_g_object_unref0 (_tmp12_);
		_tmp13_ = cancel_button;
		gtk_button_set_always_show_image (_tmp13_, TRUE);
	}
	_tmp14_ = _data2_->dialog;
	_tmp15_ = gtk_dialog_get_widget_for_response (_tmp14_, (gint) GTK_RESPONSE_OK);
	_tmp16_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp15_, gtk_button_get_type ()) ? ((GtkButton*) _tmp15_) : NULL);
	add_dialog_button = _tmp16_;
	_tmp17_ = add_dialog_button;
	if (_tmp17_ != NULL) {
		GtkButton* _tmp18_;
		GtkButton* _tmp19_;
		GtkButton* _tmp20_;
		GtkImage* _tmp21_;
		GtkImage* _tmp22_;
		GtkButton* _tmp23_;
		_tmp18_ = add_dialog_button;
		gtk_button_set_label (_tmp18_, _ ("Add"));
		_tmp19_ = add_dialog_button;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp19_, _ ("Add selected layout to the list"));
		_tmp20_ = add_dialog_button;
		_tmp21_ = (GtkImage*) gtk_image_new_from_icon_name ("list-add", (GtkIconSize) GTK_ICON_SIZE_BUTTON);
		g_object_ref_sink (_tmp21_);
		_tmp22_ = _tmp21_;
		gtk_button_set_image (_tmp20_, (GtkWidget*) _tmp22_);
		_g_object_unref0 (_tmp22_);
		_tmp23_ = add_dialog_button;
		gtk_button_set_always_show_image (_tmp23_, TRUE);
	}
	_tmp24_ = _data2_->dialog;
	_tmp25_ = gtk_dialog_get_content_area (_tmp24_);
	_tmp26_ = _g_object_ref0 (_tmp25_);
	content = _tmp26_;
	_tmp27_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
	g_object_ref_sink (_tmp27_);
	box = _tmp27_;
	_tmp28_ = box;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp28_, 10);
	_tmp29_ = box;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp29_, 10);
	_tmp30_ = box;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp30_, 10);
	_tmp31_ = box;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp31_, 10);
	_tmp32_ = content;
	_tmp33_ = box;
	gtk_box_pack_start (_tmp32_, (GtkWidget*) _tmp33_, TRUE, TRUE, (guint) 0);
	_tmp34_ = (GtkLabel*) gtk_label_new (_ ("Select a layout or enter a manual code below"));
	g_object_ref_sink (_tmp34_);
	hint = _tmp34_;
	_tmp35_ = hint;
	gtk_widget_set_halign ((GtkWidget*) _tmp35_, GTK_ALIGN_START);
	_tmp36_ = hint;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp36_, _ ("Select a layout from the list or enter it manually below"));
	_tmp37_ = box;
	_tmp38_ = hint;
	gtk_box_pack_start (_tmp37_, (GtkWidget*) _tmp38_, FALSE, FALSE, (guint) 0);
	_tmp39_ = (GtkSearchEntry*) gtk_search_entry_new ();
	g_object_ref_sink (_tmp39_);
	_data2_->search_entry = _tmp39_;
	_tmp40_ = _data2_->search_entry;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp40_, _ ("Search layouts by code or description"));
	_tmp41_ = _data2_->search_entry;
	gtk_entry_set_placeholder_text ((GtkEntry*) _tmp41_, _ ("Search by code or description"));
	_tmp42_ = box;
	_tmp43_ = _data2_->search_entry;
	gtk_box_pack_start (_tmp42_, (GtkWidget*) _tmp43_, FALSE, FALSE, (guint) 0);
	_tmp44_ = catalog_store;
	_tmp45_ = (GtkTreeModelFilter*) gtk_tree_model_filter_new ((GtkTreeModel*) _tmp44_, NULL);
	_data2_->filter_model = _tmp45_;
	_tmp46_ = _data2_->filter_model;
	gtk_tree_model_filter_set_visible_func (_tmp46_, ___lambda6__gtk_tree_model_filter_visible_func, block2_data_ref (_data2_), block2_data_unref);
	_tmp47_ = _data2_->filter_model;
	_tmp48_ = (GtkTreeModelSort*) gtk_tree_model_sort_new_with_model ((GtkTreeModel*) _tmp47_);
	sort_model = _tmp48_;
	_tmp49_ = sort_model;
	_tmp50_ = (GtkTreeView*) gtk_tree_view_new_with_model ((GtkTreeModel*) _tmp49_);
	g_object_ref_sink (_tmp50_);
	_data2_->tree_view = _tmp50_;
	_tmp51_ = _data2_->tree_view;
	gtk_tree_view_set_headers_visible (_tmp51_, TRUE);
	_tmp52_ = _data2_->tree_view;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp52_, _ ("Select a keyboard layout or variant"));
	_tmp53_ = _data2_->tree_view;
	_tmp54_ = gtk_tree_view_get_selection (_tmp53_);
	gtk_tree_selection_set_mode (_tmp54_, GTK_SELECTION_SINGLE);
	_tmp55_ = _data2_->tree_view;
	g_signal_connect_data (_tmp55_, "row-activated", (GCallback) ___lambda7__gtk_tree_view_row_activated, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp56_ = _data2_->search_entry;
	g_signal_connect_data ((GtkEditable*) _tmp56_, "changed", (GCallback) ___lambda8__gtk_editable_changed, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp57_ = (GtkCellRendererPixbuf*) gtk_cell_renderer_pixbuf_new ();
	g_object_ref_sink (_tmp57_);
	flag_renderer = _tmp57_;
	_tmp58_ = gtk_tree_view_column_new ();
	g_object_ref_sink (_tmp58_);
	flag_column = _tmp58_;
	_tmp59_ = flag_column;
	gtk_tree_view_column_set_title (_tmp59_, _ ("Flag"));
	_tmp60_ = flag_column;
	_tmp61_ = flag_renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp60_, (GtkCellRenderer*) _tmp61_, FALSE);
	_tmp62_ = flag_column;
	_tmp63_ = flag_renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp62_, (GtkCellRenderer*) _tmp63_, "pixbuf", 0);
	_tmp64_ = _data2_->tree_view;
	_tmp65_ = flag_column;
	gtk_tree_view_append_column (_tmp64_, _tmp65_);
	_tmp66_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp66_);
	code_renderer = _tmp66_;
	_tmp67_ = gtk_tree_view_column_new ();
	g_object_ref_sink (_tmp67_);
	code_column = _tmp67_;
	_tmp68_ = code_column;
	gtk_tree_view_column_set_title (_tmp68_, _ ("Layout"));
	_tmp69_ = code_column;
	_tmp70_ = code_renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp69_, (GtkCellRenderer*) _tmp70_, TRUE);
	_tmp71_ = code_column;
	_tmp72_ = code_renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp71_, (GtkCellRenderer*) _tmp72_, "text", 1);
	_tmp73_ = code_column;
	gtk_tree_view_column_set_sort_column_id (_tmp73_, 1);
	_tmp74_ = _data2_->tree_view;
	_tmp75_ = code_column;
	gtk_tree_view_append_column (_tmp74_, _tmp75_);
	_tmp76_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
	g_object_ref_sink (_tmp76_);
	desc_renderer = _tmp76_;
	_tmp77_ = gtk_tree_view_column_new ();
	g_object_ref_sink (_tmp77_);
	desc_column = _tmp77_;
	_tmp78_ = desc_column;
	gtk_tree_view_column_set_title (_tmp78_, _ ("Description"));
	_tmp79_ = desc_column;
	_tmp80_ = desc_renderer;
	gtk_cell_layout_pack_start ((GtkCellLayout*) _tmp79_, (GtkCellRenderer*) _tmp80_, TRUE);
	_tmp81_ = desc_column;
	_tmp82_ = desc_renderer;
	gtk_cell_layout_add_attribute ((GtkCellLayout*) _tmp81_, (GtkCellRenderer*) _tmp82_, "text", 2);
	_tmp83_ = desc_column;
	gtk_tree_view_column_set_sort_column_id (_tmp83_, 2);
	_tmp84_ = _data2_->tree_view;
	_tmp85_ = desc_column;
	gtk_tree_view_append_column (_tmp84_, _tmp85_);
	_tmp86_ = _data2_->tree_view;
	gtk_tree_view_set_search_column (_tmp86_, 2);
	_tmp87_ = _data2_->tree_view;
	gtk_tree_view_set_enable_search (_tmp87_, FALSE);
	_tmp88_ = sort_model;
	gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) _tmp88_, 2, GTK_SORT_ASCENDING);
	_tmp89_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
	g_object_ref_sink (_tmp89_);
	scroll = _tmp89_;
	_tmp90_ = scroll;
	gtk_scrolled_window_set_policy (_tmp90_, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	_tmp91_ = scroll;
	_tmp92_ = _data2_->tree_view;
	gtk_container_add ((GtkContainer*) _tmp91_, (GtkWidget*) _tmp92_);
	_tmp93_ = box;
	_tmp94_ = scroll;
	gtk_box_pack_start (_tmp93_, (GtkWidget*) _tmp94_, TRUE, TRUE, (guint) 0);
	_tmp95_ = (GtkLabel*) gtk_label_new (_ ("Manual layout code:"));
	g_object_ref_sink (_tmp95_);
	manual_title = _tmp95_;
	_tmp96_ = manual_title;
	gtk_widget_set_halign ((GtkWidget*) _tmp96_, GTK_ALIGN_START);
	_tmp97_ = manual_title;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp97_, _ ("Enter layout code manually (e.g., us, ru, de)"));
	_tmp98_ = box;
	_tmp99_ = manual_title;
	gtk_box_pack_start (_tmp98_, (GtkWidget*) _tmp99_, FALSE, FALSE, (guint) 0);
	_tmp100_ = (GtkEntry*) gtk_entry_new ();
	g_object_ref_sink (_tmp100_);
	manual_entry = _tmp100_;
	_tmp101_ = manual_entry;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp101_, _ ("Enter layout code manually (e.g., us, ru, de, us(intl))"));
	_tmp102_ = manual_entry;
	gtk_entry_set_placeholder_text (_tmp102_, _ ("e.g., us, ru, de, us(intl)"));
	_tmp103_ = box;
	_tmp104_ = manual_entry;
	gtk_box_pack_start (_tmp103_, (GtkWidget*) _tmp104_, FALSE, FALSE, (guint) 0);
	_tmp105_ = _data2_->dialog;
	gtk_dialog_set_default_response (_tmp105_, (gint) GTK_RESPONSE_OK);
	_tmp106_ = _data2_->dialog;
	gtk_widget_show_all ((GtkWidget*) _tmp106_);
	_tmp107_ = _data2_->tree_view;
	gtk_tree_view_collapse_all (_tmp107_);
	_tmp108_ = _data2_->search_entry;
	gtk_widget_grab_focus ((GtkWidget*) _tmp108_);
	_tmp109_ = _data2_->dialog;
	if (gtk_dialog_run (_tmp109_) == ((gint) GTK_RESPONSE_OK)) {
		gchar* code = NULL;
		GtkEntry* _tmp110_;
		const gchar* _tmp111_;
		const gchar* _tmp112_;
		gchar* _tmp113_;
		const gchar* _tmp114_;
		gboolean _tmp130_ = FALSE;
		const gchar* _tmp131_;
		_tmp110_ = manual_entry;
		_tmp111_ = gtk_entry_get_text (_tmp110_);
		_tmp112_ = _tmp111_;
		_tmp113_ = string_strip (_tmp112_);
		code = _tmp113_;
		_tmp114_ = code;
		if (g_strcmp0 (_tmp114_, "") == 0) {
			GtkTreeModel* selected_model = NULL;
			GtkTreeIter selected_iter = {0};
			GtkTreeView* _tmp115_;
			GtkTreeSelection* _tmp116_;
			GtkTreeModel* _tmp117_ = NULL;
			GtkTreeIter _tmp118_ = {0};
			gboolean _tmp119_;
			GtkTreeModel* _tmp120_;
			_tmp115_ = _data2_->tree_view;
			_tmp116_ = gtk_tree_view_get_selection (_tmp115_);
			_tmp119_ = gtk_tree_selection_get_selected (_tmp116_, &_tmp117_, &_tmp118_);
			_g_object_unref0 (selected_model);
			_tmp120_ = _g_object_ref0 (_tmp117_);
			selected_model = _tmp120_;
			selected_iter = _tmp118_;
			if (_tmp119_) {
				GtkTreeIter child_iter = {0};
				GtkTreeModelSort* _tmp121_;
				GtkTreeIter _tmp122_;
				GtkTreeIter _tmp123_ = {0};
				GtkTreeIter filter_iter = {0};
				GtkTreeModelFilter* _tmp124_;
				GtkTreeIter _tmp125_;
				GtkTreeIter _tmp126_ = {0};
				GtkTreeStore* _tmp127_;
				GtkTreeIter _tmp128_;
				gchar* _tmp129_ = NULL;
				_tmp121_ = sort_model;
				_tmp122_ = selected_iter;
				gtk_tree_model_sort_convert_iter_to_child_iter (_tmp121_, &_tmp123_, &_tmp122_);
				child_iter = _tmp123_;
				_tmp124_ = _data2_->filter_model;
				_tmp125_ = child_iter;
				gtk_tree_model_filter_convert_iter_to_child_iter (_tmp124_, &_tmp126_, &_tmp125_);
				filter_iter = _tmp126_;
				_tmp127_ = catalog_store;
				_tmp128_ = filter_iter;
				gtk_tree_model_get ((GtkTreeModel*) _tmp127_, &_tmp128_, 1, &_tmp129_, -1);
				_g_free0 (code);
				code = _tmp129_;
			}
			_g_object_unref0 (selected_model);
		}
		_tmp131_ = code;
		if (_tmp131_ == NULL) {
			_tmp130_ = TRUE;
		} else {
			const gchar* _tmp132_;
			_tmp132_ = code;
			_tmp130_ = g_strcmp0 (_tmp132_, "") == 0;
		}
		if (_tmp130_) {
			settings_window_show_error_dialog (self, _ ("Invalid layout"), _ ("Select a layout or enter a layout code."));
		} else {
			const gchar* _tmp133_;
			_tmp133_ = code;
			if (!settings_window_is_valid_layout_code (self, _tmp133_)) {
				settings_window_show_error_dialog (self, _ ("Invalid layout code"), _ ("Layout code contains invalid characters."));
			} else {
				const gchar* _tmp134_;
				_tmp134_ = code;
				if (settings_window_layout_exists (self, _tmp134_)) {
					settings_window_show_error_dialog (self, _ ("Duplicate layout"), _ ("This layout is already in the list."));
				} else {
					GtkTreeIter new_iter = {0};
					GtkListStore* _tmp135_;
					GtkTreeIter _tmp136_ = {0};
					GtkListStore* _tmp137_;
					GtkTreeIter _tmp138_;
					const gchar* _tmp139_;
					const gchar* _tmp140_;
					GdkPixbuf* _tmp141_;
					GdkPixbuf* _tmp142_;
					const gchar* _tmp143_;
					GtkTreeView* _tmp144_;
					GtkTreeSelection* _tmp145_;
					GtkTreeIter _tmp146_;
					_tmp135_ = self->priv->layout_store;
					gtk_list_store_append (_tmp135_, &_tmp136_);
					new_iter = _tmp136_;
					_tmp137_ = self->priv->layout_store;
					_tmp138_ = new_iter;
					_tmp139_ = self->priv->flag_dir_path;
					_tmp140_ = code;
					_tmp141_ = settings_window_load_flag_pixbuf (_tmp139_, _tmp140_, 32);
					_tmp142_ = _tmp141_;
					_tmp143_ = code;
					gtk_list_store_set (_tmp137_, &_tmp138_, 0, _tmp142_, 1, _tmp143_, -1);
					_g_object_unref0 (_tmp142_);
					_tmp144_ = self->priv->layout_view;
					_tmp145_ = gtk_tree_view_get_selection (_tmp144_);
					_tmp146_ = new_iter;
					gtk_tree_selection_select_iter (_tmp145_, &_tmp146_);
					settings_window_update_preview (self);
					settings_window_update_layout_buttons (self);
				}
			}
		}
		_g_free0 (code);
	}
	_tmp147_ = _data2_->dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp147_);
	_g_object_unref0 (manual_entry);
	_g_object_unref0 (manual_title);
	_g_object_unref0 (scroll);
	_g_object_unref0 (desc_column);
	_g_object_unref0 (desc_renderer);
	_g_object_unref0 (code_column);
	_g_object_unref0 (code_renderer);
	_g_object_unref0 (flag_column);
	_g_object_unref0 (flag_renderer);
	_g_object_unref0 (sort_model);
	_g_object_unref0 (hint);
	_g_object_unref0 (box);
	_g_object_unref0 (content);
	_g_object_unref0 (add_dialog_button);
	_g_object_unref0 (cancel_button);
	_g_object_unref0 (catalog_store);
	block2_data_unref (_data2_);
	_data2_ = NULL;
}

static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gint
string_last_index_of (const gchar* self,
                      const gchar* needle,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = g_strrstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static GtkTreeStore*
settings_window_build_layout_catalog_store (SettingsWindow* self)
{
	GtkTreeStore* store = NULL;
	GtkTreeStore* _tmp0_;
	GHashTable* seen = NULL;
	GHashFunc _tmp1_;
	GEqualFunc _tmp2_;
	GHashTable* _tmp3_;
	GtkTreeStore* _tmp40_;
	GError* _inner_error0_ = NULL;
	GtkTreeStore* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gtk_tree_store_new (3, gdk_pixbuf_get_type (), G_TYPE_STRING, G_TYPE_STRING);
	store = _tmp0_;
	_tmp1_ = g_str_hash;
	_tmp2_ = g_str_equal;
	_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, _g_free0_, NULL);
	seen = _tmp3_;
	{
		GKeyFile* key_file = NULL;
		GKeyFile* _tmp4_;
		GKeyFile* _tmp5_;
		const gchar* _tmp6_;
		gchar** keys = NULL;
		GKeyFile* _tmp7_;
		gsize _tmp8_ = 0;
		gchar** _tmp9_;
		gint keys_length1;
		gint _keys_size_;
		gchar** _tmp10_;
		gint _tmp10__length1;
		_tmp4_ = g_key_file_new ();
		key_file = _tmp4_;
		_tmp5_ = key_file;
		_tmp6_ = self->priv->layouts_config_path;
		g_key_file_load_from_file (_tmp5_, _tmp6_, G_KEY_FILE_NONE, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_key_file_unref0 (key_file);
			goto __catch0_g_error;
		}
		_tmp7_ = key_file;
		_tmp9_ = g_key_file_get_keys (_tmp7_, "LAYOUTS", &_tmp8_, &_inner_error0_);
		keys = _tmp9_;
		keys_length1 = _tmp8_;
		_keys_size_ = keys_length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_key_file_unref0 (key_file);
			goto __catch0_g_error;
		}
		_tmp10_ = keys;
		_tmp10__length1 = keys_length1;
		{
			gchar** key_collection = NULL;
			gint key_collection_length1 = 0;
			gint _key_collection_size_ = 0;
			gint key_it = 0;
			key_collection = _tmp10_;
			key_collection_length1 = _tmp10__length1;
			for (key_it = 0; key_it < key_collection_length1; key_it = key_it + 1) {
				gchar* _tmp11_;
				gchar* key = NULL;
				_tmp11_ = g_strdup (key_collection[key_it]);
				key = _tmp11_;
				{
					gchar* code = NULL;
					const gchar* _tmp12_;
					gchar* _tmp13_;
					gchar* _tmp14_ = NULL;
					GKeyFile* _tmp15_;
					const gchar* _tmp16_;
					gchar* _tmp17_;
					gchar* description = NULL;
					gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gchar* _tmp21_;
					const gchar* _tmp22_;
					gint open_pos = 0;
					const gchar* _tmp27_;
					gint close_pos = 0;
					const gchar* _tmp28_;
					gboolean _tmp29_ = FALSE;
					gchar* layout = NULL;
					const gchar* _tmp30_;
					gchar* _tmp31_;
					gchar* _tmp32_;
					gchar* _tmp33_;
					gchar* _tmp34_;
					GtkTreeStore* _tmp35_;
					GHashTable* _tmp36_;
					const gchar* _tmp37_;
					const gchar* _tmp38_;
					const gchar* _tmp39_;
					_tmp12_ = key;
					_tmp13_ = string_strip (_tmp12_);
					code = _tmp13_;
					_tmp15_ = key_file;
					_tmp16_ = key;
					_tmp17_ = g_key_file_get_string (_tmp15_, "LAYOUTS", _tmp16_, &_inner_error0_);
					_tmp14_ = _tmp17_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						_g_free0 (code);
						_g_free0 (key);
						keys = (_vala_array_free (keys, keys_length1, (GDestroyNotify) g_free), NULL);
						_g_key_file_unref0 (key_file);
						goto __catch0_g_error;
					}
					_tmp18_ = string_strip (_tmp14_);
					_tmp19_ = _tmp18_;
					_tmp20_ = settings_window_translate_xkeyboard_config (self, _tmp19_);
					_tmp21_ = _tmp20_;
					_g_free0 (_tmp19_);
					description = _tmp21_;
					_tmp22_ = code;
					if (string_index_of (_tmp22_, "(", 0) < 0) {
						GtkTreeStore* _tmp23_;
						GHashTable* _tmp24_;
						const gchar* _tmp25_;
						const gchar* _tmp26_;
						_tmp23_ = store;
						_tmp24_ = seen;
						_tmp25_ = code;
						_tmp26_ = description;
						settings_window_add_catalog_layout_row (self, _tmp23_, _tmp24_, _tmp25_, _tmp26_);
						_g_free0 (description);
						_g_free0 (_tmp14_);
						_g_free0 (code);
						_g_free0 (key);
						continue;
					}
					_tmp27_ = code;
					open_pos = string_index_of (_tmp27_, "(", 0);
					_tmp28_ = code;
					close_pos = string_last_index_of (_tmp28_, ")", 0);
					if (open_pos <= 0) {
						_tmp29_ = TRUE;
					} else {
						_tmp29_ = close_pos <= (open_pos + 1);
					}
					if (_tmp29_) {
						_g_free0 (description);
						_g_free0 (_tmp14_);
						_g_free0 (code);
						_g_free0 (key);
						continue;
					}
					_tmp30_ = code;
					_tmp31_ = string_substring (_tmp30_, (glong) 0, (glong) open_pos);
					_tmp32_ = _tmp31_;
					_tmp33_ = string_strip (_tmp32_);
					_tmp34_ = _tmp33_;
					_g_free0 (_tmp32_);
					layout = _tmp34_;
					_tmp35_ = store;
					_tmp36_ = seen;
					_tmp37_ = layout;
					_tmp38_ = code;
					_tmp39_ = description;
					settings_window_add_catalog_variant_row (self, _tmp35_, _tmp36_, _tmp37_, _tmp38_, _tmp39_);
					_g_free0 (layout);
					_g_free0 (description);
					_g_free0 (_tmp14_);
					_g_free0 (code);
					_g_free0 (key);
				}
			}
		}
		keys = (_vala_array_free (keys, keys_length1, (GDestroyNotify) g_free), NULL);
		_g_key_file_unref0 (key_file);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		result = store;
		_g_hash_table_unref0 (seen);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_hash_table_unref0 (seen);
		_g_object_unref0 (store);
		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;
	}
	_tmp40_ = store;
	gtk_tree_sortable_set_sort_column_id ((GtkTreeSortable*) _tmp40_, 2, GTK_SORT_ASCENDING);
	result = store;
	_g_hash_table_unref0 (seen);
	return result;
}

static void
settings_window_add_catalog_layout_row (SettingsWindow* self,
                                        GtkTreeStore* store,
                                        GHashTable* seen,
                                        const gchar* code,
                                        const gchar* description)
{
	gchar* _tmp0_;
	GtkTreeIter iter = {0};
	GtkTreeIter _tmp1_ = {0};
	GtkTreeIter _tmp2_;
	const gchar* _tmp3_;
	GdkPixbuf* _tmp4_;
	GdkPixbuf* _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (store != NULL);
	g_return_if_fail (seen != NULL);
	g_return_if_fail (code != NULL);
	g_return_if_fail (description != NULL);
	if (!settings_window_is_valid_layout_code (self, code)) {
		return;
	}
	if (g_hash_table_contains (seen, code)) {
		return;
	}
	_tmp0_ = g_strdup (code);
	g_hash_table_insert (seen, _tmp0_, (gpointer) ((gintptr) TRUE));
	gtk_tree_store_append (store, &_tmp1_, NULL);
	iter = _tmp1_;
	_tmp2_ = iter;
	_tmp3_ = self->priv->flag_dir_path;
	_tmp4_ = settings_window_load_flag_pixbuf (_tmp3_, code, 32);
	_tmp5_ = _tmp4_;
	gtk_tree_store_set (store, &_tmp2_, 0, _tmp5_, 1, code, 2, description, -1);
	_g_object_unref0 (_tmp5_);
}

static void
settings_window_add_catalog_variant_row (SettingsWindow* self,
                                         GtkTreeStore* store,
                                         GHashTable* seen,
                                         const gchar* layout,
                                         const gchar* code,
                                         const gchar* description)
{
	GtkTreeIter parent_iter = {0};
	GtkTreeIter _tmp0_ = {0};
	gboolean _tmp1_;
	gchar* _tmp2_;
	GtkTreeIter iter = {0};
	GtkTreeIter _tmp3_;
	GtkTreeIter _tmp4_ = {0};
	GtkTreeIter _tmp5_;
	const gchar* _tmp6_;
	GdkPixbuf* _tmp7_;
	GdkPixbuf* _tmp8_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (store != NULL);
	g_return_if_fail (seen != NULL);
	g_return_if_fail (layout != NULL);
	g_return_if_fail (code != NULL);
	g_return_if_fail (description != NULL);
	if (!settings_window_is_valid_layout_code (self, code)) {
		return;
	}
	if (g_hash_table_contains (seen, code)) {
		return;
	}
	_tmp1_ = settings_window_find_catalog_parent_iter (self, store, layout, &_tmp0_);
	parent_iter = _tmp0_;
	if (!_tmp1_) {
		return;
	}
	_tmp2_ = g_strdup (code);
	g_hash_table_insert (seen, _tmp2_, (gpointer) ((gintptr) TRUE));
	_tmp3_ = parent_iter;
	gtk_tree_store_append (store, &_tmp4_, &_tmp3_);
	iter = _tmp4_;
	_tmp5_ = iter;
	_tmp6_ = self->priv->flag_dir_path;
	_tmp7_ = settings_window_load_flag_pixbuf (_tmp6_, layout, 32);
	_tmp8_ = _tmp7_;
	gtk_tree_store_set (store, &_tmp5_, 0, _tmp8_, 1, code, 2, description, -1);
	_g_object_unref0 (_tmp8_);
}

static gboolean
settings_window_find_catalog_parent_iter (SettingsWindow* self,
                                          GtkTreeStore* store,
                                          const gchar* layout,
                                          GtkTreeIter* iter)
{
	GtkTreeIter _vala_iter = {0};
	GtkTreeIter current = {0};
	GtkTreeIter _tmp0_ = {0};
	gboolean _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (store != NULL, FALSE);
	g_return_val_if_fail (layout != NULL, FALSE);
	_tmp1_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) store, &_tmp0_);
	current = _tmp0_;
	if (_tmp1_) {
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				gchar* code = NULL;
				GtkTreeIter _tmp4_;
				gchar* _tmp5_ = NULL;
				const gchar* _tmp6_;
				if (!_tmp2_) {
					gboolean _tmp3_;
					_tmp3_ = gtk_tree_model_iter_next ((GtkTreeModel*) store, &current);
					if (!_tmp3_) {
						break;
					}
				}
				_tmp2_ = FALSE;
				_tmp4_ = current;
				gtk_tree_model_get ((GtkTreeModel*) store, &_tmp4_, 1, &_tmp5_, -1);
				_g_free0 (code);
				code = _tmp5_;
				_tmp6_ = code;
				if (g_strcmp0 (_tmp6_, layout) == 0) {
					GtkTreeIter _tmp7_;
					_tmp7_ = current;
					_vala_iter = _tmp7_;
					result = TRUE;
					_g_free0 (code);
					if (iter) {
						*iter = _vala_iter;
					}
					return result;
				}
				_g_free0 (code);
			}
		}
	}
	memset (&_vala_iter, 0, sizeof (GtkTreeIter));
	result = FALSE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}

static gboolean
settings_window_catalog_row_matches (SettingsWindow* self,
                                     GtkTreeModel* model,
                                     GtkTreeIter* iter,
                                     const gchar* needle)
{
	GtkTreeIter parent = {0};
	GtkTreeIter _tmp0_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	gchar* code = NULL;
	gchar* description = NULL;
	GtkTreeIter _tmp9_;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gboolean _tmp12_ = FALSE;
	const gchar* _tmp13_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (model != NULL, FALSE);
	g_return_val_if_fail (iter != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = *iter;
	_tmp2_ = gtk_tree_model_iter_parent (model, &_tmp1_, &_tmp0_);
	parent = _tmp1_;
	if (_tmp2_) {
		gchar* pc = NULL;
		gchar* pd = NULL;
		GtkTreeIter _tmp3_;
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		gboolean _tmp6_ = FALSE;
		const gchar* _tmp7_;
		_tmp3_ = parent;
		gtk_tree_model_get (model, &_tmp3_, 1, &_tmp4_, 2, &_tmp5_, -1);
		_g_free0 (pc);
		pc = _tmp4_;
		_g_free0 (pd);
		pd = _tmp5_;
		_tmp7_ = pc;
		if (settings_window_catalog_text_matches (self, _tmp7_, needle)) {
			_tmp6_ = TRUE;
		} else {
			const gchar* _tmp8_;
			_tmp8_ = pd;
			_tmp6_ = settings_window_catalog_text_matches (self, _tmp8_, needle);
		}
		result = _tmp6_;
		_g_free0 (pd);
		_g_free0 (pc);
		return result;
	}
	_tmp9_ = *iter;
	gtk_tree_model_get (model, &_tmp9_, 1, &_tmp10_, 2, &_tmp11_, -1);
	_g_free0 (code);
	code = _tmp10_;
	_g_free0 (description);
	description = _tmp11_;
	_tmp13_ = code;
	if (settings_window_catalog_text_matches (self, _tmp13_, needle)) {
		_tmp12_ = TRUE;
	} else {
		const gchar* _tmp14_;
		_tmp14_ = description;
		_tmp12_ = settings_window_catalog_text_matches (self, _tmp14_, needle);
	}
	result = _tmp12_;
	_g_free0 (description);
	_g_free0 (code);
	return result;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gboolean
settings_window_catalog_text_matches (SettingsWindow* self,
                                      const gchar* text,
                                      const gchar* needle)
{
	gchar* lowered = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar** separators = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar** _tmp10_;
	gint separators_length1;
	gint _separators_size_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (text != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = g_utf8_strdown (text, (gssize) -1);
	lowered = _tmp0_;
	_tmp1_ = lowered;
	if (g_str_has_prefix (_tmp1_, needle)) {
		result = TRUE;
		_g_free0 (lowered);
		return result;
	}
	_tmp2_ = g_strdup (" ");
	_tmp3_ = g_strdup ("(");
	_tmp4_ = g_strdup (")");
	_tmp5_ = g_strdup (",");
	_tmp6_ = g_strdup (".");
	_tmp7_ = g_strdup ("/");
	_tmp8_ = g_strdup ("-");
	_tmp9_ = g_strdup ("_");
	_tmp10_ = g_new0 (gchar*, 8 + 1);
	_tmp10_[0] = _tmp2_;
	_tmp10_[1] = _tmp3_;
	_tmp10_[2] = _tmp4_;
	_tmp10_[3] = _tmp5_;
	_tmp10_[4] = _tmp6_;
	_tmp10_[5] = _tmp7_;
	_tmp10_[6] = _tmp8_;
	_tmp10_[7] = _tmp9_;
	separators = _tmp10_;
	separators_length1 = 8;
	_separators_size_ = separators_length1;
	_tmp11_ = separators;
	_tmp11__length1 = separators_length1;
	{
		gchar** separator_collection = NULL;
		gint separator_collection_length1 = 0;
		gint _separator_collection_size_ = 0;
		gint separator_it = 0;
		separator_collection = _tmp11_;
		separator_collection_length1 = _tmp11__length1;
		for (separator_it = 0; separator_it < separator_collection_length1; separator_it = separator_it + 1) {
			gchar* _tmp12_;
			gchar* separator = NULL;
			_tmp12_ = g_strdup (separator_collection[separator_it]);
			separator = _tmp12_;
			{
				const gchar* _tmp13_;
				const gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				gboolean _tmp17_;
				_tmp13_ = lowered;
				_tmp14_ = separator;
				_tmp15_ = g_strconcat (_tmp14_, needle, NULL);
				_tmp16_ = _tmp15_;
				_tmp17_ = string_contains (_tmp13_, _tmp16_);
				_g_free0 (_tmp16_);
				if (_tmp17_) {
					result = TRUE;
					_g_free0 (separator);
					separators = (_vala_array_free (separators, separators_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (lowered);
					return result;
				}
				_g_free0 (separator);
			}
		}
	}
	result = FALSE;
	separators = (_vala_array_free (separators, separators_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (lowered);
	return result;
}

static gchar*
settings_window_translate_xkeyboard_config (SettingsWindow* self,
                                            const gchar* text)
{
	gchar* translated = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = g_strdup (g_dgettext ("xkeyboard-config", text));
	translated = _tmp0_;
	_tmp2_ = translated;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		_tmp3_ = translated;
		_tmp1_ = g_strcmp0 (_tmp3_, "") == 0;
	}
	if (_tmp1_) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup (text);
		result = _tmp4_;
		_g_free0 (translated);
		return result;
	}
	result = translated;
	return result;
}

static gboolean
settings_window_layout_exists (SettingsWindow* self,
                               const gchar* code)
{
	GtkTreeIter iter = {0};
	gboolean valid = FALSE;
	GtkListStore* _tmp0_;
	GtkTreeIter _tmp1_ = {0};
	gboolean _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (code != NULL, FALSE);
	_tmp0_ = self->priv->layout_store;
	_tmp2_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp0_, &_tmp1_);
	iter = _tmp1_;
	valid = _tmp2_;
	while (TRUE) {
		gchar* current = NULL;
		GtkListStore* _tmp3_;
		GtkTreeIter _tmp4_;
		gchar* _tmp5_ = NULL;
		const gchar* _tmp6_;
		GtkListStore* _tmp7_;
		gboolean _tmp8_;
		if (!valid) {
			break;
		}
		_tmp3_ = self->priv->layout_store;
		_tmp4_ = iter;
		gtk_tree_model_get ((GtkTreeModel*) _tmp3_, &_tmp4_, 1, &_tmp5_, -1);
		_g_free0 (current);
		current = _tmp5_;
		_tmp6_ = current;
		if (g_strcmp0 (_tmp6_, code) == 0) {
			result = TRUE;
			_g_free0 (current);
			return result;
		}
		_tmp7_ = self->priv->layout_store;
		_tmp8_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp7_, &iter);
		valid = _tmp8_;
		_g_free0 (current);
	}
	result = FALSE;
	return result;
}

static gboolean
settings_window_is_valid_layout_code (SettingsWindow* self,
                                      const gchar* code)
{
	gboolean _tmp3_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (code != NULL, FALSE);
	if (g_strcmp0 (code, "") == 0) {
		result = FALSE;
		return result;
	}
	{
		GRegex* regex = NULL;
		GRegex* _tmp0_;
		GRegex* _tmp2_;
		_tmp0_ = g_regex_new ("^[A-Za-z0-9_-]+(\\([A-Za-z0-9_-]+\\))?$", 0, 0, &_inner_error0_);
		regex = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp1_ = FALSE;
			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 _tmp1_;
		}
		_tmp2_ = regex;
		result = g_regex_match (_tmp2_, code, 0, NULL);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		result = FALSE;
		return result;
	}
	__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 _tmp3_;
}

static void
_vala_GtkTreePath_free (GtkTreePath* self)
{
	g_boxed_free (gtk_tree_path_get_type (), self);
}

static gint*
_vala_array_dup2 (gint* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gint));
	}
	return NULL;
}

static gint
settings_window_get_selected_index (SettingsWindow* self,
                                    GtkTreeIter* selected_iter)
{
	GtkTreeIter _vala_selected_iter = {0};
	GtkTreeModel* model = NULL;
	GtkTreeView* _tmp0_;
	GtkTreeSelection* _tmp1_;
	GtkTreeModel* _tmp2_ = NULL;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_;
	GtkTreeModel* _tmp5_;
	GtkTreePath* path = NULL;
	GtkTreeModel* _tmp6_;
	GtkTreeIter _tmp7_;
	GtkTreePath* _tmp8_;
	GtkTreePath* _tmp9_;
	gint* indices = NULL;
	GtkTreePath* _tmp10_;
	gint _tmp11_ = 0;
	gint* _tmp12_;
	gint* _tmp13_;
	gint _tmp13__length1;
	gint indices_length1;
	gint _indices_size_;
	gint* _tmp14_;
	gint _tmp14__length1;
	gint* _tmp15_;
	gint _tmp15__length1;
	gint _tmp16_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = self->priv->layout_view;
	_tmp1_ = gtk_tree_view_get_selection (_tmp0_);
	_tmp4_ = gtk_tree_selection_get_selected (_tmp1_, &_tmp2_, &_tmp3_);
	_g_object_unref0 (model);
	_tmp5_ = _g_object_ref0 (_tmp2_);
	model = _tmp5_;
	_vala_selected_iter = _tmp3_;
	if (!_tmp4_) {
		result = -1;
		_g_object_unref0 (model);
		if (selected_iter) {
			*selected_iter = _vala_selected_iter;
		}
		return result;
	}
	_tmp6_ = model;
	_tmp7_ = _vala_selected_iter;
	_tmp8_ = gtk_tree_model_get_path (_tmp6_, &_tmp7_);
	path = _tmp8_;
	_tmp9_ = path;
	if (_tmp9_ == NULL) {
		result = -1;
		__vala_GtkTreePath_free0 (path);
		_g_object_unref0 (model);
		if (selected_iter) {
			*selected_iter = _vala_selected_iter;
		}
		return result;
	}
	_tmp10_ = path;
	_tmp12_ = gtk_tree_path_get_indices_with_depth (_tmp10_, &_tmp11_);
	_tmp13_ = (_tmp12_ != NULL) ? _vala_array_dup2 (_tmp12_, _tmp11_) : _tmp12_;
	_tmp13__length1 = _tmp11_;
	indices = _tmp13_;
	indices_length1 = _tmp13__length1;
	_indices_size_ = indices_length1;
	_tmp14_ = indices;
	_tmp14__length1 = indices_length1;
	if (_tmp14__length1 == 0) {
		result = -1;
		indices = (g_free (indices), NULL);
		__vala_GtkTreePath_free0 (path);
		_g_object_unref0 (model);
		if (selected_iter) {
			*selected_iter = _vala_selected_iter;
		}
		return result;
	}
	_tmp15_ = indices;
	_tmp15__length1 = indices_length1;
	_tmp16_ = _tmp15_[0];
	result = _tmp16_;
	indices = (g_free (indices), NULL);
	__vala_GtkTreePath_free0 (path);
	_g_object_unref0 (model);
	if (selected_iter) {
		*selected_iter = _vala_selected_iter;
	}
	return result;
}

static void
settings_window_remove_selected_layout (SettingsWindow* self)
{
	GtkTreeIter iter = {0};
	gint selected = 0;
	GtkTreeIter _tmp0_ = {0};
	gint _tmp1_;
	GtkListStore* _tmp2_;
	gint count = 0;
	GtkListStore* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp1_ = settings_window_get_selected_index (self, &_tmp0_);
	iter = _tmp0_;
	selected = _tmp1_;
	if (selected < 0) {
		return;
	}
	_tmp2_ = self->priv->layout_store;
	gtk_list_store_remove (_tmp2_, &iter);
	_tmp3_ = self->priv->layout_store;
	count = gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp3_, NULL);
	if (count > 0) {
		gint next_index = 0;
		GtkTreeIter new_iter = {0};
		GtkListStore* _tmp4_;
		GtkTreeIter _tmp5_ = {0};
		gboolean _tmp6_;
		next_index = selected;
		if (next_index >= count) {
			next_index = count - 1;
		}
		_tmp4_ = self->priv->layout_store;
		_tmp6_ = gtk_tree_model_iter_nth_child ((GtkTreeModel*) _tmp4_, &_tmp5_, NULL, next_index);
		new_iter = _tmp5_;
		if (_tmp6_) {
			GtkTreeView* _tmp7_;
			GtkTreeSelection* _tmp8_;
			GtkTreeIter _tmp9_;
			_tmp7_ = self->priv->layout_view;
			_tmp8_ = gtk_tree_view_get_selection (_tmp7_);
			_tmp9_ = new_iter;
			gtk_tree_selection_select_iter (_tmp8_, &_tmp9_);
		}
	}
	settings_window_update_preview (self);
	settings_window_update_layout_buttons (self);
}

static void
settings_window_move_selected_layout (SettingsWindow* self,
                                      gint direction)
{
	GtkTreeIter selected_iter = {0};
	gint selected = 0;
	GtkTreeIter _tmp0_ = {0};
	gint _tmp1_;
	gint target_index = 0;
	gint count = 0;
	GtkListStore* _tmp2_;
	gboolean _tmp3_ = FALSE;
	GtkTreeIter target_iter = {0};
	GtkListStore* _tmp4_;
	GtkTreeIter _tmp5_ = {0};
	gboolean _tmp6_;
	GtkListStore* _tmp7_;
	GtkTreeIter _tmp8_;
	GtkTreeIter _tmp9_;
	GtkTreeIter new_selected = {0};
	GtkListStore* _tmp10_;
	GtkTreeIter _tmp11_ = {0};
	gboolean _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp1_ = settings_window_get_selected_index (self, &_tmp0_);
	selected_iter = _tmp0_;
	selected = _tmp1_;
	if (selected < 0) {
		return;
	}
	target_index = selected + direction;
	_tmp2_ = self->priv->layout_store;
	count = gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp2_, NULL);
	if (target_index < 0) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = target_index >= count;
	}
	if (_tmp3_) {
		return;
	}
	_tmp4_ = self->priv->layout_store;
	_tmp6_ = gtk_tree_model_iter_nth_child ((GtkTreeModel*) _tmp4_, &_tmp5_, NULL, target_index);
	target_iter = _tmp5_;
	if (!_tmp6_) {
		return;
	}
	_tmp7_ = self->priv->layout_store;
	_tmp8_ = selected_iter;
	_tmp9_ = target_iter;
	gtk_list_store_swap (_tmp7_, &_tmp8_, &_tmp9_);
	_tmp10_ = self->priv->layout_store;
	_tmp12_ = gtk_tree_model_iter_nth_child ((GtkTreeModel*) _tmp10_, &_tmp11_, NULL, target_index);
	new_selected = _tmp11_;
	if (_tmp12_) {
		GtkTreeView* _tmp13_;
		GtkTreeSelection* _tmp14_;
		GtkTreeIter _tmp15_;
		_tmp13_ = self->priv->layout_view;
		_tmp14_ = gtk_tree_view_get_selection (_tmp13_);
		_tmp15_ = new_selected;
		gtk_tree_selection_select_iter (_tmp14_, &_tmp15_);
	}
	settings_window_update_preview (self);
	settings_window_update_layout_buttons (self);
}

static void
settings_window_update_layout_buttons (SettingsWindow* self)
{
	GtkTreeIter iter = {0};
	gint selected = 0;
	GtkTreeIter _tmp0_ = {0};
	gint _tmp1_;
	gint count = 0;
	GtkListStore* _tmp2_;
	gboolean has_selection = FALSE;
	GtkButton* _tmp3_;
	gboolean _tmp4_ = FALSE;
	GtkButton* _tmp5_;
	gboolean _tmp6_ = FALSE;
	gboolean _tmp7_ = FALSE;
	GtkButton* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp1_ = settings_window_get_selected_index (self, &_tmp0_);
	iter = _tmp0_;
	selected = _tmp1_;
	_tmp2_ = self->priv->layout_store;
	count = gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp2_, NULL);
	has_selection = selected >= 0;
	_tmp3_ = self->priv->remove_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp3_, has_selection);
	if (has_selection) {
		_tmp4_ = selected > 0;
	} else {
		_tmp4_ = FALSE;
	}
	_tmp5_ = self->priv->up_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp5_, _tmp4_);
	if (has_selection) {
		_tmp7_ = selected >= 0;
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		_tmp6_ = selected < (count - 1);
	} else {
		_tmp6_ = FALSE;
	}
	_tmp8_ = self->priv->down_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp8_, _tmp6_);
}

static gboolean
settings_window_validate_form (SettingsWindow* self,
                               gchar** message)
{
	gchar* _vala_message = NULL;
	GtkListStore* _tmp0_;
	GtkTreeIter iter = {0};
	gboolean valid = FALSE;
	GtkListStore* _tmp2_;
	GtkTreeIter _tmp3_ = {0};
	gboolean _tmp4_;
	gchar* option = NULL;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp18_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->layout_store;
	if (gtk_tree_model_iter_n_children ((GtkTreeModel*) _tmp0_, NULL) == 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (_ ("Add at least one layout."));
		_g_free0 (_vala_message);
		_vala_message = _tmp1_;
		result = FALSE;
		if (message) {
			*message = _vala_message;
		} else {
			_g_free0 (_vala_message);
		}
		return result;
	}
	_tmp2_ = self->priv->layout_store;
	_tmp4_ = gtk_tree_model_get_iter_first ((GtkTreeModel*) _tmp2_, &_tmp3_);
	iter = _tmp3_;
	valid = _tmp4_;
	while (TRUE) {
		gchar* code = NULL;
		GtkListStore* _tmp5_;
		GtkTreeIter _tmp6_;
		gchar* _tmp7_ = NULL;
		const gchar* _tmp8_;
		GtkListStore* _tmp13_;
		gboolean _tmp14_;
		if (!valid) {
			break;
		}
		_tmp5_ = self->priv->layout_store;
		_tmp6_ = iter;
		gtk_tree_model_get ((GtkTreeModel*) _tmp5_, &_tmp6_, 1, &_tmp7_, -1);
		_g_free0 (code);
		code = _tmp7_;
		_tmp8_ = code;
		if (!settings_window_is_valid_layout_code (self, _tmp8_)) {
			gchar* _tmp9_;
			gchar* _tmp10_;
			const gchar* _tmp11_;
			gchar* _tmp12_;
			_tmp9_ = g_strconcat (_ ("Invalid layout code:"), " ", NULL);
			_tmp10_ = _tmp9_;
			_tmp11_ = code;
			_tmp12_ = g_strconcat (_tmp10_, _tmp11_, NULL);
			_g_free0 (_vala_message);
			_vala_message = _tmp12_;
			_g_free0 (_tmp10_);
			result = FALSE;
			_g_free0 (code);
			if (message) {
				*message = _vala_message;
			} else {
				_g_free0 (_vala_message);
			}
			return result;
		}
		_tmp13_ = self->priv->layout_store;
		_tmp14_ = gtk_tree_model_iter_next ((GtkTreeModel*) _tmp13_, &iter);
		valid = _tmp14_;
		_g_free0 (code);
	}
	_tmp15_ = settings_window_get_effective_option (self);
	option = _tmp15_;
	_tmp16_ = option;
	if (g_strcmp0 (_tmp16_, "") == 0) {
		gchar* _tmp17_;
		_tmp17_ = g_strdup (_ ("Custom XKB option cannot be empty."));
		_g_free0 (_vala_message);
		_vala_message = _tmp17_;
		result = FALSE;
		_g_free0 (option);
		if (message) {
			*message = _vala_message;
		} else {
			_g_free0 (_vala_message);
		}
		return result;
	}
	_tmp18_ = g_strdup ("");
	_g_free0 (_vala_message);
	_vala_message = _tmp18_;
	result = TRUE;
	_g_free0 (option);
	if (message) {
		*message = _vala_message;
	} else {
		_g_free0 (_vala_message);
	}
	return result;
}

static gboolean
settings_window_write_environment (SettingsWindow* self,
                                   const gchar* layouts_csv,
                                   const gchar* option,
                                   gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	gchar* content = NULL;
	gchar* _tmp0_;
	gboolean wrote_layout = FALSE;
	gboolean wrote_option = FALSE;
	GString* out_text = NULL;
	GString* _tmp5_;
	const gchar* _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gchar* _tmp45_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (layouts_csv != NULL, FALSE);
	g_return_val_if_fail (option != NULL, FALSE);
	_tmp0_ = g_strdup ("");
	content = _tmp0_;
	{
		const gchar* _tmp1_;
		gchar* _tmp2_ = NULL;
		_tmp1_ = self->priv->env_file_path;
		g_file_get_contents (_tmp1_, &_tmp2_, NULL, &_inner_error0_);
		_g_free0 (content);
		content = _tmp2_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		gchar* _tmp3_;
		g_clear_error (&_inner_error0_);
		_tmp3_ = g_strdup ("");
		_g_free0 (content);
		content = _tmp3_;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp4_ = FALSE;
		_g_free0 (content);
		_g_free0 (_vala_error_message);
		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 _tmp4_;
	}
	wrote_layout = FALSE;
	wrote_option = FALSE;
	_tmp5_ = g_string_new ("");
	out_text = _tmp5_;
	_tmp6_ = content;
	_tmp8_ = _tmp7_ = g_strsplit (_tmp6_, "\n", 0);
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp8_;
		line_collection_length1 = _vala_array_length (_tmp7_);
		for (line_it = 0; line_it < line_collection_length1; line_it = line_it + 1) {
			gchar* _tmp9_;
			gchar* line = NULL;
			_tmp9_ = g_strdup (line_collection[line_it]);
			line = _tmp9_;
			{
				const gchar* _tmp10_;
				const gchar* _tmp16_;
				const gchar* _tmp22_;
				const gchar* _tmp23_;
				_tmp10_ = line;
				if (g_str_has_prefix (_tmp10_, "XKB_DEFAULT_LAYOUT=")) {
					GString* _tmp11_;
					gchar* _tmp12_;
					gchar* _tmp13_;
					gchar* _tmp14_;
					gchar* _tmp15_;
					_tmp11_ = out_text;
					_tmp12_ = g_strconcat ("XKB_DEFAULT_LAYOUT=", layouts_csv, NULL);
					_tmp13_ = _tmp12_;
					_tmp14_ = g_strconcat (_tmp13_, "\n", NULL);
					_tmp15_ = _tmp14_;
					g_string_append (_tmp11_, _tmp15_);
					_g_free0 (_tmp15_);
					_g_free0 (_tmp13_);
					wrote_layout = TRUE;
					_g_free0 (line);
					continue;
				}
				_tmp16_ = line;
				if (g_str_has_prefix (_tmp16_, "XKB_DEFAULT_OPTIONS=")) {
					GString* _tmp17_;
					gchar* _tmp18_;
					gchar* _tmp19_;
					gchar* _tmp20_;
					gchar* _tmp21_;
					_tmp17_ = out_text;
					_tmp18_ = g_strconcat ("XKB_DEFAULT_OPTIONS=", option, NULL);
					_tmp19_ = _tmp18_;
					_tmp20_ = g_strconcat (_tmp19_, "\n", NULL);
					_tmp21_ = _tmp20_;
					g_string_append (_tmp17_, _tmp21_);
					_g_free0 (_tmp21_);
					_g_free0 (_tmp19_);
					wrote_option = TRUE;
					_g_free0 (line);
					continue;
				}
				_tmp22_ = line;
				if (g_str_has_prefix (_tmp22_, "XKB_DEFAULT_MODEL=")) {
					_g_free0 (line);
					continue;
				}
				_tmp23_ = line;
				if (g_strcmp0 (_tmp23_, "") != 0) {
					GString* _tmp24_;
					const gchar* _tmp25_;
					gchar* _tmp26_;
					gchar* _tmp27_;
					_tmp24_ = out_text;
					_tmp25_ = line;
					_tmp26_ = g_strconcat (_tmp25_, "\n", NULL);
					_tmp27_ = _tmp26_;
					g_string_append (_tmp24_, _tmp27_);
					_g_free0 (_tmp27_);
				}
				_g_free0 (line);
			}
		}
		line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	if (!wrote_layout) {
		GString* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		gchar* _tmp31_;
		gchar* _tmp32_;
		_tmp28_ = out_text;
		_tmp29_ = g_strconcat ("XKB_DEFAULT_LAYOUT=", layouts_csv, NULL);
		_tmp30_ = _tmp29_;
		_tmp31_ = g_strconcat (_tmp30_, "\n", NULL);
		_tmp32_ = _tmp31_;
		g_string_append (_tmp28_, _tmp32_);
		_g_free0 (_tmp32_);
		_g_free0 (_tmp30_);
	}
	if (!wrote_option) {
		GString* _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		gchar* _tmp36_;
		gchar* _tmp37_;
		_tmp33_ = out_text;
		_tmp34_ = g_strconcat ("XKB_DEFAULT_OPTIONS=", option, NULL);
		_tmp35_ = _tmp34_;
		_tmp36_ = g_strconcat (_tmp35_, "\n", NULL);
		_tmp37_ = _tmp36_;
		g_string_append (_tmp33_, _tmp37_);
		_g_free0 (_tmp37_);
		_g_free0 (_tmp35_);
	}
	{
		const gchar* _tmp38_;
		GString* _tmp39_;
		const gchar* _tmp40_;
		_tmp38_ = self->priv->env_file_path;
		_tmp39_ = out_text;
		_tmp40_ = _tmp39_->str;
		g_file_set_contents (_tmp38_, _tmp40_, (gssize) -1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp41_;
		const gchar* _tmp42_;
		gchar* _tmp43_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp41_ = e;
		_tmp42_ = _tmp41_->message;
		_tmp43_ = g_strdup (_tmp42_);
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp43_;
		result = FALSE;
		_g_error_free0 (e);
		_g_string_free0 (out_text);
		_g_free0 (content);
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp44_ = FALSE;
		_g_string_free0 (out_text);
		_g_free0 (content);
		_g_free0 (_vala_error_message);
		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 _tmp44_;
	}
	_tmp45_ = g_strdup ("");
	_g_free0 (_vala_error_message);
	_vala_error_message = _tmp45_;
	result = TRUE;
	_g_string_free0 (out_text);
	_g_free0 (content);
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

static gboolean
settings_window_reload_labwc (SettingsWindow* self,
                              gchar** error_message)
{
	gchar* _vala_error_message = NULL;
	gchar* labwc_path = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gint status = 0;
	gchar* std_out = NULL;
	gchar* std_err = NULL;
	gchar* _tmp17_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = g_find_program_in_path ("labwc");
	labwc_path = _tmp0_;
	_tmp2_ = labwc_path;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		const gchar* _tmp3_;
		_tmp3_ = labwc_path;
		_tmp1_ = g_strcmp0 (_tmp3_, "") == 0;
	}
	if (_tmp1_) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("'labwc' is not available in PATH.");
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp4_;
		result = FALSE;
		_g_free0 (labwc_path);
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	status = 1;
	{
		gchar* _tmp5_ = NULL;
		gchar* _tmp6_ = NULL;
		gint _tmp7_ = 0;
		g_spawn_command_line_sync ("labwc -r", &_tmp5_, &_tmp6_, &_tmp7_, &_inner_error0_);
		_g_free0 (std_out);
		std_out = _tmp5_;
		_g_free0 (std_err);
		std_err = _tmp6_;
		status = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp8_ = FALSE;
			if (_inner_error0_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_error;
			}
			_g_free0 (std_err);
			_g_free0 (std_out);
			_g_free0 (labwc_path);
			_g_free0 (_vala_error_message);
			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 _tmp8_;
		}
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		GError* e = NULL;
		GError* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp9_ = e;
		_tmp10_ = _tmp9_->message;
		_tmp11_ = g_strdup (_tmp10_);
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp11_;
		result = FALSE;
		_g_error_free0 (e);
		_g_free0 (std_err);
		_g_free0 (std_out);
		_g_free0 (labwc_path);
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gboolean _tmp12_ = FALSE;
		_g_free0 (std_err);
		_g_free0 (std_out);
		_g_free0 (labwc_path);
		_g_free0 (_vala_error_message);
		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 _tmp12_;
	}
	if (status != 0) {
		const gchar* _tmp13_ = NULL;
		const gchar* _tmp14_;
		gchar* _tmp16_;
		_tmp14_ = std_err;
		if (g_strcmp0 (_tmp14_, "") != 0) {
			const gchar* _tmp15_;
			_tmp15_ = std_err;
			_tmp13_ = _tmp15_;
		} else {
			_tmp13_ = _ ("labwc reload failed");
		}
		_tmp16_ = g_strdup (_tmp13_);
		_g_free0 (_vala_error_message);
		_vala_error_message = _tmp16_;
		result = FALSE;
		_g_free0 (std_err);
		_g_free0 (std_out);
		_g_free0 (labwc_path);
		if (error_message) {
			*error_message = _vala_error_message;
		} else {
			_g_free0 (_vala_error_message);
		}
		return result;
	}
	_tmp17_ = g_strdup ("");
	_g_free0 (_vala_error_message);
	_vala_error_message = _tmp17_;
	result = TRUE;
	_g_free0 (std_err);
	_g_free0 (std_out);
	_g_free0 (labwc_path);
	if (error_message) {
		*error_message = _vala_error_message;
	} else {
		_g_free0 (_vala_error_message);
	}
	return result;
}

static gboolean
__lambda17_ (SettingsWindow* self)
{
	gboolean result;
	settings_window_clear_status (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda17__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda17_ ((SettingsWindow*) self);
	return result;
}

static void
settings_window_apply_changes (SettingsWindow* self)
{
	gchar* validation_error = NULL;
	gchar* _tmp0_ = NULL;
	gboolean _tmp1_;
	gchar* layouts_csv = NULL;
	gchar* _tmp10_;
	gchar* option = NULL;
	gchar* _tmp11_;
	gchar* save_error = NULL;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_ = NULL;
	gboolean _tmp15_;
	gchar* reload_error = NULL;
	gchar* _tmp24_ = NULL;
	gboolean _tmp25_;
	GtkLabel* _tmp36_;
	GtkLabel* _tmp37_;
	gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	gchar* _tmp41_;
	g_return_if_fail (self != NULL);
	_tmp1_ = settings_window_validate_form (self, &_tmp0_);
	_g_free0 (validation_error);
	validation_error = _tmp0_;
	if (!_tmp1_) {
		const gchar* _tmp2_;
		GtkLabel* _tmp3_;
		GtkLabel* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp2_ = validation_error;
		settings_window_show_error_dialog (self, _ ("Cannot apply settings"), _tmp2_);
		_tmp3_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp3_);
		_tmp4_ = self->priv->status_label;
		_tmp5_ = validation_error;
		_tmp6_ = g_strconcat ("<span foreground='red'>✗ ", _tmp5_, NULL);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strconcat (_tmp7_, "</span>", NULL);
		_tmp9_ = _tmp8_;
		gtk_label_set_markup (_tmp4_, _tmp9_);
		_g_free0 (_tmp9_);
		_g_free0 (_tmp7_);
		_g_free0 (validation_error);
		return;
	}
	_tmp10_ = settings_window_collect_layouts_csv (self);
	layouts_csv = _tmp10_;
	_tmp11_ = settings_window_get_effective_option (self);
	option = _tmp11_;
	_tmp12_ = layouts_csv;
	_tmp13_ = option;
	_tmp15_ = settings_window_write_environment (self, _tmp12_, _tmp13_, &_tmp14_);
	_g_free0 (save_error);
	save_error = _tmp14_;
	if (!_tmp15_) {
		const gchar* _tmp16_;
		GtkLabel* _tmp17_;
		GtkLabel* _tmp18_;
		const gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		gchar* _tmp22_;
		gchar* _tmp23_;
		_tmp16_ = save_error;
		settings_window_show_error_dialog (self, _ ("Failed to save environment"), _tmp16_);
		_tmp17_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp17_);
		_tmp18_ = self->priv->status_label;
		_tmp19_ = save_error;
		_tmp20_ = g_strconcat ("<span foreground='red'>✗ ", _tmp19_, NULL);
		_tmp21_ = _tmp20_;
		_tmp22_ = g_strconcat (_tmp21_, "</span>", NULL);
		_tmp23_ = _tmp22_;
		gtk_label_set_markup (_tmp18_, _tmp23_);
		_g_free0 (_tmp23_);
		_g_free0 (_tmp21_);
		_g_free0 (save_error);
		_g_free0 (option);
		_g_free0 (layouts_csv);
		_g_free0 (validation_error);
		return;
	}
	_tmp25_ = settings_window_reload_labwc (self, &_tmp24_);
	_g_free0 (reload_error);
	reload_error = _tmp24_;
	if (!_tmp25_) {
		const gchar* _tmp26_;
		gchar* _tmp27_;
		gchar* _tmp28_;
		GtkLabel* _tmp29_;
		GtkLabel* _tmp30_;
		const gchar* _tmp31_;
		gchar* _tmp32_;
		gchar* _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		_tmp26_ = reload_error;
		_tmp27_ = g_strconcat (_ ("Configuration was written, but reload failed: "), _tmp26_, NULL);
		_tmp28_ = _tmp27_;
		settings_window_show_error_dialog (self, _ ("Settings saved"), _tmp28_);
		_g_free0 (_tmp28_);
		_tmp29_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp29_);
		_tmp30_ = self->priv->status_label;
		_tmp31_ = reload_error;
		_tmp32_ = g_strconcat ("<span foreground='red'>✗ ", _tmp31_, NULL);
		_tmp33_ = _tmp32_;
		_tmp34_ = g_strconcat (_tmp33_, "</span>", NULL);
		_tmp35_ = _tmp34_;
		gtk_label_set_markup (_tmp30_, _tmp35_);
		_g_free0 (_tmp35_);
		_g_free0 (_tmp33_);
		_g_free0 (reload_error);
		_g_free0 (save_error);
		_g_free0 (option);
		_g_free0 (layouts_csv);
		_g_free0 (validation_error);
		return;
	}
	_tmp36_ = self->priv->status_label;
	gtk_widget_show ((GtkWidget*) _tmp36_);
	_tmp37_ = self->priv->status_label;
	_tmp38_ = g_strconcat ("<span foreground='green'>✓ ", _ ("Changes applied. labwc was reloaded."), NULL);
	_tmp39_ = _tmp38_;
	_tmp40_ = g_strconcat (_tmp39_, "</span>", NULL);
	_tmp41_ = _tmp40_;
	gtk_label_set_markup (_tmp37_, _tmp41_);
	_g_free0 (_tmp41_);
	_g_free0 (_tmp39_);
	g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 5000, ___lambda17__gsource_func, g_object_ref (self), g_object_unref);
	_g_free0 (reload_error);
	_g_free0 (save_error);
	_g_free0 (option);
	_g_free0 (layouts_csv);
	_g_free0 (validation_error);
}

static gboolean
___lambda20_ (SettingsWindow* self)
{
	gboolean result;
	settings_window_clear_status (self);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda20__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda20_ ((SettingsWindow*) self);
	return result;
}

static void
settings_window_apply_to_wm (SettingsWindow* self)
{
	gboolean _tmp0_ = FALSE;
	gchar* validation_error = NULL;
	gchar* _tmp1_ = NULL;
	gboolean _tmp2_;
	GtkMessageDialog* confirm_dialog = NULL;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GtkMessageDialog* _tmp13_;
	GtkMessageDialog* _tmp14_;
	GtkMessageDialog* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gint response = 0;
	GtkMessageDialog* _tmp20_;
	GtkMessageDialog* _tmp21_;
	gchar* layouts_csv = NULL;
	gchar* _tmp22_;
	gchar* option = NULL;
	gchar* _tmp23_;
	WMConfigModifierXKBConfig* current_config = NULL;
	WMConfigModifierXKBConfig* xkb_config = NULL;
	WMConfigModifierXKBConfig* _tmp27_;
	WMConfigModifierXKBConfig* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_ = NULL;
	WMConfigModifierXKBConfig* _tmp31_;
	gchar* current_opts = NULL;
	gchar* _tmp35_;
	WMConfigModifierXKBConfig* _tmp36_;
	const gchar* _tmp37_;
	const gchar* _tmp38_;
	gchar* _tmp39_;
	gchar* _tmp40_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	if (self->priv->detected_wm == WM_DETECTOR_WAYLAND_WM_UNKNOWN) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->detected_wm == WM_DETECTOR_WAYLAND_WM_LABWC;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = settings_window_validate_form (self, &_tmp1_);
	_g_free0 (validation_error);
	validation_error = _tmp1_;
	if (!_tmp2_) {
		const gchar* _tmp3_;
		GtkLabel* _tmp4_;
		GtkLabel* _tmp5_;
		const gchar* _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = validation_error;
		settings_window_show_error_dialog (self, _ ("Cannot apply to WM"), _tmp3_);
		_tmp4_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp4_);
		_tmp5_ = self->priv->status_label;
		_tmp6_ = validation_error;
		_tmp7_ = g_strconcat ("<span foreground='red'>✗ ", _tmp6_, NULL);
		_tmp8_ = _tmp7_;
		_tmp9_ = g_strconcat (_tmp8_, "</span>", NULL);
		_tmp10_ = _tmp9_;
		gtk_label_set_markup (_tmp5_, _tmp10_);
		_g_free0 (_tmp10_);
		_g_free0 (_tmp8_);
		_g_free0 (validation_error);
		return;
	}
	_tmp11_ = wm_detector_get_name (self->priv->detected_wm);
	_tmp12_ = _tmp11_;
	_tmp13_ = (GtkMessageDialog*) gtk_message_dialog_new ((GtkWindow*) self, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _ ("Apply XKB configuration to %s?"), _tmp12_);
	g_object_ref_sink (_tmp13_);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp12_);
	confirm_dialog = _tmp14_;
	_tmp15_ = confirm_dialog;
	_tmp16_ = wm_detector_get_name (self->priv->detected_wm);
	_tmp17_ = _tmp16_;
	_tmp18_ = g_strdup_printf (_ ("This will modify your %s configuration file.\n" "A backup will be created automatically before applying.\n\n" "Do you want to continue?"), _tmp17_);
	_tmp19_ = _tmp18_;
	g_object_set (_tmp15_, "secondary-text", _tmp19_, NULL);
	_g_free0 (_tmp19_);
	_g_free0 (_tmp17_);
	_tmp20_ = confirm_dialog;
	response = gtk_dialog_run ((GtkDialog*) _tmp20_);
	_tmp21_ = confirm_dialog;
	gtk_widget_destroy ((GtkWidget*) _tmp21_);
	if (response != ((gint) GTK_RESPONSE_YES)) {
		_g_object_unref0 (confirm_dialog);
		_g_free0 (validation_error);
		return;
	}
	_tmp22_ = settings_window_collect_layouts_csv (self);
	layouts_csv = _tmp22_;
	_tmp23_ = settings_window_get_effective_option (self);
	option = _tmp23_;
	current_config = NULL;
	{
		WMConfigModifierXKBConfig* _tmp24_ = NULL;
		WMConfigModifierXKBConfig* _tmp25_;
		WMConfigModifierXKBConfig* _tmp26_;
		_tmp25_ = wm_config_modifier_read_from_wm (self->priv->detected_wm, &_inner_error0_);
		_tmp24_ = _tmp25_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp26_ = _tmp24_;
		_tmp24_ = NULL;
		_wm_config_modifier_xkb_config_unref0 (current_config);
		current_config = _tmp26_;
		_wm_config_modifier_xkb_config_unref0 (_tmp24_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
		_wm_config_modifier_xkb_config_unref0 (current_config);
		current_config = NULL;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_wm_config_modifier_xkb_config_unref0 (current_config);
		_g_free0 (option);
		_g_free0 (layouts_csv);
		_g_object_unref0 (confirm_dialog);
		_g_free0 (validation_error);
		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;
	}
	_tmp27_ = wm_config_modifier_xkb_config_new ();
	xkb_config = _tmp27_;
	_tmp28_ = xkb_config;
	_tmp29_ = layouts_csv;
	wm_config_modifier_xkb_config_set_layout (_tmp28_, _tmp29_);
	_tmp31_ = current_config;
	if (_tmp31_ != NULL) {
		WMConfigModifierXKBConfig* _tmp32_;
		const gchar* _tmp33_;
		const gchar* _tmp34_;
		_tmp32_ = current_config;
		_tmp33_ = wm_config_modifier_xkb_config_get_options (_tmp32_);
		_tmp34_ = _tmp33_;
		_tmp30_ = _tmp34_;
	} else {
		_tmp30_ = "";
	}
	_tmp35_ = g_strdup (_tmp30_);
	current_opts = _tmp35_;
	_tmp36_ = xkb_config;
	_tmp37_ = current_opts;
	_tmp38_ = option;
	_tmp39_ = settings_window_merge_grp_option (self, _tmp37_, _tmp38_);
	_tmp40_ = _tmp39_;
	wm_config_modifier_xkb_config_set_options (_tmp36_, _tmp40_);
	_g_free0 (_tmp40_);
	{
		gchar* config_path = NULL;
		gchar* _tmp41_;
		const gchar* _tmp42_;
		gchar* _tmp43_;
		gchar* _tmp44_;
		gboolean _tmp45_ = FALSE;
		WMConfigModifierXKBConfig* _tmp46_;
		GtkLabel* _tmp60_;
		GtkLabel* _tmp61_;
		gchar* _tmp62_;
		gchar* _tmp63_;
		gchar* _tmp64_;
		gchar* _tmp65_;
		_tmp41_ = wm_detector_get_config_path (self->priv->detected_wm);
		config_path = _tmp41_;
		_tmp42_ = config_path;
		_tmp43_ = wm_detector_get_name (self->priv->detected_wm);
		_tmp44_ = _tmp43_;
		wm_config_backup_create_backup (_tmp42_, _tmp44_, &_inner_error0_);
		_g_free0 (_tmp44_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (config_path);
			goto __catch1_g_error;
		}
		_tmp46_ = xkb_config;
		_tmp45_ = wm_config_modifier_apply_to_wm (self->priv->detected_wm, _tmp46_, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (config_path);
			goto __catch1_g_error;
		}
		if (!_tmp45_) {
			gchar* _tmp47_;
			gchar* _tmp48_;
			gchar* _tmp49_;
			gchar* _tmp50_;
			GtkLabel* _tmp51_;
			gchar* _tmp52_;
			gchar* _tmp53_;
			gchar* _tmp54_;
			gchar* _tmp55_;
			gchar* _tmp56_;
			gchar* _tmp57_;
			gchar* _tmp58_;
			gchar* _tmp59_;
			_tmp47_ = wm_detector_get_name (self->priv->detected_wm);
			_tmp48_ = _tmp47_;
			_tmp49_ = g_strdup_printf (_ ("Could not modify %s configuration."), _tmp48_);
			_tmp50_ = _tmp49_;
			settings_window_show_error_dialog (self, _ ("Failed to apply to WM"), _tmp50_);
			_g_free0 (_tmp50_);
			_g_free0 (_tmp48_);
			_tmp51_ = self->priv->status_label;
			_tmp52_ = wm_detector_get_name (self->priv->detected_wm);
			_tmp53_ = _tmp52_;
			_tmp54_ = g_strdup_printf (_ ("Could not modify %s configuration."), _tmp53_);
			_tmp55_ = _tmp54_;
			_tmp56_ = g_strconcat ("<span foreground='red'>✗ ", _tmp55_, NULL);
			_tmp57_ = _tmp56_;
			_tmp58_ = g_strconcat (_tmp57_, "</span>", NULL);
			_tmp59_ = _tmp58_;
			gtk_label_set_markup (_tmp51_, _tmp59_);
			_g_free0 (_tmp59_);
			_g_free0 (_tmp57_);
			_g_free0 (_tmp55_);
			_g_free0 (_tmp53_);
			_g_free0 (config_path);
			_g_free0 (current_opts);
			_wm_config_modifier_xkb_config_unref0 (xkb_config);
			_wm_config_modifier_xkb_config_unref0 (current_config);
			_g_free0 (option);
			_g_free0 (layouts_csv);
			_g_object_unref0 (confirm_dialog);
			_g_free0 (validation_error);
			return;
		}
		_tmp60_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp60_);
		_tmp61_ = self->priv->status_label;
		_tmp62_ = g_strconcat ("<span foreground='green'>✓ ", _ ("Changes saved. Restart your WM to see the result."), NULL);
		_tmp63_ = _tmp62_;
		_tmp64_ = g_strconcat (_tmp63_, "</span>", NULL);
		_tmp65_ = _tmp64_;
		gtk_label_set_markup (_tmp61_, _tmp65_);
		_g_free0 (_tmp65_);
		_g_free0 (_tmp63_);
		g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 5000, ____lambda20__gsource_func, g_object_ref (self), g_object_unref);
		_g_free0 (config_path);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		GError* _tmp66_;
		const gchar* _tmp67_;
		GtkLabel* _tmp68_;
		GtkLabel* _tmp69_;
		GError* _tmp70_;
		const gchar* _tmp71_;
		gchar* _tmp72_;
		gchar* _tmp73_;
		gchar* _tmp74_;
		gchar* _tmp75_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp66_ = e;
		_tmp67_ = _tmp66_->message;
		settings_window_show_error_dialog (self, _ ("Error applying to WM"), _tmp67_);
		_tmp68_ = self->priv->status_label;
		gtk_widget_show ((GtkWidget*) _tmp68_);
		_tmp69_ = self->priv->status_label;
		_tmp70_ = e;
		_tmp71_ = _tmp70_->message;
		_tmp72_ = g_strconcat ("<span foreground='red'>✗ ", _tmp71_, NULL);
		_tmp73_ = _tmp72_;
		_tmp74_ = g_strconcat (_tmp73_, "</span>", NULL);
		_tmp75_ = _tmp74_;
		gtk_label_set_markup (_tmp69_, _tmp75_);
		_g_free0 (_tmp75_);
		_g_free0 (_tmp73_);
		_g_error_free0 (e);
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (current_opts);
		_wm_config_modifier_xkb_config_unref0 (xkb_config);
		_wm_config_modifier_xkb_config_unref0 (current_config);
		_g_free0 (option);
		_g_free0 (layouts_csv);
		_g_object_unref0 (confirm_dialog);
		_g_free0 (validation_error);
		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;
	}
	_g_free0 (current_opts);
	_wm_config_modifier_xkb_config_unref0 (xkb_config);
	_wm_config_modifier_xkb_config_unref0 (current_config);
	_g_free0 (option);
	_g_free0 (layouts_csv);
	_g_object_unref0 (confirm_dialog);
	_g_free0 (validation_error);
}

static void
settings_window_show_error_dialog (SettingsWindow* self,
                                   const gchar* title,
                                   const gchar* details)
{
	GtkMessageDialog* dialog = NULL;
	GtkMessageDialog* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (title != NULL);
	g_return_if_fail (details != NULL);
	_tmp0_ = (GtkMessageDialog*) gtk_message_dialog_new ((GtkWindow*) self, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", title);
	g_object_ref_sink (_tmp0_);
	dialog = _tmp0_;
	g_object_set (dialog, "secondary-text", details, NULL);
	gtk_dialog_run ((GtkDialog*) dialog);
	gtk_widget_destroy ((GtkWidget*) dialog);
	_g_object_unref0 (dialog);
}

static void
settings_window_class_init (SettingsWindowClass * klass,
                            gpointer klass_data)
{
	settings_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SettingsWindow_private_offset);
	G_OBJECT_CLASS (klass)->finalize = settings_window_finalize;
}

static void
settings_window_instance_init (SettingsWindow * self,
                               gpointer klass)
{
	self->priv = settings_window_get_instance_private (self);
}

static void
settings_window_finalize (GObject * obj)
{
	SettingsWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_SETTINGS_WINDOW, SettingsWindow);
	_g_object_unref0 (self->priv->layout_store);
	_g_object_unref0 (self->priv->layout_view);
	_g_object_unref0 (self->priv->shortcut_combo);
	_g_object_unref0 (self->priv->custom_option_entry);
	_g_object_unref0 (self->priv->preview_layout_label);
	_g_object_unref0 (self->priv->preview_option_label);
	_g_object_unref0 (self->priv->remove_button);
	_g_object_unref0 (self->priv->up_button);
	_g_object_unref0 (self->priv->down_button);
	_g_object_unref0 (self->priv->apply_wm_button);
	_g_object_unref0 (self->priv->status_label);
	_g_object_unref0 (self->priv->initial_snapshot);
	_g_free0 (self->priv->env_file_path);
	_g_free0 (self->priv->flag_dir_path);
	_g_free0 (self->priv->layouts_config_path);
	G_OBJECT_CLASS (settings_window_parent_class)->finalize (obj);
}

static GType
settings_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SettingsWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) settings_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SettingsWindow), 0, (GInstanceInitFunc) settings_window_instance_init, NULL };
	GType settings_window_type_id;
	settings_window_type_id = g_type_register_static (gtk_application_window_get_type (), "SettingsWindow", &g_define_type_info, 0);
	SettingsWindow_private_offset = g_type_add_instance_private (settings_window_type_id, sizeof (SettingsWindowPrivate));
	return settings_window_type_id;
}

GType
settings_window_get_type (void)
{
	static volatile gsize settings_window_type_id__once = 0;
	if (g_once_init_enter (&settings_window_type_id__once)) {
		GType settings_window_type_id;
		settings_window_type_id = settings_window_get_type_once ();
		g_once_init_leave (&settings_window_type_id__once, settings_window_type_id);
	}
	return settings_window_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 gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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;
}

