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

/*
 * Copyright (c) 2023-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <gdk/gdk.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <gio/gio.h>
#include <gdk/wayland/gdkwayland.h>
#include <gdk/x11/gdkx.h>
#include <cairo-gobject.h>
#include "ft_ui.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

#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block31Data Block31Data;
typedef struct _Block32Data Block32Data;
typedef struct _FtGetWindowIdentifierData FtGetWindowIdentifierData;

struct _Block31Data {
	int _ref_count_;
	gpointer _async_data_;
};

struct _Block32Data {
	int _ref_count_;
	Block31Data * _data31_;
	gchar* handle;
};

struct _FtGetWindowIdentifierData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GtkWindow* window;
	gchar* result;
	Block31Data* _data31_;
	GtkWindow* _tmp0_;
	GdkSurface* _tmp1_;
	GdkSurface* _tmp2_;
	GdkSurface* surface;
	GdkSurface* _tmp3_;
	GdkSurface* _tmp4_;
	GdkSurface* _tmp5_;
	GdkDisplay* _tmp6_;
	GdkDisplay* _tmp7_;
	GdkDisplay* display;
	GdkDisplay* _tmp8_;
	GdkDisplay* _tmp9_;
	Block32Data* _data32_;
	GdkWaylandToplevel* wayland_toplevel;
	GdkSurface* _tmp10_;
	GdkWaylandToplevel* _tmp11_;
	GdkWaylandToplevel* _tmp12_;
	gboolean wait_for_handle;
	GdkWaylandToplevel* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	GdkDisplay* _tmp21_;
	GdkX11Surface* x11_surface;
	GdkSurface* _tmp22_;
	GdkX11Surface* _tmp23_;
	GdkX11Surface* _tmp24_;
	gint xid;
	GdkX11Surface* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
};

VALA_EXTERN void ft_blend_colors (GdkRGBA* background_color,
                      GdkRGBA* foreground_color,
                      GdkRGBA* result);
VALA_EXTERN gfloat ft_get_color_luminance (GdkRGBA* color);
VALA_EXTERN void ft_get_background_color (GdkRGBA* foreground_color,
                              GdkRGBA* result);
VALA_EXTERN void ft_get_chart_primary_color (GdkRGBA* foreground_color,
                                 GdkRGBA* result);
VALA_EXTERN void ft_get_chart_secondary_color (GdkRGBA* foreground_color,
                                   GdkRGBA* result);
VALA_EXTERN GtkWidget* ft_get_child_by_buildable_id (GtkWidget* widget,
                                         const gchar* buildable_id);
VALA_EXTERN gchar* ft_capitalize_words (const gchar* text);
static void ft_get_window_identifier_data_free (gpointer _data);
VALA_EXTERN void ft_get_window_identifier (GtkWindow* window,
                               GAsyncReadyCallback _callback_,
                               gpointer _user_data_);
VALA_EXTERN gchar* ft_get_window_identifier_finish (GAsyncResult* _res_);
static gboolean ft_get_window_identifier_co (FtGetWindowIdentifierData* _data_);
static Block31Data* block31_data_ref (Block31Data* _data31_);
static void block31_data_unref (void * _userdata_);
static Block32Data* block32_data_ref (Block32Data* _data32_);
static void block32_data_unref (void * _userdata_);
static void ____lambda51_ (Block32Data* _data32_,
                    GdkWaylandToplevel* _toplevel,
                    const gchar* _handle);
static void _____lambda51__gdk_wayland_toplevel_exported (GdkWaylandToplevel* toplevel,
                                                   const gchar* handle,
                                                   gpointer self);
VALA_EXTERN GtkOrientation ft_get_opposite_orientation (GtkOrientation orientation);
VALA_EXTERN void ft_normalize_rectangle (GdkRectangle* rect);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

void
ft_blend_colors (GdkRGBA* background_color,
                 GdkRGBA* foreground_color,
                 GdkRGBA* result)
{
	gfloat alpha = 0.0F;
	GdkRGBA _tmp0_;
	GdkRGBA _tmp1_;
	GdkRGBA _tmp2_;
	GdkRGBA _tmp3_;
	GdkRGBA _tmp4_;
	GdkRGBA _tmp5_;
	GdkRGBA _tmp6_;
	GdkRGBA _tmp7_;
	GdkRGBA _tmp8_;
	GdkRGBA _tmp9_ = {0};
	g_return_if_fail (background_color != NULL);
	g_return_if_fail (foreground_color != NULL);
	_tmp0_ = *foreground_color;
	alpha = _tmp0_.alpha;
	_tmp1_ = *background_color;
	_tmp2_ = *foreground_color;
	_tmp3_ = *background_color;
	_tmp4_ = *foreground_color;
	_tmp5_ = *background_color;
	_tmp6_ = *foreground_color;
	_tmp7_ = *background_color;
	_tmp8_ = *background_color;
	memset (&_tmp9_, 0, sizeof (GdkRGBA));
	_tmp9_.red = ((1.0f - alpha) * _tmp1_.red) + (alpha * _tmp2_.red);
	_tmp9_.green = ((1.0f - alpha) * _tmp3_.green) + (alpha * _tmp4_.green);
	_tmp9_.blue = ((1.0f - alpha) * _tmp5_.blue) + (alpha * _tmp6_.blue);
	_tmp9_.alpha = _tmp7_.alpha + ((1.0f - _tmp8_.alpha) * alpha);
	*result = _tmp9_;
	return;
}

/**
     * Calculate relative luminance of a color according to WCAG 2.0
     * https://www.w3.org/TR/WCAG20/#relativeluminancedef
     */
