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

/*
 * SPDX-License-Identifier: GPL-2-or-later
 * SPDX-FileCopyrightText: 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel)
 *                         2025 elementary, Inc. (https://elementary.io)
 */

#include "wingpanel-interface.h"
#include <meta/workspace.h>
#include <meta/window.h>
#include <glib.h>
#include <glib-object.h>
#include <meta/meta-workspace-manager.h>
#include <meta/display.h>
#include <meta/common.h>
#include <gala.h>
#include <clutter/clutter.h>
#include <float.h>
#include <math.h>
#include <graphene-gobject.h>
#include <mtk/mtk.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	WINGPANEL_INTERFACE_FOCUS_MANAGER_0_PROPERTY,
	WINGPANEL_INTERFACE_FOCUS_MANAGER_NUM_PROPERTIES
};
static GParamSpec* wingpanel_interface_focus_manager_properties[WINGPANEL_INTERFACE_FOCUS_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;
typedef struct _Block3Data Block3Data;

struct _WingpanelInterfaceFocusManagerPrivate {
	MetaWorkspace* current_workspace;
	MetaWindow* last_focused_window;
	MetaWindow* last_focused_dialog_window;
};

struct _Block2Data {
	int _ref_count_;
	WingpanelInterfaceFocusManager* self;
	MetaWindow* window;
	gint x;
	gint y;
};

struct _Block3Data {
	int _ref_count_;
	Block2Data * _data2_;
	GalaWindowManager* wm;
	ClutterStage* stage;
	GalaModalProxy* proxy;
	gulong handler;
	gboolean started_drag;
	gfloat start_x;
	gfloat start_y;
};

static gint WingpanelInterfaceFocusManager_private_offset;
static gpointer wingpanel_interface_focus_manager_parent_class = NULL;

static void __lambda16_ (WingpanelInterfaceFocusManager* self);
static void wingpanel_interface_focus_manager_update_current_workspace (WingpanelInterfaceFocusManager* self);
static void ___lambda16__meta_workspace_manager_workspace_switched (MetaWorkspaceManager* _sender,
                                                             gint object,
                                                             gint p0,
                                                             MetaMotionDirection p1,
                                                             gpointer self);
static void wingpanel_interface_focus_manager_window_created (WingpanelInterfaceFocusManager* self,
                                                       MetaWindow* window);
static void _wingpanel_interface_focus_manager_window_created_meta_display_window_created (MetaDisplay* _sender,
                                                                                    MetaWindow* object,
                                                                                    gpointer self);
static void ___lambda17_ (WingpanelInterfaceFocusManager* self);
static void ____lambda17__meta_window_unmanaged (MetaWindow* _sender,
                                          gpointer self);
static void wingpanel_interface_focus_manager_window_focused (WingpanelInterfaceFocusManager* self,
                                                       MetaWindow* window);
static void _wingpanel_interface_focus_manager_window_focused_meta_window_focus (MetaWindow* _sender,
                                                                          gpointer self);
static void wingpanel_interface_focus_manager_window_unmanaged (WingpanelInterfaceFocusManager* self,
                                                         MetaWindow* window);
static void _wingpanel_interface_focus_manager_window_unmanaged_meta_window_unmanaged (MetaWindow* _sender,
                                                                                gpointer self);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static gboolean wingpanel_interface_focus_manager_get_can_grab_window (MetaWindow* window,
                                                                gint x,
                                                                gint y);
static void ___lambda18_ (Block2Data* _data2_,
                   MetaWindow* win);
static void ____lambda18__gfunc (gconstpointer data,
                          gpointer self);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static gboolean ___lambda19_ (Block3Data* _data3_,
                       ClutterEvent* event);
static gboolean ____lambda19__clutter_actor_captured_event (ClutterActor* _sender,
                                                     ClutterEvent* event,
                                                     gpointer self);
static void wingpanel_interface_focus_manager_finalize (GObject * obj);
static GType wingpanel_interface_focus_manager_get_type_once (void);

static inline gpointer
wingpanel_interface_focus_manager_get_instance_private (WingpanelInterfaceFocusManager* self)
{
	return G_STRUCT_MEMBER_P (self, WingpanelInterfaceFocusManager_private_offset);
}

static void
__lambda16_ (WingpanelInterfaceFocusManager* self)
{
	wingpanel_interface_focus_manager_update_current_workspace (self);
}

static void
___lambda16__meta_workspace_manager_workspace_switched (MetaWorkspaceManager* _sender,
                                                        gint object,
                                                        gint p0,
                                                        MetaMotionDirection p1,
                                                        gpointer self)
{
	__lambda16_ ((WingpanelInterfaceFocusManager*) self);
}

WingpanelInterfaceFocusManager*
wingpanel_interface_focus_manager_construct (GType object_type)
{
	WingpanelInterfaceFocusManager * self = NULL;
	MetaWorkspaceManager* manager = NULL;
	MetaDisplay* _tmp0_;
	MetaWorkspaceManager* _tmp1_;
	self = (WingpanelInterfaceFocusManager*) g_object_new (object_type, NULL);
	_tmp0_ = wingpanel_interface_main_display;
	_tmp1_ = meta_display_get_workspace_manager (_tmp0_);
	manager = _tmp1_;
	g_signal_connect_object (manager, "workspace-switched", (GCallback) ___lambda16__meta_workspace_manager_workspace_switched, self, 0);
	wingpanel_interface_focus_manager_update_current_workspace (self);
	return self;
}

WingpanelInterfaceFocusManager*
wingpanel_interface_focus_manager_new (void)
{
	return wingpanel_interface_focus_manager_construct (WINGPANEL_INTERFACE_TYPE_FOCUS_MANAGER);
}

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

static void
_wingpanel_interface_focus_manager_window_created_meta_display_window_created (MetaDisplay* _sender,
                                                                               MetaWindow* object,
                                                                               gpointer self)
{
	wingpanel_interface_focus_manager_window_created ((WingpanelInterfaceFocusManager*) self, object);
}

void
wingpanel_interface_focus_manager_remember_focused_window (WingpanelInterfaceFocusManager* self)
{
	GList* windows = NULL;
	MetaWorkspace* _tmp0_;
	GList* _tmp1_;
	GList* _tmp2_;
	MetaDisplay* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->current_workspace;
	_tmp1_ = meta_workspace_list_windows (_tmp0_);
	windows = _tmp1_;
	_tmp2_ = windows;
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp2_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			MetaWindow* window = NULL;
			window = (MetaWindow*) window_it->data;
			{
				MetaWindow* _tmp3_;
				MetaWindow* _tmp4_;
				_tmp3_ = window;
				wingpanel_interface_focus_manager_window_created (self, _tmp3_);
				_tmp4_ = window;
				if (meta_window_has_focus (_tmp4_)) {
					MetaWindow* _tmp5_;
					MetaWindow* _tmp6_;
					_tmp5_ = window;
					_tmp6_ = _g_object_ref0 (_tmp5_);
					_g_object_unref0 (self->priv->last_focused_window);
					self->priv->last_focused_window = _tmp6_;
				}
			}
		}
	}
	_tmp7_ = wingpanel_interface_main_display;
	g_signal_connect_object (_tmp7_, "window-created", (GCallback) _wingpanel_interface_focus_manager_window_created_meta_display_window_created, self, 0);
	(windows == NULL) ? NULL : (windows = (g_list_free (windows), NULL));
}

