/* crystal_dock_helper.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from crystal_dock_helper.vala, do not modify */

/*
 * This file is part of budgie-desktop
 *
 * Copyright Budgie Desktop Developers
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gstdio.h>
#include <unistd.h>

#define BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MIN 5000
#define BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MAX 30000
#define BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_INCREMENT 5000
#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 BUDGIE_TYPE_CRYSTAL_DOCK_HELPER (budgie_crystal_dock_helper_get_type ())
#define BUDGIE_CRYSTAL_DOCK_HELPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_CRYSTAL_DOCK_HELPER, BudgieCrystalDockHelper))
#define BUDGIE_CRYSTAL_DOCK_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_CRYSTAL_DOCK_HELPER, BudgieCrystalDockHelperClass))
#define BUDGIE_IS_CRYSTAL_DOCK_HELPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_CRYSTAL_DOCK_HELPER))
#define BUDGIE_IS_CRYSTAL_DOCK_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_CRYSTAL_DOCK_HELPER))
#define BUDGIE_CRYSTAL_DOCK_HELPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_CRYSTAL_DOCK_HELPER, BudgieCrystalDockHelperClass))

typedef struct _BudgieCrystalDockHelper BudgieCrystalDockHelper;
typedef struct _BudgieCrystalDockHelperClass BudgieCrystalDockHelperClass;
typedef struct _BudgieCrystalDockHelperPrivate BudgieCrystalDockHelperPrivate;
enum  {
	BUDGIE_CRYSTAL_DOCK_HELPER_0_PROPERTY,
	BUDGIE_CRYSTAL_DOCK_HELPER_NUM_PROPERTIES
};
static GParamSpec* budgie_crystal_dock_helper_properties[BUDGIE_CRYSTAL_DOCK_HELPER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
enum  {
	BUDGIE_CRYSTAL_DOCK_HELPER_DOCK_CONFIG_CHANGED_SIGNAL,
	BUDGIE_CRYSTAL_DOCK_HELPER_NUM_SIGNALS
};
static guint budgie_crystal_dock_helper_signals[BUDGIE_CRYSTAL_DOCK_HELPER_NUM_SIGNALS] = {0};

struct _BudgieCrystalDockHelper {
	GObject parent_instance;
	BudgieCrystalDockHelperPrivate * priv;
};

struct _BudgieCrystalDockHelperClass {
	GObjectClass parent_class;
};

struct _BudgieCrystalDockHelperPrivate {
	GFileMonitor* config_monitor;
	guint dock_check_timeout;
	gboolean last_dock_running;
	gboolean crystal_dock_installed;
	gint current_poll_interval;
	gchar* config_dir;
};

static gint BudgieCrystalDockHelper_private_offset;
static gpointer budgie_crystal_dock_helper_parent_class = NULL;

VALA_EXTERN GType budgie_crystal_dock_helper_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieCrystalDockHelper, g_object_unref)
static void budgie_crystal_dock_helper_cleanup_monitors (BudgieCrystalDockHelper* self);
VALA_EXTERN BudgieCrystalDockHelper* budgie_crystal_dock_helper_new (void);
VALA_EXTERN BudgieCrystalDockHelper* budgie_crystal_dock_helper_construct (GType object_type);
static void budgie_crystal_dock_helper_setup_monitors (BudgieCrystalDockHelper* self);
static void budgie_crystal_dock_helper_setup_config_file_monitor (BudgieCrystalDockHelper* self);
static void budgie_crystal_dock_helper_setup_process_monitor (BudgieCrystalDockHelper* self);
static void ___lambda5_ (BudgieCrystalDockHelper* self,
                  GFile* file,
                  GFile* other_file,
                  GFileMonitorEvent event_type);
static gboolean ____lambda6_ (BudgieCrystalDockHelper* self);
static gboolean _____lambda6__gsource_func (gpointer self);
static void ____lambda5__g_file_monitor_changed (GFileMonitor* _sender,
                                          GFile* file,
                                          GFile* other_file,
                                          GFileMonitorEvent event_type,
                                          gpointer self);
static gboolean budgie_crystal_dock_helper_is_running (BudgieCrystalDockHelper* self);
static gboolean budgie_crystal_dock_helper_check_process_state (BudgieCrystalDockHelper* self);
static gboolean _budgie_crystal_dock_helper_check_process_state_gsource_func (gpointer self);
static void budgie_crystal_dock_helper_adjust_poll_interval (BudgieCrystalDockHelper* self);
static gchar* budgie_crystal_dock_helper_get_panel_edge (BudgieCrystalDockHelper* self,
                                                  const gchar* config_path);
VALA_EXTERN gchar** budgie_crystal_dock_helper_get_active_edges (BudgieCrystalDockHelper* self,
                                                     gint* result_length1);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
VALA_EXTERN gchar* budgie_crystal_dock_helper_apply_borders (BudgieCrystalDockHelper* self,
                                                 const gchar* original_path);
static void budgie_crystal_dock_helper_finalize (GObject * obj);
static GType budgie_crystal_dock_helper_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
budgie_crystal_dock_helper_get_instance_private (BudgieCrystalDockHelper* self)
{
	return G_STRUCT_MEMBER_P (self, BudgieCrystalDockHelper_private_offset);
}

BudgieCrystalDockHelper*
budgie_crystal_dock_helper_construct (GType object_type)
{
	BudgieCrystalDockHelper * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	self = (BudgieCrystalDockHelper*) g_object_new (object_type, NULL);
	_tmp0_ = g_find_program_in_path ("crystal-dock");
	_tmp1_ = _tmp0_;
	self->priv->crystal_dock_installed = _tmp1_ != NULL;
	_g_free0 (_tmp1_);
	if (self->priv->crystal_dock_installed) {
		g_message ("crystal_dock_helper.vala:39: Crystal Dock is installed, setting up mon" \
"itoring");
		budgie_crystal_dock_helper_setup_monitors (self);
	}
	return self;
}

BudgieCrystalDockHelper*
budgie_crystal_dock_helper_new (void)
{
	return budgie_crystal_dock_helper_construct (BUDGIE_TYPE_CRYSTAL_DOCK_HELPER);
}

/**
* Setup monitoring for Crystal Dock config changes and process state
*/
static void
budgie_crystal_dock_helper_setup_monitors (BudgieCrystalDockHelper* self)
{
	g_return_if_fail (self != NULL);
	budgie_crystal_dock_helper_setup_config_file_monitor (self);
	budgie_crystal_dock_helper_setup_process_monitor (self);
}

