/* background.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from background.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <libgnome-desktop/gnome-bg.h>
#include <gsettings-desktop-schemas/gdesktop-enums.h>

#define BUDGIE_BACKGROUND_SCHEMA "org.gnome.desktop.background"
#define BUDGIE_ACCOUNTS_SCHEMA "org.freedesktop.Accounts"
#define BUDGIE_GNOME_COLOR_HACK "budgie-control-center/pixmaps/noise-texture-light.png"
#define BUDGIE_BACKGROUND_BACKGROUND_TIMEOUT 850
#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_BACKGROUND (budgie_background_get_type ())
#define BUDGIE_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_BACKGROUND, BudgieBackground))
#define BUDGIE_BACKGROUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_BACKGROUND, BudgieBackgroundClass))
#define BUDGIE_IS_BACKGROUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_BACKGROUND))
#define BUDGIE_IS_BACKGROUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_BACKGROUND))
#define BUDGIE_BACKGROUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_BACKGROUND, BudgieBackgroundClass))

typedef struct _BudgieBackground BudgieBackground;
typedef struct _BudgieBackgroundClass BudgieBackgroundClass;
typedef struct _BudgieBackgroundPrivate BudgieBackgroundPrivate;

#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;
enum  {
	BUDGIE_BACKGROUND_0_PROPERTY,
	BUDGIE_BACKGROUND_NUM_PROPERTIES
};
static GParamSpec* budgie_background_properties[BUDGIE_BACKGROUND_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block7Data Block7Data;

struct _BudgieBackground {
	GObject parent_instance;
	BudgieBackgroundPrivate * priv;
};

struct _BudgieBackgroundClass {
	GObjectClass parent_class;
};

struct _BudgieBackgroundPrivate {
	GSettings* settings;
	GnomeBG* gnome_bg;
	GSubprocess* bg;
	BudgieCrystalDockHelper* crystal_dock_helper;
};

struct _Block7Data {
	int _ref_count_;
	BudgieBackground* self;
	GSubprocess* new_bg;
};

static gint BudgieBackground_private_offset;
static gpointer budgie_background_parent_class = NULL;

VALA_EXTERN GType budgie_background_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieBackground, g_object_unref)
VALA_EXTERN GType budgie_crystal_dock_helper_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BudgieCrystalDockHelper, g_object_unref)
static gboolean budgie_background_is_color_wallpaper (BudgieBackground* self,
                                               const gchar* bg_filename);
static gchar* budgie_background_get_swaybg_mode (BudgieBackground* self);
VALA_EXTERN BudgieBackground* budgie_background_new (void);
VALA_EXTERN BudgieBackground* budgie_background_construct (GType object_type);
static gboolean __lambda29_ (BudgieBackground* self);
static gboolean ___lambda29__g_settings_change_event (GSettings* _sender,
                                               GQuark* keys,
                                               gint n_keys,
                                               gpointer self);
static void __lambda30_ (BudgieBackground* self);
static void budgie_background_update (BudgieBackground* self);
static void ___lambda30__gnome_bg_changed (GnomeBG* _sender,
                                    gpointer self);
VALA_EXTERN BudgieCrystalDockHelper* budgie_crystal_dock_helper_new (void);
VALA_EXTERN BudgieCrystalDockHelper* budgie_crystal_dock_helper_construct (GType object_type);
static void __lambda32_ (BudgieBackground* self);
static void ___lambda32__budgie_crystal_dock_helper_dock_config_changed (BudgieCrystalDockHelper* _sender,
                                                                  gpointer self);
static void budgie_background_set_accountsservice_user_bg (BudgieBackground* self,
                                                    const gchar* background);
static Block7Data* block7_data_ref (Block7Data* _data7_);
static void block7_data_unref (void * _userdata_);
VALA_EXTERN gchar* budgie_crystal_dock_helper_apply_borders (BudgieCrystalDockHelper* self,
                                                 const gchar* original_path);
static gboolean ____lambda31_ (Block7Data* _data7_);
static gboolean _____lambda31__gsource_func (gpointer self);
static void budgie_background_finalize (GObject * obj);
static GType budgie_background_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 inline gpointer
budgie_background_get_instance_private (BudgieBackground* self)
{
	return G_STRUCT_MEMBER_P (self, BudgieBackground_private_offset);
}

/**
* Determine if the wallpaper is a colour wallpaper or not
*/
static gboolean
budgie_background_is_color_wallpaper (BudgieBackground* self,
                                      const gchar* bg_filename)
{
	gboolean _tmp0_ = FALSE;
	GnomeBG* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	if (bg_filename == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = self->priv->gnome_bg;
	if (gnome_bg_get_placement (_tmp1_) == G_DESKTOP_BACKGROUND_STYLE_NONE) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_str_has_suffix (bg_filename, BUDGIE_GNOME_COLOR_HACK);
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	result = FALSE;
	return result;
}

/**
* Translate GNOME desktop background picture-options to swaybg mode
*/
static gchar*
budgie_background_get_swaybg_mode (BudgieBackground* self)
{
	GDesktopBackgroundStyle placement = 0;
	GnomeBG* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->gnome_bg;
	placement = gnome_bg_get_placement (_tmp0_);
	switch (placement) {
		case G_DESKTOP_BACKGROUND_STYLE_NONE:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("fill");
			result = _tmp1_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_WALLPAPER:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("tile");
			result = _tmp2_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_CENTERED:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("center");
			result = _tmp3_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_SCALED:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("fit");
			result = _tmp4_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_STRETCHED:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("stretch");
			result = _tmp5_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_ZOOM:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup ("fill");
			result = _tmp6_;
			return result;
		}
		case G_DESKTOP_BACKGROUND_STYLE_SPANNED:
		{
			gchar* _tmp7_;
			_tmp7_ = g_strdup ("fill");
			result = _tmp7_;
			return result;
		}
		default:
		{
			gchar* _tmp8_;
			_tmp8_ = g_strdup ("fill");
			result = _tmp8_;
			return result;
		}
	}
}

