/* composer-window.c generated by valac 0.56.19, the Vala compiler
 * generated from composer-window.vala, do not modify */

/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 * Copyright 2019 Michael Gratton <mike@vee.net>
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later). See the COPYING file in this distribution.
 */

#include "geary-client-46.0.h"
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <glib-object.h>
#include "geary-engine.h"
#include <cairo-gobject.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  {
	COMPOSER_WINDOW_0_PROPERTY,
	COMPOSER_WINDOW_APPLICATION_PROPERTY,
	COMPOSER_WINDOW_NUM_PROPERTIES
};
static GParamSpec* composer_window_properties[COMPOSER_WINDOW_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block78Data Block78Data;

#define APPLICATION_TYPE_CONTROLLER (application_controller_get_type ())
#define APPLICATION_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), APPLICATION_TYPE_CONTROLLER, ApplicationController))
#define APPLICATION_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), APPLICATION_TYPE_CONTROLLER, ApplicationControllerClass))
#define APPLICATION_IS_CONTROLLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), APPLICATION_TYPE_CONTROLLER))
#define APPLICATION_IS_CONTROLLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APPLICATION_TYPE_CONTROLLER))
#define APPLICATION_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APPLICATION_TYPE_CONTROLLER, ApplicationControllerClass))

typedef struct _ApplicationController ApplicationController;
typedef struct _ApplicationControllerClass ApplicationControllerClass;

struct _ComposerWindowPrivate {
	ComposerWidget* _composer;
};

struct _Block78Data {
	int _ref_count_;
	ComposerWindow* self;
	ApplicationClient* application;
};

static gint ComposerWindow_private_offset;
static gpointer composer_window_parent_class = NULL;
static ComposerContainerIface * composer_window_composer_container_parent_iface = NULL;

static Block78Data* block78_data_ref (Block78Data* _data78_);
static void block78_data_unref (void * _userdata_);
VALA_EXTERN void composer_container_set_composer (ComposerContainer* self,
                                      ComposerWidget* value);
VALA_EXTERN ComposerWidget* composer_container_get_composer (ComposerContainer* self);
VALA_EXTERN void composer_widget_set_mode (ComposerWidget* self,
                               ComposerWidgetPresentationMode new_mode);
VALA_EXTERN void composer_widget_embed_header (ComposerWidget* self);
VALA_EXTERN ComposerHeaderbar* composer_widget_get_header (ComposerWidget* self);
static gboolean __lambda142_ (Block78Data* _data78_,
                       GtkWidget* w,
                       GdkEventFocus* e);
VALA_EXTERN GType application_controller_get_type (void) G_GNUC_CONST ;
VALA_EXTERN ApplicationController* application_client_get_controller (ApplicationClient* self);
VALA_EXTERN void application_controller_window_focus_in (ApplicationController* self);
static gboolean ___lambda142__gtk_widget_focus_in_event (GtkWidget* _sender,
                                                  GdkEventFocus* event,
                                                  gpointer self);
static gboolean __lambda143_ (Block78Data* _data78_,
                       GtkWidget* w,
                       GdkEventFocus* e);
VALA_EXTERN void application_controller_window_focus_out (ApplicationController* self);
static gboolean ___lambda143__gtk_widget_focus_out_event (GtkWidget* _sender,
                                                   GdkEventFocus* event,
                                                   gpointer self);
static void composer_window_real_close (ComposerContainer* base);
VALA_EXTERN void composer_widget_free_header (ComposerWidget* self);
static void composer_window_real_show (GtkWidget* base);
static void composer_window_save_window_geometry (ComposerWindow* self);
static void composer_window_real_size_allocate (GtkWidget* base,
                                         GtkAllocation* allocation);
static gboolean composer_window_real_delete_event (GtkWidget* base,
                                            GdkEventAny* event);
static void composer_window_finalize (GObject * obj);
static GType composer_window_get_type_once (void);
static void _vala_composer_window_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec);
static void _vala_composer_window_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec);

