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

/*
 * This file is part of budgie-desktop.
 *
 * Copyright (C) 2015-2016 Ikey Doherty <ikey@solus-project.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 */

#include <glib.h>
#include <glib-object.h>
#include <plugin.h>
#include <gtk/gtk.h>
#include <BudgieToplevel.h>
#include <gdk/gdk.h>
#include <cairo.h>
#include <float.h>
#include <math.h>


#define BUDGIE_TYPE_POPOVER_MANAGER_IMPL (budgie_popover_manager_impl_get_type ())
#define BUDGIE_POPOVER_MANAGER_IMPL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_POPOVER_MANAGER_IMPL, BudgiePopoverManagerImpl))
#define BUDGIE_POPOVER_MANAGER_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_POPOVER_MANAGER_IMPL, BudgiePopoverManagerImplClass))
#define BUDGIE_IS_POPOVER_MANAGER_IMPL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_POPOVER_MANAGER_IMPL))
#define BUDGIE_IS_POPOVER_MANAGER_IMPL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_POPOVER_MANAGER_IMPL))
#define BUDGIE_POPOVER_MANAGER_IMPL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_POPOVER_MANAGER_IMPL, BudgiePopoverManagerImplClass))

typedef struct _BudgiePopoverManagerImpl BudgiePopoverManagerImpl;
typedef struct _BudgiePopoverManagerImplClass BudgiePopoverManagerImplClass;
typedef struct _BudgiePopoverManagerImplPrivate BudgiePopoverManagerImplPrivate;

#define BUDGIE_TYPE_PANEL (budgie_panel_get_type ())
#define BUDGIE_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BUDGIE_TYPE_PANEL, BudgiePanel))
#define BUDGIE_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BUDGIE_TYPE_PANEL, BudgiePanelClass))
#define BUDGIE_IS_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BUDGIE_TYPE_PANEL))
#define BUDGIE_IS_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BUDGIE_TYPE_PANEL))
#define BUDGIE_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BUDGIE_TYPE_PANEL, BudgiePanelClass))

typedef struct _BudgiePanel BudgiePanel;
typedef struct _BudgiePanelClass BudgiePanelClass;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;

struct _BudgiePopoverManagerImpl {
	GObject parent_instance;
	BudgiePopoverManagerImplPrivate * priv;
};

struct _BudgiePopoverManagerImplClass {
	GObjectClass parent_class;
};

struct _BudgiePopoverManagerImplPrivate {
	GHashTable* widgets;
	BudgiePanel* owner;
	GtkPopover* visible_popover;
	gboolean grabbed;
	gboolean mousing;
};

struct _Block2Data {
	int _ref_count_;
	BudgiePopoverManagerImpl* self;
	BudgiePanel* owner;
};


static gpointer budgie_popover_manager_impl_parent_class = NULL;
static BudgiePopoverManagerIface* budgie_popover_manager_impl_budgie_popover_manager_parent_iface = NULL;