static void
___lambda17_ (WingpanelInterfaceFocusManager* self)
{
	_g_object_unref0 (self->priv->last_focused_dialog_window);
	self->priv->last_focused_dialog_window = NULL;
	wingpanel_interface_focus_manager_restore_focused_window (self);
}

static void
____lambda17__meta_window_unmanaged (MetaWindow* _sender,
                                     gpointer self)
{
	___lambda17_ ((WingpanelInterfaceFocusManager*) self);
}

static void
_wingpanel_interface_focus_manager_window_focused_meta_window_focus (MetaWindow* _sender,
                                                                     gpointer self)
{
	wingpanel_interface_focus_manager_window_focused ((WingpanelInterfaceFocusManager*) self, _sender);
}

static void
_wingpanel_interface_focus_manager_window_unmanaged_meta_window_unmanaged (MetaWindow* _sender,
                                                                           gpointer self)
{
	wingpanel_interface_focus_manager_window_unmanaged ((WingpanelInterfaceFocusManager*) self, _sender);
}

void
wingpanel_interface_focus_manager_restore_focused_window (WingpanelInterfaceFocusManager* self)
{
	MetaDisplay* display = NULL;
	MetaDisplay* _tmp0_;
	MetaWindow* _tmp1_;
	GList* windows = NULL;
	MetaWorkspace* _tmp8_;
	GList* _tmp9_;
	GList* _tmp10_;
	MetaDisplay* _tmp15_;
	guint _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = wingpanel_interface_main_display;
	display = _tmp0_;
	_tmp1_ = self->priv->last_focused_dialog_window;
	if (_tmp1_ != NULL) {
		MetaWindow* _tmp2_;
		MetaDisplay* _tmp3_;
		MetaWindow* _tmp4_;
		_tmp2_ = self->priv->last_focused_dialog_window;
		_tmp3_ = display;
		meta_window_focus (_tmp2_, meta_display_get_current_time (_tmp3_));
		_tmp4_ = self->priv->last_focused_dialog_window;
		g_signal_connect_object (_tmp4_, "unmanaged", (GCallback) ____lambda17__meta_window_unmanaged, self, 0);
	} else {
		MetaWindow* _tmp5_;
		_tmp5_ = self->priv->last_focused_window;
		if (_tmp5_ != NULL) {
			MetaWindow* _tmp6_;
			MetaDisplay* _tmp7_;
			_tmp6_ = self->priv->last_focused_window;
			_tmp7_ = display;
			meta_window_focus (_tmp6_, meta_display_get_current_time (_tmp7_));
		}
	}
	_tmp8_ = self->priv->current_workspace;
	_tmp9_ = meta_workspace_list_windows (_tmp8_);
	windows = _tmp9_;
	_tmp10_ = windows;
	{
		GList* window_collection = NULL;
		GList* window_it = NULL;
		window_collection = _tmp10_;
		for (window_it = window_collection; window_it != NULL; window_it = window_it->next) {
			MetaWindow* window = NULL;
			window = (MetaWindow*) window_it->data;
			{
				MetaWindow* _tmp11_;
				guint _tmp12_;
				MetaWindow* _tmp13_;
				guint _tmp14_;
				_tmp11_ = window;
				g_signal_parse_name ("focus", meta_window_get_type (), &_tmp12_, NULL, FALSE);
				g_signal_handlers_disconnect_matched (_tmp11_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp12_, 0, NULL, (GCallback) _wingpanel_interface_focus_manager_window_focused_meta_window_focus, self);
				_tmp13_ = window;
				g_signal_parse_name ("unmanaged", meta_window_get_type (), &_tmp14_, NULL, FALSE);
				g_signal_handlers_disconnect_matched (_tmp13_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp14_, 0, NULL, (GCallback) _wingpanel_interface_focus_manager_window_unmanaged_meta_window_unmanaged, self);
			}
		}
	}
	_tmp15_ = wingpanel_interface_main_display;
	g_signal_parse_name ("window-created", meta_display_get_type (), &_tmp16_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp15_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp16_, 0, NULL, (GCallback) _wingpanel_interface_focus_manager_window_created_meta_display_window_created, self);
	(windows == NULL) ? NULL : (windows = (g_list_free (windows), NULL));
}