/**
* Cleanup monitors on destruction
*/
static void
budgie_crystal_dock_helper_cleanup_monitors (BudgieCrystalDockHelper* self)
{
	GFileMonitor* _tmp0_;
	g_return_if_fail (self != NULL);
	if (self->priv->dock_check_timeout > ((guint) 0)) {
		g_source_remove (self->priv->dock_check_timeout);
		self->priv->dock_check_timeout = (guint) 0;
	}
	_tmp0_ = self->priv->config_monitor;
	if (_tmp0_ != NULL) {
		GFileMonitor* _tmp1_;
		_tmp1_ = self->priv->config_monitor;
		g_file_monitor_cancel (_tmp1_);
		_g_object_unref0 (self->priv->config_monitor);
		self->priv->config_monitor = NULL;
	}
}

/**
* Setup file monitor for Crystal Dock config directory
*/
static gboolean
____lambda6_ (BudgieCrystalDockHelper* self)
{
	gboolean result;
	g_signal_emit (self, budgie_crystal_dock_helper_signals[BUDGIE_CRYSTAL_DOCK_HELPER_DOCK_CONFIG_CHANGED_SIGNAL], 0);
	result = FALSE;
	return result;
}

static gboolean
_____lambda6__gsource_func (gpointer self)
{
	gboolean result;
	result = ____lambda6_ ((BudgieCrystalDockHelper*) self);
	return result;
}

static void
___lambda5_ (BudgieCrystalDockHelper* self,
             GFile* file,
             GFile* other_file,
             GFileMonitorEvent event_type)
{
	gchar* basename = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	g_return_if_fail (file != NULL);
	_tmp0_ = g_file_get_basename (file);
	basename = _tmp0_;
	_tmp2_ = basename;
	if (g_str_has_prefix (_tmp2_, "panel_")) {
		const gchar* _tmp3_;
		_tmp3_ = basename;
		_tmp1_ = g_str_has_suffix (_tmp3_, ".conf");
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		switch (event_type) {
			case G_FILE_MONITOR_EVENT_CHANGED:
			case G_FILE_MONITOR_EVENT_CREATED:
			case G_FILE_MONITOR_EVENT_DELETED:
			{
				const gchar* _tmp4_;
				_tmp4_ = basename;
				g_debug ("crystal_dock_helper.vala:89: Crystal Dock config changed: %s", _tmp4_);
				g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 200, _____lambda6__gsource_func, g_object_ref (self), g_object_unref);
				break;
			}
			default:
			{
				break;
			}
		}
	}
	_g_free0 (basename);
}

static void
____lambda5__g_file_monitor_changed (GFileMonitor* _sender,
                                     GFile* file,
                                     GFile* other_file,
                                     GFileMonitorEvent event_type,
                                     gpointer self)
{
	___lambda5_ ((BudgieCrystalDockHelper*) self, file, other_file, event_type);
}