static inline gpointer
composer_window_get_instance_private (ComposerWindow* self)
{
	return G_STRUCT_MEMBER_P (self, ComposerWindow_private_offset);
}

static GtkApplicationWindow*
composer_window_real_get_top_window (ComposerContainer* base)
{
	GtkApplicationWindow* result;
	ComposerWindow* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	result = G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_window_get_type (), GtkApplicationWindow);
	return result;
}

ApplicationClient*
composer_window_get_application (ComposerWindow* self)
{
	ApplicationClient* result;
	GtkApplication* _tmp0_;
	g_return_val_if_fail (COMPOSER_IS_WINDOW (self), NULL);
	_tmp0_ = gtk_window_get_application (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_window_get_type (), GtkApplicationWindow), gtk_window_get_type (), GtkWindow));
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp0_, APPLICATION_TYPE_CLIENT, ApplicationClient);
	return result;
}

void
composer_window_set_application (ComposerWindow* self,
                                 ApplicationClient* value)
{
	g_return_if_fail (COMPOSER_IS_WINDOW (self));
	gtk_window_set_application (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_window_get_type (), GtkApplicationWindow), gtk_window_get_type (), GtkWindow), G_TYPE_CHECK_INSTANCE_CAST (value, gtk_application_get_type (), GtkApplication));
	g_object_notify_by_pspec ((GObject *) self, composer_window_properties[COMPOSER_WINDOW_APPLICATION_PROPERTY]);
}

static ComposerWidget*
composer_window_real_get_composer (ComposerContainer* base)
{
	ComposerWidget* result;
	ComposerWindow* self;
	ComposerWidget* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	_tmp0_ = self->priv->_composer;
	result = _tmp0_;
	return result;
}

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

static void
composer_window_real_set_composer (ComposerContainer* base,
                                   ComposerWidget* value)
{
	ComposerWindow* self;
	ComposerWidget* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_composer);
	self->priv->_composer = _tmp0_;
}

static Block78Data*
block78_data_ref (Block78Data* _data78_)
{
	g_atomic_int_inc (&_data78_->_ref_count_);
	return _data78_;
}

static void
block78_data_unref (void * _userdata_)
{
	Block78Data* _data78_;
	_data78_ = (Block78Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data78_->_ref_count_)) {
		ComposerWindow* self;
		self = _data78_->self;
		_g_object_unref0 (_data78_->application);
		_g_object_unref0 (self);
		g_slice_free (Block78Data, _data78_);
	}
}

static gboolean
__lambda142_ (Block78Data* _data78_,
              GtkWidget* w,
              GdkEventFocus* e)
{
	ComposerWindow* self;
	ApplicationController* _tmp0_;
	ApplicationController* _tmp1_;
	gboolean result;
	self = _data78_->self;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (w, gtk_widget_get_type ()), FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = application_client_get_controller (_data78_->application);
	_tmp1_ = _tmp0_;
	application_controller_window_focus_in (_tmp1_);
	result = FALSE;
	return result;
}

static gboolean
___lambda142__gtk_widget_focus_in_event (GtkWidget* _sender,
                                         GdkEventFocus* event,
                                         gpointer self)
{
	gboolean result;
	result = __lambda142_ (self, _sender, event);
	return result;
}

static gboolean
__lambda143_ (Block78Data* _data78_,
              GtkWidget* w,
              GdkEventFocus* e)
{
	ComposerWindow* self;
	ApplicationController* _tmp0_;
	ApplicationController* _tmp1_;
	gboolean result;
	self = _data78_->self;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (w, gtk_widget_get_type ()), FALSE);
	g_return_val_if_fail (e != NULL, FALSE);
	_tmp0_ = application_client_get_controller (_data78_->application);
	_tmp1_ = _tmp0_;
	application_controller_window_focus_out (_tmp1_);
	result = FALSE;
	return result;
}

static gboolean
___lambda143__gtk_widget_focus_out_event (GtkWidget* _sender,
                                          GdkEventFocus* event,
                                          gpointer self)
{
	gboolean result;
	result = __lambda143_ (self, _sender, event);
	return result;
}

