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

/*
 * Copyright (c) 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel)
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 */

#include "wingpanel-interface.h"
#include <glib.h>
#include <meta/workspace.h>
#include <glib-object.h>
#include <gala.h>
#include <meta/meta-background-group.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <meta/meta-workspace-manager.h>
#include <meta/display.h>
#include <meta/common.h>
#include <meta/window.h>
#include <gdk/gdk.h>
#include <string.h>
#include <cairo-gobject.h>
#include <stdlib.h>

#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MINIMIZE_DURATION 200
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_SNAP_DURATION 250
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_WALLPAPER_TRANSITION_DURATION 150
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_WORKSPACE_SWITCH_DURATION 300
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_ACUTANCE_THRESHOLD ((gdouble) 8)
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_STD_THRESHOLD ((gdouble) 45)
#define WINGPANEL_INTERFACE_BACKGROUND_MANAGER_LUMINANCE_THRESHOLD ((gdouble) 180)

enum  {
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_0_PROPERTY,
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY,
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY,
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_NUM_PROPERTIES
};
static GParamSpec* wingpanel_interface_background_manager_properties[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _wingpanel_interface_utils_color_information_free0(var) ((var == NULL) ? NULL : (var = (wingpanel_interface_utils_color_information_free (var), NULL)))
typedef struct _Block1Data Block1Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData;
enum  {
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_STATE_CHANGED_SIGNAL,
	WINGPANEL_INTERFACE_BACKGROUND_MANAGER_NUM_SIGNALS
};
static guint wingpanel_interface_background_manager_signals[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_NUM_SIGNALS] = {0};

struct _WingpanelInterfaceBackgroundManagerPrivate {
	gint _monitor;
	gint _panel_height;
	gulong wallpaper_hook_id;
	MetaWorkspace* current_workspace;
	BackgroundState current_state;
	WingpanelInterfaceUtilsColorInformation* bk_color_info;
};

struct _Block1Data {
	int _ref_count_;
	WingpanelInterfaceBackgroundManager* self;
	GSourceFunc callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
	gpointer _async_data_;
};

struct _WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	WingpanelInterfaceBackgroundManager* self;
	Block1Data* _data1_;
	GdkRectangle monitor_geometry;
	GdkScreen* _tmp0_;
	gint _tmp1_;
	GdkRectangle _tmp2_;
	GalaWindowManager* _tmp3_;
	gint _tmp4_;
	GdkRectangle _tmp5_;
	gint _tmp6_;
};

static gint WingpanelInterfaceBackgroundManager_private_offset;
static gpointer wingpanel_interface_background_manager_parent_class = NULL;

static void wingpanel_interface_background_manager_connect_signals (WingpanelInterfaceBackgroundManager* self);
static void __lambda13_ (WingpanelInterfaceBackgroundManager* self,
                  GObject* obj,
                  GAsyncResult* res);
static void wingpanel_interface_background_manager_update_current_workspace (WingpanelInterfaceBackgroundManager* self);
static void ___lambda13__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void __lambda4_ (WingpanelInterfaceBackgroundManager* self);
static void ___lambda4__meta_workspace_manager_workspace_switched (MetaWorkspaceManager* _sender,
                                                            gint object,
                                                            gint p0,
                                                            MetaMotionDirection p1,
                                                            gpointer self);
static gboolean __lambda8_ (WingpanelInterfaceBackgroundManager* self,
                     GSignalInvocationHint* ihint,
                     GValue* param_values,
                     guint param_values_length1);
static void __lambda12_ (WingpanelInterfaceBackgroundManager* self,
                  GObject* obj,
                  GAsyncResult* res);
static void wingpanel_interface_background_manager_check_for_state_change (WingpanelInterfaceBackgroundManager* self,
                                                                    guint animation_duration);
static void ___lambda12__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static gboolean ___lambda8__gsignal_emission_hook (GSignalInvocationHint* ihint,
                                            guint n_param_values,
                                            GValue* param_values,
                                            gpointer self);
static void wingpanel_interface_background_manager_on_window_added (WingpanelInterfaceBackgroundManager* self,
                                                             MetaWindow* window);
static void _wingpanel_interface_background_manager_on_window_added_meta_workspace_window_added (MetaWorkspace* _sender,
                                                                                          MetaWindow* object,
                                                                                          gpointer self);
static void wingpanel_interface_background_manager_on_window_removed (WingpanelInterfaceBackgroundManager* self,
                                                               MetaWindow* window);