GType budgie_popover_manager_impl_get_type (void) G_GNUC_CONST;
GType budgie_panel_get_type (void) G_GNUC_CONST;
#define BUDGIE_POPOVER_MANAGER_IMPL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BUDGIE_TYPE_POPOVER_MANAGER_IMPL, BudgiePopoverManagerImplPrivate))
enum  {
	BUDGIE_POPOVER_MANAGER_IMPL_DUMMY_PROPERTY
};
BudgiePopoverManagerImpl* budgie_popover_manager_impl_new (BudgiePanel* owner);
BudgiePopoverManagerImpl* budgie_popover_manager_impl_construct (GType object_type, BudgiePanel* owner);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static void _g_object_unref0_ (gpointer var);
static gboolean __lambda7_ (BudgiePopoverManagerImpl* self);
static void budgie_popover_manager_impl_make_modal (BudgiePopoverManagerImpl* self, GtkPopover* pop, gboolean modal);
static gboolean ___lambda7__gtk_widget_focus_out_event (GtkWidget* _sender, GdkEventFocus* event, gpointer self);
static gboolean __lambda8_ (Block2Data* _data2_, GtkWidget* w, GdkEventButton* e);
static gboolean ___lambda8__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
static void budgie_popover_manager_impl_real_unregister_popover (BudgiePopoverManager* base, GtkWidget* widg);
static void budgie_popover_manager_impl_real_show_popover (BudgiePopoverManager* base, GtkWidget* parent);
void budgie_panel_set_expanded (BudgiePanel* self, gboolean expanded);
static void budgie_popover_manager_impl_on_widget_mapped (BudgiePopoverManagerImpl* self, GtkWidget* p);
static void budgie_popover_manager_impl_on_popover_closed (BudgiePopoverManagerImpl* self, GtkPopover* p);
static gboolean budgie_popover_manager_impl_enter_notify_event (BudgiePopoverManagerImpl* self, GtkWidget* w, GdkEvent* e);
static void budgie_popover_manager_impl_notify_visible (BudgiePopoverManagerImpl* self, GObject* o, GParamSpec* spec);
static void budgie_popover_manager_impl_real_register_popover (BudgiePopoverManager* base, GtkWidget* widg, GtkPopover* popover);
static void _budgie_popover_manager_impl_on_widget_mapped_gtk_widget_map (GtkWidget* _sender, gpointer self);
static void _budgie_popover_manager_impl_on_popover_closed_gtk_popover_closed (GtkPopover* _sender, gpointer self);
static gboolean _budgie_popover_manager_impl_enter_notify_event_gtk_widget_enter_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self);
static void _budgie_popover_manager_impl_notify_visible_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void __lambda10_ (BudgiePopoverManagerImpl* self, GtkWidget* w);
static void ___lambda10__gtk_widget_destroy (GtkWidget* _sender, gpointer self);
static void budgie_popover_manager_impl_finalize (GObject* obj);


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


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


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		BudgiePopoverManagerImpl* self;
		self = _data2_->self;
		_g_object_unref0 (_data2_->owner);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static void _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


static gboolean __lambda7_ (BudgiePopoverManagerImpl* self) {
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	GtkPopover* _tmp1_ = NULL;
	_tmp0_ = self->priv->mousing;
	if (_tmp0_) {
		result = GDK_EVENT_PROPAGATE;
		return result;
	}
	_tmp1_ = self->priv->visible_popover;
	if (_tmp1_ != NULL) {
		GtkPopover* _tmp2_ = NULL;
		GtkPopover* _tmp3_ = NULL;
		_tmp2_ = self->priv->visible_popover;
		gtk_widget_hide ((GtkWidget*) _tmp2_);
		_tmp3_ = self->priv->visible_popover;
		budgie_popover_manager_impl_make_modal (self, _tmp3_, FALSE);
		self->priv->visible_popover = NULL;
	}
	result = GDK_EVENT_PROPAGATE;
	return result;
}


static gboolean ___lambda7__gtk_widget_focus_out_event (GtkWidget* _sender, GdkEventFocus* event, gpointer self) {
	gboolean result;
	result = __lambda7_ ((BudgiePopoverManagerImpl*) self);
	return result;
}