gfloat
ft_get_color_luminance (GdkRGBA* color)
{
	gfloat _tmp0_ = 0.0F;
	GdkRGBA _tmp1_;
	gfloat r = 0.0F;
	gfloat _tmp4_ = 0.0F;
	GdkRGBA _tmp5_;
	gfloat g = 0.0F;
	gfloat _tmp8_ = 0.0F;
	GdkRGBA _tmp9_;
	gfloat b = 0.0F;
	gfloat result;
	g_return_val_if_fail (color != NULL, -1.0F);
	_tmp1_ = *color;
	if (_tmp1_.red <= 0.03928f) {
		GdkRGBA _tmp2_;
		_tmp2_ = *color;
		_tmp0_ = _tmp2_.red / 12.92f;
	} else {
		GdkRGBA _tmp3_;
		_tmp3_ = *color;
		_tmp0_ = (gfloat) pow ((gdouble) ((_tmp3_.red + 0.055f) / 1.055f), 2.4);
	}
	r = _tmp0_;
	_tmp5_ = *color;
	if (_tmp5_.green <= 0.03928f) {
		GdkRGBA _tmp6_;
		_tmp6_ = *color;
		_tmp4_ = _tmp6_.green / 12.92f;
	} else {
		GdkRGBA _tmp7_;
		_tmp7_ = *color;
		_tmp4_ = (gfloat) pow ((gdouble) ((_tmp7_.green + 0.055f) / 1.055f), 2.4);
	}
	g = _tmp4_;
	_tmp9_ = *color;
	if (_tmp9_.blue <= 0.03928f) {
		GdkRGBA _tmp10_;
		_tmp10_ = *color;
		_tmp8_ = _tmp10_.blue / 12.92f;
	} else {
		GdkRGBA _tmp11_;
		_tmp11_ = *color;
		_tmp8_ = (gfloat) pow ((gdouble) ((_tmp11_.blue + 0.055f) / 1.055f), 2.4);
	}
	b = _tmp8_;
	result = ((0.2126f * r) + (0.7152f * g)) + (0.0722f * b);
	return result;
}

/**
     * Deduce background color from foreground color based on luminance.
     *
     * If foreground is dark (luminance < 0.5), assume light background (98% luminance).
     * If foreground is bright, assume darker background (20% luminance).
     */