static void
wingpanel_interface_focus_manager_window_created (WingpanelInterfaceFocusManager* self,
                                                  MetaWindow* window)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	g_signal_connect_object (window, "focus", (GCallback) _wingpanel_interface_focus_manager_window_focused_meta_window_focus, self, 0);
	g_signal_connect_object (window, "unmanaged", (GCallback) _wingpanel_interface_focus_manager_window_unmanaged_meta_window_unmanaged, self, 0);
}

static void
wingpanel_interface_focus_manager_window_focused (WingpanelInterfaceFocusManager* self,
                                                  MetaWindow* window)
{
	MetaWindowType _tmp0_;
	MetaWindowType _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	_tmp0_ = meta_window_get_window_type (window);
	_tmp1_ = _tmp0_;
	if (_tmp1_ == META_WINDOW_DIALOG) {
		MetaWindow* _tmp2_;
		_tmp2_ = _g_object_ref0 (window);
		_g_object_unref0 (self->priv->last_focused_dialog_window);
		self->priv->last_focused_dialog_window = _tmp2_;
	} else {
		MetaWindowType _tmp3_;
		MetaWindowType _tmp4_;
		_tmp3_ = meta_window_get_window_type (window);
		_tmp4_ = _tmp3_;
		if (_tmp4_ != META_WINDOW_DOCK) {
			MetaWindow* _tmp5_;
			_tmp5_ = _g_object_ref0 (window);
			_g_object_unref0 (self->priv->last_focused_window);
			self->priv->last_focused_window = _tmp5_;
		}
	}
}