static gboolean
__lambda29_ (BudgieBackground* self)
{
	GnomeBG* _tmp0_;
	GSettings* _tmp1_;
	gboolean result;
	_tmp0_ = self->priv->gnome_bg;
	_tmp1_ = self->priv->settings;
	gnome_bg_load_from_preferences (_tmp0_, _tmp1_);
	result = FALSE;
	return result;
}

static gboolean
___lambda29__g_settings_change_event (GSettings* _sender,
                                      GQuark* keys,
                                      gint n_keys,
                                      gpointer self)
{
	gboolean result;
	result = __lambda29_ ((BudgieBackground*) self);
	return result;
}

static void
__lambda30_ (BudgieBackground* self)
{
	budgie_background_update (self);
}

static void
___lambda30__gnome_bg_changed (GnomeBG* _sender,
                               gpointer self)
{
	__lambda30_ ((BudgieBackground*) self);
}

static void
__lambda32_ (BudgieBackground* self)
{
	g_message ("background.vala:103: Crystal Dock configuration changed, updating wall" \
"paper");
	budgie_background_update (self);
}

static void
___lambda32__budgie_crystal_dock_helper_dock_config_changed (BudgieCrystalDockHelper* _sender,
                                                             gpointer self)
{
	__lambda32_ ((BudgieBackground*) self);
}