void
ft_get_background_color (GdkRGBA* foreground_color,
                         GdkRGBA* result)
{
	gfloat foreground_luminance = 0.0F;
	GdkRGBA _tmp0_;
	gfloat _tmp1_ = 0.0F;
	gfloat background_luminance = 0.0F;
	GdkRGBA _tmp2_ = {0};
	g_return_if_fail (foreground_color != NULL);
	_tmp0_ = *foreground_color;
	foreground_luminance = ft_get_color_luminance (&_tmp0_);
	if (foreground_luminance < 0.5f) {
		_tmp1_ = 0.98f;
	} else {
		_tmp1_ = 0.20f;
	}
	background_luminance = _tmp1_;
	memset (&_tmp2_, 0, sizeof (GdkRGBA));
	_tmp2_.red = background_luminance;
	_tmp2_.green = background_luminance;
	_tmp2_.blue = background_luminance;
	_tmp2_.alpha = 1.0f;
	*result = _tmp2_;
	return;
}

/**
     * Compute primary color for charts from a foreground color.
     * The primary color is basically a foreground color with no alpha.
     */
void
ft_get_chart_primary_color (GdkRGBA* foreground_color,
                            GdkRGBA* result)
{
	GdkRGBA background_color = {0};
	GdkRGBA _tmp0_;
	GdkRGBA _tmp1_ = {0};
	GdkRGBA _tmp2_;
	GdkRGBA _tmp3_;
	GdkRGBA _tmp4_ = {0};
	g_return_if_fail (foreground_color != NULL);
	_tmp0_ = *foreground_color;
	ft_get_background_color (&_tmp0_, &_tmp1_);
	background_color = _tmp1_;
	_tmp2_ = background_color;
	_tmp3_ = *foreground_color;
	ft_blend_colors (&_tmp2_, &_tmp3_, &_tmp4_);
	*result = _tmp4_;
	return;
}

/**
     * Compute secondary color for charts from a foreground color.
     */
void
ft_get_chart_secondary_color (GdkRGBA* foreground_color,
                              GdkRGBA* result)
{
	GdkRGBA secondary_color = {0};
	GdkRGBA _tmp0_;
	GdkRGBA _tmp1_ = {0};
	g_return_if_fail (foreground_color != NULL);
	_tmp0_ = *foreground_color;
	ft_get_chart_primary_color (&_tmp0_, &_tmp1_);
	secondary_color = _tmp1_;
	secondary_color.alpha = secondary_color.alpha * 0.2f;
	*result = secondary_color;
	return;
}

GtkWidget*
ft_get_child_by_buildable_id (GtkWidget* widget,
                              const gchar* buildable_id)
{
	GtkWidget* child = NULL;
	GtkWidget* _tmp0_;
	GtkWidget* result;
	g_return_val_if_fail (widget != NULL, NULL);
	g_return_val_if_fail (buildable_id != NULL, NULL);
	_tmp0_ = gtk_widget_get_first_child (widget);
	child = _tmp0_;
	while (TRUE) {
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		const gchar* _tmp3_;
		GtkWidget* nested_child = NULL;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		_tmp1_ = child;
		if (!(_tmp1_ != NULL)) {
			break;
		}
		_tmp2_ = child;
		_tmp3_ = gtk_buildable_get_buildable_id ((GtkBuildable*) _tmp2_);
		if (g_strcmp0 (_tmp3_, buildable_id) == 0) {
			GtkWidget* _tmp4_;
			_tmp4_ = child;
			result = _tmp4_;
			return result;
		}
		_tmp5_ = child;
		_tmp6_ = ft_get_child_by_buildable_id (_tmp5_, buildable_id);
		nested_child = _tmp6_;
		_tmp7_ = nested_child;
		if (_tmp7_ != NULL) {
			GtkWidget* _tmp8_;
			_tmp8_ = nested_child;
			result = _tmp8_;
			return result;
		}
		_tmp9_ = child;
		_tmp10_ = gtk_widget_get_next_sibling (_tmp9_);
		child = _tmp10_;
	}
	result = NULL;
	return result;
}

