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

/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: 2019-2025 elementary, Inc. (https://elementary.io)
 *                         2011-2012 Giulio Collura
 */

#include "slingshot.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
#include <pango/pango.h>
#include <gio/gio.h>
#include <granite.h>
#include <float.h>
#include <math.h>

#define SLINGSHOT_WIDGETS_APP_BUTTON_ICON_SIZE 64
#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  {
	SLINGSHOT_WIDGETS_APP_BUTTON_0_PROPERTY,
	SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY,
	SLINGSHOT_WIDGETS_APP_BUTTON_NUM_PROPERTIES
};
static GParamSpec* slingshot_widgets_app_button_properties[SLINGSHOT_WIDGETS_APP_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_GdkEvent_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEvent_free (var), NULL)))
#define __vala_GdkEventSequence_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEventSequence_free (var), NULL)))
enum  {
	SLINGSHOT_WIDGETS_APP_BUTTON_APP_LAUNCHED_SIGNAL,
	SLINGSHOT_WIDGETS_APP_BUTTON_NUM_SIGNALS
};
static guint slingshot_widgets_app_button_signals[SLINGSHOT_WIDGETS_APP_BUTTON_NUM_SIGNALS] = {0};

struct _SlingshotWidgetsAppButtonPrivate {
	SlingshotBackendApp* _app;
	GtkLabel* badge;
	gboolean dragging;
	GtkGestureMultiPress* click_controller;
	GtkEventControllerKey* menu_key_controller;
};

static gint SlingshotWidgetsAppButton_private_offset;
static gpointer slingshot_widgets_app_button_parent_class = NULL;

static void slingshot_widgets_app_button_update_badge_count (SlingshotWidgetsAppButton* self);
static void slingshot_widgets_app_button_update_badge_visibility (SlingshotWidgetsAppButton* self);
static GObject * slingshot_widgets_app_button_constructor (GType type,
                                                    guint n_construct_properties,
                                                    GObjectConstructParam * construct_properties);
static void _slingshot_widgets_app_button___lambda38_ (SlingshotWidgetsAppButton* self);
static void __slingshot_widgets_app_button___lambda38__slingshot_backend_app_launched (SlingshotBackendApp* _sender,
                                                                                SlingshotBackendApp* app,
                                                                                gpointer self);
static void _slingshot_widgets_app_button_launch_app_gtk_button_clicked (GtkButton* _sender,
                                                                  gpointer self);
static void _slingshot_widgets_app_button___lambda39_ (SlingshotWidgetsAppButton* self,
                                                gint n_press,
                                                gdouble x,
                                                gdouble y);
static GdkEvent* _vala_GdkEvent_copy (GdkEvent* self);
static void _vala_GdkEvent_free (GdkEvent* self);
static void _vala_GdkEventSequence_free (GdkEventSequence* self);
static void __slingshot_widgets_app_button___lambda39__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                                 gint n_press,
                                                                                 gdouble x,
                                                                                 gdouble y,
                                                                                 gpointer self);
static void _slingshot_widgets_app_button___lambda40_ (SlingshotWidgetsAppButton* self,
                                                guint keyval,
                                                guint keycode,
                                                GdkModifierType state);
static void __slingshot_widgets_app_button___lambda40__gtk_event_controller_key_key_released (GtkEventControllerKey* _sender,
                                                                                       guint keyval,
                                                                                       guint keycode,
                                                                                       GdkModifierType state,
                                                                                       gpointer self);
static void _slingshot_widgets_app_button___lambda41_ (SlingshotWidgetsAppButton* self,
                                                GdkDragContext* ctx);
static void __slingshot_widgets_app_button___lambda41__gtk_widget_drag_begin (GtkWidget* _sender,
                                                                       GdkDragContext* context,
                                                                       gpointer self);
static void _slingshot_widgets_app_button___lambda42_ (SlingshotWidgetsAppButton* self);
static void __slingshot_widgets_app_button___lambda42__gtk_widget_drag_end (GtkWidget* _sender,
                                                                     GdkDragContext* context,
                                                                     gpointer self);
static void _slingshot_widgets_app_button___lambda43_ (SlingshotWidgetsAppButton* self,
                                                GdkDragContext* ctx,
                                                GtkSelectionData* sel,
                                                guint info,
                                                guint time);
static void __slingshot_widgets_app_button___lambda43__gtk_widget_drag_data_get (GtkWidget* _sender,
                                                                          GdkDragContext* context,
                                                                          GtkSelectionData* selection_data,
                                                                          guint info,
                                                                          guint time_,
                                                                          gpointer self);