static void
wingpanel_interface_focus_manager_window_unmanaged (WingpanelInterfaceFocusManager* self,
                                                    MetaWindow* window)
{
	guint _tmp0_;
	guint _tmp1_;
	MetaWindow* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (window != NULL);
	g_signal_parse_name ("focus", meta_window_get_type (), &_tmp0_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp0_, 0, NULL, (GCallback) _wingpanel_interface_focus_manager_window_focused_meta_window_focus, self);
	g_signal_parse_name ("unmanaged", meta_window_get_type (), &_tmp1_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (window, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp1_, 0, NULL, (GCallback) _wingpanel_interface_focus_manager_window_unmanaged_meta_window_unmanaged, self);
	_tmp2_ = self->priv->last_focused_window;
	if (_tmp2_ == window) {
		_g_object_unref0 (self->priv->last_focused_window);
		self->priv->last_focused_window = 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_)) {
		WingpanelInterfaceFocusManager* self;
		self = _data2_->self;
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}

static void
___lambda18_ (Block2Data* _data2_,
              MetaWindow* win)
{
	WingpanelInterfaceFocusManager* self;
	MetaWindow* _tmp0_;
	self = _data2_->self;
	g_return_if_fail (win != NULL);
	_tmp0_ = _data2_->window;
	if (_tmp0_ != NULL) {
		return;
	}
	if (wingpanel_interface_focus_manager_get_can_grab_window (win, _data2_->x, _data2_->y)) {
		_data2_->window = win;
	}
}

static void
____lambda18__gfunc (gconstpointer data,
                     gpointer self)
{
	___lambda18_ (self, (MetaWindow*) data);
}

static Block3Data*
block3_data_ref (Block3Data* _data3_)
{
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}

static void
block3_data_unref (void * _userdata_)
{
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		WingpanelInterfaceFocusManager* self;
		self = _data3_->_data2_->self;
		_g_object_unref0 (_data3_->proxy);
		block2_data_unref (_data3_->_data2_);
		_data3_->_data2_ = NULL;
		g_slice_free (Block3Data, _data3_);
	}
}