static gboolean
string_get_next_char (const gchar* self,
                      gint* index,
                      gunichar* c)
{
	gunichar _vala_c = 0U;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_vala_c = g_utf8_get_char (((gchar*) self) + (*index));
	if (_vala_c != ((gunichar) 0)) {
		gchar* _tmp0_;
		_tmp0_ = g_utf8_next_char (((gchar*) self) + (*index));
		*index = (gint) (_tmp0_ - ((gchar*) self));
		result = TRUE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	} else {
		result = FALSE;
		if (c) {
			*c = _vala_c;
		}
		return result;
	}
}

gchar*
ft_capitalize_words (const gchar* text)
{
	GString* string_builder = NULL;
	GString* _tmp0_;
	gboolean capitalize_next = FALSE;
	gint index = 0;
	gunichar chr = 0U;
	GString* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* result;
	g_return_val_if_fail (text != NULL, NULL);
	_tmp0_ = g_string_new ("");
	string_builder = _tmp0_;
	capitalize_next = TRUE;
	index = 0;
	while (TRUE) {
		gunichar _tmp1_ = 0U;
		gboolean _tmp2_;
		_tmp2_ = string_get_next_char (text, &index, &_tmp1_);
		chr = _tmp1_;
		if (!_tmp2_) {
			break;
		}
		if (chr == ((gunichar) ' ')) {
			GString* _tmp3_;
			_tmp3_ = string_builder;
			g_string_append_unichar (_tmp3_, chr);
			capitalize_next = TRUE;
		} else {
			gboolean _tmp4_ = FALSE;
			if (capitalize_next) {
				_tmp4_ = g_unichar_islower (chr);
			} else {
				_tmp4_ = FALSE;
			}
			if (_tmp4_) {
				GString* _tmp5_;
				_tmp5_ = string_builder;
				g_string_append_unichar (_tmp5_, g_unichar_toupper (chr));
				capitalize_next = FALSE;
			} else {
				GString* _tmp6_;
				_tmp6_ = string_builder;
				g_string_append_unichar (_tmp6_, chr);
				capitalize_next = FALSE;
			}
		}
	}
	_tmp7_ = string_builder;
	_tmp8_ = _tmp7_->str;
	_tmp9_ = g_strdup (_tmp8_);
	result = _tmp9_;
	_g_string_free0 (string_builder);
	return result;
}

static void
ft_get_window_identifier_data_free (gpointer _data)
{
	FtGetWindowIdentifierData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->window);
	_g_free0 (_data_->result);
	g_slice_free (FtGetWindowIdentifierData, _data_);
}

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

void
ft_get_window_identifier (GtkWindow* window,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	FtGetWindowIdentifierData* _data_;
	GtkWindow* _tmp0_;
	_data_ = g_slice_new0 (FtGetWindowIdentifierData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_get_window_identifier_data_free);
	_tmp0_ = _g_object_ref0 (window);
	_g_object_unref0 (_data_->window);
	_data_->window = _tmp0_;
	ft_get_window_identifier_co (_data_);
}

gchar*
ft_get_window_identifier_finish (GAsyncResult* _res_)
{
	gchar* result;
	FtGetWindowIdentifierData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

/**
     * Function to get xdg-desktop-portal compatible window ID
     *
     * https://flatpak.github.io/xdg-desktop-portal/docs/window-identifiers.html
     */
static Block31Data*
block31_data_ref (Block31Data* _data31_)
{
	g_atomic_int_inc (&_data31_->_ref_count_);
	return _data31_;
}

static void
block31_data_unref (void * _userdata_)
{
	Block31Data* _data31_;
	_data31_ = (Block31Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data31_->_ref_count_)) {
		g_slice_free (Block31Data, _data31_);
	}
}