ComposerWindow*
composer_window_construct (GType object_type,
                           ComposerWidget* composer,
                           ApplicationClient* application)
{
	ComposerWindow * self = NULL;
	Block78Data* _data78_;
	ApplicationClient* _tmp0_;
	ComposerWidget* _tmp1_;
	ComposerWidget* _tmp2_;
	GtkWindowGroup* group = NULL;
	GtkWindowGroup* _tmp3_;
	GtkWindowGroup* _tmp4_;
	GValue _tmp5_ = {0};
	ComposerWidget* _tmp6_;
	ComposerWidget* _tmp7_;
	ComposerWidget* _tmp8_;
	ComposerWidget* _tmp9_;
	ApplicationConfiguration* _tmp10_;
	ApplicationConfiguration* _tmp11_;
	ApplicationConfigurationDesktopEnvironment _tmp12_;
	ApplicationConfigurationDesktopEnvironment _tmp13_;
	g_return_val_if_fail (COMPOSER_IS_WIDGET (composer), NULL);
	g_return_val_if_fail (APPLICATION_IS_CLIENT (application), NULL);
	_data78_ = g_slice_new0 (Block78Data);
	_data78_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (application);
	_g_object_unref0 (_data78_->application);
	_data78_->application = _tmp0_;
	self = (ComposerWindow*) g_object_new (object_type, "application", _data78_->application, "type", GTK_WINDOW_TOPLEVEL, NULL);
	_data78_->self = g_object_ref (self);
	composer_container_set_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer), composer);
	_tmp1_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
	_tmp2_ = _tmp1_;
	composer_widget_set_mode (_tmp2_, COMPOSER_WIDGET_PRESENTATION_MODE_DETACHED);
	_tmp3_ = gtk_window_group_new ();
	group = _tmp3_;
	_tmp4_ = group;
	gtk_window_group_add_window (_tmp4_, G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow));
	g_value_init (&_tmp5_, G_TYPE_STRING);
	g_value_set_string (&_tmp5_, "GearyComposerWindow");
	g_object_set_property (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject), "name", &_tmp5_);
	G_IS_VALUE (&_tmp5_) ? (g_value_unset (&_tmp5_), NULL) : NULL;
	_tmp6_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
	_tmp7_ = _tmp6_;
	gtk_container_add (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_container_get_type (), GtkContainer), G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, gtk_widget_get_type (), GtkWidget));
	_tmp8_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
	_tmp9_ = _tmp8_;
	composer_widget_update_window_title (_tmp9_);
	_tmp10_ = application_client_get_config (_data78_->application);
	_tmp11_ = _tmp10_;
	_tmp12_ = application_configuration_get_desktop_environment (_tmp11_);
	_tmp13_ = _tmp12_;
	if (_tmp13_ == APPLICATION_CONFIGURATION_DESKTOP_ENVIRONMENT_UNITY) {
		composer_widget_embed_header (composer);
	} else {
		ComposerWidget* _tmp14_;
		ComposerWidget* _tmp15_;
		ComposerHeaderbar* _tmp16_;
		ComposerHeaderbar* _tmp17_;
		_tmp14_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
		_tmp15_ = _tmp14_;
		_tmp16_ = composer_widget_get_header (_tmp15_);
		_tmp17_ = _tmp16_;
		gtk_window_set_titlebar (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, gtk_widget_get_type (), GtkWidget));
	}
	g_signal_connect_data (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), "focus-in-event", (GCallback) ___lambda142__gtk_widget_focus_in_event, block78_data_ref (_data78_), (GClosureNotify) block78_data_unref, 0);
	g_signal_connect_data (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget), "focus-out-event", (GCallback) ___lambda143__gtk_widget_focus_out_event, block78_data_ref (_data78_), (GClosureNotify) block78_data_unref, 0);
	gtk_widget_show (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
	gtk_window_set_position (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), GTK_WIN_POS_CENTER);
	_g_object_unref0 (group);
	block78_data_unref (_data78_);
	_data78_ = NULL;
	return self;
}

