/* recording-area.c generated by valac 0.56.17, the Vala compiler
 * generated from recording-area.vala, do not modify */

/*
Peek Copyright (c) 2016-2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/

#include "../../application.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <string.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_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

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

void
peek_recording_recording_area_create_for_widget (GtkWidget* recording_view,
                                                 PeekRecordingRecordingArea* result)
{
	GdkWindow* recording_view_window = NULL;
	GdkWindow* _tmp0_;
	GdkWindow* _tmp1_;
	PeekRecordingRecordingArea area = {0};
	GtkWidget* _tmp2_;
	PeekRecordingRecordingArea _tmp3_ = {0};
	GdkWindow* _tmp4_;
	gint _tmp5_ = 0;
	gint _tmp6_ = 0;
	gint relative_left = 0;
	gint relative_top = 0;
	GtkWidget* _tmp7_;
	gint _tmp8_ = 0;
	gint _tmp9_ = 0;
	PeekRecordingRecordingArea _tmp10_;
	PeekRecordingRecordingArea _tmp11_;
	PeekRecordingRecordingArea _tmp12_;
	PeekRecordingRecordingArea _tmp13_;
	PeekRecordingRecordingArea _tmp14_;
	PeekRecordingRecordingArea _tmp15_;
	GdkScreen* screen = NULL;
	GdkScreen* _tmp16_;
	GdkScreen* _tmp17_;
	gint screen_width = 0;
	GdkScreen* _tmp18_;
	gint screen_height = 0;
	GdkScreen* _tmp19_;
	PeekRecordingRecordingArea _tmp20_;
	PeekRecordingRecordingArea _tmp21_;
	PeekRecordingRecordingArea _tmp22_;
	PeekRecordingRecordingArea _tmp23_;
	PeekRecordingRecordingArea _tmp25_;
	PeekRecordingRecordingArea _tmp26_;
	PeekRecordingRecordingArea _tmp28_;
	PeekRecordingRecordingArea _tmp29_;
	PeekRecordingRecordingArea _tmp30_;
	PeekRecordingRecordingArea _tmp31_;
	gint scale_factor = 0;
	GdkWindow* _tmp32_;
	PeekRecordingRecordingArea _tmp33_;
	PeekRecordingRecordingArea _tmp34_;
	PeekRecordingRecordingArea _tmp35_;
	PeekRecordingRecordingArea _tmp36_;
	g_return_if_fail (recording_view != NULL);
	_tmp0_ = gtk_widget_get_window (recording_view);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	recording_view_window = _tmp1_;
	_tmp2_ = _g_object_ref0 (recording_view);
	memset (&_tmp3_, 0, sizeof (PeekRecordingRecordingArea));
	_g_object_unref0 (_tmp3_.widget);
	_tmp3_.widget = _tmp2_;
	_tmp3_.width = gtk_widget_get_allocated_width (recording_view);
	_tmp3_.height = gtk_widget_get_allocated_height (recording_view);
	area = _tmp3_;
	_tmp4_ = recording_view_window;
	gdk_window_get_origin (_tmp4_, &_tmp5_, &_tmp6_);
	area.left = _tmp5_;
	area.top = _tmp6_;
	_tmp7_ = gtk_widget_get_toplevel (recording_view);
	gtk_widget_translate_coordinates (recording_view, _tmp7_, 0, 0, &_tmp8_, &_tmp9_);
	relative_left = _tmp8_;
	relative_top = _tmp9_;
	_tmp10_ = area;
	area.left = _tmp10_.left + relative_left;
	_tmp11_ = area;
	area.top = _tmp11_.top + relative_top;
	_tmp12_ = area;
	_tmp13_ = area;
	_tmp14_ = area;
	_tmp15_ = area;
	g_debug ("recording-area.vala:38: Absolute recording area x: %d, y: %d, w: %d, h" \
": %d", _tmp12_.left, _tmp13_.top, _tmp14_.width, _tmp15_.height);
	_tmp16_ = gtk_widget_get_screen (recording_view);
	_tmp17_ = _g_object_ref0 (_tmp16_);
	screen = _tmp17_;
	_tmp18_ = screen;
	screen_width = gdk_screen_get_width (_tmp18_);
	_tmp19_ = screen;
	screen_height = gdk_screen_get_height (_tmp19_);
	g_debug ("recording-area.vala:45: Screen w: %d, h: %d", screen_width, screen_height);
	_tmp20_ = area;
	area.left = MIN (MAX (0, _tmp20_.left), screen_width);
	_tmp21_ = area;
	area.top = MIN (MAX (0, _tmp21_.top), screen_height);
	_tmp22_ = area;
	_tmp23_ = area;
	if ((_tmp22_.left + _tmp23_.width) > screen_width) {
		PeekRecordingRecordingArea _tmp24_;
		_tmp24_ = area;
		area.width = screen_width - _tmp24_.left;
	}
	_tmp25_ = area;
	_tmp26_ = area;
	if ((_tmp25_.top + _tmp26_.height) > screen_height) {
		PeekRecordingRecordingArea _tmp27_;
		_tmp27_ = area;
		area.height = screen_height - _tmp27_.top;
	}
	_tmp28_ = area;
	_tmp29_ = area;
	_tmp30_ = area;
	_tmp31_ = area;
	g_debug ("recording-area.vala:58: Clipped recording area x: %d, y: %d, w: %d, h:" \
" %d", _tmp28_.left, _tmp29_.top, _tmp30_.width, _tmp31_.height);
	_tmp32_ = recording_view_window;
	scale_factor = gdk_window_get_scale_factor (_tmp32_);
	area.left = area.left * scale_factor;
	area.top = area.top * scale_factor;
	area.width = area.width * scale_factor;
	area.height = area.height * scale_factor;
	_tmp33_ = area;
	_tmp34_ = area;
	_tmp35_ = area;
	_tmp36_ = area;
	g_debug ("recording-area.vala:69: Scaled recording area x: %d, y: %d, w: %d, h: " \
"%d", _tmp33_.left, _tmp34_.top, _tmp35_.width, _tmp36_.height);
	*result = area;
	_g_object_unref0 (screen);
	_g_object_unref0 (recording_view_window);
	return;
}

gboolean
peek_recording_recording_area_equals (PeekRecordingRecordingArea *self,
                                      PeekRecordingRecordingArea* other)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean result;
	if (other == NULL) {
		result = FALSE;
		return result;
	}
	if ((*self).left == (*other).left) {
		_tmp3_ = (*self).top == (*other).top;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		_tmp2_ = (*self).width == (*other).width;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_tmp1_ = (*self).height == (*other).height;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp4_ = (*self).widget;
		_tmp5_ = (*other).widget;
		_tmp0_ = _tmp4_ == _tmp5_;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

void
peek_recording_recording_area_copy (const PeekRecordingRecordingArea* self,
                                    PeekRecordingRecordingArea* dest)
{
	GtkWidget* _tmp0_;
	GtkWidget* _tmp1_;
	(*dest).left = (*self).left;
	(*dest).top = (*self).top;
	(*dest).width = (*self).width;
	(*dest).height = (*self).height;
	_tmp0_ = (*self).widget;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 ((*dest).widget);
	(*dest).widget = _tmp1_;
}

void
peek_recording_recording_area_destroy (PeekRecordingRecordingArea* self)
{
	_g_object_unref0 ((*self).widget);
}

PeekRecordingRecordingArea*
peek_recording_recording_area_dup (const PeekRecordingRecordingArea* self)
{
	PeekRecordingRecordingArea* dup;
	dup = g_new0 (PeekRecordingRecordingArea, 1);
	peek_recording_recording_area_copy (self, dup);
	return dup;
}

void
peek_recording_recording_area_free (PeekRecordingRecordingArea* self)
{
	peek_recording_recording_area_destroy (self);
	g_free (self);
}

static GType
peek_recording_recording_area_get_type_once (void)
{
	GType peek_recording_recording_area_type_id;
	peek_recording_recording_area_type_id = g_boxed_type_register_static ("PeekRecordingRecordingArea", (GBoxedCopyFunc) peek_recording_recording_area_dup, (GBoxedFreeFunc) peek_recording_recording_area_free);
	return peek_recording_recording_area_type_id;
}

GType
peek_recording_recording_area_get_type (void)
{
	static volatile gsize peek_recording_recording_area_type_id__once = 0;
	if (g_once_init_enter (&peek_recording_recording_area_type_id__once)) {
		GType peek_recording_recording_area_type_id;
		peek_recording_recording_area_type_id = peek_recording_recording_area_get_type_once ();
		g_once_init_leave (&peek_recording_recording_area_type_id__once, peek_recording_recording_area_type_id);
	}
	return peek_recording_recording_area_type_id__once;
}

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;
}