static void _wingpanel_interface_background_manager_on_window_removed_meta_workspace_window_removed (MetaWorkspace* _sender,
                                                                                              MetaWindow* object,
                                                                                              gpointer self);
static void wingpanel_interface_background_manager_register_window (WingpanelInterfaceBackgroundManager* self,
                                                             MetaWindow* window);
static void __lambda5_ (WingpanelInterfaceBackgroundManager* self);
static void ___lambda5__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void __lambda6_ (WingpanelInterfaceBackgroundManager* self);
static void ___lambda6__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static void __lambda7_ (WingpanelInterfaceBackgroundManager* self);
static void ___lambda7__meta_window_workspace_changed (MetaWindow* _sender,
                                                gpointer self);
static void wingpanel_interface_background_manager_update_bk_color_info_data_free (gpointer _data);
static gboolean wingpanel_interface_background_manager_update_bk_color_info_co (WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean _wingpanel_interface_background_manager_update_bk_color_info_co_gsource_func (gpointer self);
static gint wingpanel_interface_background_manager_get_monitor (WingpanelInterfaceBackgroundManager* self);
static gint wingpanel_interface_background_manager_get_panel_height (WingpanelInterfaceBackgroundManager* self);
static void __lambda11_ (Block1Data* _data1_,
                  GObject* obj,
                  GAsyncResult* res);
static void ___lambda11__gasync_ready_callback (GObject* source_object,
                                         GAsyncResult* res,
                                         gpointer self);
static void g_cclosure_user_marshal_VOID__ENUM_UINT (GClosure * closure,
                                              GValue * return_value,
                                              guint n_param_values,
                                              const GValue * param_values,
                                              gpointer invocation_hint,
                                              gpointer marshal_data);
static void wingpanel_interface_background_manager_finalize (GObject * obj);
static GType wingpanel_interface_background_manager_get_type_once (void);
static void _vala_wingpanel_interface_background_manager_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec);
static void _vala_wingpanel_interface_background_manager_set_property (GObject * object,
                                                                guint property_id,
                                                                const GValue * value,
                                                                GParamSpec * pspec);

static GType
background_state_get_type_once (void)
{
	static const GEnumValue values[] = {{BACKGROUND_STATE_LIGHT, "BACKGROUND_STATE_LIGHT", "light"}, {BACKGROUND_STATE_DARK, "BACKGROUND_STATE_DARK", "dark"}, {BACKGROUND_STATE_MAXIMIZED, "BACKGROUND_STATE_MAXIMIZED", "maximized"}, {BACKGROUND_STATE_TRANSLUCENT_DARK, "BACKGROUND_STATE_TRANSLUCENT_DARK", "translucent-dark"}, {BACKGROUND_STATE_TRANSLUCENT_LIGHT, "BACKGROUND_STATE_TRANSLUCENT_LIGHT", "translucent-light"}, {0, NULL, NULL}};
	GType background_state_type_id;
	background_state_type_id = g_enum_register_static ("BackgroundState", values);
	return background_state_type_id;
}

GType
background_state_get_type (void)
{
	static volatile gsize background_state_type_id__once = 0;
	if (g_once_init_enter (&background_state_type_id__once)) {
		GType background_state_type_id;
		background_state_type_id = background_state_get_type_once ();
		g_once_init_leave (&background_state_type_id__once, background_state_type_id);
	}
	return background_state_type_id__once;
}

static inline gpointer
wingpanel_interface_background_manager_get_instance_private (WingpanelInterfaceBackgroundManager* self)
{
	return G_STRUCT_MEMBER_P (self, WingpanelInterfaceBackgroundManager_private_offset);
}

static void
__lambda13_ (WingpanelInterfaceBackgroundManager* self,
             GObject* obj,
             GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	wingpanel_interface_background_manager_update_bk_color_info_finish (self, res);
	wingpanel_interface_background_manager_update_current_workspace (self);
}

static void
___lambda13__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda13_ ((WingpanelInterfaceBackgroundManager*) self, source_object, res);
	g_object_unref (self);
}

WingpanelInterfaceBackgroundManager*
wingpanel_interface_background_manager_construct (GType object_type,
                                                  gint monitor,
                                                  gint panel_height)
{
	WingpanelInterfaceBackgroundManager * self = NULL;
	self = (WingpanelInterfaceBackgroundManager*) g_object_new (object_type, "monitor", monitor, "panel-height", panel_height, NULL);
	wingpanel_interface_background_manager_connect_signals (self);
	wingpanel_interface_background_manager_update_bk_color_info (self, ___lambda13__gasync_ready_callback, g_object_ref (self));
	return self;
}