ComposerWindow*
composer_window_new (ComposerWidget* composer,
                     ApplicationClient* application)
{
	return composer_window_construct (COMPOSER_TYPE_WINDOW, composer, application);
}

/** {@inheritDoc} */
static void
composer_window_real_close (ComposerContainer* base)
{
	ComposerWindow * self;
	ComposerWidget* _tmp0_;
	ComposerWidget* _tmp1_;
	ComposerWidget* _tmp2_;
	ComposerWidget* _tmp3_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	_tmp0_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
	_tmp1_ = _tmp0_;
	composer_widget_free_header (_tmp1_);
	_tmp2_ = composer_container_get_composer (G_TYPE_CHECK_INSTANCE_CAST (self, COMPOSER_TYPE_CONTAINER, ComposerContainer));
	_tmp3_ = _tmp2_;
	gtk_container_remove (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_container_get_type (), GtkContainer), G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, gtk_widget_get_type (), GtkWidget));
	gtk_widget_destroy (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

static void
composer_window_real_show (GtkWidget* base)
{
	ComposerWindow * self;
	GdkDisplay* display = NULL;
	GdkDisplay* _tmp0_;
	GdkDisplay* _tmp1_;
	GdkDisplay* _tmp2_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	_tmp0_ = gdk_display_get_default ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	display = _tmp1_;
	_tmp2_ = display;
	if (_tmp2_ != NULL) {
		GdkMonitor* monitor = NULL;
		GdkDisplay* _tmp3_;
		GdkMonitor* _tmp4_;
		GdkMonitor* _tmp5_;
		GdkMonitor* _tmp6_;
		gint* size = NULL;
		ApplicationClient* _tmp10_;
		ApplicationClient* _tmp11_;
		ApplicationConfiguration* _tmp12_;
		ApplicationConfiguration* _tmp13_;
		gint _tmp14_ = 0;
		gint* _tmp15_;
		gint size_length1;
		gint _size_size_;
		gboolean _tmp16_ = FALSE;
		gboolean _tmp17_ = FALSE;
		gboolean _tmp18_ = FALSE;
		gboolean _tmp19_ = FALSE;
		GdkMonitor* _tmp20_;
		_tmp3_ = display;
		_tmp4_ = gdk_display_get_primary_monitor (_tmp3_);
		_tmp5_ = _g_object_ref0 (_tmp4_);
		monitor = _tmp5_;
		_tmp6_ = monitor;
		if (_tmp6_ == NULL) {
			GdkDisplay* _tmp7_;
			GdkMonitor* _tmp8_;
			GdkMonitor* _tmp9_;
			_tmp7_ = display;
			_tmp8_ = gdk_display_get_monitor_at_point (_tmp7_, 1, 1);
			_tmp9_ = _g_object_ref0 (_tmp8_);
			_g_object_unref0 (monitor);
			monitor = _tmp9_;
		}
		_tmp10_ = composer_window_get_application (self);
		_tmp11_ = _tmp10_;
		_tmp12_ = application_client_get_config (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp15_ = application_configuration_get_composer_window_size (_tmp13_, &_tmp14_);
		size = _tmp15_;
		size_length1 = _tmp14_;
		_size_size_ = size_length1;
		_tmp20_ = monitor;
		if (_tmp20_ != NULL) {
			gint* _tmp21_;
			gint _tmp21__length1;
			gint _tmp22_;
			_tmp21_ = size;
			_tmp21__length1 = size_length1;
			_tmp22_ = _tmp21_[0];
			_tmp19_ = _tmp22_ >= 0;
		} else {
			_tmp19_ = FALSE;
		}
		if (_tmp19_) {
			gint* _tmp23_;
			gint _tmp23__length1;
			gint _tmp24_;
			GdkMonitor* _tmp25_;
			GdkRectangle _tmp26_ = {0};
			GdkRectangle _tmp27_;
			_tmp23_ = size;
			_tmp23__length1 = size_length1;
			_tmp24_ = _tmp23_[0];
			_tmp25_ = monitor;
			gdk_monitor_get_geometry (_tmp25_, &_tmp26_);
			_tmp27_ = _tmp26_;
			_tmp18_ = _tmp24_ <= _tmp27_.width;
		} else {
			_tmp18_ = FALSE;
		}
		if (_tmp18_) {
			gint* _tmp28_;
			gint _tmp28__length1;
			gint _tmp29_;
			_tmp28_ = size;
			_tmp28__length1 = size_length1;
			_tmp29_ = _tmp28_[1];
			_tmp17_ = _tmp29_ >= 0;
		} else {
			_tmp17_ = FALSE;
		}
		if (_tmp17_) {
			gint* _tmp30_;
			gint _tmp30__length1;
			gint _tmp31_;
			GdkMonitor* _tmp32_;
			GdkRectangle _tmp33_ = {0};
			GdkRectangle _tmp34_;
			_tmp30_ = size;
			_tmp30__length1 = size_length1;
			_tmp31_ = _tmp30_[1];
			_tmp32_ = monitor;
			gdk_monitor_get_geometry (_tmp32_, &_tmp33_);
			_tmp34_ = _tmp33_;
			_tmp16_ = _tmp31_ <= _tmp34_.height;
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			gint* _tmp35_;
			gint _tmp35__length1;
			gint _tmp36_;
			gint* _tmp37_;
			gint _tmp37__length1;
			gint _tmp38_;
			_tmp35_ = size;
			_tmp35__length1 = size_length1;
			_tmp36_ = _tmp35_[0];
			_tmp37_ = size;
			_tmp37__length1 = size_length1;
			_tmp38_ = _tmp37_[1];
			gtk_window_set_default_size (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), _tmp36_, _tmp38_);
		} else {
			gtk_window_set_default_size (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), 680, 600);
		}
		size = (g_free (size), NULL);
		_g_object_unref0 (monitor);
	}
	GTK_WIDGET_CLASS (composer_window_parent_class)->show (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_window_get_type (), GtkApplicationWindow), gtk_widget_get_type (), GtkWidget));
	_g_object_unref0 (display);
}