static void
budgie_crystal_dock_helper_setup_config_file_monitor (BudgieCrystalDockHelper* self)
{
	const gchar* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->config_dir;
	if (!g_file_test (_tmp0_, G_FILE_TEST_IS_DIR)) {
		return;
	}
	{
		GFile* config_file = NULL;
		const gchar* _tmp1_;
		GFile* _tmp2_;
		GFileMonitor* _tmp3_ = NULL;
		GFile* _tmp4_;
		GFileMonitor* _tmp5_;
		GFileMonitor* _tmp6_;
		GFileMonitor* _tmp7_;
		_tmp1_ = self->priv->config_dir;
		_tmp2_ = g_file_new_for_path (_tmp1_);
		config_file = _tmp2_;
		_tmp4_ = config_file;
		_tmp5_ = g_file_monitor_directory (_tmp4_, G_FILE_MONITOR_NONE, NULL, &_inner_error0_);
		_tmp3_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (config_file);
			goto __catch0_g_error;
		}
		_tmp6_ = _tmp3_;
		_tmp3_ = NULL;
		_g_object_unref0 (self->priv->config_monitor);
		self->priv->config_monitor = _tmp6_;
		_tmp7_ = self->priv->config_monitor;
		g_signal_connect_object (_tmp7_, "changed", (GCallback) ____lambda5__g_file_monitor_changed, self, 0);
		g_debug ("crystal_dock_helper.vala:102: Monitoring Crystal Dock config for chang" \
"es");
		_g_object_unref0 (_tmp3_);
		_g_object_unref0 (config_file);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp8_;
		const gchar* _tmp9_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_warning ("crystal_dock_helper.vala:105: Failed to setup Crystal Dock config moni" \
"tor: %s", _tmp9_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
}

/**
* Setup adaptive process polling
*/
static gboolean
_budgie_crystal_dock_helper_check_process_state_gsource_func (gpointer self)
{
	gboolean result;
	result = budgie_crystal_dock_helper_check_process_state ((BudgieCrystalDockHelper*) self);
	return result;
}

static void
budgie_crystal_dock_helper_setup_process_monitor (BudgieCrystalDockHelper* self)
{
	g_return_if_fail (self != NULL);
	self->priv->last_dock_running = budgie_crystal_dock_helper_is_running (self);
	self->priv->current_poll_interval = BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MIN;
	self->priv->dock_check_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) self->priv->current_poll_interval, _budgie_crystal_dock_helper_check_process_state_gsource_func, g_object_ref (self), g_object_unref);
}

/**
* Check Crystal Dock process state and adjust polling interval
*/
static gboolean
budgie_crystal_dock_helper_check_process_state (BudgieCrystalDockHelper* self)
{
	gboolean currently_running = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	currently_running = budgie_crystal_dock_helper_is_running (self);
	if (currently_running != self->priv->last_dock_running) {
		const gchar* _tmp0_ = NULL;
		if (currently_running) {
			_tmp0_ = "started";
		} else {
			_tmp0_ = "stopped";
		}
		g_debug ("crystal_dock_helper.vala:127: Crystal Dock %s", _tmp0_);
		self->priv->last_dock_running = currently_running;
		g_signal_emit (self, budgie_crystal_dock_helper_signals[BUDGIE_CRYSTAL_DOCK_HELPER_DOCK_CONFIG_CHANGED_SIGNAL], 0);
		if (self->priv->current_poll_interval != BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MIN) {
			self->priv->current_poll_interval = BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MIN;
			budgie_crystal_dock_helper_adjust_poll_interval (self);
		}
	} else {
		if (self->priv->current_poll_interval < BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MAX) {
			self->priv->current_poll_interval = self->priv->current_poll_interval + BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_INCREMENT;
			if (self->priv->current_poll_interval > BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MAX) {
				self->priv->current_poll_interval = BUDGIE_CRYSTAL_DOCK_HELPER_POLL_INTERVAL_MAX;
			}
			budgie_crystal_dock_helper_adjust_poll_interval (self);
		}
	}
	result = TRUE;
	return result;
}

/**
* Adjust polling interval by recreating the timeout
*/
static void
budgie_crystal_dock_helper_adjust_poll_interval (BudgieCrystalDockHelper* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->dock_check_timeout > ((guint) 0)) {
		g_source_remove (self->priv->dock_check_timeout);
	}
	self->priv->dock_check_timeout = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) self->priv->current_poll_interval, _budgie_crystal_dock_helper_check_process_state_gsource_func, g_object_ref (self), g_object_unref);
}

