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

/*-
 * Copyright 2017-2022 elementary. Inc. (https://elementary.io)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <granite-7.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <glib/gi18n-lib.h>

#define GETTEXT_PACKAGE "io.elementary.shortcut-overlay"
#define LOCALEDIR "/usr/share/locale"
#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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define SHORTCUT_OVERLAY_TYPE_APPLICATION (shortcut_overlay_application_get_type ())
#define SHORTCUT_OVERLAY_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUT_OVERLAY_TYPE_APPLICATION, ShortcutOverlayApplication))
#define SHORTCUT_OVERLAY_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHORTCUT_OVERLAY_TYPE_APPLICATION, ShortcutOverlayApplicationClass))
#define SHORTCUT_OVERLAY_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHORTCUT_OVERLAY_TYPE_APPLICATION))
#define SHORTCUT_OVERLAY_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHORTCUT_OVERLAY_TYPE_APPLICATION))
#define SHORTCUT_OVERLAY_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHORTCUT_OVERLAY_TYPE_APPLICATION, ShortcutOverlayApplicationClass))

typedef struct _ShortcutOverlayApplication ShortcutOverlayApplication;
typedef struct _ShortcutOverlayApplicationClass ShortcutOverlayApplicationClass;
typedef struct _ShortcutOverlayApplicationPrivate ShortcutOverlayApplicationPrivate;
enum  {
	SHORTCUT_OVERLAY_APPLICATION_0_PROPERTY,
	SHORTCUT_OVERLAY_APPLICATION_NUM_PROPERTIES
};
static GParamSpec* shortcut_overlay_application_properties[SHORTCUT_OVERLAY_APPLICATION_NUM_PROPERTIES];

#define SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW (shortcut_overlay_main_window_get_type ())
#define SHORTCUT_OVERLAY_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW, ShortcutOverlayMainWindow))
#define SHORTCUT_OVERLAY_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW, ShortcutOverlayMainWindowClass))
#define SHORTCUT_OVERLAY_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW))
#define SHORTCUT_OVERLAY_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW))
#define SHORTCUT_OVERLAY_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SHORTCUT_OVERLAY_TYPE_MAIN_WINDOW, ShortcutOverlayMainWindowClass))

typedef struct _ShortcutOverlayMainWindow ShortcutOverlayMainWindow;
typedef struct _ShortcutOverlayMainWindowClass ShortcutOverlayMainWindowClass;
typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _ShortcutOverlayApplication {
	GtkApplication parent_instance;
	ShortcutOverlayApplicationPrivate * priv;
};

struct _ShortcutOverlayApplicationClass {
	GtkApplicationClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	ShortcutOverlayApplication* self;
	ShortcutOverlayMainWindow* main_window;
	GSimpleAction* quit_action;
	GraniteSettings* granite_settings;
	GtkSettings* gtk_settings;
};

static gpointer shortcut_overlay_application_parent_class = NULL;

VALA_EXTERN GType shortcut_overlay_application_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ShortcutOverlayApplication, g_object_unref)
VALA_EXTERN ShortcutOverlayApplication* shortcut_overlay_application_new (void);
VALA_EXTERN ShortcutOverlayApplication* shortcut_overlay_application_construct (GType object_type);
static void shortcut_overlay_application_real_activate (GApplication* base);
VALA_EXTERN GType shortcut_overlay_main_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ShortcutOverlayMainWindow, g_object_unref)
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
VALA_EXTERN ShortcutOverlayMainWindow* shortcut_overlay_main_window_new (GtkApplication* application);
VALA_EXTERN ShortcutOverlayMainWindow* shortcut_overlay_main_window_construct (GType object_type,
                                                                   GtkApplication* application);
static void ___lambda5_ (Block1Data* _data1_);
static void ____lambda5__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                                    gpointer self);
static void __lambda6_ (Block1Data* _data1_);
static gboolean ___lambda7_ (Block1Data* _data1_);
static gboolean ____lambda7__gsource_func (gpointer self);
static void ___lambda6__g_simple_action_activate (GSimpleAction* _sender,
                                           GVariant* parameter,
                                           gpointer self);
static void __lambda8_ (Block1Data* _data1_);
static void ___lambda8__g_object_notify (GObject* _sender,
                                  GParamSpec* pspec,
                                  gpointer self);
static GType shortcut_overlay_application_get_type_once (void);
static gint _vala_main (gchar** args,
                 gint args_length1);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

ShortcutOverlayApplication*
shortcut_overlay_application_construct (GType object_type)
{
	ShortcutOverlayApplication * self = NULL;
	self = (ShortcutOverlayApplication*) g_object_new (object_type, "application-id", "io.elementary.shortcut-overlay", "flags", G_APPLICATION_FLAGS_NONE, NULL);
	return self;
}

ShortcutOverlayApplication*
shortcut_overlay_application_new (void)
{
	return shortcut_overlay_application_construct (SHORTCUT_OVERLAY_TYPE_APPLICATION);
}

static Block1Data*
block1_data_ref (Block1Data* _data1_)
{
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}

static void
block1_data_unref (void * _userdata_)
{
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		ShortcutOverlayApplication* self;
		self = _data1_->self;
		_g_object_unref0 (_data1_->gtk_settings);
		_g_object_unref0 (_data1_->granite_settings);
		_g_object_unref0 (_data1_->quit_action);
		_g_object_unref0 (_data1_->main_window);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}

static void
___lambda5_ (Block1Data* _data1_)
{
	ShortcutOverlayApplication* self;
	GSimpleAction* _tmp0_;
	self = _data1_->self;
	_tmp0_ = _data1_->quit_action;
	g_signal_emit_by_name (_tmp0_, "activate", NULL);
}

static void
____lambda5__gtk_event_controller_focus_leave (GtkEventControllerFocus* _sender,
                                               gpointer self)
{
	___lambda5_ (self);
}

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

static gboolean
___lambda7_ (Block1Data* _data1_)
{
	ShortcutOverlayApplication* self;
	ShortcutOverlayMainWindow* _tmp0_;
	gboolean result;
	self = _data1_->self;
	_tmp0_ = _data1_->main_window;
	gtk_window_destroy ((GtkWindow*) _tmp0_);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
____lambda7__gsource_func (gpointer self)
{
	gboolean result;
	result = ___lambda7_ (self);
	return result;
}

static void
__lambda6_ (Block1Data* _data1_)
{
	ShortcutOverlayApplication* self;
	ShortcutOverlayMainWindow* _tmp0_;
	self = _data1_->self;
	_tmp0_ = _data1_->main_window;
	if (_tmp0_ != NULL) {
		ShortcutOverlayMainWindow* _tmp1_;
		_tmp1_ = _data1_->main_window;
		gtk_widget_hide ((GtkWidget*) _tmp1_);
		g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 500, ____lambda7__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	}
}

static void
___lambda6__g_simple_action_activate (GSimpleAction* _sender,
                                      GVariant* parameter,
                                      gpointer self)
{
	__lambda6_ (self);
}

static void
__lambda8_ (Block1Data* _data1_)
{
	ShortcutOverlayApplication* self;
	GtkSettings* _tmp0_;
	GraniteSettings* _tmp1_;
	GraniteSettingsColorScheme _tmp2_;
	GraniteSettingsColorScheme _tmp3_;
	self = _data1_->self;
	_tmp0_ = _data1_->gtk_settings;
	_tmp1_ = _data1_->granite_settings;
	_tmp2_ = granite_settings_get_prefers_color_scheme (_tmp1_);
	_tmp3_ = _tmp2_;
	g_object_set (_tmp0_, "gtk-application-prefer-dark-theme", _tmp3_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
}

static void
___lambda8__g_object_notify (GObject* _sender,
                             GParamSpec* pspec,
                             gpointer self)
{
	__lambda8_ (self);
}

static void
shortcut_overlay_application_real_activate (GApplication* base)
{
	ShortcutOverlayApplication * self;
	Block1Data* _data1_;
	GList* windows = NULL;
	GList* _tmp0_;
	GList* _tmp1_;
	ShortcutOverlayMainWindow* _tmp4_;
	ShortcutOverlayMainWindow* _tmp5_;
	GSimpleAction* _tmp6_;
	GSimpleAction* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar** _tmp10_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	GSimpleAction* _tmp17_;
	GraniteSettings* _tmp18_;
	GraniteSettings* _tmp19_;
	GtkSettings* _tmp20_;
	GtkSettings* _tmp21_;
	GtkSettings* _tmp22_;
	GraniteSettings* _tmp23_;
	GraniteSettingsColorScheme _tmp24_;
	GraniteSettingsColorScheme _tmp25_;
	GraniteSettings* _tmp26_;
	self = (ShortcutOverlayApplication*) base;
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = gtk_application_get_windows ((GtkApplication*) self);
	windows = _tmp0_;
	_tmp1_ = windows;
	if (g_list_length (_tmp1_) > ((guint) 0)) {
		GList* _tmp2_;
		gconstpointer _tmp3_;
		_tmp2_ = windows;
		_tmp3_ = _tmp2_->data;
		gtk_window_destroy ((GtkWindow*) _tmp3_);
		block1_data_unref (_data1_);
		_data1_ = NULL;
		return;
	}
	_tmp4_ = shortcut_overlay_main_window_new ((GtkApplication*) self);
	g_object_ref_sink (_tmp4_);
	_data1_->main_window = _tmp4_;
	_tmp5_ = _data1_->main_window;
	gtk_window_present ((GtkWindow*) _tmp5_);
	_tmp6_ = g_simple_action_new ("quit", NULL);
	_data1_->quit_action = _tmp6_;
	_tmp7_ = _data1_->quit_action;
	g_action_map_add_action ((GActionMap*) self, (GAction*) _tmp7_);
	_tmp8_ = g_strdup ("Escape");
	_tmp9_ = g_strdup ("<Ctrl>Q");
	_tmp10_ = g_new0 (gchar*, 2 + 1);
	_tmp10_[0] = _tmp8_;
	_tmp10_[1] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 2;
	gtk_application_set_accels_for_action ((GtkApplication*) self, "app.quit", _tmp11_);
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) g_free), NULL);
	if (!isatty (STDIN_FILENO)) {
		GtkEventControllerFocus* focus_controller = NULL;
		GtkEventControllerFocus* _tmp12_;
		GtkEventControllerFocus* _tmp13_;
		ShortcutOverlayMainWindow* _tmp14_;
		GtkEventControllerFocus* _tmp15_;
		GtkEventController* _tmp16_;
		_tmp12_ = (GtkEventControllerFocus*) gtk_event_controller_focus_new ();
		focus_controller = _tmp12_;
		_tmp13_ = focus_controller;
		g_signal_connect_data (_tmp13_, "leave", (GCallback) ____lambda5__gtk_event_controller_focus_leave, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
		_tmp14_ = _data1_->main_window;
		_tmp15_ = focus_controller;
		_tmp16_ = _g_object_ref0 ((GtkEventController*) _tmp15_);
		gtk_widget_add_controller (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, gtk_widget_get_type (), GtkWidget), _tmp16_);
		_g_object_unref0 (focus_controller);
	}
	_tmp17_ = _data1_->quit_action;
	g_signal_connect_data (_tmp17_, "activate", (GCallback) ___lambda6__g_simple_action_activate, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	_tmp18_ = granite_settings_get_default ();
	_tmp19_ = _g_object_ref0 (_tmp18_);
	_data1_->granite_settings = _tmp19_;
	_tmp20_ = gtk_settings_get_default ();
	_tmp21_ = _g_object_ref0 (_tmp20_);
	_data1_->gtk_settings = _tmp21_;
	_tmp22_ = _data1_->gtk_settings;
	_tmp23_ = _data1_->granite_settings;
	_tmp24_ = granite_settings_get_prefers_color_scheme (_tmp23_);
	_tmp25_ = _tmp24_;
	g_object_set (_tmp22_, "gtk-application-prefer-dark-theme", _tmp25_ == GRANITE_SETTINGS_COLOR_SCHEME_DARK, NULL);
	_tmp26_ = _data1_->granite_settings;
	g_signal_connect_data ((GObject*) _tmp26_, "notify::prefers-color-scheme", (GCallback) ___lambda8__g_object_notify, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}

static void
shortcut_overlay_application_class_init (ShortcutOverlayApplicationClass * klass,
                                         gpointer klass_data)
{
	shortcut_overlay_application_parent_class = g_type_class_peek_parent (klass);
	((GApplicationClass *) klass)->activate = (void (*) (GApplication*)) shortcut_overlay_application_real_activate;
}

static void
shortcut_overlay_application_instance_init (ShortcutOverlayApplication * self,
                                            gpointer klass)
{
}

static GType
shortcut_overlay_application_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ShortcutOverlayApplicationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) shortcut_overlay_application_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ShortcutOverlayApplication), 0, (GInstanceInitFunc) shortcut_overlay_application_instance_init, NULL };
	GType shortcut_overlay_application_type_id;
	shortcut_overlay_application_type_id = g_type_register_static (gtk_application_get_type (), "ShortcutOverlayApplication", &g_define_type_info, 0);
	return shortcut_overlay_application_type_id;
}

GType
shortcut_overlay_application_get_type (void)
{
	static volatile gsize shortcut_overlay_application_type_id__once = 0;
	if (g_once_init_enter (&shortcut_overlay_application_type_id__once)) {
		GType shortcut_overlay_application_type_id;
		shortcut_overlay_application_type_id = shortcut_overlay_application_get_type_once ();
		g_once_init_leave (&shortcut_overlay_application_type_id__once, shortcut_overlay_application_type_id);
	}
	return shortcut_overlay_application_type_id__once;
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	ShortcutOverlayApplication* application = NULL;
	ShortcutOverlayApplication* _tmp0_;
	gint result;
	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
	_tmp0_ = shortcut_overlay_application_new ();
	application = _tmp0_;
	result = g_application_run ((GApplication*) application, (gint) args_length1, args);
	_g_object_unref0 (application);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return _vala_main (argv, argc);
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