static void
composer_window_save_window_geometry (ComposerWindow* self)
{
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (COMPOSER_IS_WINDOW (self));
	g_object_get (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), "is-maximized", &_tmp0_, NULL);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		GdkDisplay* display = NULL;
		GdkDisplay* _tmp2_;
		GdkDisplay* _tmp3_;
		GdkWindow* window = NULL;
		GdkWindow* _tmp4_;
		GdkWindow* _tmp5_;
		gboolean _tmp6_ = FALSE;
		GdkDisplay* _tmp7_;
		_tmp2_ = gtk_widget_get_display (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
		_tmp3_ = _g_object_ref0 (_tmp2_);
		display = _tmp3_;
		_tmp4_ = gtk_widget_get_window (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
		_tmp5_ = _g_object_ref0 (_tmp4_);
		window = _tmp5_;
		_tmp7_ = display;
		if (_tmp7_ != NULL) {
			GdkWindow* _tmp8_;
			_tmp8_ = window;
			_tmp6_ = _tmp8_ != NULL;
		} else {
			_tmp6_ = FALSE;
		}
		if (_tmp6_) {
			GdkMonitor* monitor = NULL;
			GdkDisplay* _tmp9_;
			GdkWindow* _tmp10_;
			GdkMonitor* _tmp11_;
			GdkMonitor* _tmp12_;
			gint width = 0;
			gint height = 0;
			gint _tmp13_ = 0;
			gint _tmp14_ = 0;
			gboolean _tmp15_ = FALSE;
			gboolean _tmp16_ = FALSE;
			gboolean _tmp17_ = FALSE;
			_tmp9_ = display;
			_tmp10_ = window;
			_tmp11_ = gdk_display_get_monitor_at_window (_tmp9_, _tmp10_);
			_tmp12_ = _g_object_ref0 (_tmp11_);
			monitor = _tmp12_;
			width = 0;
			height = 0;
			gtk_window_get_size (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_window_get_type (), GtkWindow), &_tmp13_, &_tmp14_);
			width = _tmp13_;
			height = _tmp14_;
			if (width > 0) {
				GdkMonitor* _tmp18_;
				GdkRectangle _tmp19_ = {0};
				GdkRectangle _tmp20_;
				_tmp18_ = monitor;
				gdk_monitor_get_geometry (_tmp18_, &_tmp19_);
				_tmp20_ = _tmp19_;
				_tmp17_ = width <= _tmp20_.width;
			} else {
				_tmp17_ = FALSE;
			}
			if (_tmp17_) {
				_tmp16_ = height > 0;
			} else {
				_tmp16_ = FALSE;
			}
			if (_tmp16_) {
				GdkMonitor* _tmp21_;
				GdkRectangle _tmp22_ = {0};
				GdkRectangle _tmp23_;
				_tmp21_ = monitor;
				gdk_monitor_get_geometry (_tmp21_, &_tmp22_);
				_tmp23_ = _tmp22_;
				_tmp15_ = height <= _tmp23_.height;
			} else {
				_tmp15_ = FALSE;
			}
			if (_tmp15_) {
				ApplicationClient* _tmp24_;
				ApplicationClient* _tmp25_;
				ApplicationConfiguration* _tmp26_;
				ApplicationConfiguration* _tmp27_;
				gint* _tmp28_;
				gint* _tmp29_;
				gint _tmp29__length1;
				_tmp24_ = composer_window_get_application (self);
				_tmp25_ = _tmp24_;
				_tmp26_ = application_client_get_config (_tmp25_);
				_tmp27_ = _tmp26_;
				_tmp28_ = g_new0 (gint, 2);
				_tmp28_[0] = width;
				_tmp28_[1] = height;
				_tmp29_ = _tmp28_;
				_tmp29__length1 = 2;
				application_configuration_set_composer_window_size (_tmp27_, _tmp29_, (gint) 2);
				_tmp29_ = (g_free (_tmp29_), NULL);
			}
			_g_object_unref0 (monitor);
		}
		_g_object_unref0 (window);
		_g_object_unref0 (display);
	}
}