WingpanelInterfaceBackgroundManager*
wingpanel_interface_background_manager_new (gint monitor,
                                            gint panel_height)
{
	return wingpanel_interface_background_manager_construct (WINGPANEL_INTERFACE_TYPE_BACKGROUND_MANAGER, monitor, panel_height);
}

static void
__lambda4_ (WingpanelInterfaceBackgroundManager* self)
{
	wingpanel_interface_background_manager_update_current_workspace (self);
}

static void
___lambda4__meta_workspace_manager_workspace_switched (MetaWorkspaceManager* _sender,
                                                       gint object,
                                                       gint p0,
                                                       MetaMotionDirection p1,
                                                       gpointer self)
{
	__lambda4_ ((WingpanelInterfaceBackgroundManager*) self);
}

static void
__lambda12_ (WingpanelInterfaceBackgroundManager* self,
             GObject* obj,
             GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	wingpanel_interface_background_manager_update_bk_color_info_finish (self, res);
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_WALLPAPER_TRANSITION_DURATION);
}

static void
___lambda12__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda12_ ((WingpanelInterfaceBackgroundManager*) self, source_object, res);
	g_object_unref (self);
}

static gboolean
__lambda8_ (WingpanelInterfaceBackgroundManager* self,
            GSignalInvocationHint* ihint,
            GValue* param_values,
            guint param_values_length1)
{
	gboolean result;
	g_return_val_if_fail (ihint != NULL, FALSE);
	wingpanel_interface_background_manager_update_bk_color_info (self, ___lambda12__gasync_ready_callback, g_object_ref (self));
	result = TRUE;
	return result;
}

static gboolean
___lambda8__gsignal_emission_hook (GSignalInvocationHint* ihint,
                                   guint n_param_values,
                                   GValue* param_values,
                                   gpointer self)
{
	gboolean result;
	result = __lambda8_ ((WingpanelInterfaceBackgroundManager*) self, ihint, param_values, n_param_values);
	return result;
}

static void
wingpanel_interface_background_manager_connect_signals (WingpanelInterfaceBackgroundManager* self)
{
	MetaWorkspaceManager* manager = NULL;
	MetaDisplay* _tmp0_;
	MetaWorkspaceManager* _tmp1_;
	guint signal_id = 0U;
	GalaWindowManager* _tmp2_;
	MetaBackgroundGroup* _tmp3_;
	MetaBackgroundGroup* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = wingpanel_interface_main_display;
	_tmp1_ = meta_display_get_workspace_manager (_tmp0_);
	manager = _tmp1_;
	g_signal_connect_object (manager, "workspace-switched", (GCallback) ___lambda4__meta_workspace_manager_workspace_switched, self, 0);
	_tmp2_ = wingpanel_interface_main_wm;
	_tmp3_ = gala_window_manager_get_background_group (_tmp2_);
	_tmp4_ = _tmp3_;
	signal_id = g_signal_lookup ("changed", G_TYPE_FROM_INSTANCE ((GObject*) _tmp4_));
	self->priv->wallpaper_hook_id = g_signal_add_emission_hook (signal_id, (GQuark) 0, ___lambda8__gsignal_emission_hook, g_object_ref (self), g_object_unref);
}

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

static void
_wingpanel_interface_background_manager_on_window_added_meta_workspace_window_added (MetaWorkspace* _sender,
                                                                                     MetaWindow* object,
                                                                                     gpointer self)
{
	wingpanel_interface_background_manager_on_window_added ((WingpanelInterfaceBackgroundManager*) self, object);
}

static void
_wingpanel_interface_background_manager_on_window_removed_meta_workspace_window_removed (MetaWorkspace* _sender,
                                                                                         MetaWindow* object,
                                                                                         gpointer self)
{
	wingpanel_interface_background_manager_on_window_removed ((WingpanelInterfaceBackgroundManager*) self, object);
}