static Block32Data*
block32_data_ref (Block32Data* _data32_)
{
	g_atomic_int_inc (&_data32_->_ref_count_);
	return _data32_;
}

static void
block32_data_unref (void * _userdata_)
{
	Block32Data* _data32_;
	_data32_ = (Block32Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data32_->_ref_count_)) {
		_g_free0 (_data32_->handle);
		block31_data_unref (_data32_->_data31_);
		_data32_->_data31_ = NULL;
		g_slice_free (Block32Data, _data32_);
	}
}

static void
____lambda51_ (Block32Data* _data32_,
               GdkWaylandToplevel* _toplevel,
               const gchar* _handle)
{
	Block31Data* _data31_;
	gchar* _tmp0_;
	_data31_ = _data32_->_data31_;
	g_return_if_fail (_toplevel != NULL);
	g_return_if_fail (_handle != NULL);
	_tmp0_ = g_strdup (_handle);
	_g_free0 (_data32_->handle);
	_data32_->handle = _tmp0_;
	ft_get_window_identifier_co (_data31_->_async_data_);
}

static void
_____lambda51__gdk_wayland_toplevel_exported (GdkWaylandToplevel* toplevel,
                                              const gchar* handle,
                                              gpointer self)
{
	____lambda51_ (self, toplevel, handle);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static gboolean
ft_get_window_identifier_co (FtGetWindowIdentifierData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data31_ = g_slice_new0 (Block31Data);
	_data_->_data31_->_ref_count_ = 1;
	_data_->_data31_->_async_data_ = _data_;
	_data_->_tmp0_ = _data_->window;
	_data_->_tmp1_ = NULL;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp2_ = gtk_native_get_surface ((GtkNative*) _data_->_tmp0_);
		_data_->_tmp1_ = _data_->_tmp2_;
	}
	_data_->_tmp3_ = _g_object_ref0 (_data_->_tmp1_);
	_data_->surface = _data_->_tmp3_;
	_data_->_tmp5_ = _data_->surface;
	_data_->_tmp4_ = _data_->_tmp5_;
	_data_->_tmp6_ = NULL;
	if (_data_->_tmp4_ != NULL) {
		_data_->_tmp7_ = gdk_surface_get_display (_data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp7_;
	}
	_data_->_tmp8_ = _g_object_ref0 (_data_->_tmp6_);
	_data_->display = _data_->_tmp8_;
	_data_->_tmp9_ = _data_->display;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp9_, gdk_wayland_display_get_type ())) {
		_data_->_data32_ = g_slice_new0 (Block32Data);
		_data_->_data32_->_ref_count_ = 1;
		_data_->_data32_->_data31_ = block31_data_ref (_data_->_data31_);
		_data_->_tmp10_ = _data_->surface;
		_data_->_tmp11_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp10_, gdk_wayland_toplevel_get_type ()) ? ((GdkWaylandToplevel*) _data_->_tmp10_) : NULL);
		_data_->wayland_toplevel = _data_->_tmp11_;
		_data_->_data32_->handle = NULL;
		_data_->_tmp12_ = _data_->wayland_toplevel;
		if (_data_->_tmp12_ != NULL) {
			_data_->_tmp13_ = _data_->wayland_toplevel;
			_data_->wait_for_handle = gdk_wayland_toplevel_export_handle (_data_->_tmp13_, _____lambda51__gdk_wayland_toplevel_exported, block32_data_ref (_data_->_data32_), block32_data_unref);
			if (_data_->wait_for_handle) {
				_data_->_state_ = 1;
				return FALSE;
				_state_1:
				;
			}
			_data_->_tmp15_ = _data_->_data32_->handle;
			if (_data_->_tmp15_ != NULL) {
				_data_->_tmp16_ = _data_->_data32_->handle;
				_data_->_tmp17_ = string_to_string (_data_->_tmp16_);
				_data_->_tmp18_ = g_strconcat ("wayland:", _data_->_tmp17_, NULL);
				_g_free0 (_data_->_tmp14_);
				_data_->_tmp14_ = _data_->_tmp18_;
			} else {
				_data_->_tmp19_ = g_strdup ("");
				_g_free0 (_data_->_tmp14_);
				_data_->_tmp14_ = _data_->_tmp19_;
			}
			_data_->_tmp20_ = _data_->_tmp14_;
			_data_->_tmp14_ = NULL;
			_data_->result = _data_->_tmp20_;
			_g_free0 (_data_->_tmp14_);
			_g_object_unref0 (_data_->wayland_toplevel);
			block32_data_unref (_data_->_data32_);
			_data_->_data32_ = NULL;
			_g_object_unref0 (_data_->display);
			_g_object_unref0 (_data_->surface);
			block31_data_unref (_data_->_data31_);
			_data_->_data31_ = 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;
		}
		_g_object_unref0 (_data_->wayland_toplevel);
		block32_data_unref (_data_->_data32_);
		_data_->_data32_ = NULL;
	}
	_data_->_tmp21_ = _data_->display;
	if (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp21_, gdk_x11_display_get_type ())) {
		_data_->_tmp22_ = _data_->surface;
		_data_->_tmp23_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp22_, gdk_x11_surface_get_type ()) ? ((GdkX11Surface*) _data_->_tmp22_) : NULL);
		_data_->x11_surface = _data_->_tmp23_;
		_data_->_tmp24_ = _data_->x11_surface;
		if (_data_->_tmp24_ != NULL) {
			_data_->_tmp25_ = _data_->x11_surface;
			_data_->xid = (gint) gdk_x11_surface_get_xid (_data_->_tmp25_);
			_data_->_tmp26_ = g_strdup_printf ("%i", _data_->xid);
			_data_->_tmp27_ = _data_->_tmp26_;
			_data_->_tmp28_ = g_strconcat ("x11:", _data_->_tmp27_, NULL);
			_data_->_tmp29_ = _data_->_tmp28_;
			_g_free0 (_data_->_tmp27_);
			_data_->result = _data_->_tmp29_;
			_g_object_unref0 (_data_->x11_surface);
			_g_object_unref0 (_data_->display);
			_g_object_unref0 (_data_->surface);
			block31_data_unref (_data_->_data31_);
			_data_->_data31_ = 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;
		}
		_g_object_unref0 (_data_->x11_surface);
	}
	_data_->_tmp30_ = g_strdup ("");
	_data_->result = _data_->_tmp30_;
	_g_object_unref0 (_data_->display);
	_g_object_unref0 (_data_->surface);
	block31_data_unref (_data_->_data31_);
	_data_->_data31_ = 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;
}