static void
composer_window_real_size_allocate (GtkWidget* base,
                                    GtkAllocation* allocation)
{
	ComposerWindow * self;
	GtkAllocation _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	g_return_if_fail (allocation != NULL);
	_tmp0_ = *allocation;
	GTK_WIDGET_CLASS (composer_window_parent_class)->size_allocate (G_TYPE_CHECK_INSTANCE_CAST (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_application_window_get_type (), GtkApplicationWindow), gtk_widget_get_type (), GtkWidget), &_tmp0_);
	composer_window_save_window_geometry (self);
}

static gboolean
composer_window_real_delete_event (GtkWidget* base,
                                   GdkEventAny* event)
{
	ComposerWindow * self;
	ComposerWidget* child = NULL;
	GtkWidget* _tmp0_;
	ComposerWidget* _tmp1_;
	gboolean ret = FALSE;
	gboolean _tmp2_ = FALSE;
	ComposerWidget* _tmp3_;
	gboolean result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, COMPOSER_TYPE_WINDOW, ComposerWindow);
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = gtk_bin_get_child (G_TYPE_CHECK_INSTANCE_CAST (self, gtk_bin_get_type (), GtkBin));
	_tmp1_ = _g_object_ref0 (COMPOSER_IS_WIDGET (_tmp0_) ? ((ComposerWidget*) _tmp0_) : NULL);
	child = _tmp1_;
	ret = GDK_EVENT_PROPAGATE;
	_tmp3_ = child;
	if (_tmp3_ != NULL) {
		ComposerWidget* _tmp4_;
		_tmp4_ = child;
		_tmp2_ = composer_widget_conditional_close (_tmp4_, TRUE, FALSE) == COMPOSER_WIDGET_CLOSE_STATUS_CANCELLED;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		ret = GDK_EVENT_STOP;
	}
	result = ret;
	_g_object_unref0 (child);
	return result;
}