static void
wingpanel_interface_background_manager_update_current_workspace (WingpanelInterfaceBackgroundManager* self)
{
	MetaWorkspaceManager* manager = NULL;
	MetaDisplay* _tmp0_;
	MetaWorkspaceManager* _tmp1_;
	MetaWorkspace* workspace = NULL;
	MetaWorkspaceManager* _tmp2_;
	MetaWorkspace* _tmp3_;
	MetaWorkspace* _tmp4_;
	MetaWorkspace* _tmp5_;
	MetaWorkspace* _tmp6_;
	MetaWorkspace* _tmp11_;
	MetaWorkspace* _tmp12_;
	MetaWorkspace* _tmp13_;
	GList* _tmp14_;
	MetaWorkspace* _tmp18_;
	MetaWorkspace* _tmp19_;
	g_return_if_fail (self != NULL);
	_tmp0_ = wingpanel_interface_main_display;
	_tmp1_ = meta_display_get_workspace_manager (_tmp0_);
	manager = _tmp1_;
	_tmp2_ = manager;
	_tmp3_ = meta_workspace_manager_get_active_workspace (_tmp2_);
	_tmp4_ = _g_object_ref0 (_tmp3_);
	workspace = _tmp4_;
	_tmp5_ = workspace;
	if (_tmp5_ == NULL) {
		g_warning ("BackgroundManager.vala:92: Cannot get active workspace");
		_g_object_unref0 (workspace);
		return;
	}
	_tmp6_ = self->priv->current_workspace;
	if (_tmp6_ != NULL) {
		MetaWorkspace* _tmp7_;
		guint _tmp8_;
		MetaWorkspace* _tmp9_;
		guint _tmp10_;
		_tmp7_ = self->priv->current_workspace;
		g_signal_parse_name ("window-added", meta_workspace_get_type (), &_tmp8_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp7_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp8_, 0, NULL, (GCallback) _wingpanel_interface_background_manager_on_window_added_meta_workspace_window_added, self);
		_tmp9_ = self->priv->current_workspace;
		g_signal_parse_name ("window-removed", meta_workspace_get_type (), &_tmp10_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp9_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp10_, 0, NULL, (GCallback) _wingpanel_interface_background_manager_on_window_removed_meta_workspace_window_removed, self);
	}
	_tmp11_ = workspace;
	_tmp12_ = _g_object_ref0 (_tmp11_);
	_g_object_unref0 (self->priv->current_workspace);
	self->priv->current_workspace = _tmp12_;
	_tmp13_ = self->priv->current_workspace;
	_tmp14_ = meta_workspace_list_windows (_tmp13_);
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp14_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			MetaWindow* _tmp15_;
			MetaWindow* window = NULL;
			_tmp15_ = _g_object_ref0 ((MetaWindow*) window_it->data);
			window = _tmp15_;
			{
				MetaWindow* _tmp16_;
				_tmp16_ = window;
				if (meta_window_is_on_primary_monitor (_tmp16_)) {
					MetaWindow* _tmp17_;
					_tmp17_ = window;
					wingpanel_interface_background_manager_register_window (self, _tmp17_);
				}
				_g_object_unref0 (window);
			}
		}
		(window_collection == NULL) ? NULL : (window_collection = (g_list_free (window_collection), NULL));
	}
	_tmp18_ = self->priv->current_workspace;
	g_signal_connect_object (_tmp18_, "window-added", (GCallback) _wingpanel_interface_background_manager_on_window_added_meta_workspace_window_added, self, 0);
	_tmp19_ = self->priv->current_workspace;
	g_signal_connect_object (_tmp19_, "window-removed", (GCallback) _wingpanel_interface_background_manager_on_window_removed_meta_workspace_window_removed, self, 0);
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_WORKSPACE_SWITCH_DURATION);
	_g_object_unref0 (workspace);
}

static void
__lambda5_ (WingpanelInterfaceBackgroundManager* self)
{
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_SNAP_DURATION);
}

static void
___lambda5__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda5_ ((WingpanelInterfaceBackgroundManager*) self);
}

static void
__lambda6_ (WingpanelInterfaceBackgroundManager* self)
{
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MINIMIZE_DURATION);
}

static void
___lambda6__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda6_ ((WingpanelInterfaceBackgroundManager*) self);
}

static void
__lambda7_ (WingpanelInterfaceBackgroundManager* self)
{
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_WORKSPACE_SWITCH_DURATION);
}

static void
___lambda7__meta_window_workspace_changed (MetaWindow* _sender,
                                           gpointer self)
{
	__lambda7_ ((WingpanelInterfaceBackgroundManager*) self);
}