/**
* Check if crystal-dock process is running
*/
static gboolean
budgie_crystal_dock_helper_is_running (BudgieCrystalDockHelper* self)
{
	gboolean _tmp5_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		gchar* stdout_str = NULL;
		gint exit_status = 0;
		gchar* _tmp0_ = NULL;
		gint _tmp1_ = 0;
		g_spawn_command_line_sync ("pgrep -x crystal-dock", &_tmp0_, NULL, &_tmp1_, &_inner_error0_);
		_g_free0 (stdout_str);
		stdout_str = _tmp0_;
		exit_status = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp2_ = FALSE;
			_g_free0 (stdout_str);
			if (_inner_error0_->domain == G_SPAWN_ERROR) {
				goto __catch0_g_spawn_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 _tmp2_;
		}
		result = exit_status == 0;
		_g_free0 (stdout_str);
		return result;
	}
	goto __finally0;
	__catch0_g_spawn_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("crystal_dock_helper.vala:180: Failed to check for crystal-dock process" \
": %s", _tmp4_);
		result = FALSE;
		_g_error_free0 (e);
		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 _tmp5_;
}

/**
* Get edge position from a single panel config file
* Returns: "top", "bottom", "left", "right", or null
*/
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*
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 gchar*
budgie_crystal_dock_helper_get_panel_edge (BudgieCrystalDockHelper* self,
                                           const gchar* config_path)
{
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (config_path != NULL, NULL);
	if (!g_file_test (config_path, G_FILE_TEST_EXISTS)) {
		result = NULL;
		return result;
	}
	{
		gchar* contents = NULL;
		gchar* _tmp0_ = NULL;
		gchar** lines = NULL;
		const gchar* _tmp1_;
		gchar** _tmp2_;
		gchar** _tmp3_;
		gint lines_length1;
		gint _lines_size_;
		gchar** _tmp4_;
		gint _tmp4__length1;
		g_file_get_contents (config_path, &_tmp0_, NULL, &_inner_error0_);
		_g_free0 (contents);
		contents = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_free0 (contents);
			goto __catch0_g_error;
		}
		_tmp1_ = contents;
		_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, "\n", 0);
		lines = _tmp3_;
		lines_length1 = _vala_array_length (_tmp2_);
		_lines_size_ = lines_length1;
		_tmp4_ = lines;
		_tmp4__length1 = lines_length1;
		{
			gchar** line_collection = NULL;
			gint line_collection_length1 = 0;
			gint _line_collection_size_ = 0;
			gint line_it = 0;
			line_collection = _tmp4_;
			line_collection_length1 = _tmp4__length1;
			for (line_it = 0; line_it < line_collection_length1; line_it = line_it + 1) {
				gchar* _tmp5_;
				gchar* line = NULL;
				_tmp5_ = g_strdup (line_collection[line_it]);
				line = _tmp5_;
				{
					const gchar* _tmp6_;
					_tmp6_ = line;
					if (g_str_has_prefix (_tmp6_, "position=")) {
						gchar* pos_str = NULL;
						const gchar* _tmp7_;
						gchar* _tmp8_;
						gchar* _tmp9_;
						gchar* _tmp10_;
						gchar* _tmp11_;
						gint position = 0;
						const gchar* _tmp12_;
						_tmp7_ = line;
						_tmp8_ = string_substring (_tmp7_, (glong) 9, (glong) -1);
						_tmp9_ = _tmp8_;
						_tmp10_ = string_strip (_tmp9_);
						_tmp11_ = _tmp10_;
						_g_free0 (_tmp9_);
						pos_str = _tmp11_;
						_tmp12_ = pos_str;
						position = atoi (_tmp12_);
						switch (position) {
							case 0:
							{
								gchar* _tmp13_;
								_tmp13_ = g_strdup ("top");
								result = _tmp13_;
								_g_free0 (pos_str);
								_g_free0 (line);
								lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (contents);
								return result;
							}
							case 1:
							{
								gchar* _tmp14_;
								_tmp14_ = g_strdup ("bottom");
								result = _tmp14_;
								_g_free0 (pos_str);
								_g_free0 (line);
								lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (contents);
								return result;
							}
							case 2:
							{
								gchar* _tmp15_;
								_tmp15_ = g_strdup ("left");
								result = _tmp15_;
								_g_free0 (pos_str);
								_g_free0 (line);
								lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (contents);
								return result;
							}
							case 3:
							{
								gchar* _tmp16_;
								_tmp16_ = g_strdup ("right");
								result = _tmp16_;
								_g_free0 (pos_str);
								_g_free0 (line);
								lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (contents);
								return result;
							}
							default:
							{
								result = NULL;
								_g_free0 (pos_str);
								_g_free0 (line);
								lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
								_g_free0 (contents);
								return result;
							}
						}
						_g_free0 (pos_str);
					}
					_g_free0 (line);
				}
			}
		}
		lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (contents);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp17_;
		const gchar* _tmp18_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp17_ = e;
		_tmp18_ = _tmp17_->message;
		g_warning ("crystal_dock_helper.vala:215: Failed to read Crystal Dock config %s: %" \
"s", config_path, _tmp18_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	result = NULL;
	return result;
}