static void _slingshot_widgets_app_button_update_badge_count_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self);
static void _slingshot_widgets_app_button_update_badge_visibility_g_object_notify (GObject* _sender,
                                                                            GParamSpec* pspec,
                                                                            gpointer self);
static void slingshot_widgets_app_button_finalize (GObject * obj);
static GType slingshot_widgets_app_button_get_type_once (void);
static void _vala_slingshot_widgets_app_button_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_slingshot_widgets_app_button_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec);
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);

static inline gpointer
slingshot_widgets_app_button_get_instance_private (SlingshotWidgetsAppButton* self)
{
	return G_STRUCT_MEMBER_P (self, SlingshotWidgetsAppButton_private_offset);
}

SlingshotWidgetsAppButton*
slingshot_widgets_app_button_construct (GType object_type,
                                        SlingshotBackendApp* app)
{
	SlingshotWidgetsAppButton * self = NULL;
	g_return_val_if_fail (app != NULL, NULL);
	self = (SlingshotWidgetsAppButton*) g_object_new (object_type, "app", app, NULL);
	return self;
}

SlingshotWidgetsAppButton*
slingshot_widgets_app_button_new (SlingshotBackendApp* app)
{
	return slingshot_widgets_app_button_construct (SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, app);
}

void
slingshot_widgets_app_button_launch_app (SlingshotWidgetsAppButton* self)
{
	SlingshotBackendApp* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app;
	slingshot_backend_app_launch (_tmp0_);
}

static void
slingshot_widgets_app_button_update_badge_count (SlingshotWidgetsAppButton* self)
{
	SlingshotBackendApp* _tmp0_;
	gint64 _tmp1_;
	gint64 _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_app;
	_tmp1_ = slingshot_backend_app_get_current_count (_tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ > ((gint64) 999)) {
		GtkLabel* _tmp3_;
		_tmp3_ = self->priv->badge;
		gtk_label_set_label (_tmp3_, "999+");
	} else {
		GtkLabel* _tmp4_;
		SlingshotBackendApp* _tmp5_;
		gint64 _tmp6_;
		gint64 _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		_tmp4_ = self->priv->badge;
		_tmp5_ = self->priv->_app;
		_tmp6_ = slingshot_backend_app_get_current_count (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = g_strdup_printf ("%lld", _tmp7_);
		_tmp9_ = _tmp8_;
		gtk_label_set_label (_tmp4_, _tmp9_);
		_g_free0 (_tmp9_);
	}
	slingshot_widgets_app_button_update_badge_visibility (self);
}

static void
slingshot_widgets_app_button_update_badge_visibility (SlingshotWidgetsAppButton* self)
{
	gboolean _tmp0_ = FALSE;
	SlingshotBackendApp* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	gboolean count_visible = FALSE;
	GtkLabel* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_app;
	_tmp2_ = slingshot_backend_app_get_count_visible (_tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		SlingshotBackendApp* _tmp4_;
		gint64 _tmp5_;
		gint64 _tmp6_;
		_tmp4_ = self->priv->_app;
		_tmp5_ = slingshot_backend_app_get_current_count (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = _tmp6_ > ((gint64) 0);
	} else {
		_tmp0_ = FALSE;
	}
	count_visible = _tmp0_;
	_tmp7_ = self->priv->badge;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp7_, !count_visible);
	if (count_visible) {
		GtkLabel* _tmp8_;
		_tmp8_ = self->priv->badge;
		gtk_widget_show_all ((GtkWidget*) _tmp8_);
	} else {
		GtkLabel* _tmp9_;
		_tmp9_ = self->priv->badge;
		gtk_widget_hide ((GtkWidget*) _tmp9_);
	}
}

SlingshotBackendApp*
slingshot_widgets_app_button_get_app (SlingshotWidgetsAppButton* self)
{
	SlingshotBackendApp* result;
	SlingshotBackendApp* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_app;
	result = _tmp0_;
	return result;
}

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

static void
slingshot_widgets_app_button_set_app (SlingshotWidgetsAppButton* self,
                                      SlingshotBackendApp* value)
{
	SlingshotBackendApp* old_value;
	g_return_if_fail (self != NULL);
	old_value = slingshot_widgets_app_button_get_app (self);
	if (old_value != value) {
		SlingshotBackendApp* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_app);
		self->priv->_app = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, slingshot_widgets_app_button_properties[SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY]);
	}
}