static gboolean
___lambda19_ (Block3Data* _data3_,
              ClutterEvent* event)
{
	Block2Data* _data2_;
	WingpanelInterfaceFocusManager* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GalaWindowManager* _tmp13_;
	GalaModalProxy* _tmp14_;
	ClutterStage* _tmp15_;
	gboolean result;
	_data2_ = _data3_->_data2_;
	self = _data2_->self;
	g_return_val_if_fail (event != NULL, FALSE);
	if (clutter_event_type (event) == CLUTTER_LEAVE) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = clutter_event_type (event) == CLUTTER_ENTER;
	}
	if (_tmp0_) {
		result = CLUTTER_EVENT_PROPAGATE;
		return result;
	}
	if (clutter_event_type (event) == CLUTTER_MOTION) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = clutter_event_type (event) == CLUTTER_TOUCH_UPDATE;
	}
	if (_tmp1_) {
		gfloat current_x = 0.0F;
		gfloat current_y = 0.0F;
		gfloat _tmp4_ = 0.0F;
		gfloat _tmp5_ = 0.0F;
		gfloat dx = 0.0F;
		gfloat dy = 0.0F;
		gint drag_threshold = 0;
		ClutterSettings* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		MetaWindow* _tmp9_;
		ClutterInputDevice* _tmp10_;
		ClutterEventSequence* _tmp11_;
		graphene_point_t _tmp12_ = {0};
		if (!_data3_->started_drag) {
			gfloat _tmp2_ = 0.0F;
			gfloat _tmp3_ = 0.0F;
			_data3_->started_drag = TRUE;
			clutter_event_get_coords (event, &_tmp2_, &_tmp3_);
			_data3_->start_x = _tmp2_;
			_data3_->start_y = _tmp3_;
			result = CLUTTER_EVENT_PROPAGATE;
			return result;
		}
		clutter_event_get_coords (event, &_tmp4_, &_tmp5_);
		current_x = _tmp4_;
		current_y = _tmp5_;
		dx = _data3_->start_x - current_x;
		dy = _data3_->start_y - current_y;
		_tmp6_ = clutter_settings_get_default ();
		g_object_get (_tmp6_, "dnd-drag-threshold", &_tmp7_, NULL);
		_tmp8_ = _tmp7_;
		drag_threshold = _tmp8_;
		if (((dx * dx) + (dy * dy)) < ((gfloat) (drag_threshold * drag_threshold))) {
			result = CLUTTER_EVENT_PROPAGATE;
			return result;
		}
		_tmp9_ = _data2_->window;
		_tmp10_ = clutter_event_get_device (event);
		_tmp11_ = clutter_event_get_event_sequence (event);
		_tmp12_.x = (gfloat) _data2_->x;
		_tmp12_.y = (gfloat) _data2_->y;
		meta_window_begin_grab_op (_tmp9_, META_GRAB_OP_MOVING, _tmp10_, _tmp11_, clutter_event_get_time (event), &_tmp12_);
	}
	_tmp13_ = _data3_->wm;
	_tmp14_ = _data3_->proxy;
	gala_window_manager_pop_modal (_tmp13_, _tmp14_);
	_tmp15_ = _data3_->stage;
	g_signal_handler_disconnect ((GObject*) _tmp15_, _data3_->handler);
	result = CLUTTER_EVENT_PROPAGATE;
	return result;
}

static gboolean
____lambda19__clutter_actor_captured_event (ClutterActor* _sender,
                                            ClutterEvent* event,
                                            gpointer self)
{
	gboolean result;
	result = ___lambda19_ (self, event);
	return result;
}