inline GtkOrientation
ft_get_opposite_orientation (GtkOrientation orientation)
{
	GtkOrientation _tmp0_ = 0;
	GtkOrientation result;
	if (orientation == GTK_ORIENTATION_HORIZONTAL) {
		_tmp0_ = GTK_ORIENTATION_VERTICAL;
	} else {
		_tmp0_ = GTK_ORIENTATION_HORIZONTAL;
	}
	result = _tmp0_;
	return result;
}

void
ft_normalize_rectangle (GdkRectangle* rect)
{
	GdkRectangle _tmp0_;
	GdkRectangle _tmp3_;
	g_return_if_fail (rect != NULL);
	_tmp0_ = *rect;
	if (_tmp0_.width < 0) {
		GdkRectangle _tmp1_;
		GdkRectangle _tmp2_;
		_tmp1_ = *rect;
		(*rect).x = (*rect).x + _tmp1_.width;
		_tmp2_ = *rect;
		(*rect).width = abs (_tmp2_.width);
	}
	_tmp3_ = *rect;
	if (_tmp3_.height < 0) {
		GdkRectangle _tmp4_;
		GdkRectangle _tmp5_;
		_tmp4_ = *rect;
		(*rect).y = (*rect).y + _tmp4_.height;
		_tmp5_ = *rect;
		(*rect).height = abs (_tmp5_.height);
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