static void
wingpanel_interface_background_manager_register_window (WingpanelInterfaceBackgroundManager* self,
                                                        MetaWindow* window)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	g_signal_connect_object ((GObject*) window, "notify::maximized-vertically", (GCallback) ___lambda5__g_object_notify, self, 0);
	g_signal_connect_object ((GObject*) window, "notify::minimized", (GCallback) ___lambda6__g_object_notify, self, 0);
	g_signal_connect_object (window, "workspace-changed", (GCallback) ___lambda7__meta_window_workspace_changed, self, 0);
}

static void
wingpanel_interface_background_manager_on_window_added (WingpanelInterfaceBackgroundManager* self,
                                                        MetaWindow* window)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	wingpanel_interface_background_manager_register_window (self, window);
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_SNAP_DURATION);
}

static void
wingpanel_interface_background_manager_on_window_removed (WingpanelInterfaceBackgroundManager* self,
                                                          MetaWindow* window)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	wingpanel_interface_background_manager_check_for_state_change (self, (guint) WINGPANEL_INTERFACE_BACKGROUND_MANAGER_SNAP_DURATION);
}

static void
wingpanel_interface_background_manager_update_bk_color_info_data_free (gpointer _data)
{
	WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData, _data_);
}

void
wingpanel_interface_background_manager_update_bk_color_info (WingpanelInterfaceBackgroundManager* self,
                                                             GAsyncReadyCallback _callback_,
                                                             gpointer _user_data_)
{
	WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData* _data_;
	WingpanelInterfaceBackgroundManager* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, wingpanel_interface_background_manager_update_bk_color_info_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	wingpanel_interface_background_manager_update_bk_color_info_co (_data_);
}