static gboolean __lambda8_ (Block2Data* _data2_, GtkWidget* w, GdkEventButton* e) {
	BudgiePopoverManagerImpl* self;
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	GtkAllocation alloc = {0};
	GtkPopover* _tmp1_ = NULL;
	GtkAllocation _tmp2_ = {0};
	BudgiePanel* _tmp3_ = NULL;
	BudgiePanelPosition _tmp4_ = 0;
	BudgiePanelPosition _tmp5_ = 0;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp13_ = FALSE;
	GdkEventButton* _tmp14_ = NULL;
	gdouble _tmp15_ = 0.0;
	GtkAllocation _tmp16_ = {0};
	gint _tmp17_ = 0;
	self = _data2_->self;
	g_return_val_if_fail (w != NULL, FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = self->priv->grabbed;
	if (!_tmp0_) {
		result = GDK_EVENT_PROPAGATE;
		return result;
	}
	_tmp1_ = self->priv->visible_popover;
	gtk_widget_get_allocation ((GtkWidget*) _tmp1_, &_tmp2_);
	alloc = _tmp2_;
	_tmp3_ = _data2_->owner;
	_tmp4_ = budgie_toplevel_get_position ((BudgieToplevel*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == BUDGIE_PANEL_POSITION_BOTTOM) {
		GtkAllocation parent = {0};
		BudgiePanel* _tmp6_ = NULL;
		GtkAllocation _tmp7_ = {0};
		GtkAllocation _tmp8_ = {0};
		gint _tmp9_ = 0;
		GtkAllocation _tmp10_ = {0};
		gint _tmp11_ = 0;
		_tmp6_ = _data2_->owner;
		gtk_widget_get_allocation ((GtkWidget*) _tmp6_, &_tmp7_);
		parent = _tmp7_;
		_tmp8_ = parent;
		_tmp9_ = _tmp8_.height;
		_tmp10_ = alloc;
		_tmp11_ = _tmp10_.height;
		alloc.y = _tmp9_ - _tmp11_;
	}
	_tmp14_ = e;
	_tmp15_ = _tmp14_->x;
	_tmp16_ = alloc;
	_tmp17_ = _tmp16_.x;
	if (_tmp15_ < ((gdouble) _tmp17_)) {
		_tmp13_ = TRUE;
	} else {
		GdkEventButton* _tmp18_ = NULL;
		gdouble _tmp19_ = 0.0;
		GtkAllocation _tmp20_ = {0};
		gint _tmp21_ = 0;
		GtkAllocation _tmp22_ = {0};
		gint _tmp23_ = 0;
		_tmp18_ = e;
		_tmp19_ = _tmp18_->x;
		_tmp20_ = alloc;
		_tmp21_ = _tmp20_.x;
		_tmp22_ = alloc;
		_tmp23_ = _tmp22_.width;
		_tmp13_ = _tmp19_ > ((gdouble) (_tmp21_ + _tmp23_));
	}
	if (_tmp13_) {
		_tmp12_ = TRUE;
	} else {
		gboolean _tmp24_ = FALSE;
		GdkEventButton* _tmp25_ = NULL;
		gdouble _tmp26_ = 0.0;
		GtkAllocation _tmp27_ = {0};
		gint _tmp28_ = 0;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->y;
		_tmp27_ = alloc;
		_tmp28_ = _tmp27_.y;
		if (_tmp26_ < ((gdouble) _tmp28_)) {
			_tmp24_ = TRUE;
		} else {
			GdkEventButton* _tmp29_ = NULL;
			gdouble _tmp30_ = 0.0;
			GtkAllocation _tmp31_ = {0};
			gint _tmp32_ = 0;
			GtkAllocation _tmp33_ = {0};
			gint _tmp34_ = 0;
			_tmp29_ = e;
			_tmp30_ = _tmp29_->y;
			_tmp31_ = alloc;
			_tmp32_ = _tmp31_.y;
			_tmp33_ = alloc;
			_tmp34_ = _tmp33_.height;
			_tmp24_ = _tmp30_ > ((gdouble) (_tmp32_ + _tmp34_));
		}
		_tmp12_ = _tmp24_;
	}
	if (_tmp12_) {
		GtkPopover* _tmp35_ = NULL;
		GtkPopover* _tmp36_ = NULL;
		_tmp35_ = self->priv->visible_popover;
		gtk_widget_hide ((GtkWidget*) _tmp35_);
		_tmp36_ = self->priv->visible_popover;
		budgie_popover_manager_impl_make_modal (self, _tmp36_, FALSE);
		self->priv->visible_popover = NULL;
	}
	result = GDK_EVENT_STOP;
	return result;
}


static gboolean ___lambda8__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
	gboolean result;
	result = __lambda8_ (self, _sender, event);
	return result;
}


BudgiePopoverManagerImpl* budgie_popover_manager_impl_construct (GType object_type, BudgiePanel* owner) {
	BudgiePopoverManagerImpl * self = NULL;
	Block2Data* _data2_;
	BudgiePanel* _tmp0_ = NULL;
	BudgiePanel* _tmp1_ = NULL;
	BudgiePanel* _tmp2_ = NULL;
	GHashFunc _tmp3_ = NULL;
	GEqualFunc _tmp4_ = NULL;
	GHashTable* _tmp5_ = NULL;
	BudgiePanel* _tmp6_ = NULL;
	BudgiePanel* _tmp7_ = NULL;
	BudgiePanel* _tmp8_ = NULL;
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_tmp0_ = owner;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (_data2_->owner);
	_data2_->owner = _tmp1_;
	self = (BudgiePopoverManagerImpl*) g_object_new (object_type, NULL);
	_data2_->self = g_object_ref (self);
	_tmp2_ = _data2_->owner;
	self->priv->owner = _tmp2_;
	_tmp3_ = g_direct_hash;
	_tmp4_ = g_direct_equal;
	_tmp5_ = g_hash_table_new_full (_tmp3_, _tmp4_, _g_object_unref0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->widgets);
	self->priv->widgets = _tmp5_;
	_tmp6_ = _data2_->owner;
	g_signal_connect_object ((GtkWidget*) _tmp6_, "focus-out-event", (GCallback) ___lambda7__gtk_widget_focus_out_event, self, 0);
	_tmp7_ = _data2_->owner;
	g_signal_connect_data ((GtkWidget*) _tmp7_, "button-press-event", (GCallback) ___lambda8__gtk_widget_button_press_event, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	_tmp8_ = _data2_->owner;
	gtk_widget_add_events ((GtkWidget*) _tmp8_, (gint) ((GDK_POINTER_MOTION_MASK | GDK_ENTER_NOTIFY_MASK) | GDK_BUTTON_PRESS_MASK));
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return self;
}


BudgiePopoverManagerImpl* budgie_popover_manager_impl_new (BudgiePanel* owner) {
	return budgie_popover_manager_impl_construct (BUDGIE_TYPE_POPOVER_MANAGER_IMPL, owner);
}


static void budgie_popover_manager_impl_make_modal (BudgiePopoverManagerImpl* self, GtkPopover* pop, gboolean modal) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GtkPopover* _tmp2_ = NULL;
	gboolean _tmp6_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp2_ = pop;
	if (_tmp2_ == NULL) {
		_tmp1_ = TRUE;
	} else {
		GtkPopover* _tmp3_ = NULL;
		GdkWindow* _tmp4_ = NULL;
		_tmp3_ = pop;
		_tmp4_ = gtk_widget_get_window ((GtkWidget*) _tmp3_);
		_tmp1_ = _tmp4_ == NULL;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gboolean _tmp5_ = FALSE;
		_tmp5_ = self->priv->mousing;
		_tmp0_ = _tmp5_;
	}
	if (_tmp0_) {
		return;
	}
	_tmp6_ = modal;
	if (_tmp6_) {
		gboolean _tmp7_ = FALSE;
		BudgiePanel* _tmp8_ = NULL;
		BudgiePanel* _tmp9_ = NULL;
		GtkPopover* _tmp10_ = NULL;
		_tmp7_ = self->priv->grabbed;
		if (_tmp7_) {
			return;
		}
		_tmp8_ = self->priv->owner;
		gtk_grab_add ((GtkWidget*) _tmp8_);
		_tmp9_ = self->priv->owner;
		gtk_window_set_focus ((GtkWindow*) _tmp9_, NULL);
		_tmp10_ = pop;
		gtk_widget_grab_focus ((GtkWidget*) _tmp10_);
		self->priv->grabbed = TRUE;
	} else {
		gboolean _tmp11_ = FALSE;
		BudgiePanel* _tmp12_ = NULL;
		BudgiePanel* _tmp13_ = NULL;
		_tmp11_ = self->priv->grabbed;
		if (!_tmp11_) {
			return;
		}
		_tmp12_ = self->priv->owner;
		gtk_grab_remove ((GtkWidget*) _tmp12_);
		_tmp13_ = self->priv->owner;
		gtk_widget_grab_focus ((GtkWidget*) _tmp13_);
		self->priv->grabbed = FALSE;
	}
}


static void budgie_popover_manager_impl_real_unregister_popover (BudgiePopoverManager* base, GtkWidget* widg) {
	BudgiePopoverManagerImpl * self;
	GHashTable* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GHashTable* _tmp3_ = NULL;
	GtkWidget* _tmp4_ = NULL;
	self = (BudgiePopoverManagerImpl*) base;
	_tmp0_ = self->priv->widgets;
	_tmp1_ = widg;
	_tmp2_ = g_hash_table_contains (_tmp0_, _tmp1_);
	if (!_tmp2_) {
		return;
	}
	_tmp3_ = self->priv->widgets;
	_tmp4_ = widg;
	g_hash_table_remove (_tmp3_, _tmp4_);
}


static void budgie_popover_manager_impl_real_show_popover (BudgiePopoverManager* base, GtkWidget* parent) {
	BudgiePopoverManagerImpl * self;
	GtkPopover* pop = NULL;
	GHashTable* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	GtkPopover* _tmp3_ = NULL;
	BudgiePanel* _tmp4_ = NULL;
	GtkPopover* _tmp5_ = NULL;
	self = (BudgiePopoverManagerImpl*) base;
	_tmp0_ = self->priv->widgets;
	_tmp1_ = parent;
	_tmp2_ = g_hash_table_lookup (_tmp0_, _tmp1_);
	pop = (GtkPopover*) _tmp2_;
	_tmp3_ = pop;
	if (_tmp3_ == NULL) {
		return;
	}
	_tmp4_ = self->priv->owner;
	budgie_panel_set_expanded (_tmp4_, TRUE);
	_tmp5_ = pop;
	gtk_widget_show ((GtkWidget*) _tmp5_);
}


static void budgie_popover_manager_impl_on_widget_mapped (BudgiePopoverManagerImpl* self, GtkWidget* p) {
	BudgiePanel* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkPopover* _tmp2_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->owner;
	budgie_panel_set_expanded (_tmp0_, TRUE);
	_tmp1_ = p;
	self->priv->visible_popover = G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, gtk_popover_get_type ()) ? ((GtkPopover*) _tmp1_) : NULL;
	_tmp2_ = self->priv->visible_popover;
	budgie_popover_manager_impl_make_modal (self, _tmp2_, TRUE);
}