BudgieBackground*
budgie_background_construct (GType object_type)
{
	BudgieBackground * self = NULL;
	GSettings* _tmp0_;
	GnomeBG* _tmp1_;
	GSettings* _tmp2_;
	GnomeBG* _tmp3_;
	GnomeBG* _tmp4_;
	GSettings* _tmp5_;
	BudgieCrystalDockHelper* _tmp6_;
	BudgieCrystalDockHelper* _tmp7_;
	self = (BudgieBackground*) g_object_new (object_type, NULL);
	_tmp0_ = g_settings_new (BUDGIE_BACKGROUND_SCHEMA);
	_g_object_unref0 (self->priv->settings);
	self->priv->settings = _tmp0_;
	_tmp1_ = gnome_bg_new ();
	_g_object_unref0 (self->priv->gnome_bg);
	self->priv->gnome_bg = _tmp1_;
	_tmp2_ = self->priv->settings;
	g_signal_connect_object (_tmp2_, "change-event", (GCallback) ___lambda29__g_settings_change_event, self, 0);
	_tmp3_ = self->priv->gnome_bg;
	g_signal_connect_object (_tmp3_, "changed", (GCallback) ___lambda30__gnome_bg_changed, self, 0);
	_tmp4_ = self->priv->gnome_bg;
	_tmp5_ = self->priv->settings;
	gnome_bg_load_from_preferences (_tmp4_, _tmp5_);
	_tmp6_ = budgie_crystal_dock_helper_new ();
	_g_object_unref0 (self->priv->crystal_dock_helper);
	self->priv->crystal_dock_helper = _tmp6_;
	_tmp7_ = self->priv->crystal_dock_helper;
	g_signal_connect_object (_tmp7_, "dock-config-changed", (GCallback) ___lambda32__budgie_crystal_dock_helper_dock_config_changed, self, 0);
	return self;
}

BudgieBackground*
budgie_background_new (void)
{
	return budgie_background_construct (BUDGIE_TYPE_BACKGROUND);
}