static void
_slingshot_widgets_app_button___lambda38_ (SlingshotWidgetsAppButton* self)
{
	g_signal_emit (self, slingshot_widgets_app_button_signals[SLINGSHOT_WIDGETS_APP_BUTTON_APP_LAUNCHED_SIGNAL], 0);
}

static void
__slingshot_widgets_app_button___lambda38__slingshot_backend_app_launched (SlingshotBackendApp* _sender,
                                                                           SlingshotBackendApp* app,
                                                                           gpointer self)
{
	_slingshot_widgets_app_button___lambda38_ ((SlingshotWidgetsAppButton*) self);
}

static void
_slingshot_widgets_app_button_launch_app_gtk_button_clicked (GtkButton* _sender,
                                                             gpointer self)
{
	slingshot_widgets_app_button_launch_app ((SlingshotWidgetsAppButton*) self);
}

static GdkEvent*
_vala_GdkEvent_copy (GdkEvent* self)
{
	return g_boxed_copy (gdk_event_get_type (), self);
}

static gpointer
__vala_GdkEvent_copy0 (gpointer self)
{
	return self ? _vala_GdkEvent_copy (self) : NULL;
}

static void
_vala_GdkEvent_free (GdkEvent* self)
{
	g_boxed_free (gdk_event_get_type (), self);
}

static void
_vala_GdkEventSequence_free (GdkEventSequence* self)
{
	g_boxed_free (gdk_event_sequence_get_type (), self);
}