static void
composer_window_class_init (ComposerWindowClass * klass,
                            gpointer klass_data)
{
	composer_window_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ComposerWindow_private_offset);
	((GtkWidgetClass *) klass)->show = (void (*) (GtkWidget*)) composer_window_real_show;
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, GtkAllocation*)) composer_window_real_size_allocate;
	((GtkWidgetClass *) klass)->delete_event = (gboolean (*) (GtkWidget*, GdkEventAny*)) composer_window_real_delete_event;
	G_OBJECT_CLASS (klass)->get_property = _vala_composer_window_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_composer_window_set_property;
	G_OBJECT_CLASS (klass)->finalize = composer_window_finalize;
	/** {@inheritDoc} */
	g_object_class_install_property (G_OBJECT_CLASS (klass), COMPOSER_WINDOW_APPLICATION_PROPERTY, composer_window_properties[COMPOSER_WINDOW_APPLICATION_PROPERTY] = g_param_spec_object ("application", "application", "application", APPLICATION_TYPE_CLIENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "geary-composer-box");
}

static void
composer_window_composer_container_interface_init (ComposerContainerIface * iface,
                                                   gpointer iface_data)
{
	composer_window_composer_container_parent_iface = g_type_interface_peek_parent (iface);
	iface->close = (void (*) (ComposerContainer*)) composer_window_real_close;
	iface->get_top_window = composer_window_real_get_top_window;
	iface->get_composer = composer_window_real_get_composer;
	iface->set_composer = composer_window_real_set_composer;
}

static void
composer_window_instance_init (ComposerWindow * self,
                               gpointer klass)
{
	self->priv = composer_window_get_instance_private (self);
}

static void
composer_window_finalize (GObject * obj)
{
	ComposerWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, COMPOSER_TYPE_WINDOW, ComposerWindow);
	_g_object_unref0 (self->priv->_composer);
	G_OBJECT_CLASS (composer_window_parent_class)->finalize (obj);
}

/**
 * A container detached composers, i.e. in their own separate window.
 *
 * Adding a composer to this container places it in {@link
 * Widget.PresentationMode.DETACHED} mode.
 */
static GType
composer_window_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ComposerWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) composer_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ComposerWindow), 0, (GInstanceInitFunc) composer_window_instance_init, NULL };
	static const GInterfaceInfo composer_container_info = { (GInterfaceInitFunc) composer_window_composer_container_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType composer_window_type_id;
	composer_window_type_id = g_type_register_static (gtk_application_window_get_type (), "ComposerWindow", &g_define_type_info, 0);
	g_type_add_interface_static (composer_window_type_id, COMPOSER_TYPE_CONTAINER, &composer_container_info);
	ComposerWindow_private_offset = g_type_add_instance_private (composer_window_type_id, sizeof (ComposerWindowPrivate));
	return composer_window_type_id;
}

GType
composer_window_get_type (void)
{
	static volatile gsize composer_window_type_id__once = 0;
	if (g_once_init_enter (&composer_window_type_id__once)) {
		GType composer_window_type_id;
		composer_window_type_id = composer_window_get_type_once ();
		g_once_init_leave (&composer_window_type_id__once, composer_window_type_id);
	}
	return composer_window_type_id__once;
}

static void
_vala_composer_window_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec)
{
	ComposerWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPOSER_TYPE_WINDOW, ComposerWindow);
	switch (property_id) {
		case COMPOSER_WINDOW_APPLICATION_PROPERTY:
		g_value_set_object (value, composer_window_get_application (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_composer_window_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec)
{
	ComposerWindow * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, COMPOSER_TYPE_WINDOW, ComposerWindow);
	switch (property_id) {
		case COMPOSER_WINDOW_APPLICATION_PROPERTY:
		composer_window_set_application (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