void
wingpanel_interface_background_manager_update_bk_color_info_finish (WingpanelInterfaceBackgroundManager* self,
                                                                    GAsyncResult* _res_)
{
	WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

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_)) {
		WingpanelInterfaceBackgroundManager* self;
		self = _data1_->self;
		(_data1_->callback_target_destroy_notify == NULL) ? NULL : (_data1_->callback_target_destroy_notify (_data1_->callback_target), NULL);
		_data1_->callback = NULL;
		_data1_->callback_target = NULL;
		_data1_->callback_target_destroy_notify = NULL;
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static gboolean
_wingpanel_interface_background_manager_update_bk_color_info_co_gsource_func (gpointer self)
{
	gboolean result;
	result = wingpanel_interface_background_manager_update_bk_color_info_co (self);
	return result;
}

static gpointer
_wingpanel_interface_utils_color_information_dup0 (gpointer self)
{
	return self ? wingpanel_interface_utils_color_information_dup (self) : NULL;
}

static void
__lambda11_ (Block1Data* _data1_,
             GObject* obj,
             GAsyncResult* res)
{
	WingpanelInterfaceBackgroundManager* self;
	GError* _inner_error0_ = NULL;
	self = _data1_->self;
	g_return_if_fail (res != NULL);
	{
		WingpanelInterfaceUtilsColorInformation _tmp0_ = {0};
		WingpanelInterfaceUtilsColorInformation _tmp1_ = {0};
		WingpanelInterfaceUtilsColorInformation* _tmp2_;
		wingpanel_interface_utils_get_background_color_information_finish (res, &_tmp1_, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _wingpanel_interface_utils_color_information_dup0 (&_tmp0_);
		_wingpanel_interface_utils_color_information_free0 (self->priv->bk_color_info);
		self->priv->bk_color_info = _tmp2_;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("BackgroundManager.vala:150: %s", _tmp4_);
		_g_error_free0 (e);
	}
	__finally0:
	{
		GError* _inner_error1_ = NULL;
		_data1_->callback (_data1_->callback_target);
	}
	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;
	}
}

static void
___lambda11__gasync_ready_callback (GObject* source_object,
                                    GAsyncResult* res,
                                    gpointer self)
{
	__lambda11_ (self, source_object, res);
	block1_data_unref (self);
}

static gboolean
wingpanel_interface_background_manager_update_bk_color_info_co (WingpanelInterfaceBackgroundManagerUpdateBkColorInfoData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_data1_->self = g_object_ref (_data_->self);
	_data_->_data1_->_async_data_ = _data_;
	_data_->_data1_->callback = _wingpanel_interface_background_manager_update_bk_color_info_co_gsource_func;
	_data_->_data1_->callback_target = _data_;
	_data_->_data1_->callback_target_destroy_notify = NULL;
	_data_->_tmp0_ = gdk_screen_get_default ();
	_data_->_tmp1_ = _data_->self->priv->_monitor;
	memset (&_data_->_tmp2_, 0, sizeof (GdkRectangle));
	gdk_screen_get_monitor_geometry (_data_->_tmp0_, _data_->_tmp1_, &_data_->_tmp2_);
	_data_->monitor_geometry = _data_->_tmp2_;
	_data_->_tmp3_ = wingpanel_interface_main_wm;
	_data_->_tmp4_ = _data_->self->priv->_monitor;
	_data_->_tmp5_ = _data_->monitor_geometry;
	_data_->_tmp6_ = _data_->self->priv->_panel_height;
	wingpanel_interface_utils_get_background_color_information (_data_->_tmp3_, _data_->_tmp4_, 0, 0, _data_->_tmp5_.width, _data_->_tmp6_, ___lambda11__gasync_ready_callback, block1_data_ref (_data_->_data1_));
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

/**
     * Check if Wingpanel's background state should change.
     *
     * The state is defined as follows:
     *  - If there's a maximized window, the state should be MAXIMIZED;
     *  - If no information about the background could be gathered, it should be TRANSLUCENT;
     *  - If there's too much contrast or sharpness, it should be TRANSLUCENT;
     *  - If the background is too bright, it should be DARK;
     *  - Else it should be LIGHT.
     */
static void
wingpanel_interface_background_manager_check_for_state_change (WingpanelInterfaceBackgroundManager* self,
                                                               guint animation_duration)
{
	gboolean has_maximized_window = FALSE;
	MetaWorkspace* _tmp0_;
	GList* _tmp1_;
	BackgroundState new_state = 0;
	g_return_if_fail (self != NULL);
	has_maximized_window = FALSE;
	_tmp0_ = self->priv->current_workspace;
	_tmp1_ = meta_workspace_list_windows (_tmp0_);
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp1_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			MetaWindow* _tmp2_;
			MetaWindow* window = NULL;
			_tmp2_ = _g_object_ref0 ((MetaWindow*) window_it->data);
			window = _tmp2_;
			{
				MetaWindow* _tmp3_;
				_tmp3_ = window;
				if (meta_window_is_on_primary_monitor (_tmp3_)) {
					gboolean _tmp4_ = FALSE;
					MetaWindow* _tmp5_;
					gboolean _tmp6_;
					gboolean _tmp7_;
					_tmp5_ = window;
					g_object_get (_tmp5_, "minimized", &_tmp6_, NULL);
					_tmp7_ = _tmp6_;
					if (!_tmp7_) {
						MetaWindow* _tmp8_;
						gboolean _tmp9_;
						gboolean _tmp10_;
						_tmp8_ = window;
						g_object_get (_tmp8_, "maximized-vertically", &_tmp9_, NULL);
						_tmp10_ = _tmp9_;
						_tmp4_ = _tmp10_;
					} else {
						_tmp4_ = FALSE;
					}
					if (_tmp4_) {
						has_maximized_window = TRUE;
						_g_object_unref0 (window);
						break;
					}
				}
				_g_object_unref0 (window);
			}
		}
		(window_collection == NULL) ? NULL : (window_collection = (g_list_free (window_collection), NULL));
	}
	if (has_maximized_window) {
		new_state = BACKGROUND_STATE_MAXIMIZED;
	} else {
		WingpanelInterfaceUtilsColorInformation* _tmp11_;
		_tmp11_ = self->priv->bk_color_info;
		if (_tmp11_ == NULL) {
			new_state = BACKGROUND_STATE_TRANSLUCENT_LIGHT;
		} else {
			gdouble luminance_std = 0.0;
			WingpanelInterfaceUtilsColorInformation* _tmp12_;
			gboolean _tmp13_ = FALSE;
			gboolean _tmp14_ = FALSE;
			gboolean bg_is_busy = FALSE;
			gboolean bg_is_dark = FALSE;
			WingpanelInterfaceUtilsColorInformation* _tmp19_;
			gboolean bg_is_busy_dark = FALSE;
			WingpanelInterfaceUtilsColorInformation* _tmp20_;
			gboolean _tmp21_ = FALSE;
			_tmp12_ = self->priv->bk_color_info;
			luminance_std = sqrt ((*_tmp12_).luminance_variance);
			if (luminance_std > WINGPANEL_INTERFACE_BACKGROUND_MANAGER_STD_THRESHOLD) {
				_tmp14_ = TRUE;
			} else {
				gboolean _tmp15_ = FALSE;
				WingpanelInterfaceUtilsColorInformation* _tmp16_;
				_tmp16_ = self->priv->bk_color_info;
				if ((*_tmp16_).mean_luminance < WINGPANEL_INTERFACE_BACKGROUND_MANAGER_LUMINANCE_THRESHOLD) {
					WingpanelInterfaceUtilsColorInformation* _tmp17_;
					_tmp17_ = self->priv->bk_color_info;
					_tmp15_ = ((*_tmp17_).mean_luminance + (1.645 * luminance_std)) > WINGPANEL_INTERFACE_BACKGROUND_MANAGER_LUMINANCE_THRESHOLD;
				} else {
					_tmp15_ = FALSE;
				}
				_tmp14_ = _tmp15_;
			}
			if (_tmp14_) {
				_tmp13_ = TRUE;
			} else {
				WingpanelInterfaceUtilsColorInformation* _tmp18_;
				_tmp18_ = self->priv->bk_color_info;
				_tmp13_ = (*_tmp18_).mean_acutance > WINGPANEL_INTERFACE_BACKGROUND_MANAGER_ACUTANCE_THRESHOLD;
			}
			bg_is_busy = _tmp13_;
			_tmp19_ = self->priv->bk_color_info;
			bg_is_dark = (*_tmp19_).mean_luminance > WINGPANEL_INTERFACE_BACKGROUND_MANAGER_LUMINANCE_THRESHOLD;
			_tmp20_ = self->priv->bk_color_info;
			bg_is_busy_dark = ((*_tmp20_).mean_luminance * 1.25) > WINGPANEL_INTERFACE_BACKGROUND_MANAGER_LUMINANCE_THRESHOLD;
			if (bg_is_busy) {
				_tmp21_ = bg_is_busy_dark;
			} else {
				_tmp21_ = FALSE;
			}
			if (_tmp21_) {
				new_state = BACKGROUND_STATE_TRANSLUCENT_DARK;
			} else {
				if (bg_is_busy) {
					new_state = BACKGROUND_STATE_TRANSLUCENT_LIGHT;
				} else {
					if (bg_is_dark) {
						new_state = BACKGROUND_STATE_DARK;
					} else {
						new_state = BACKGROUND_STATE_LIGHT;
					}
				}
			}
		}
	}
	if (new_state != self->priv->current_state) {
		self->priv->current_state = new_state;
		g_signal_emit (self, wingpanel_interface_background_manager_signals[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_STATE_CHANGED_SIGNAL], 0, self->priv->current_state, animation_duration);
	}
}