static void budgie_popover_manager_impl_on_popover_closed (BudgiePopoverManagerImpl* self, GtkPopover* p) {
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->mousing;
	if (!_tmp1_) {
		gboolean _tmp2_ = FALSE;
		_tmp2_ = self->priv->grabbed;
		_tmp0_ = _tmp2_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GtkPopover* _tmp3_ = NULL;
		_tmp3_ = p;
		budgie_popover_manager_impl_make_modal (self, _tmp3_, FALSE);
		self->priv->visible_popover = NULL;
	}
}


static gboolean budgie_popover_manager_impl_enter_notify_event (BudgiePopoverManagerImpl* self, GtkWidget* w, GdkEvent* e) {
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->mousing;
	if (_tmp0_) {
		result = GDK_EVENT_PROPAGATE;
		return result;
	}
	_tmp1_ = self->priv->grabbed;
	if (_tmp1_) {
		gboolean _tmp2_ = FALSE;
		GHashTable* _tmp3_ = NULL;
		GtkWidget* _tmp4_ = NULL;
		gboolean _tmp5_ = FALSE;
		_tmp3_ = self->priv->widgets;
		_tmp4_ = w;
		_tmp5_ = g_hash_table_contains (_tmp3_, _tmp4_);
		if (_tmp5_) {
			GtkWidget* _tmp6_ = NULL;
			gboolean _tmp7_ = FALSE;
			_tmp6_ = w;
			_tmp7_ = gtk_widget_get_visible (_tmp6_);
			_tmp2_ = _tmp7_;
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			gboolean _tmp8_ = FALSE;
			GtkPopover* _tmp9_ = NULL;
			GHashTable* _tmp10_ = NULL;
			GtkWidget* _tmp11_ = NULL;
			gconstpointer _tmp12_ = NULL;
			_tmp9_ = self->priv->visible_popover;
			_tmp10_ = self->priv->widgets;
			_tmp11_ = w;
			_tmp12_ = g_hash_table_lookup (_tmp10_, _tmp11_);
			if (_tmp9_ != ((GtkPopover*) _tmp12_)) {
				GtkPopover* _tmp13_ = NULL;
				_tmp13_ = self->priv->visible_popover;
				_tmp8_ = _tmp13_ != NULL;
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				GtkPopover* _tmp14_ = NULL;
				GHashTable* _tmp15_ = NULL;
				GtkWidget* _tmp16_ = NULL;
				gconstpointer _tmp17_ = NULL;
				GtkPopover* _tmp18_ = NULL;
				BudgiePanel* _tmp19_ = NULL;
				GtkPopover* _tmp20_ = NULL;
				self->priv->mousing = TRUE;
				_tmp14_ = self->priv->visible_popover;
				gtk_widget_hide ((GtkWidget*) _tmp14_);
				_tmp15_ = self->priv->widgets;
				_tmp16_ = w;
				_tmp17_ = g_hash_table_lookup (_tmp15_, _tmp16_);
				self->priv->visible_popover = (GtkPopover*) _tmp17_;
				_tmp18_ = self->priv->visible_popover;
				gtk_widget_show_all ((GtkWidget*) _tmp18_);
				_tmp19_ = self->priv->owner;
				gtk_window_set_focus ((GtkWindow*) _tmp19_, NULL);
				_tmp20_ = self->priv->visible_popover;
				gtk_widget_grab_focus ((GtkWidget*) _tmp20_);
				self->priv->mousing = FALSE;
			}
		}
		result = GDK_EVENT_STOP;
		return result;
	}
	result = GDK_EVENT_PROPAGATE;
	return result;
}