gboolean
wingpanel_interface_focus_manager_begin_grab_focused_window (WingpanelInterfaceFocusManager* self,
                                                             gint x,
                                                             gint y)
{
	Block2Data* _data2_;
	MetaDisplay* display = NULL;
	MetaDisplay* _tmp0_;
	MetaDisplay* _tmp1_;
	MetaWindow* _tmp2_;
	gboolean _tmp3_ = FALSE;
	MetaWindow* _tmp4_;
	MetaWindow* _tmp15_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_data2_->self = g_object_ref (self);
	_data2_->x = x;
	_data2_->y = y;
	_tmp0_ = wingpanel_interface_main_display;
	display = _tmp0_;
	_tmp1_ = display;
	_tmp2_ = meta_display_get_focus_window (_tmp1_);
	_data2_->window = _tmp2_;
	_tmp4_ = _data2_->window;
	if (_tmp4_ == NULL) {
		_tmp3_ = TRUE;
	} else {
		MetaWindow* _tmp5_;
		_tmp5_ = _data2_->window;
		_tmp3_ = !wingpanel_interface_focus_manager_get_can_grab_window (_tmp5_, _data2_->x, _data2_->y);
	}
	if (_tmp3_) {
		MetaWorkspace* workspace = NULL;
		MetaDisplay* _tmp6_;
		MetaWorkspaceManager* _tmp7_;
		MetaWorkspace* _tmp8_;
		GList* windows = NULL;
		MetaWorkspace* _tmp9_;
		GList* _tmp10_;
		GList* _tmp11_;
		GList* copy = NULL;
		GList* _tmp12_;
		GList* _tmp13_;
		GList* _tmp14_;
		_tmp6_ = display;
		_tmp7_ = meta_display_get_workspace_manager (_tmp6_);
		_tmp8_ = meta_workspace_manager_get_active_workspace (_tmp7_);
		workspace = _tmp8_;
		_tmp9_ = workspace;
		_tmp10_ = meta_workspace_list_windows (_tmp9_);
		windows = _tmp10_;
		_tmp11_ = windows;
		if (_tmp11_ == NULL) {
			result = FALSE;
			(windows == NULL) ? NULL : (windows = (g_list_free (windows), NULL));
			block2_data_unref (_data2_);
			_data2_ = NULL;
			return result;
		}
		_data2_->window = NULL;
		_tmp12_ = windows;
		_tmp13_ = g_list_copy (_tmp12_);
		copy = _tmp13_;
		copy = g_list_reverse (copy);
		_tmp14_ = copy;
		g_list_foreach (_tmp14_, ____lambda18__gfunc, _data2_);
		(copy == NULL) ? NULL : (copy = (g_list_free (copy), NULL));
		(windows == NULL) ? NULL : (windows = (g_list_free (windows), NULL));
	}
	_tmp15_ = _data2_->window;
	if (_tmp15_ != NULL) {
		Block3Data* _data3_;
		GalaWindowManager* _tmp16_;
		GalaWindowManager* _tmp17_;
		ClutterStage* _tmp18_;
		ClutterStage* _tmp19_;
		GalaWindowManager* _tmp20_;
		ClutterStage* _tmp21_;
		GalaModalProxy* _tmp22_;
		ClutterStage* _tmp23_;
		gulong _tmp24_;
		_data3_ = g_slice_new0 (Block3Data);
		_data3_->_ref_count_ = 1;
		_data3_->_data2_ = block2_data_ref (_data2_);
		_tmp16_ = wingpanel_interface_main_wm;
		_data3_->wm = _tmp16_;
		_tmp17_ = _data3_->wm;
		_tmp18_ = gala_window_manager_get_stage (_tmp17_);
		_tmp19_ = _tmp18_;
		_data3_->stage = _tmp19_;
		_tmp20_ = _data3_->wm;
		_tmp21_ = _data3_->stage;
		_tmp22_ = gala_window_manager_push_modal (_tmp20_, (ClutterActor*) _tmp21_, TRUE);
		_data3_->proxy = _tmp22_;
		_data3_->handler = (gulong) 0;
		_data3_->started_drag = FALSE;
		_data3_->start_x = (gfloat) 0;
		_data3_->start_y = (gfloat) 0;
		_tmp23_ = _data3_->stage;
		_tmp24_ = g_signal_connect_data ((ClutterActor*) _tmp23_, "captured-event", (GCallback) ____lambda19__clutter_actor_captured_event, block3_data_ref (_data3_), (GClosureNotify) block3_data_unref, 0);
		_data3_->handler = _tmp24_;
		result = TRUE;
		block3_data_unref (_data3_);
		_data3_ = NULL;
		block2_data_unref (_data2_);
		_data2_ = NULL;
		return result;
	}
	result = FALSE;
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return result;
}

static gboolean
wingpanel_interface_focus_manager_get_can_grab_window (MetaWindow* window,
                                                       gint x,
                                                       gint y)
{
	MtkRectangle frame = {0};
	MtkRectangle _tmp0_ = {0};
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean result;
	g_return_val_if_fail (window != NULL, FALSE);
	meta_window_get_frame_rect (window, &_tmp0_);
	frame = _tmp0_;
	g_object_get (window, "minimized", &_tmp4_, NULL);
	_tmp5_ = _tmp4_;
	if (!_tmp5_) {
		gboolean _tmp6_;
		gboolean _tmp7_;
		g_object_get (window, "maximized-vertically", &_tmp6_, NULL);
		_tmp7_ = _tmp6_;
		_tmp3_ = _tmp7_;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		MtkRectangle _tmp8_;
		_tmp8_ = frame;
		_tmp2_ = x >= _tmp8_.x;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		MtkRectangle _tmp9_;
		MtkRectangle _tmp10_;
		_tmp9_ = frame;
		_tmp10_ = frame;
		_tmp1_ = x <= (_tmp9_.x + _tmp10_.width);
	} else {
		_tmp1_ = FALSE;
	}
	result = _tmp1_;
	return result;
}