static gint
wingpanel_interface_background_manager_get_monitor (WingpanelInterfaceBackgroundManager* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_monitor;
	return result;
}

static void
wingpanel_interface_background_manager_set_monitor (WingpanelInterfaceBackgroundManager* self,
                                                    gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = wingpanel_interface_background_manager_get_monitor (self);
	if (old_value != value) {
		self->priv->_monitor = value;
		g_object_notify_by_pspec ((GObject *) self, wingpanel_interface_background_manager_properties[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY]);
	}
}

static gint
wingpanel_interface_background_manager_get_panel_height (WingpanelInterfaceBackgroundManager* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_panel_height;
	return result;
}

static void
wingpanel_interface_background_manager_set_panel_height (WingpanelInterfaceBackgroundManager* self,
                                                         gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = wingpanel_interface_background_manager_get_panel_height (self);
	if (old_value != value) {
		self->priv->_panel_height = value;
		g_object_notify_by_pspec ((GObject *) self, wingpanel_interface_background_manager_properties[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__ENUM_UINT (GClosure * closure,
                                         GValue * return_value,
                                         guint n_param_values,
                                         const GValue * param_values,
                                         gpointer invocation_hint,
                                         gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__ENUM_UINT) (gpointer data1, gint arg_1, guint arg_2, gpointer data2);
	register GMarshalFunc_VOID__ENUM_UINT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__ENUM_UINT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_enum (param_values + 1), g_value_get_uint (param_values + 2), data2);
}

static void
wingpanel_interface_background_manager_class_init (WingpanelInterfaceBackgroundManagerClass * klass,
                                                   gpointer klass_data)
{
	wingpanel_interface_background_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WingpanelInterfaceBackgroundManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_wingpanel_interface_background_manager_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_wingpanel_interface_background_manager_set_property;
	G_OBJECT_CLASS (klass)->finalize = wingpanel_interface_background_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY, wingpanel_interface_background_manager_properties[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY] = g_param_spec_int ("monitor", "monitor", "monitor", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY, wingpanel_interface_background_manager_properties[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY] = g_param_spec_int ("panel-height", "panel-height", "panel-height", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	wingpanel_interface_background_manager_signals[WINGPANEL_INTERFACE_BACKGROUND_MANAGER_STATE_CHANGED_SIGNAL] = g_signal_new ("state-changed", WINGPANEL_INTERFACE_TYPE_BACKGROUND_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__ENUM_UINT, G_TYPE_NONE, 2, TYPE_BACKGROUND_STATE, G_TYPE_UINT);
}

static void
wingpanel_interface_background_manager_instance_init (WingpanelInterfaceBackgroundManager * self,
                                                      gpointer klass)
{
	self->priv = wingpanel_interface_background_manager_get_instance_private (self);
	self->priv->current_workspace = NULL;
	self->priv->current_state = BACKGROUND_STATE_LIGHT;
	self->priv->bk_color_info = NULL;
}

static void
wingpanel_interface_background_manager_finalize (GObject * obj)
{
	WingpanelInterfaceBackgroundManager * self;
	guint signal_id = 0U;
	GalaWindowManager* _tmp0_;
	MetaBackgroundGroup* _tmp1_;
	MetaBackgroundGroup* _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_INTERFACE_TYPE_BACKGROUND_MANAGER, WingpanelInterfaceBackgroundManager);
	_tmp0_ = wingpanel_interface_main_wm;
	_tmp1_ = gala_window_manager_get_background_group (_tmp0_);
	_tmp2_ = _tmp1_;
	signal_id = g_signal_lookup ("changed", G_TYPE_FROM_INSTANCE ((GObject*) _tmp2_));
	g_signal_remove_emission_hook (signal_id, self->priv->wallpaper_hook_id);
	_g_object_unref0 (self->priv->current_workspace);
	_wingpanel_interface_utils_color_information_free0 (self->priv->bk_color_info);
	G_OBJECT_CLASS (wingpanel_interface_background_manager_parent_class)->finalize (obj);
}

static GType
wingpanel_interface_background_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WingpanelInterfaceBackgroundManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wingpanel_interface_background_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WingpanelInterfaceBackgroundManager), 0, (GInstanceInitFunc) wingpanel_interface_background_manager_instance_init, NULL };
	GType wingpanel_interface_background_manager_type_id;
	wingpanel_interface_background_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "WingpanelInterfaceBackgroundManager", &g_define_type_info, 0);
	WingpanelInterfaceBackgroundManager_private_offset = g_type_add_instance_private (wingpanel_interface_background_manager_type_id, sizeof (WingpanelInterfaceBackgroundManagerPrivate));
	return wingpanel_interface_background_manager_type_id;
}