static void budgie_popover_manager_impl_notify_visible (BudgiePopoverManagerImpl* self, GObject* o, GParamSpec* spec) {
	GtkPopover* popover = NULL;
	GObject* _tmp0_ = NULL;
	GtkPopover* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	GtkPopover* _tmp5_ = NULL;
	gboolean _tmp6_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (spec != NULL);
	_tmp0_ = o;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_popover_get_type ()) ? ((GtkPopover*) _tmp0_) : NULL);
	popover = _tmp1_;
	_tmp3_ = self->priv->mousing;
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		gboolean _tmp4_ = FALSE;
		_tmp4_ = self->priv->grabbed;
		_tmp2_ = _tmp4_;
	}
	if (_tmp2_) {
		_g_object_unref0 (popover);
		return;
	}
	_tmp5_ = popover;
	_tmp6_ = gtk_widget_get_visible ((GtkWidget*) _tmp5_);
	if (!_tmp6_) {
		GtkPopover* _tmp7_ = NULL;
		BudgiePanel* _tmp8_ = NULL;
		_tmp7_ = self->priv->visible_popover;
		budgie_popover_manager_impl_make_modal (self, _tmp7_, FALSE);
		self->priv->visible_popover = NULL;
		_tmp8_ = self->priv->owner;
		budgie_panel_set_expanded (_tmp8_, FALSE);
	}
	_g_object_unref0 (popover);
}