static void
_slingshot_widgets_app_button___lambda39_ (SlingshotWidgetsAppButton* self,
                                           gint n_press,
                                           gdouble x,
                                           gdouble y)
{
	GdkEventSequence* sequence = NULL;
	GtkGestureMultiPress* _tmp0_;
	GdkEventSequence* _tmp1_;
	GdkEvent* event = NULL;
	GtkGestureMultiPress* _tmp2_;
	GdkEventSequence* _tmp3_;
	GdkEvent* _tmp4_;
	GdkEvent* _tmp5_;
	GdkEvent* _tmp6_;
	_tmp0_ = self->priv->click_controller;
	_tmp1_ = gtk_gesture_single_get_current_sequence ((GtkGestureSingle*) _tmp0_);
	sequence = _tmp1_;
	_tmp2_ = self->priv->click_controller;
	_tmp3_ = sequence;
	_tmp4_ = gtk_gesture_get_last_event ((GtkGesture*) _tmp2_, _tmp3_);
	_tmp5_ = __vala_GdkEvent_copy0 (_tmp4_);
	event = _tmp5_;
	_tmp6_ = event;
	if (gdk_event_triggers_context_menu (_tmp6_)) {
		GtkMenu* context_menu = NULL;
		SlingshotBackendApp* _tmp7_;
		GMenu* _tmp8_;
		GMenu* _tmp9_;
		GtkMenu* _tmp10_;
		GtkMenu* _tmp11_;
		GtkMenu* _tmp12_;
		SlingshotBackendApp* _tmp13_;
		GSimpleActionGroup* _tmp14_;
		GSimpleActionGroup* _tmp15_;
		GtkMenu* _tmp16_;
		GtkGestureMultiPress* _tmp17_;
		GtkGestureMultiPress* _tmp18_;
		_tmp7_ = self->priv->_app;
		_tmp8_ = slingshot_backend_app_get_menu_model (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = (GtkMenu*) gtk_menu_new_from_model ((GMenuModel*) _tmp9_);
		g_object_ref_sink (_tmp10_);
		_tmp11_ = _tmp10_;
		_g_object_unref0 (_tmp9_);
		context_menu = _tmp11_;
		_tmp12_ = context_menu;
		_tmp13_ = self->priv->_app;
		_tmp14_ = slingshot_backend_app_get_action_group (_tmp13_);
		_tmp15_ = _tmp14_;
		gtk_widget_insert_action_group ((GtkWidget*) _tmp12_, SLINGSHOT_BACKEND_APP_ACTION_GROUP_PREFIX, (GActionGroup*) _tmp15_);
		_tmp16_ = context_menu;
		gtk_menu_popup_at_pointer (_tmp16_, NULL);
		_tmp17_ = self->priv->click_controller;
		gtk_gesture_set_state ((GtkGesture*) _tmp17_, GTK_EVENT_SEQUENCE_CLAIMED);
		_tmp18_ = self->priv->click_controller;
		gtk_event_controller_reset ((GtkEventController*) _tmp18_);
		_g_object_unref0 (context_menu);
	}
	__vala_GdkEvent_free0 (event);
	__vala_GdkEventSequence_free0 (sequence);
}

static void
__slingshot_widgets_app_button___lambda39__gtk_gesture_multi_press_pressed (GtkGestureMultiPress* _sender,
                                                                            gint n_press,
                                                                            gdouble x,
                                                                            gdouble y,
                                                                            gpointer self)
{
	_slingshot_widgets_app_button___lambda39_ ((SlingshotWidgetsAppButton*) self, n_press, x, y);
}

static void
_slingshot_widgets_app_button___lambda40_ (SlingshotWidgetsAppButton* self,
                                           guint keyval,
                                           guint keycode,
                                           GdkModifierType state)
{
	GdkModifierType mods = 0U;
	mods = state & gtk_accelerator_get_default_mod_mask ();
	switch (keyval) {
		case GDK_KEY_F10:
		{
			if (mods == GDK_SHIFT_MASK) {
				GtkMenu* context_menu = NULL;
				SlingshotBackendApp* _tmp0_;
				GMenu* _tmp1_;
				GMenu* _tmp2_;
				GtkMenu* _tmp3_;
				GtkMenu* _tmp4_;
				GtkMenu* _tmp5_;
				SlingshotBackendApp* _tmp6_;
				GSimpleActionGroup* _tmp7_;
				GSimpleActionGroup* _tmp8_;
				GtkMenu* _tmp9_;
				_tmp0_ = self->priv->_app;
				_tmp1_ = slingshot_backend_app_get_menu_model (_tmp0_);
				_tmp2_ = _tmp1_;
				_tmp3_ = (GtkMenu*) gtk_menu_new_from_model ((GMenuModel*) _tmp2_);
				g_object_ref_sink (_tmp3_);
				_tmp4_ = _tmp3_;
				_g_object_unref0 (_tmp2_);
				context_menu = _tmp4_;
				_tmp5_ = context_menu;
				_tmp6_ = self->priv->_app;
				_tmp7_ = slingshot_backend_app_get_action_group (_tmp6_);
				_tmp8_ = _tmp7_;
				gtk_widget_insert_action_group ((GtkWidget*) _tmp5_, SLINGSHOT_BACKEND_APP_ACTION_GROUP_PREFIX, (GActionGroup*) _tmp8_);
				_tmp9_ = context_menu;
				gtk_menu_popup_at_widget (_tmp9_, (GtkWidget*) self, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, NULL);
				_g_object_unref0 (context_menu);
			}
			break;
		}
		case GDK_KEY_Menu:
		case GDK_KEY_MenuKB:
		{
			GtkMenu* context_menu = NULL;
			SlingshotBackendApp* _tmp10_;
			GMenu* _tmp11_;
			GMenu* _tmp12_;
			GtkMenu* _tmp13_;
			GtkMenu* _tmp14_;
			GtkMenu* _tmp15_;
			SlingshotBackendApp* _tmp16_;
			GSimpleActionGroup* _tmp17_;
			GSimpleActionGroup* _tmp18_;
			GtkMenu* _tmp19_;
			_tmp10_ = self->priv->_app;
			_tmp11_ = slingshot_backend_app_get_menu_model (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = (GtkMenu*) gtk_menu_new_from_model ((GMenuModel*) _tmp12_);
			g_object_ref_sink (_tmp13_);
			_tmp14_ = _tmp13_;
			_g_object_unref0 (_tmp12_);
			context_menu = _tmp14_;
			_tmp15_ = context_menu;
			_tmp16_ = self->priv->_app;
			_tmp17_ = slingshot_backend_app_get_action_group (_tmp16_);
			_tmp18_ = _tmp17_;
			gtk_widget_insert_action_group ((GtkWidget*) _tmp15_, SLINGSHOT_BACKEND_APP_ACTION_GROUP_PREFIX, (GActionGroup*) _tmp18_);
			_tmp19_ = context_menu;
			gtk_menu_popup_at_widget (_tmp19_, (GtkWidget*) self, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, NULL);
			_g_object_unref0 (context_menu);
			break;
		}
		default:
		{
			return;
		}
	}
}

static void
__slingshot_widgets_app_button___lambda40__gtk_event_controller_key_key_released (GtkEventControllerKey* _sender,
                                                                                  guint keyval,
                                                                                  guint keycode,
                                                                                  GdkModifierType state,
                                                                                  gpointer self)
{
	_slingshot_widgets_app_button___lambda40_ ((SlingshotWidgetsAppButton*) self, keyval, keycode, state);
}

static void
_slingshot_widgets_app_button___lambda41_ (SlingshotWidgetsAppButton* self,
                                           GdkDragContext* ctx)
{
	SlingshotBackendApp* _tmp0_;
	GIcon* _tmp1_;
	GIcon* _tmp2_;
	g_return_if_fail (ctx != NULL);
	self->priv->dragging = TRUE;
	_tmp0_ = self->priv->_app;
	_tmp1_ = slingshot_backend_app_get_icon (_tmp0_);
	_tmp2_ = _tmp1_;
	gtk_drag_set_icon_gicon (ctx, _tmp2_, 16, 16);
	g_signal_emit (self, slingshot_widgets_app_button_signals[SLINGSHOT_WIDGETS_APP_BUTTON_APP_LAUNCHED_SIGNAL], 0);
}

static void
__slingshot_widgets_app_button___lambda41__gtk_widget_drag_begin (GtkWidget* _sender,
                                                                  GdkDragContext* context,
                                                                  gpointer self)
{
	_slingshot_widgets_app_button___lambda41_ ((SlingshotWidgetsAppButton*) self, context);
}

static void
_slingshot_widgets_app_button___lambda42_ (SlingshotWidgetsAppButton* self)
{
	self->priv->dragging = FALSE;
}

static void
__slingshot_widgets_app_button___lambda42__gtk_widget_drag_end (GtkWidget* _sender,
                                                                GdkDragContext* context,
                                                                gpointer self)
{
	_slingshot_widgets_app_button___lambda42_ ((SlingshotWidgetsAppButton*) self);
}

static void
_slingshot_widgets_app_button___lambda43_ (SlingshotWidgetsAppButton* self,
                                           GdkDragContext* ctx,
                                           GtkSelectionData* sel,
                                           guint info,
                                           guint time)
{
	SlingshotBackendApp* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GFile* _tmp3_;
	GFile* _tmp4_;
	gchar* _tmp5_;
	gchar** _tmp6_;
	gchar** _tmp7_;
	gint _tmp7__length1;
	g_return_if_fail (ctx != NULL);
	g_return_if_fail (sel != NULL);
	_tmp0_ = self->priv->_app;
	_tmp1_ = slingshot_backend_app_get_desktop_path (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_file_new_for_path (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_file_get_uri (_tmp4_);
	_tmp6_ = g_new0 (gchar*, 1 + 1);
	_tmp6_[0] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 1;
	gtk_selection_data_set_uris (sel, _tmp7_);
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (_tmp4_);
}

static void
__slingshot_widgets_app_button___lambda43__gtk_widget_drag_data_get (GtkWidget* _sender,
                                                                     GdkDragContext* context,
                                                                     GtkSelectionData* selection_data,
                                                                     guint info,
                                                                     guint time_,
                                                                     gpointer self)
{
	_slingshot_widgets_app_button___lambda43_ ((SlingshotWidgetsAppButton*) self, context, selection_data, info, time_);
}

static void
_slingshot_widgets_app_button_update_badge_count_g_object_notify (GObject* _sender,
                                                                  GParamSpec* pspec,
                                                                  gpointer self)
{
	slingshot_widgets_app_button_update_badge_count ((SlingshotWidgetsAppButton*) self);
}

static void
_slingshot_widgets_app_button_update_badge_visibility_g_object_notify (GObject* _sender,
                                                                       GParamSpec* pspec,
                                                                       gpointer self)
{
	slingshot_widgets_app_button_update_badge_visibility ((SlingshotWidgetsAppButton*) self);
}

static GObject *
slingshot_widgets_app_button_constructor (GType type,
                                          guint n_construct_properties,
                                          GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SlingshotWidgetsAppButton * self;
	GtkTargetEntry dnd = {0};
	GtkTargetEntry _tmp0_ = {0};
	GtkTargetEntry _tmp1_;
	GtkTargetEntry* _tmp2_;
	GtkTargetEntry* _tmp3_;
	gint _tmp3__length1;
	SlingshotBackendApp* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	GtkStyleContext* _tmp7_;
	GtkLabel* app_label = NULL;
	SlingshotBackendApp* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	GtkLabel* _tmp11_ = NULL;
	GIcon* icon = NULL;
	SlingshotBackendApp* _tmp12_;
	GIcon* _tmp13_;
	GIcon* _tmp14_;
	GIcon* _tmp15_;
	GtkIconTheme* theme = NULL;
	GtkIconTheme* _tmp16_;
	gboolean _tmp17_ = FALSE;
	GIcon* _tmp18_;
	GtkImage* image = NULL;
	GIcon* _tmp24_;
	GtkImage* _tmp25_ = NULL;
	GtkLabel* _tmp26_ = NULL;
	GtkLabel* _tmp27_;
	GtkStyleContext* _tmp28_;
	GtkOverlay* overlay = NULL;
	GtkImage* _tmp29_;
	GtkWidget* _tmp30_;
	GtkOverlay* _tmp31_ = NULL;
	GtkOverlay* _tmp32_;
	GtkLabel* _tmp33_;
	GtkBox* box = NULL;
	GtkBox* _tmp34_ = NULL;
	GtkBox* _tmp35_;
	GtkOverlay* _tmp36_;
	GtkBox* _tmp37_;
	GtkLabel* _tmp38_;
	GtkBox* _tmp39_;
	SlingshotBackendApp* _tmp40_;
	GtkGestureMultiPress* _tmp41_ = NULL;
	GtkGestureMultiPress* _tmp42_;
	GtkEventControllerKey* _tmp43_;
	GtkEventControllerKey* _tmp44_;
	SlingshotBackendApp* _tmp45_;
	SlingshotBackendApp* _tmp46_;
	SlingshotBackendApp* _tmp47_;
	GtkImage* _tmp48_;
	parent_class = G_OBJECT_CLASS (slingshot_widgets_app_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, SlingshotWidgetsAppButton);
	_tmp0_.target = "text/uri-list";
	_tmp0_.flags = (guint) 0;
	_tmp0_.info = (guint) 0;
	dnd = _tmp0_;
	_tmp1_ = dnd;
	_tmp2_ = g_new0 (GtkTargetEntry, 1);
	_tmp2_[0] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 1;
	gtk_drag_source_set ((GtkWidget*) self, GDK_BUTTON1_MASK, _tmp3_, (gint) 1, GDK_ACTION_COPY);
	_tmp3_ = (g_free (_tmp3_), NULL);
	_tmp4_ = self->priv->_app;
	_tmp5_ = slingshot_backend_app_get_description (_tmp4_);
	_tmp6_ = _tmp5_;
	gtk_widget_set_tooltip_text ((GtkWidget*) self, _tmp6_);
	_tmp7_ = gtk_widget_get_style_context ((GtkWidget*) self);
	gtk_style_context_add_class (_tmp7_, GTK_STYLE_CLASS_FLAT);
	_tmp8_ = self->priv->_app;
	_tmp9_ = slingshot_backend_app_get_name (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = (GtkLabel*) gtk_label_new (_tmp10_);
	gtk_widget_set_halign ((GtkWidget*) _tmp11_, GTK_ALIGN_CENTER);
	gtk_label_set_ellipsize (_tmp11_, PANGO_ELLIPSIZE_END);
	gtk_label_set_justify (_tmp11_, GTK_JUSTIFY_CENTER);
	gtk_label_set_lines (_tmp11_, 2);
	gtk_label_set_max_width_chars (_tmp11_, 16);
	gtk_label_set_width_chars (_tmp11_, 16);
	g_object_set (_tmp11_, "wrap-mode", PANGO_WRAP_WORD_CHAR, NULL);
	g_object_ref_sink (_tmp11_);
	app_label = _tmp11_;
	_tmp12_ = self->priv->_app;
	_tmp13_ = slingshot_backend_app_get_icon (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = _g_object_ref0 (_tmp14_);
	icon = _tmp15_;
	_tmp16_ = gtk_icon_theme_get_default ();
	theme = _tmp16_;
	_tmp18_ = icon;
	if (_tmp18_ == NULL) {
		_tmp17_ = TRUE;
	} else {
		GtkIconTheme* _tmp19_;
		GIcon* _tmp20_;
		GtkIconInfo* _tmp21_;
		GtkIconInfo* _tmp22_;
		_tmp19_ = theme;
		_tmp20_ = icon;
		_tmp21_ = gtk_icon_theme_lookup_by_gicon (_tmp19_, _tmp20_, SLINGSHOT_WIDGETS_APP_BUTTON_ICON_SIZE, GTK_ICON_LOOKUP_USE_BUILTIN);
		_tmp22_ = _tmp21_;
		_tmp17_ = _tmp22_ == NULL;
		_g_object_unref0 (_tmp22_);
	}
	if (_tmp17_) {
		GThemedIcon* _tmp23_;
		_tmp23_ = (GThemedIcon*) g_themed_icon_new ("application-default-icon");
		_g_object_unref0 (icon);
		icon = (GIcon*) _tmp23_;
	}
	_tmp24_ = icon;
	_tmp25_ = (GtkImage*) gtk_image_new_from_gicon (_tmp24_, (GtkIconSize) SLINGSHOT_WIDGETS_APP_BUTTON_ICON_SIZE);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp25_, 9);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp25_, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp25_, 6);
	gtk_image_set_pixel_size (_tmp25_, SLINGSHOT_WIDGETS_APP_BUTTON_ICON_SIZE);
	g_object_ref_sink (_tmp25_);
	image = _tmp25_;
	_tmp26_ = (GtkLabel*) gtk_label_new ("!");
	gtk_widget_set_halign ((GtkWidget*) _tmp26_, GTK_ALIGN_END);
	gtk_widget_set_valign ((GtkWidget*) _tmp26_, GTK_ALIGN_START);
	gtk_widget_set_visible ((GtkWidget*) _tmp26_, FALSE);
	g_object_ref_sink (_tmp26_);
	_g_object_unref0 (self->priv->badge);
	self->priv->badge = _tmp26_;
	_tmp27_ = self->priv->badge;
	_tmp28_ = gtk_widget_get_style_context ((GtkWidget*) _tmp27_);
	gtk_style_context_add_class (_tmp28_, GRANITE_STYLE_CLASS_BADGE);
	_tmp29_ = image;
	_tmp30_ = _g_object_ref0 ((GtkWidget*) _tmp29_);
	_tmp31_ = (GtkOverlay*) gtk_overlay_new ();
	g_object_set ((GtkContainer*) _tmp31_, "child", _tmp30_, NULL);
	_g_object_unref0 (_tmp30_);
	gtk_widget_set_halign ((GtkWidget*) _tmp31_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp31_);
	overlay = _tmp31_;
	_tmp32_ = overlay;
	_tmp33_ = self->priv->badge;
	gtk_overlay_add_overlay (_tmp32_, (GtkWidget*) _tmp33_);
	_tmp34_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	gtk_widget_set_halign ((GtkWidget*) _tmp34_, GTK_ALIGN_CENTER);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp34_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp34_, TRUE);
	g_object_ref_sink (_tmp34_);
	box = _tmp34_;
	_tmp35_ = box;
	_tmp36_ = overlay;
	gtk_container_add ((GtkContainer*) _tmp35_, (GtkWidget*) _tmp36_);
	_tmp37_ = box;
	_tmp38_ = app_label;
	gtk_container_add ((GtkContainer*) _tmp37_, (GtkWidget*) _tmp38_);
	_tmp39_ = box;
	g_object_set ((GtkContainer*) self, "child", (GtkWidget*) _tmp39_, NULL);
	_tmp40_ = self->priv->_app;
	g_signal_connect_object (_tmp40_, "launched", (GCallback) __slingshot_widgets_app_button___lambda38__slingshot_backend_app_launched, self, 0);
	g_signal_connect_object ((GtkButton*) self, "clicked", (GCallback) _slingshot_widgets_app_button_launch_app_gtk_button_clicked, self, 0);
	_tmp41_ = (GtkGestureMultiPress*) gtk_gesture_multi_press_new ((GtkWidget*) self);
	gtk_gesture_single_set_button ((GtkGestureSingle*) _tmp41_, (guint) 0);
	gtk_gesture_single_set_exclusive ((GtkGestureSingle*) _tmp41_, TRUE);
	_g_object_unref0 (self->priv->click_controller);
	self->priv->click_controller = _tmp41_;
	_tmp42_ = self->priv->click_controller;
	g_signal_connect_object (_tmp42_, "pressed", (GCallback) __slingshot_widgets_app_button___lambda39__gtk_gesture_multi_press_pressed, self, 0);
	_tmp43_ = (GtkEventControllerKey*) gtk_event_controller_key_new ((GtkWidget*) self);
	_g_object_unref0 (self->priv->menu_key_controller);
	self->priv->menu_key_controller = _tmp43_;
	_tmp44_ = self->priv->menu_key_controller;
	g_signal_connect_object (_tmp44_, "key-released", (GCallback) __slingshot_widgets_app_button___lambda40__gtk_event_controller_key_key_released, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "drag-begin", (GCallback) __slingshot_widgets_app_button___lambda41__gtk_widget_drag_begin, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "drag-end", (GCallback) __slingshot_widgets_app_button___lambda42__gtk_widget_drag_end, self, 0);
	g_signal_connect_object ((GtkWidget*) self, "drag-data-get", (GCallback) __slingshot_widgets_app_button___lambda43__gtk_widget_drag_data_get, self, 0);
	_tmp45_ = self->priv->_app;
	g_signal_connect_object ((GObject*) _tmp45_, "notify::current-count", (GCallback) _slingshot_widgets_app_button_update_badge_count_g_object_notify, self, 0);
	_tmp46_ = self->priv->_app;
	g_signal_connect_object ((GObject*) _tmp46_, "notify::count-visible", (GCallback) _slingshot_widgets_app_button_update_badge_visibility_g_object_notify, self, 0);
	slingshot_widgets_app_button_update_badge_count (self);
	_tmp47_ = self->priv->_app;
	_tmp48_ = image;
	g_object_bind_property_with_closures ((GObject*) _tmp47_, "icon", (GObject*) _tmp48_, "gicon", G_BINDING_DEFAULT, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_g_object_unref0 (box);
	_g_object_unref0 (overlay);
	_g_object_unref0 (image);
	_g_object_unref0 (icon);
	_g_object_unref0 (app_label);
	return obj;
}

static void
slingshot_widgets_app_button_class_init (SlingshotWidgetsAppButtonClass * klass,
                                         gpointer klass_data)
{
	slingshot_widgets_app_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SlingshotWidgetsAppButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_slingshot_widgets_app_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_slingshot_widgets_app_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = slingshot_widgets_app_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = slingshot_widgets_app_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY, slingshot_widgets_app_button_properties[SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY] = g_param_spec_object ("app", "app", "app", SLINGSHOT_BACKEND_TYPE_APP, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	slingshot_widgets_app_button_signals[SLINGSHOT_WIDGETS_APP_BUTTON_APP_LAUNCHED_SIGNAL] = g_signal_new ("app-launched", SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
slingshot_widgets_app_button_instance_init (SlingshotWidgetsAppButton * self,
                                            gpointer klass)
{
	self->priv = slingshot_widgets_app_button_get_instance_private (self);
	self->priv->dragging = FALSE;
}

static void
slingshot_widgets_app_button_finalize (GObject * obj)
{
	SlingshotWidgetsAppButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, SlingshotWidgetsAppButton);
	_g_object_unref0 (self->priv->_app);
	_g_object_unref0 (self->priv->badge);
	_g_object_unref0 (self->priv->click_controller);
	_g_object_unref0 (self->priv->menu_key_controller);
	G_OBJECT_CLASS (slingshot_widgets_app_button_parent_class)->finalize (obj);
}

static GType
slingshot_widgets_app_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SlingshotWidgetsAppButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) slingshot_widgets_app_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SlingshotWidgetsAppButton), 0, (GInstanceInitFunc) slingshot_widgets_app_button_instance_init, NULL };
	GType slingshot_widgets_app_button_type_id;
	slingshot_widgets_app_button_type_id = g_type_register_static (gtk_button_get_type (), "SlingshotWidgetsAppButton", &g_define_type_info, 0);
	SlingshotWidgetsAppButton_private_offset = g_type_add_instance_private (slingshot_widgets_app_button_type_id, sizeof (SlingshotWidgetsAppButtonPrivate));
	return slingshot_widgets_app_button_type_id;
}

GType
slingshot_widgets_app_button_get_type (void)
{
	static volatile gsize slingshot_widgets_app_button_type_id__once = 0;
	if (g_once_init_enter (&slingshot_widgets_app_button_type_id__once)) {
		GType slingshot_widgets_app_button_type_id;
		slingshot_widgets_app_button_type_id = slingshot_widgets_app_button_get_type_once ();
		g_once_init_leave (&slingshot_widgets_app_button_type_id__once, slingshot_widgets_app_button_type_id);
	}
	return slingshot_widgets_app_button_type_id__once;
}

static void
_vala_slingshot_widgets_app_button_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	SlingshotWidgetsAppButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, SlingshotWidgetsAppButton);
	switch (property_id) {
		case SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY:
		g_value_set_object (value, slingshot_widgets_app_button_get_app (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_slingshot_widgets_app_button_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	SlingshotWidgetsAppButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, SLINGSHOT_WIDGETS_TYPE_APP_BUTTON, SlingshotWidgetsAppButton);
	switch (property_id) {
		case SLINGSHOT_WIDGETS_APP_BUTTON_APP_PROPERTY:
		slingshot_widgets_app_button_set_app (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