/**
* Detect all Crystal Dock panel edges
* Returns: array of active edges (e.g., ["top", "bottom"])
*/
static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

gchar**
budgie_crystal_dock_helper_get_active_edges (BudgieCrystalDockHelper* self,
                                             gint* result_length1)
{
	gchar** edges = NULL;
	gchar** _tmp0_;
	gint edges_length1;
	gint _edges_size_;
	const gchar* _tmp2_;
	gchar** _tmp19_;
	gint _tmp19__length1;
	gchar** result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	edges = _tmp0_;
	edges_length1 = 0;
	_edges_size_ = edges_length1;
	if (!self->priv->crystal_dock_installed) {
		gchar** _tmp1_;
		gint _tmp1__length1;
		_tmp1_ = edges;
		_tmp1__length1 = edges_length1;
		if (result_length1) {
			*result_length1 = _tmp1__length1;
		}
		result = _tmp1_;
		return result;
	}
	_tmp2_ = self->priv->config_dir;
	if (!g_file_test (_tmp2_, G_FILE_TEST_IS_DIR)) {
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp3_ = edges;
		_tmp3__length1 = edges_length1;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		return result;
	}
	{
		gint i = 0;
		i = 1;
		{
			gboolean _tmp4_ = FALSE;
			_tmp4_ = TRUE;
			while (TRUE) {
				gchar* panel_file = NULL;
				gchar* _tmp6_;
				gchar* config_path = NULL;
				const gchar* _tmp7_;
				const gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* edge = NULL;
				const gchar* _tmp10_;
				gchar* _tmp11_;
				const gchar* _tmp12_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (!(i <= 4)) {
					break;
				}
				_tmp6_ = g_strdup_printf ("panel_%d.conf", i);
				panel_file = _tmp6_;
				_tmp7_ = self->priv->config_dir;
				_tmp8_ = panel_file;
				_tmp9_ = g_build_filename (_tmp7_, _tmp8_, NULL);
				config_path = _tmp9_;
				_tmp10_ = config_path;
				_tmp11_ = budgie_crystal_dock_helper_get_panel_edge (self, _tmp10_);
				edge = _tmp11_;
				_tmp12_ = edge;
				if (_tmp12_ != NULL) {
					gboolean already_added = FALSE;
					gchar** _tmp13_;
					gint _tmp13__length1;
					already_added = FALSE;
					_tmp13_ = edges;
					_tmp13__length1 = edges_length1;
					{
						gchar** existing_edge_collection = NULL;
						gint existing_edge_collection_length1 = 0;
						gint _existing_edge_collection_size_ = 0;
						gint existing_edge_it = 0;
						existing_edge_collection = _tmp13_;
						existing_edge_collection_length1 = _tmp13__length1;
						for (existing_edge_it = 0; existing_edge_it < existing_edge_collection_length1; existing_edge_it = existing_edge_it + 1) {
							gchar* _tmp14_;
							gchar* existing_edge = NULL;
							_tmp14_ = g_strdup (existing_edge_collection[existing_edge_it]);
							existing_edge = _tmp14_;
							{
								const gchar* _tmp15_;
								const gchar* _tmp16_;
								_tmp15_ = existing_edge;
								_tmp16_ = edge;
								if (g_strcmp0 (_tmp15_, _tmp16_) == 0) {
									already_added = TRUE;
									_g_free0 (existing_edge);
									break;
								}
								_g_free0 (existing_edge);
							}
						}
					}
					if (!already_added) {
						const gchar* _tmp17_;
						gchar* _tmp18_;
						_tmp17_ = edge;
						_tmp18_ = g_strdup (_tmp17_);
						_vala_array_add1 (&edges, &edges_length1, &_edges_size_, _tmp18_);
					}
				}
				_g_free0 (edge);
				_g_free0 (config_path);
				_g_free0 (panel_file);
			}
		}
	}
	_tmp19_ = edges;
	_tmp19__length1 = edges_length1;
	if (result_length1) {
		*result_length1 = _tmp19__length1;
	}
	result = _tmp19_;
	return result;
}

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