static void _budgie_popover_manager_impl_on_widget_mapped_gtk_widget_map (GtkWidget* _sender, gpointer self) {
	budgie_popover_manager_impl_on_widget_mapped ((BudgiePopoverManagerImpl*) self, _sender);
}


static void _budgie_popover_manager_impl_on_popover_closed_gtk_popover_closed (GtkPopover* _sender, gpointer self) {
	budgie_popover_manager_impl_on_popover_closed ((BudgiePopoverManagerImpl*) self, _sender);
}


static gboolean _budgie_popover_manager_impl_enter_notify_event_gtk_widget_enter_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self) {
	gboolean result;
	result = budgie_popover_manager_impl_enter_notify_event ((BudgiePopoverManagerImpl*) self, _sender, event);
	return result;
}


static void _budgie_popover_manager_impl_notify_visible_g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	budgie_popover_manager_impl_notify_visible ((BudgiePopoverManagerImpl*) self, _sender, pspec);
}


static void __lambda10_ (BudgiePopoverManagerImpl* self, GtkWidget* w) {
	GHashTable* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	g_return_if_fail (w != NULL);
	_tmp0_ = self->priv->widgets;
	_tmp1_ = w;
	g_hash_table_remove (_tmp0_, _tmp1_);
}


static void ___lambda10__gtk_widget_destroy (GtkWidget* _sender, gpointer self) {
	__lambda10_ ((BudgiePopoverManagerImpl*) self, _sender);
}