/**
* call accountsservice dbus with the background file name
* to update the greeter background if the display
* manager supports the dbus call.
*/
static void
budgie_background_set_accountsservice_user_bg (BudgieBackground* self,
                                               const gchar* background)
{
	GDBusConnection* bus = NULL;
	GVariant* variant = NULL;
	gboolean _tmp18_ = FALSE;
	GVariant* _tmp19_;
	gchar* object_path = NULL;
	GVariant* _tmp22_;
	GVariant* _tmp23_;
	GVariant* _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (background != NULL);
	{
		GDBusConnection* _tmp0_ = NULL;
		GDBusConnection* _tmp1_;
		GDBusConnection* _tmp2_;
		_tmp1_ = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			_g_variant_unref0 (variant);
			_g_object_unref0 (bus);
			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_ = _tmp0_;
		_tmp0_ = NULL;
		_g_object_unref0 (bus);
		bus = _tmp2_;
		_g_object_unref0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("background.vala:121: Failed to get system bus: %s", _tmp4_);
		_g_error_free0 (e);
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		return;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		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;
	}
	{
		GVariant* _tmp5_ = NULL;
		GDBusConnection* _tmp6_;
		const gchar* _tmp7_;
		GVariant* _tmp8_;
		GVariant* _tmp9_;
		GVariantType* _tmp10_;
		GVariantType* _tmp11_;
		GVariant* _tmp12_;
		GVariant* _tmp13_;
		GVariant* _tmp14_;
		_tmp6_ = bus;
		_tmp7_ = g_get_user_name ();
		_tmp8_ = g_variant_new ("(s)", _tmp7_, NULL);
		g_variant_ref_sink (_tmp8_);
		_tmp9_ = _tmp8_;
		_tmp10_ = g_variant_type_new ("(o)");
		_tmp11_ = _tmp10_;
		_tmp12_ = g_dbus_connection_call_sync (_tmp6_, BUDGIE_ACCOUNTS_SCHEMA, "/org/freedesktop/Accounts", BUDGIE_ACCOUNTS_SCHEMA, "FindUserByName", _tmp9_, _tmp11_, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &_inner_error0_);
		_tmp13_ = _tmp12_;
		_g_variant_type_free0 (_tmp11_);
		_g_variant_unref0 (_tmp9_);
		_tmp5_ = _tmp13_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch1_g_error;
		}
		_tmp14_ = _tmp5_;
		_tmp5_ = NULL;
		_g_variant_unref0 (variant);
		variant = _tmp14_;
		_g_variant_unref0 (_tmp5_);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp15_;
		GError* _tmp16_;
		const gchar* _tmp17_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp15_ = g_get_user_name ();
		_tmp16_ = e;
		_tmp17_ = _tmp16_->message;
		g_warning ("background.vala:129: Could not contact accounts service to look up '%s" \
"': %s", _tmp15_, _tmp17_);
		_g_error_free0 (e);
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		return;
	}
	__finally1:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		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;
	}
	_tmp19_ = variant;
	if (_tmp19_ == NULL) {
		_tmp18_ = TRUE;
	} else {
		GVariant* _tmp20_;
		_tmp20_ = variant;
		_tmp18_ = g_variant_n_children (_tmp20_) == ((gsize) 0);
	}
	if (_tmp18_) {
		const gchar* _tmp21_;
		_tmp21_ = g_get_user_name ();
		g_warning ("background.vala:135: Invalid response from AccountsService for user '%" \
"s'", _tmp21_);
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		return;
	}
	_tmp22_ = variant;
	_tmp23_ = g_variant_get_child_value (_tmp22_, (gsize) 0);
	_tmp24_ = _tmp23_;
	_tmp25_ = g_variant_get_string (_tmp24_, NULL);
	_tmp26_ = g_strdup (_tmp25_);
	_tmp27_ = _tmp26_;
	_g_variant_unref0 (_tmp24_);
	object_path = _tmp27_;
	{
		GDBusConnection* _tmp28_;
		const gchar* _tmp29_;
		GVariant* _tmp30_;
		GVariant* _tmp31_;
		GVariant* _tmp32_;
		GVariant* _tmp33_;
		GVariantType* _tmp34_;
		GVariantType* _tmp35_;
		GVariant* _tmp36_;
		GVariant* _tmp37_;
		_tmp28_ = bus;
		_tmp29_ = object_path;
		_tmp30_ = g_variant_new_string (background);
		g_variant_ref_sink (_tmp30_);
		_tmp31_ = _tmp30_;
		_tmp32_ = g_variant_new ("(ssv)", "org.freedesktop.DisplayManager.AccountsService", "BackgroundFile", _tmp31_, NULL);
		g_variant_ref_sink (_tmp32_);
		_tmp33_ = _tmp32_;
		_tmp34_ = g_variant_type_new ("()");
		_tmp35_ = _tmp34_;
		_tmp36_ = g_dbus_connection_call_sync (_tmp28_, BUDGIE_ACCOUNTS_SCHEMA, _tmp29_, "org.freedesktop.DBus.Properties", "Set", _tmp33_, _tmp35_, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &_inner_error0_);
		_tmp37_ = _tmp36_;
		_g_variant_unref0 (_tmp37_);
		_g_variant_type_free0 (_tmp35_);
		_g_variant_unref0 (_tmp33_);
		_g_variant_unref0 (_tmp31_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
		GError* _tmp38_;
		const gchar* _tmp39_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp38_ = e;
		_tmp39_ = _tmp38_->message;
		g_warning ("background.vala:147: Failed to set the background '%s': %s", background, _tmp39_);
		_g_error_free0 (e);
	}
	__finally2:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (object_path);
		_g_variant_unref0 (variant);
		_g_object_unref0 (bus);
		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 (object_path);
	_g_variant_unref0 (variant);
	_g_object_unref0 (bus);
}

static Block7Data*
block7_data_ref (Block7Data* _data7_)
{
	g_atomic_int_inc (&_data7_->_ref_count_);
	return _data7_;
}

static void
block7_data_unref (void * _userdata_)
{
	Block7Data* _data7_;
	_data7_ = (Block7Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data7_->_ref_count_)) {
		BudgieBackground* self;
		self = _data7_->self;
		_g_object_unref0 (_data7_->new_bg);
		_g_object_unref0 (self);
		g_slice_free (Block7Data, _data7_);
	}
}

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