static void
wingpanel_interface_focus_manager_update_current_workspace (WingpanelInterfaceFocusManager* self)
{
	MetaWorkspaceManager* manager = NULL;
	MetaDisplay* _tmp0_;
	MetaWorkspaceManager* _tmp1_;
	MetaWorkspace* workspace = NULL;
	MetaWorkspaceManager* _tmp2_;
	MetaWorkspaceManager* _tmp3_;
	MetaWorkspace* _tmp4_;
	MetaWorkspace* _tmp5_;
	MetaWorkspace* _tmp6_;
	MetaWorkspace* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = wingpanel_interface_main_display;
	_tmp1_ = meta_display_get_workspace_manager (_tmp0_);
	manager = _tmp1_;
	_tmp2_ = manager;
	_tmp3_ = manager;
	_tmp4_ = meta_workspace_manager_get_workspace_by_index (_tmp2_, meta_workspace_manager_get_active_workspace_index (_tmp3_));
	workspace = _tmp4_;
	_tmp5_ = workspace;
	if (_tmp5_ == NULL) {
		g_warning ("FocusManager.vala:176: Cannot get active workspace");
		return;
	}
	_tmp6_ = workspace;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (self->priv->current_workspace);
	self->priv->current_workspace = _tmp7_;
}

static void
wingpanel_interface_focus_manager_class_init (WingpanelInterfaceFocusManagerClass * klass,
                                              gpointer klass_data)
{
	wingpanel_interface_focus_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WingpanelInterfaceFocusManager_private_offset);
	G_OBJECT_CLASS (klass)->finalize = wingpanel_interface_focus_manager_finalize;
}

static void
wingpanel_interface_focus_manager_instance_init (WingpanelInterfaceFocusManager * self,
                                                 gpointer klass)
{
	self->priv = wingpanel_interface_focus_manager_get_instance_private (self);
	self->priv->current_workspace = NULL;
	self->priv->last_focused_window = NULL;
	self->priv->last_focused_dialog_window = NULL;
}

static void
wingpanel_interface_focus_manager_finalize (GObject * obj)
{
	WingpanelInterfaceFocusManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WINGPANEL_INTERFACE_TYPE_FOCUS_MANAGER, WingpanelInterfaceFocusManager);
	_g_object_unref0 (self->priv->current_workspace);
	_g_object_unref0 (self->priv->last_focused_window);
	_g_object_unref0 (self->priv->last_focused_dialog_window);
	G_OBJECT_CLASS (wingpanel_interface_focus_manager_parent_class)->finalize (obj);
}

static GType
wingpanel_interface_focus_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WingpanelInterfaceFocusManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wingpanel_interface_focus_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WingpanelInterfaceFocusManager), 0, (GInstanceInitFunc) wingpanel_interface_focus_manager_instance_init, NULL };
	GType wingpanel_interface_focus_manager_type_id;
	wingpanel_interface_focus_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "WingpanelInterfaceFocusManager", &g_define_type_info, 0);
	WingpanelInterfaceFocusManager_private_offset = g_type_add_instance_private (wingpanel_interface_focus_manager_type_id, sizeof (WingpanelInterfaceFocusManagerPrivate));
	return wingpanel_interface_focus_manager_type_id;
}

GType
wingpanel_interface_focus_manager_get_type (void)
{
	static volatile gsize wingpanel_interface_focus_manager_type_id__once = 0;
	if (g_once_init_enter (&wingpanel_interface_focus_manager_type_id__once)) {
		GType wingpanel_interface_focus_manager_type_id;
		wingpanel_interface_focus_manager_type_id = wingpanel_interface_focus_manager_get_type_once ();
		g_once_init_leave (&wingpanel_interface_focus_manager_type_id__once, wingpanel_interface_focus_manager_type_id);
	}
	return wingpanel_interface_focus_manager_type_id__once;
}