static void budgie_popover_manager_impl_real_register_popover (BudgiePopoverManager* base, GtkWidget* widg, GtkPopover* popover) {
	BudgiePopoverManagerImpl * self;
	GHashTable* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_ = NULL;
	GtkPopover* _tmp5_ = NULL;
	GtkPopover* _tmp6_ = NULL;
	GtkWidget* _tmp7_ = NULL;
	GtkPopover* _tmp8_ = NULL;
	GtkPopover* _tmp9_ = NULL;
	GtkPopover* _tmp10_ = NULL;
	GHashTable* _tmp11_ = NULL;
	GtkWidget* _tmp12_ = NULL;
	GtkWidget* _tmp13_ = NULL;
	GtkPopover* _tmp14_ = NULL;
	GtkPopover* _tmp15_ = NULL;
	self = (BudgiePopoverManagerImpl*) base;
	_tmp0_ = self->priv->widgets;
	_tmp1_ = widg;
	_tmp2_ = g_hash_table_contains (_tmp0_, _tmp1_);
	if (_tmp2_) {
		return;
	}
	_tmp3_ = widg;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp3_, gtk_menu_button_get_type ())) {
		GtkWidget* _tmp4_ = NULL;
		_tmp4_ = widg;
		g_object_set ((GtkWidget*) (G_TYPE_CHECK_INSTANCE_TYPE (_tmp4_, gtk_menu_button_get_type ()) ? ((GtkMenuButton*) _tmp4_) : NULL), "can-focus", FALSE, NULL);
	}
	_tmp5_ = popover;
	g_signal_connect_object ((GtkWidget*) _tmp5_, "map", (GCallback) _budgie_popover_manager_impl_on_widget_mapped_gtk_widget_map, self, 0);
	_tmp6_ = popover;
	g_signal_connect_object (_tmp6_, "closed", (GCallback) _budgie_popover_manager_impl_on_popover_closed_gtk_popover_closed, self, 0);
	_tmp7_ = widg;
	g_signal_connect_object (_tmp7_, "enter-notify-event", (GCallback) _budgie_popover_manager_impl_enter_notify_event_gtk_widget_enter_notify_event, self, 0);
	_tmp8_ = popover;
	g_signal_connect_object ((GObject*) _tmp8_, "notify::visible", (GCallback) _budgie_popover_manager_impl_notify_visible_g_object_notify, self, G_CONNECT_AFTER);
	_tmp9_ = popover;
	g_signal_connect_object ((GtkWidget*) _tmp9_, "destroy", (GCallback) ___lambda10__gtk_widget_destroy, self, 0);
	_tmp10_ = popover;
	gtk_popover_set_modal (_tmp10_, FALSE);
	_tmp11_ = self->priv->widgets;
	_tmp12_ = widg;
	_tmp13_ = _g_object_ref0 (_tmp12_);
	_tmp14_ = popover;
	_tmp15_ = _g_object_ref0 (_tmp14_);
	g_hash_table_insert (_tmp11_, _tmp13_, _tmp15_);
}


static void budgie_popover_manager_impl_class_init (BudgiePopoverManagerImplClass * klass) {
	budgie_popover_manager_impl_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (BudgiePopoverManagerImplPrivate));
	G_OBJECT_CLASS (klass)->finalize = budgie_popover_manager_impl_finalize;
}


static void budgie_popover_manager_impl_budgie_popover_manager_interface_init (BudgiePopoverManagerIface * iface) {
	budgie_popover_manager_impl_budgie_popover_manager_parent_iface = g_type_interface_peek_parent (iface);
	iface->unregister_popover = (void (*)(BudgiePopoverManager*, GtkWidget*)) budgie_popover_manager_impl_real_unregister_popover;
	iface->show_popover = (void (*)(BudgiePopoverManager*, GtkWidget*)) budgie_popover_manager_impl_real_show_popover;
	iface->register_popover = (void (*)(BudgiePopoverManager*, GtkWidget*, GtkPopover*)) budgie_popover_manager_impl_real_register_popover;
}


static void budgie_popover_manager_impl_instance_init (BudgiePopoverManagerImpl * self) {
	self->priv = BUDGIE_POPOVER_MANAGER_IMPL_GET_PRIVATE (self);
	self->priv->visible_popover = NULL;
	self->priv->grabbed = FALSE;
	self->priv->mousing = FALSE;
}


static void budgie_popover_manager_impl_finalize (GObject* obj) {
	BudgiePopoverManagerImpl * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BUDGIE_TYPE_POPOVER_MANAGER_IMPL, BudgiePopoverManagerImpl);
	_g_hash_table_unref0 (self->priv->widgets);
	G_OBJECT_CLASS (budgie_popover_manager_impl_parent_class)->finalize (obj);
}


GType budgie_popover_manager_impl_get_type (void) {
	static volatile gsize budgie_popover_manager_impl_type_id__volatile = 0;
	if (g_once_init_enter (&budgie_popover_manager_impl_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (BudgiePopoverManagerImplClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_popover_manager_impl_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgiePopoverManagerImpl), 0, (GInstanceInitFunc) budgie_popover_manager_impl_instance_init, NULL };
		static const GInterfaceInfo budgie_popover_manager_info = { (GInterfaceInitFunc) budgie_popover_manager_impl_budgie_popover_manager_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType budgie_popover_manager_impl_type_id;
		budgie_popover_manager_impl_type_id = g_type_register_static (G_TYPE_OBJECT, "BudgiePopoverManagerImpl", &g_define_type_info, 0);
		g_type_add_interface_static (budgie_popover_manager_impl_type_id, budgie_popover_manager_get_type (), &budgie_popover_manager_info);
		g_once_init_leave (&budgie_popover_manager_impl_type_id__volatile, budgie_popover_manager_impl_type_id);
	}
	return budgie_popover_manager_impl_type_id__volatile;
}