static gboolean
____lambda31_ (Block7Data* _data7_)
{
	BudgieBackground* self;
	GSubprocess* _tmp0_;
	GSubprocess* _tmp2_;
	GSubprocess* _tmp3_;
	gboolean result;
	self = _data7_->self;
	_tmp0_ = self->priv->bg;
	if (_tmp0_ != NULL) {
		GSubprocess* _tmp1_;
		_tmp1_ = self->priv->bg;
		g_subprocess_force_exit (_tmp1_);
	}
	_tmp2_ = _data7_->new_bg;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (self->priv->bg);
	self->priv->bg = _tmp3_;
	result = FALSE;
	return result;
}

static gboolean
_____lambda31__gsource_func (gpointer self)
{
	gboolean result;
	result = ____lambda31_ (self);
	return result;
}

static void
budgie_background_update (BudgieBackground* self)
{
	gchar* bg_filename = NULL;
	GnomeBG* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_ = FALSE;
	const gchar* _tmp5_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->gnome_bg;
	_tmp1_ = gnome_bg_get_filename (_tmp0_);
	_tmp2_ = g_strdup (_tmp1_);
	bg_filename = _tmp2_;
	_tmp3_ = bg_filename;
	if (_tmp3_ == NULL) {
		g_warning ("background.vala:156: No background filename available");
		_g_free0 (bg_filename);
		return;
	}
	_tmp5_ = bg_filename;
	if (!budgie_background_is_color_wallpaper (self, _tmp5_)) {
		const gchar* _tmp6_;
		_tmp6_ = bg_filename;
		_tmp4_ = !g_str_has_suffix (_tmp6_, ".xml");
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		Block7Data* _data7_;
		gchar* swaybg_mode = NULL;
		gchar* _tmp7_;
		gchar* wallpaper_path = NULL;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		gboolean is_modified = FALSE;
		BudgieCrystalDockHelper* _tmp10_;
		gchar** cmdline = NULL;
		gchar* _tmp17_;
		gchar* _tmp18_;
		const gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		const gchar* _tmp22_;
		gchar* _tmp23_;
		gchar** _tmp24_;
		gint cmdline_length1;
		gint _cmdline_size_;
		const gchar* _tmp31_;
		_data7_ = g_slice_new0 (Block7Data);
		_data7_->_ref_count_ = 1;
		_data7_->self = g_object_ref (self);
		_tmp7_ = budgie_background_get_swaybg_mode (self);
		swaybg_mode = _tmp7_;
		_tmp8_ = bg_filename;
		_tmp9_ = g_strdup (_tmp8_);
		wallpaper_path = _tmp9_;
		is_modified = FALSE;
		_tmp10_ = self->priv->crystal_dock_helper;
		if (_tmp10_ != NULL) {
			gchar* bordered_path = NULL;
			BudgieCrystalDockHelper* _tmp11_;
			const gchar* _tmp12_;
			gchar* _tmp13_;
			const gchar* _tmp14_;
			_tmp11_ = self->priv->crystal_dock_helper;
			_tmp12_ = bg_filename;
			_tmp13_ = budgie_crystal_dock_helper_apply_borders (_tmp11_, _tmp12_);
			bordered_path = _tmp13_;
			_tmp14_ = bordered_path;
			if (_tmp14_ != NULL) {
				const gchar* _tmp15_;
				gchar* _tmp16_;
				_tmp15_ = bordered_path;
				_tmp16_ = g_strdup (_tmp15_);
				_g_free0 (wallpaper_path);
				wallpaper_path = _tmp16_;
				is_modified = TRUE;
			}
			_g_free0 (bordered_path);
		}
		_tmp17_ = g_strdup ("swaybg");
		_tmp18_ = g_strdup ("-i");
		_tmp19_ = wallpaper_path;
		_tmp20_ = g_strdup (_tmp19_);
		_tmp21_ = g_strdup ("--mode");
		_tmp22_ = swaybg_mode;
		_tmp23_ = g_strdup (_tmp22_);
		_tmp24_ = g_new0 (gchar*, 5 + 1);
		_tmp24_[0] = _tmp17_;
		_tmp24_[1] = _tmp18_;
		_tmp24_[2] = _tmp20_;
		_tmp24_[3] = _tmp21_;
		_tmp24_[4] = _tmp23_;
		cmdline = _tmp24_;
		cmdline_length1 = 5;
		_cmdline_size_ = cmdline_length1;
		{
			GSubprocess* _tmp25_ = NULL;
			gchar** _tmp26_;
			gint _tmp26__length1;
			GSubprocess* _tmp27_;
			GSubprocess* _tmp28_;
			_tmp26_ = cmdline;
			_tmp26__length1 = cmdline_length1;
			_tmp27_ = g_subprocess_newv (_tmp26_, G_SUBPROCESS_FLAGS_NONE, &_inner_error0_);
			_tmp25_ = _tmp27_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp28_ = _tmp25_;
			_tmp25_ = NULL;
			_g_object_unref0 (_data7_->new_bg);
			_data7_->new_bg = _tmp28_;
			g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) BUDGIE_BACKGROUND_BACKGROUND_TIMEOUT, _____lambda31__gsource_func, block7_data_ref (_data7_), block7_data_unref);
			_g_object_unref0 (_tmp25_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp29_;
			const gchar* _tmp30_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp29_ = e;
			_tmp30_ = _tmp29_->message;
			g_warning ("background.vala:191: Error starting swaybg: %s", _tmp30_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (wallpaper_path);
			_g_free0 (swaybg_mode);
			block7_data_unref (_data7_);
			_data7_ = NULL;
			_g_free0 (bg_filename);
			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;
		}
		_tmp31_ = bg_filename;
		budgie_background_set_accountsservice_user_bg (self, _tmp31_);
		cmdline = (_vala_array_free (cmdline, cmdline_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (wallpaper_path);
		_g_free0 (swaybg_mode);
		block7_data_unref (_data7_);
		_data7_ = NULL;
	}
	_g_free0 (bg_filename);
}

static void
budgie_background_class_init (BudgieBackgroundClass * klass,
                              gpointer klass_data)
{
	budgie_background_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BudgieBackground_private_offset);
	G_OBJECT_CLASS (klass)->finalize = budgie_background_finalize;
}

static void
budgie_background_instance_init (BudgieBackground * self,
                                 gpointer klass)
{
	self->priv = budgie_background_get_instance_private (self);
	self->priv->settings = NULL;
	self->priv->bg = NULL;
	self->priv->crystal_dock_helper = NULL;
}

static void
budgie_background_finalize (GObject * obj)
{
	BudgieBackground * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BUDGIE_TYPE_BACKGROUND, BudgieBackground);
	_g_object_unref0 (self->priv->settings);
	_g_object_unref0 (self->priv->gnome_bg);
	_g_object_unref0 (self->priv->bg);
	_g_object_unref0 (self->priv->crystal_dock_helper);
	G_OBJECT_CLASS (budgie_background_parent_class)->finalize (obj);
}

static GType
budgie_background_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BudgieBackgroundClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_background_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgieBackground), 0, (GInstanceInitFunc) budgie_background_instance_init, NULL };
	GType budgie_background_type_id;
	budgie_background_type_id = g_type_register_static (G_TYPE_OBJECT, "BudgieBackground", &g_define_type_info, 0);
	BudgieBackground_private_offset = g_type_add_instance_private (budgie_background_type_id, sizeof (BudgieBackgroundPrivate));
	return budgie_background_type_id;
}

GType
budgie_background_get_type (void)
{
	static volatile gsize budgie_background_type_id__once = 0;
	if (g_once_init_enter (&budgie_background_type_id__once)) {
		GType budgie_background_type_id;
		budgie_background_type_id = budgie_background_get_type_once ();
		g_once_init_leave (&budgie_background_type_id__once, budgie_background_type_id);
	}
	return budgie_background_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);
}