GType
wingpanel_interface_background_manager_get_type (void)
{
	static volatile gsize wingpanel_interface_background_manager_type_id__once = 0;
	if (g_once_init_enter (&wingpanel_interface_background_manager_type_id__once)) {
		GType wingpanel_interface_background_manager_type_id;
		wingpanel_interface_background_manager_type_id = wingpanel_interface_background_manager_get_type_once ();
		g_once_init_leave (&wingpanel_interface_background_manager_type_id__once, wingpanel_interface_background_manager_type_id);
	}
	return wingpanel_interface_background_manager_type_id__once;
}

static void
_vala_wingpanel_interface_background_manager_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec)
{
	WingpanelInterfaceBackgroundManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WINGPANEL_INTERFACE_TYPE_BACKGROUND_MANAGER, WingpanelInterfaceBackgroundManager);
	switch (property_id) {
		case WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY:
		g_value_set_int (value, wingpanel_interface_background_manager_get_monitor (self));
		break;
		case WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY:
		g_value_set_int (value, wingpanel_interface_background_manager_get_panel_height (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_wingpanel_interface_background_manager_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec)
{
	WingpanelInterfaceBackgroundManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WINGPANEL_INTERFACE_TYPE_BACKGROUND_MANAGER, WingpanelInterfaceBackgroundManager);
	switch (property_id) {
		case WINGPANEL_INTERFACE_BACKGROUND_MANAGER_MONITOR_PROPERTY:
		wingpanel_interface_background_manager_set_monitor (self, g_value_get_int (value));
		break;
		case WINGPANEL_INTERFACE_BACKGROUND_MANAGER_PANEL_HEIGHT_PROPERTY:
		wingpanel_interface_background_manager_set_panel_height (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