gchar*
budgie_crystal_dock_helper_apply_borders (BudgieCrystalDockHelper* self,
                                          const gchar* original_path)
{
	gboolean _tmp0_ = FALSE;
	gchar** edges = NULL;
	gint _tmp2_ = 0;
	gchar** _tmp3_;
	gint edges_length1;
	gint _edges_size_;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar* runtime_dir = NULL;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* output_path = NULL;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* current_input = NULL;
	gchar* _tmp12_;
	gchar* temp_output = NULL;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	const gchar* _tmp53_;
	gchar* _tmp57_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (original_path != NULL, NULL);
	if (!self->priv->crystal_dock_installed) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = !self->priv->last_dock_running;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (original_path);
		result = _tmp1_;
		return result;
	}
	_tmp3_ = budgie_crystal_dock_helper_get_active_edges (self, &_tmp2_);
	edges = _tmp3_;
	edges_length1 = _tmp2_;
	_edges_size_ = edges_length1;
	_tmp4_ = edges;
	_tmp4__length1 = edges_length1;
	if (_tmp4__length1 == 0) {
		gchar* _tmp5_;
		_tmp5_ = g_strdup (original_path);
		result = _tmp5_;
		edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp6_ = g_getenv ("XDG_RUNTIME_DIR");
	_tmp7_ = g_strdup (_tmp6_);
	runtime_dir = _tmp7_;
	_tmp8_ = runtime_dir;
	if (_tmp8_ == NULL) {
		gchar* _tmp9_;
		_tmp9_ = g_strdup_printf ("/run/user/%d", (gint) getuid ());
		_g_free0 (runtime_dir);
		runtime_dir = _tmp9_;
	}
	_tmp10_ = runtime_dir;
	_tmp11_ = g_build_filename (_tmp10_, "budgie_wallpaper_bordered.jpg", NULL);
	output_path = _tmp11_;
	_tmp12_ = g_strdup (original_path);
	current_input = _tmp12_;
	_tmp13_ = output_path;
	_tmp14_ = g_strdup (_tmp13_);
	temp_output = _tmp14_;
	_tmp15_ = edges;
	_tmp15__length1 = edges_length1;
	{
		gchar** edge_collection = NULL;
		gint edge_collection_length1 = 0;
		gint _edge_collection_size_ = 0;
		gint edge_it = 0;
		edge_collection = _tmp15_;
		edge_collection_length1 = _tmp15__length1;
		for (edge_it = 0; edge_it < edge_collection_length1; edge_it = edge_it + 1) {
			gchar* _tmp16_;
			gchar* edge = NULL;
			_tmp16_ = g_strdup (edge_collection[edge_it]);
			edge = _tmp16_;
			{
				gchar* gravity = NULL;
				gchar* splice = NULL;
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				GQuark _tmp20_ = 0U;
				static GQuark _tmp19_label0 = 0;
				static GQuark _tmp19_label1 = 0;
				static GQuark _tmp19_label2 = 0;
				static GQuark _tmp19_label3 = 0;
				gchar** cmdline = NULL;
				gchar* _tmp29_;
				const gchar* _tmp30_;
				gchar* _tmp31_;
				gchar* _tmp32_;
				const gchar* _tmp33_;
				gchar* _tmp34_;
				gchar* _tmp35_;
				gchar* _tmp36_;
				gchar* _tmp37_;
				const gchar* _tmp38_;
				gchar* _tmp39_;
				const gchar* _tmp40_;
				gchar* _tmp41_;
				gchar** _tmp42_;
				gint cmdline_length1;
				gint _cmdline_size_;
				_tmp17_ = edge;
				_tmp18_ = _tmp17_;
				_tmp20_ = (NULL == _tmp18_) ? 0 : g_quark_from_string (_tmp18_);
				if (_tmp20_ == ((0 != _tmp19_label0) ? _tmp19_label0 : (_tmp19_label0 = g_quark_from_static_string ("top")))) {
					switch (0) {
						default:
						{
							gchar* _tmp21_;
							gchar* _tmp22_;
							_tmp21_ = g_strdup ("North");
							_g_free0 (gravity);
							gravity = _tmp21_;
							_tmp22_ = g_strdup ("0x2");
							_g_free0 (splice);
							splice = _tmp22_;
							break;
						}
					}
				} else if (_tmp20_ == ((0 != _tmp19_label1) ? _tmp19_label1 : (_tmp19_label1 = g_quark_from_static_string ("bottom")))) {
					switch (0) {
						default:
						{
							gchar* _tmp23_;
							gchar* _tmp24_;
							_tmp23_ = g_strdup ("South");
							_g_free0 (gravity);
							gravity = _tmp23_;
							_tmp24_ = g_strdup ("0x2");
							_g_free0 (splice);
							splice = _tmp24_;
							break;
						}
					}
				} else if (_tmp20_ == ((0 != _tmp19_label2) ? _tmp19_label2 : (_tmp19_label2 = g_quark_from_static_string ("left")))) {
					switch (0) {
						default:
						{
							gchar* _tmp25_;
							gchar* _tmp26_;
							_tmp25_ = g_strdup ("West");
							_g_free0 (gravity);
							gravity = _tmp25_;
							_tmp26_ = g_strdup ("2x0");
							_g_free0 (splice);
							splice = _tmp26_;
							break;
						}
					}
				} else if (_tmp20_ == ((0 != _tmp19_label3) ? _tmp19_label3 : (_tmp19_label3 = g_quark_from_static_string ("right")))) {
					switch (0) {
						default:
						{
							gchar* _tmp27_;
							gchar* _tmp28_;
							_tmp27_ = g_strdup ("East");
							_g_free0 (gravity);
							gravity = _tmp27_;
							_tmp28_ = g_strdup ("2x0");
							_g_free0 (splice);
							splice = _tmp28_;
							break;
						}
					}
				} else {
					switch (0) {
						default:
						{
							_g_free0 (splice);
							_g_free0 (gravity);
							_g_free0 (edge);
							continue;
						}
					}
				}
				_tmp29_ = g_strdup ("convert");
				_tmp30_ = current_input;
				_tmp31_ = g_strdup (_tmp30_);
				_tmp32_ = g_strdup ("-gravity");
				_tmp33_ = gravity;
				_tmp34_ = g_strdup (_tmp33_);
				_tmp35_ = g_strdup ("-background");
				_tmp36_ = g_strdup ("black");
				_tmp37_ = g_strdup ("-splice");
				_tmp38_ = splice;
				_tmp39_ = g_strdup (_tmp38_);
				_tmp40_ = temp_output;
				_tmp41_ = g_strdup (_tmp40_);
				_tmp42_ = g_new0 (gchar*, 9 + 1);
				_tmp42_[0] = _tmp29_;
				_tmp42_[1] = _tmp31_;
				_tmp42_[2] = _tmp32_;
				_tmp42_[3] = _tmp34_;
				_tmp42_[4] = _tmp35_;
				_tmp42_[5] = _tmp36_;
				_tmp42_[6] = _tmp37_;
				_tmp42_[7] = _tmp39_;
				_tmp42_[8] = _tmp41_;
				cmdline = _tmp42_;
				cmdline_length1 = 9;
				_cmdline_size_ = cmdline_length1;
				{
					gint exit_status = 0;
					gchar** _tmp43_;
					gint _tmp43__length1;
					gint _tmp44_ = 0;
					const gchar* _tmp47_;
					gchar* _tmp48_;
					_tmp43_ = cmdline;
					_tmp43__length1 = cmdline_length1;
					g_spawn_sync (NULL, _tmp43_, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &_tmp44_, &_inner_error0_);
					exit_status = _tmp44_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						if (_inner_error0_->domain == G_SPAWN_ERROR) {
							goto __catch0_g_spawn_error;
						}
						cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (splice);
						_g_free0 (gravity);
						_g_free0 (edge);
						_g_free0 (temp_output);
						_g_free0 (current_input);
						_g_free0 (output_path);
						_g_free0 (runtime_dir);
						edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
						g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
						g_clear_error (&_inner_error0_);
						return NULL;
					}
					if (exit_status != 0) {
						const gchar* _tmp45_;
						gchar* _tmp46_;
						_tmp45_ = edge;
						g_warning ("crystal_dock_helper.vala:334: ImageMagick convert failed for %s edge w" \
"ith status %d", _tmp45_, exit_status);
						_tmp46_ = g_strdup (original_path);
						result = _tmp46_;
						cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
						_g_free0 (splice);
						_g_free0 (gravity);
						_g_free0 (edge);
						_g_free0 (temp_output);
						_g_free0 (current_input);
						_g_free0 (output_path);
						_g_free0 (runtime_dir);
						edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
						return result;
					}
					_tmp47_ = temp_output;
					_tmp48_ = g_strdup (_tmp47_);
					_g_free0 (current_input);
					current_input = _tmp48_;
				}
				goto __finally0;
				__catch0_g_spawn_error:
				{
					GError* e = NULL;
					const gchar* _tmp49_;
					GError* _tmp50_;
					const gchar* _tmp51_;
					gchar* _tmp52_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp49_ = edge;
					_tmp50_ = e;
					_tmp51_ = _tmp50_->message;
					g_warning ("crystal_dock_helper.vala:342: Failed to spawn ImageMagick convert for " \
"%s edge: %s", _tmp49_, _tmp51_);
					_tmp52_ = g_strdup (original_path);
					result = _tmp52_;
					_g_error_free0 (e);
					cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (splice);
					_g_free0 (gravity);
					_g_free0 (edge);
					_g_free0 (temp_output);
					_g_free0 (current_input);
					_g_free0 (output_path);
					_g_free0 (runtime_dir);
					edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				__finally0:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (splice);
					_g_free0 (gravity);
					_g_free0 (edge);
					_g_free0 (temp_output);
					_g_free0 (current_input);
					_g_free0 (output_path);
					_g_free0 (runtime_dir);
					edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
					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;
				}
				cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (splice);
				_g_free0 (gravity);
				_g_free0 (edge);
			}
		}
	}
	_tmp53_ = output_path;
	if (g_file_test (_tmp53_, G_FILE_TEST_EXISTS)) {
		gchar* edges_str = NULL;
		gchar** _tmp54_;
		gint _tmp54__length1;
		gchar* _tmp55_;
		const gchar* _tmp56_;
		_tmp54_ = edges;
		_tmp54__length1 = edges_length1;
		_tmp55_ = _vala_g_strjoinv (", ", _tmp54_, (gint) _tmp54__length1);
		edges_str = _tmp55_;
		_tmp56_ = edges_str;
		g_debug ("crystal_dock_helper.vala:349: Applied borders on edges: %s", _tmp56_);
		result = output_path;
		_g_free0 (edges_str);
		_g_free0 (temp_output);
		_g_free0 (current_input);
		_g_free0 (runtime_dir);
		edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp57_ = g_strdup (original_path);
	result = _tmp57_;
	_g_free0 (temp_output);
	_g_free0 (current_input);
	_g_free0 (output_path);
	_g_free0 (runtime_dir);
	edges = (_vala_array_free (edges, edges_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static void
budgie_crystal_dock_helper_class_init (BudgieCrystalDockHelperClass * klass,
                                       gpointer klass_data)
{
	budgie_crystal_dock_helper_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BudgieCrystalDockHelper_private_offset);
	G_OBJECT_CLASS (klass)->finalize = budgie_crystal_dock_helper_finalize;
	budgie_crystal_dock_helper_signals[BUDGIE_CRYSTAL_DOCK_HELPER_DOCK_CONFIG_CHANGED_SIGNAL] = g_signal_new ("dock-config-changed", BUDGIE_TYPE_CRYSTAL_DOCK_HELPER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
budgie_crystal_dock_helper_instance_init (BudgieCrystalDockHelper * self,
                                          gpointer klass)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	self->priv = budgie_crystal_dock_helper_get_instance_private (self);
	self->priv->config_monitor = NULL;
	self->priv->dock_check_timeout = (guint) 0;
	self->priv->last_dock_running = FALSE;
	self->priv->crystal_dock_installed = FALSE;
	self->priv->current_poll_interval = 5000;
	_tmp0_ = g_get_user_config_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "crystal-dock", "Budgie", NULL);
	self->priv->config_dir = _tmp1_;
}

static void
budgie_crystal_dock_helper_finalize (GObject * obj)
{
	BudgieCrystalDockHelper * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BUDGIE_TYPE_CRYSTAL_DOCK_HELPER, BudgieCrystalDockHelper);
	budgie_crystal_dock_helper_cleanup_monitors (self);
	_g_object_unref0 (self->priv->config_monitor);
	_g_free0 (self->priv->config_dir);
	G_OBJECT_CLASS (budgie_crystal_dock_helper_parent_class)->finalize (obj);
}

/**
* Helper class to handle Crystal Dock autohide gap workaround
* Monitors Crystal Dock configuration and adds 1px borders to wallpapers
* to mask the gap left by autohide mode
*/
static GType
budgie_crystal_dock_helper_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BudgieCrystalDockHelperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_crystal_dock_helper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgieCrystalDockHelper), 0, (GInstanceInitFunc) budgie_crystal_dock_helper_instance_init, NULL };
	GType budgie_crystal_dock_helper_type_id;
	budgie_crystal_dock_helper_type_id = g_type_register_static (G_TYPE_OBJECT, "BudgieCrystalDockHelper", &g_define_type_info, 0);
	BudgieCrystalDockHelper_private_offset = g_type_add_instance_private (budgie_crystal_dock_helper_type_id, sizeof (BudgieCrystalDockHelperPrivate));
	return budgie_crystal_dock_helper_type_id;
}

GType
budgie_crystal_dock_helper_get_type (void)
{
	static volatile gsize budgie_crystal_dock_helper_type_id__once = 0;
	if (g_once_init_enter (&budgie_crystal_dock_helper_type_id__once)) {
		GType budgie_crystal_dock_helper_type_id;
		budgie_crystal_dock_helper_type_id = budgie_crystal_dock_helper_get_type_once ();
		g_once_init_leave (&budgie_crystal_dock_helper_type_id__once, budgie_crystal_dock_helper_type_id);
	}
	return budgie_crystal_dock_helper_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;
}

