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

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

#define DC_WEBXDC_AVAILABLE TRUE
#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 DC_TYPE_WEBXDC_APPS_BAR (dc_webxdc_apps_bar_get_type ())
#define DC_WEBXDC_APPS_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBar))
#define DC_WEBXDC_APPS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBarClass))
#define DC_IS_WEBXDC_APPS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_WEBXDC_APPS_BAR))
#define DC_IS_WEBXDC_APPS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_WEBXDC_APPS_BAR))
#define DC_WEBXDC_APPS_BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBarClass))

typedef struct _DcWebxdcAppsBar DcWebxdcAppsBar;
typedef struct _DcWebxdcAppsBarClass DcWebxdcAppsBarClass;
typedef struct _DcWebxdcAppsBarPrivate DcWebxdcAppsBarPrivate;

#define DC_TYPE_RPC_CLIENT (dc_rpc_client_get_type ())
#define DC_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_RPC_CLIENT, DcRpcClient))
#define DC_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_RPC_CLIENT, DcRpcClientClass))
#define DC_IS_RPC_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_RPC_CLIENT))
#define DC_IS_RPC_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_RPC_CLIENT))
#define DC_RPC_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_RPC_CLIENT, DcRpcClientClass))

typedef struct _DcRpcClient DcRpcClient;
typedef struct _DcRpcClientClass DcRpcClientClass;

#define DC_TYPE_PINNED_MESSAGES_MANAGER (dc_pinned_messages_manager_get_type ())
#define DC_PINNED_MESSAGES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManager))
#define DC_PINNED_MESSAGES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManagerClass))
#define DC_IS_PINNED_MESSAGES_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER))
#define DC_IS_PINNED_MESSAGES_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_PINNED_MESSAGES_MANAGER))
#define DC_PINNED_MESSAGES_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_PINNED_MESSAGES_MANAGER, DcPinnedMessagesManagerClass))

typedef struct _DcPinnedMessagesManager DcPinnedMessagesManager;
typedef struct _DcPinnedMessagesManagerClass DcPinnedMessagesManagerClass;
enum  {
	DC_WEBXDC_APPS_BAR_0_PROPERTY,
	DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY,
	DC_WEBXDC_APPS_BAR_NUM_PROPERTIES
};
static GParamSpec* dc_webxdc_apps_bar_properties[DC_WEBXDC_APPS_BAR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block79Data Block79Data;

#define DC_WEBXDC_TYPE_MONITOR (dc_webxdc_monitor_get_type ())
#define DC_WEBXDC_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitor))
#define DC_WEBXDC_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitorClass))
#define DC_WEBXDC_IS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_WEBXDC_TYPE_MONITOR))
#define DC_WEBXDC_IS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_WEBXDC_TYPE_MONITOR))
#define DC_WEBXDC_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_WEBXDC_TYPE_MONITOR, DcWebxdcMonitorClass))

typedef struct _DcWebxdcMonitor DcWebxdcMonitor;
typedef struct _DcWebxdcMonitorClass DcWebxdcMonitorClass;

#define DC_WEBXDC_TYPE_CARD_INFO (dc_webxdc_card_info_get_type ())
#define DC_WEBXDC_CARD_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfo))
#define DC_WEBXDC_CARD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfoClass))
#define DC_WEBXDC_IS_CARD_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_WEBXDC_TYPE_CARD_INFO))
#define DC_WEBXDC_IS_CARD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_WEBXDC_TYPE_CARD_INFO))
#define DC_WEBXDC_CARD_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_WEBXDC_TYPE_CARD_INFO, DcWebxdcCardInfoClass))

typedef struct _DcWebxdcCardInfo DcWebxdcCardInfo;
typedef struct _DcWebxdcCardInfoClass DcWebxdcCardInfoClass;
#define _dc_webxdc_card_info_unref0(var) ((var == NULL) ? NULL : (var = (dc_webxdc_card_info_unref (var), NULL)))
typedef struct _DcWebxdcAppsBarLoadForChatData DcWebxdcAppsBarLoadForChatData;
typedef struct _Block80Data Block80Data;
typedef struct _DcWebxdcCardInfoPrivate DcWebxdcCardInfoPrivate;
typedef struct _Block81Data Block81Data;

#define DC_TYPE_POPOVER_BUTTON (dc_popover_button_get_type ())
#define DC_POPOVER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_POPOVER_BUTTON, DcPopoverButton))
#define DC_POPOVER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_POPOVER_BUTTON, DcPopoverButtonClass))
#define DC_IS_POPOVER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_POPOVER_BUTTON))
#define DC_IS_POPOVER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_POPOVER_BUTTON))
#define DC_POPOVER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_POPOVER_BUTTON, DcPopoverButtonClass))

typedef struct _DcPopoverButton DcPopoverButton;
typedef struct _DcPopoverButtonClass DcPopoverButtonClass;
enum  {
	DC_WEBXDC_APPS_BAR_SCROLL_REQUESTED_SIGNAL,
	DC_WEBXDC_APPS_BAR_FORWARD_REQUESTED_SIGNAL,
	DC_WEBXDC_APPS_BAR_SAVE_REQUESTED_SIGNAL,
	DC_WEBXDC_APPS_BAR_NUM_SIGNALS
};
static guint dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_NUM_SIGNALS] = {0};

struct _DcWebxdcAppsBar {
	GObject parent_instance;
	DcWebxdcAppsBarPrivate * priv;
};

struct _DcWebxdcAppsBarClass {
	GObjectClass parent_class;
};

struct _DcWebxdcAppsBarPrivate {
	GtkRevealer* _revealer;
	DcRpcClient* rpc;
	DcPinnedMessagesManager* pinned;
	GtkBox* bar_content;
	gint chat_id;
	guint load_generation;
	gulong monitor_handler;
	gboolean closed;
};

struct _Block79Data {
	int _ref_count_;
	GWeakRef bar_ref;
};

struct _DcWebxdcAppsBarLoadForChatData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcWebxdcAppsBar* self;
	gint chat_id;
	guint generation;
	guint _tmp0_;
	gboolean _tmp1_;
	gboolean _tmp2_;
	DcRpcClient* _tmp3_;
	gint* app_ids;
	DcRpcClient* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	gint* _tmp8_;
	gint app_ids_length1;
	gint _app_ids_size_;
	gint* _tmp9_;
	gint _tmp9__length1;
	GtkBox* next_content;
	GtkBox* _tmp10_;
	GtkBox* _tmp11_;
	gint* _tmp12_;
	gint _tmp12__length1;
	gint* app_id_collection;
	gint app_id_collection_length1;
	gint _app_id_collection_size_;
	gint app_id_it;
	gint app_id;
	DcWebxdcCardInfo* info;
	DcWebxdcCardInfo* _tmp13_;
	gboolean _tmp14_;
	GtkBox* _tmp15_;
	DcWebxdcCardInfo* _tmp16_;
	GtkWidget* _tmp17_;
	GtkWidget* _tmp18_;
	GtkBox* _tmp19_;
	GtkWidget* _tmp20_;
	GtkBox* _tmp21_;
	GtkBox* _tmp22_;
	GtkRevealer* _tmp23_;
	GtkBox* _tmp24_;
	GtkBox* _tmp25_;
	GtkRevealer* _tmp26_;
};

struct _Block80Data {
	int _ref_count_;
	DcWebxdcAppsBar* self;
	GtkBox* box;
	gint msg_id;
};

struct _DcWebxdcCardInfo {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DcWebxdcCardInfoPrivate * priv;
	gchar* name;
	GdkTexture* icon;
};

struct _DcWebxdcCardInfoClass {
	GTypeClass parent_class;
	void (*finalize) (DcWebxdcCardInfo *self);
};

struct _Block81Data {
	int _ref_count_;
	DcWebxdcAppsBar* self;
	gint msg_id;
};

static gint DcWebxdcAppsBar_private_offset;
static gpointer dc_webxdc_apps_bar_parent_class = NULL;

VALA_EXTERN GType dc_webxdc_apps_bar_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcAppsBar, g_object_unref)
VALA_EXTERN GType dc_rpc_client_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcRpcClient, g_object_unref)
VALA_EXTERN GType dc_pinned_messages_manager_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPinnedMessagesManager, g_object_unref)
VALA_EXTERN DcWebxdcAppsBar* dc_webxdc_apps_bar_new (void);
VALA_EXTERN DcWebxdcAppsBar* dc_webxdc_apps_bar_construct (GType object_type);
static void dc_webxdc_apps_bar_set_revealer (DcWebxdcAppsBar* self,
                                      GtkRevealer* value);
VALA_EXTERN GtkRevealer* dc_webxdc_apps_bar_get_revealer (DcWebxdcAppsBar* self);
static void __lambda56_ (DcWebxdcAppsBar* self);
static void ___lambda56__g_object_notify (GObject* _sender,
                                   GParamSpec* pspec,
                                   gpointer self);
static gulong dc_webxdc_apps_bar_connect_monitor (DcWebxdcAppsBar* target);
static Block79Data* block79_data_ref (Block79Data* _data79_);
static void block79_data_unref (void * _userdata_);
VALA_EXTERN GType dc_webxdc_monitor_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcMonitor, g_object_unref)
VALA_EXTERN DcWebxdcMonitor* dc_webxdc_monitor_get_default (void);
static void __lambda57_ (Block79Data* _data79_,
                  gint msg_id);
VALA_EXTERN void dc_webxdc_apps_bar_load_for_chat (DcWebxdcAppsBar* self,
                                       gint chat_id,
                                       GAsyncReadyCallback _callback_,
                                       gpointer _user_data_);
VALA_EXTERN void dc_webxdc_apps_bar_load_for_chat_finish (DcWebxdcAppsBar* self,
                                              GAsyncResult* _res_);
static void ___lambda57__dc_webxdc_monitor_changed (DcWebxdcMonitor* _sender,
                                             gint msg_id,
                                             gpointer self);
VALA_EXTERN void dc_webxdc_apps_bar_set_rpc (DcWebxdcAppsBar* self,
                                 DcRpcClient* r);
VALA_EXTERN void dc_webxdc_apps_bar_set_pinned (DcWebxdcAppsBar* self,
                                    DcPinnedMessagesManager* p);
static void dc_webxdc_apps_bar_load_for_chat_data_free (gpointer _data);
static gboolean dc_webxdc_apps_bar_load_for_chat_co (DcWebxdcAppsBarLoadForChatData* _data_);
static void dc_webxdc_apps_bar_hide_bar (DcWebxdcAppsBar* self);
VALA_EXTERN gint* dc_webxdc_running_apps (gint account_id,
                              gint chat_id,
                              gint* result_length1);
VALA_EXTERN gint dc_rpc_client_get_account_id (DcRpcClient* self);
VALA_EXTERN gpointer dc_webxdc_card_info_ref (gpointer instance);
VALA_EXTERN void dc_webxdc_card_info_unref (gpointer instance);
VALA_EXTERN GParamSpec* dc_webxdc_param_spec_card_info (const gchar* name,
                                            const gchar* nick,
                                            const gchar* blurb,
                                            GType object_type,
                                            GParamFlags flags);
VALA_EXTERN void dc_webxdc_value_set_card_info (GValue* value,
                                    gpointer v_object);
VALA_EXTERN void dc_webxdc_value_take_card_info (GValue* value,
                                     gpointer v_object);
VALA_EXTERN gpointer dc_webxdc_value_get_card_info (const GValue* value);
VALA_EXTERN GType dc_webxdc_card_info_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcWebxdcCardInfo, dc_webxdc_card_info_unref)
VALA_EXTERN void dc_webxdc_card_info (gint msg_id,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_);
VALA_EXTERN DcWebxdcCardInfo* dc_webxdc_card_info_finish (GAsyncResult* _res_);
static void dc_webxdc_apps_bar_load_for_chat_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
VALA_EXTERN gboolean dc_webxdc_is_running (gint msg_id);
static GtkWidget* dc_webxdc_apps_bar_build_row (DcWebxdcAppsBar* self,
                                         gint msg_id,
                                         DcWebxdcCardInfo* info);
static Block80Data* block80_data_ref (Block80Data* _data80_);
static void block80_data_unref (void * _userdata_);
static void __lambda61_ (Block80Data* _data80_);
VALA_EXTERN void dc_webxdc_present_app (gint msg_id);
static void ___lambda61__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static GtkButton* dc_webxdc_apps_bar_bar_button (const gchar* icon_name,
                                          const gchar* tooltip);
static void __lambda62_ (Block80Data* _data80_);
VALA_EXTERN void dc_webxdc_minimize_app (gint msg_id);
static void ___lambda62__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda63_ (Block80Data* _data80_);
VALA_EXTERN void dc_webxdc_stop_app (gint msg_id);
static void ___lambda63__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void __lambda64_ (Block80Data* _data80_,
                  gint n_press,
                  gdouble x,
                  gdouble y);
static void dc_webxdc_apps_bar_show_context_menu (DcWebxdcAppsBar* self,
                                           GtkWidget* parent,
                                           gint msg_id,
                                           gdouble x,
                                           gdouble y);
static void ___lambda64__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                             gint n_press,
                                             gdouble x,
                                             gdouble y,
                                             gpointer self);
static Block81Data* block81_data_ref (Block81Data* _data81_);
static void block81_data_unref (void * _userdata_);
VALA_EXTERN GtkPopover* dc_popover_menu (GtkWidget* parent,
                             gdouble x,
                             gdouble y,
                             GtkBox** vbox);
VALA_EXTERN GType dc_popover_button_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcPopoverButton, g_object_unref)
VALA_EXTERN DcPopoverButton* dc_popover_button_new (GtkPopover* popover,
                                        const gchar* label,
                                        gboolean destructive,
                                        gboolean hexpand);
VALA_EXTERN DcPopoverButton* dc_popover_button_construct (GType object_type,
                                              GtkPopover* popover,
                                              const gchar* label,
                                              gboolean destructive,
                                              gboolean hexpand);
static void __lambda67_ (Block81Data* _data81_);
static void ___lambda67__dc_popover_button_selected (DcPopoverButton* _sender,
                                              gpointer self);
static void __lambda68_ (Block81Data* _data81_);
static void ___lambda68__dc_popover_button_selected (DcPopoverButton* _sender,
                                              gpointer self);
static void __lambda69_ (Block81Data* _data81_);
static void ___lambda69__dc_popover_button_selected (DcPopoverButton* _sender,
                                              gpointer self);
VALA_EXTERN gboolean dc_pinned_messages_manager_is_pinned (DcPinnedMessagesManager* self,
                                               gint msg_id);
static void ___lambda70_ (Block81Data* _data81_);
VALA_EXTERN void dc_pinned_messages_manager_toggle_pin (DcPinnedMessagesManager* self,
                                            gint msg_id,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN void dc_pinned_messages_manager_toggle_pin_finish (DcPinnedMessagesManager* self,
                                                   GAsyncResult* _res_);
static void ____lambda70__dc_popover_button_selected (DcPopoverButton* _sender,
                                               gpointer self);
static void __lambda71_ (Block81Data* _data81_);
static void ___lambda71__dc_popover_button_selected (DcPopoverButton* _sender,
                                              gpointer self);
VALA_EXTERN void dc_webxdc_apps_bar_close (DcWebxdcAppsBar* self);
static void dc_webxdc_apps_bar_real_dispose (GObject* base);
static void dc_webxdc_apps_bar_finalize (GObject * obj);
static GType dc_webxdc_apps_bar_get_type_once (void);
static void _vala_dc_webxdc_apps_bar_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);
static void _vala_dc_webxdc_apps_bar_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_webxdc_apps_bar_get_instance_private (DcWebxdcAppsBar* self)
{
	return G_STRUCT_MEMBER_P (self, DcWebxdcAppsBar_private_offset);
}

static void
__lambda56_ (DcWebxdcAppsBar* self)
{
	gboolean _tmp0_ = FALSE;
	GtkRevealer* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	_tmp1_ = self->priv->_revealer;
	_tmp2_ = gtk_revealer_get_reveal_child (_tmp1_);
	_tmp3_ = _tmp2_;
	if (!_tmp3_) {
		GtkRevealer* _tmp4_;
		gboolean _tmp5_;
		gboolean _tmp6_;
		_tmp4_ = self->priv->_revealer;
		_tmp5_ = gtk_revealer_get_child_revealed (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = !_tmp6_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GtkRevealer* _tmp7_;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		_tmp7_ = self->priv->_revealer;
		_tmp8_ = gtk_revealer_get_child (_tmp7_);
		_tmp9_ = _tmp8_;
		gtk_widget_set_visible (_tmp9_, FALSE);
	}
}

static void
___lambda56__g_object_notify (GObject* _sender,
                              GParamSpec* pspec,
                              gpointer self)
{
	__lambda56_ ((DcWebxdcAppsBar*) self);
}

DcWebxdcAppsBar*
dc_webxdc_apps_bar_construct (GType object_type)
{
	DcWebxdcAppsBar * self = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkRevealer* _tmp2_;
	GtkRevealer* _tmp3_;
	GtkRevealer* _tmp4_;
	GtkBox* _tmp5_;
	GtkRevealer* _tmp6_;
	GtkRevealer* _tmp7_;
	GtkBox* _tmp8_;
	GtkRevealer* _tmp9_;
	self = (DcWebxdcAppsBar*) g_object_new (object_type, NULL);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->bar_content);
	self->priv->bar_content = _tmp0_;
	_tmp1_ = self->priv->bar_content;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "webxdc-bar");
	_tmp2_ = (GtkRevealer*) gtk_revealer_new ();
	g_object_ref_sink (_tmp2_);
	_tmp3_ = _tmp2_;
	dc_webxdc_apps_bar_set_revealer (self, _tmp3_);
	_g_object_unref0 (_tmp3_);
	_tmp4_ = self->priv->_revealer;
	_tmp5_ = self->priv->bar_content;
	gtk_revealer_set_child (_tmp4_, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->_revealer;
	gtk_revealer_set_reveal_child (_tmp6_, FALSE);
	_tmp7_ = self->priv->_revealer;
	gtk_revealer_set_transition_type (_tmp7_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	_tmp8_ = self->priv->bar_content;
	gtk_widget_set_visible ((GtkWidget*) _tmp8_, FALSE);
	_tmp9_ = self->priv->_revealer;
	g_signal_connect_object ((GObject*) _tmp9_, "notify::child-revealed", (GCallback) ___lambda56__g_object_notify, self, 0);
	self->priv->monitor_handler = dc_webxdc_apps_bar_connect_monitor (self);
	return self;
}

DcWebxdcAppsBar*
dc_webxdc_apps_bar_new (void)
{
	return dc_webxdc_apps_bar_construct (DC_TYPE_WEBXDC_APPS_BAR);
}

static Block79Data*
block79_data_ref (Block79Data* _data79_)
{
	g_atomic_int_inc (&_data79_->_ref_count_);
	return _data79_;
}

static void
block79_data_unref (void * _userdata_)
{
	Block79Data* _data79_;
	_data79_ = (Block79Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data79_->_ref_count_)) {
		g_weak_ref_clear (&_data79_->bar_ref);
		g_slice_free (Block79Data, _data79_);
	}
}

static void
__lambda57_ (Block79Data* _data79_,
             gint msg_id)
{
	DcWebxdcAppsBar* bar = NULL;
	GObject* _tmp0_;
	DcWebxdcAppsBar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	DcWebxdcAppsBar* _tmp3_;
	_tmp0_ = g_weak_ref_get (&_data79_->bar_ref);
	_tmp1_ = DC_IS_WEBXDC_APPS_BAR (_tmp0_) ? ((DcWebxdcAppsBar*) _tmp0_) : NULL;
	if (_tmp1_ == NULL) {
		_g_object_unref0 (_tmp0_);
	}
	bar = _tmp1_;
	_tmp3_ = bar;
	if (_tmp3_ != NULL) {
		DcWebxdcAppsBar* _tmp4_;
		_tmp4_ = bar;
		_tmp2_ = !_tmp4_->priv->closed;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		DcWebxdcAppsBar* _tmp5_;
		DcWebxdcAppsBar* _tmp6_;
		_tmp5_ = bar;
		_tmp6_ = bar;
		dc_webxdc_apps_bar_load_for_chat (_tmp5_, _tmp6_->priv->chat_id, NULL, NULL);
	}
	_g_object_unref0 (bar);
}

static void
___lambda57__dc_webxdc_monitor_changed (DcWebxdcMonitor* _sender,
                                        gint msg_id,
                                        gpointer self)
{
	__lambda57_ (self, msg_id);
}

static gulong
dc_webxdc_apps_bar_connect_monitor (DcWebxdcAppsBar* target)
{
	Block79Data* _data79_;
	DcWebxdcMonitor* _tmp0_;
	DcWebxdcMonitor* _tmp1_;
	gulong _tmp2_;
	gulong _tmp3_;
	gulong result;
	g_return_val_if_fail (target != NULL, 0UL);
	_data79_ = g_slice_new0 (Block79Data);
	_data79_->_ref_count_ = 1;
	g_weak_ref_init (&_data79_->bar_ref, (GObject*) target);
	_tmp0_ = dc_webxdc_monitor_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = g_signal_connect_data (_tmp1_, "changed", (GCallback) ___lambda57__dc_webxdc_monitor_changed, block79_data_ref (_data79_), (GClosureNotify) block79_data_unref, 0);
	_tmp3_ = _tmp2_;
	_g_object_unref0 (_tmp1_);
	result = _tmp3_;
	block79_data_unref (_data79_);
	_data79_ = NULL;
	return result;
}

void
dc_webxdc_apps_bar_set_rpc (DcWebxdcAppsBar* self,
                            DcRpcClient* r)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (r != NULL);
	self->priv->rpc = r;
}

void
dc_webxdc_apps_bar_set_pinned (DcWebxdcAppsBar* self,
                               DcPinnedMessagesManager* p)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (p != NULL);
	self->priv->pinned = p;
}

static void
dc_webxdc_apps_bar_load_for_chat_data_free (gpointer _data)
{
	DcWebxdcAppsBarLoadForChatData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (DcWebxdcAppsBarLoadForChatData, _data_);
}

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

void
dc_webxdc_apps_bar_load_for_chat (DcWebxdcAppsBar* self,
                                  gint chat_id,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	DcWebxdcAppsBarLoadForChatData* _data_;
	DcWebxdcAppsBar* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DcWebxdcAppsBarLoadForChatData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_webxdc_apps_bar_load_for_chat_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->chat_id = chat_id;
	dc_webxdc_apps_bar_load_for_chat_co (_data_);
}

void
dc_webxdc_apps_bar_load_for_chat_finish (DcWebxdcAppsBar* self,
                                         GAsyncResult* _res_)
{
	DcWebxdcAppsBarLoadForChatData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_webxdc_apps_bar_load_for_chat_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	DcWebxdcAppsBarLoadForChatData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_webxdc_apps_bar_load_for_chat_co (_data_);
}

static gboolean
dc_webxdc_apps_bar_load_for_chat_co (DcWebxdcAppsBarLoadForChatData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->closed) {
		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;
	}
	_data_->self->priv->chat_id = _data_->chat_id;
	_data_->self->priv->load_generation = _data_->self->priv->load_generation + 1;
	_data_->_tmp0_ = _data_->self->priv->load_generation;
	_data_->generation = _data_->_tmp0_;
	if (_data_->chat_id <= 0) {
		_data_->_tmp2_ = TRUE;
	} else {
		_data_->_tmp2_ = !DC_WEBXDC_AVAILABLE;
	}
	if (_data_->_tmp2_) {
		_data_->_tmp1_ = TRUE;
	} else {
		_data_->_tmp3_ = _data_->self->priv->rpc;
		_data_->_tmp1_ = _data_->_tmp3_ == NULL;
	}
	if (_data_->_tmp1_) {
		dc_webxdc_apps_bar_hide_bar (_data_->self);
		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;
	}
	_data_->_tmp4_ = _data_->self->priv->rpc;
	_data_->_tmp5_ = dc_rpc_client_get_account_id (_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	_data_->_tmp7_ = 0;
	_data_->_tmp8_ = dc_webxdc_running_apps (_data_->_tmp6_, _data_->chat_id, &_data_->_tmp7_);
	_data_->app_ids = _data_->_tmp8_;
	_data_->app_ids_length1 = _data_->_tmp7_;
	_data_->_app_ids_size_ = _data_->app_ids_length1;
	_data_->_tmp9_ = _data_->app_ids;
	_data_->_tmp9__length1 = _data_->app_ids_length1;
	if (_data_->_tmp9__length1 == 0) {
		dc_webxdc_apps_bar_hide_bar (_data_->self);
		_data_->app_ids = (g_free (_data_->app_ids), 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;
	}
	_data_->_tmp10_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_data_->_tmp10_);
	_data_->next_content = _data_->_tmp10_;
	_data_->_tmp11_ = _data_->next_content;
	gtk_widget_add_css_class ((GtkWidget*) _data_->_tmp11_, "webxdc-bar");
	_data_->_tmp12_ = _data_->app_ids;
	_data_->_tmp12__length1 = _data_->app_ids_length1;
	{
		_data_->app_id_collection_length1 = 0;
		_data_->_app_id_collection_size_ = 0;
		_data_->app_id_collection = _data_->_tmp12_;
		_data_->app_id_collection_length1 = _data_->_tmp12__length1;
		for (_data_->app_id_it = 0; _data_->app_id_it < _data_->app_id_collection_length1; _data_->app_id_it = _data_->app_id_it + 1) {
			_data_->app_id = _data_->app_id_collection[_data_->app_id_it];
			{
				_data_->_state_ = 1;
				dc_webxdc_card_info (_data_->app_id, dc_webxdc_apps_bar_load_for_chat_ready, _data_);
				return FALSE;
				_state_1:
				_data_->_tmp13_ = dc_webxdc_card_info_finish (_data_->_res_);
				_data_->info = _data_->_tmp13_;
				if (_data_->self->priv->closed) {
					_data_->_tmp14_ = TRUE;
				} else {
					_data_->_tmp14_ = _data_->generation != _data_->self->priv->load_generation;
				}
				if (_data_->_tmp14_) {
					_dc_webxdc_card_info_unref0 (_data_->info);
					_g_object_unref0 (_data_->next_content);
					_data_->app_ids = (g_free (_data_->app_ids), 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;
				}
				if (!dc_webxdc_is_running (_data_->app_id)) {
					_dc_webxdc_card_info_unref0 (_data_->info);
					continue;
				}
				_data_->_tmp15_ = _data_->next_content;
				_data_->_tmp16_ = _data_->info;
				_data_->_tmp17_ = dc_webxdc_apps_bar_build_row (_data_->self, _data_->app_id, _data_->_tmp16_);
				_data_->_tmp18_ = _data_->_tmp17_;
				gtk_box_append (_data_->_tmp15_, _data_->_tmp18_);
				_g_object_unref0 (_data_->_tmp18_);
				_dc_webxdc_card_info_unref0 (_data_->info);
			}
		}
	}
	_data_->_tmp19_ = _data_->next_content;
	_data_->_tmp20_ = gtk_widget_get_first_child ((GtkWidget*) _data_->_tmp19_);
	if (_data_->_tmp20_ == NULL) {
		dc_webxdc_apps_bar_hide_bar (_data_->self);
		_g_object_unref0 (_data_->next_content);
		_data_->app_ids = (g_free (_data_->app_ids), 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;
	}
	_data_->_tmp21_ = _data_->next_content;
	_data_->_tmp22_ = _g_object_ref0 (_data_->_tmp21_);
	_g_object_unref0 (_data_->self->priv->bar_content);
	_data_->self->priv->bar_content = _data_->_tmp22_;
	_data_->_tmp23_ = _data_->self->priv->_revealer;
	_data_->_tmp24_ = _data_->self->priv->bar_content;
	gtk_revealer_set_child (_data_->_tmp23_, (GtkWidget*) _data_->_tmp24_);
	_data_->_tmp25_ = _data_->self->priv->bar_content;
	gtk_widget_set_visible ((GtkWidget*) _data_->_tmp25_, TRUE);
	_data_->_tmp26_ = _data_->self->priv->_revealer;
	gtk_revealer_set_reveal_child (_data_->_tmp26_, TRUE);
	_g_object_unref0 (_data_->next_content);
	_data_->app_ids = (g_free (_data_->app_ids), 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;
}

static void
dc_webxdc_apps_bar_hide_bar (DcWebxdcAppsBar* self)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, FALSE);
}

static Block80Data*
block80_data_ref (Block80Data* _data80_)
{
	g_atomic_int_inc (&_data80_->_ref_count_);
	return _data80_;
}

static void
block80_data_unref (void * _userdata_)
{
	Block80Data* _data80_;
	_data80_ = (Block80Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data80_->_ref_count_)) {
		DcWebxdcAppsBar* self;
		self = _data80_->self;
		_g_object_unref0 (_data80_->box);
		_g_object_unref0 (self);
		g_slice_free (Block80Data, _data80_);
	}
}

static void
__lambda61_ (Block80Data* _data80_)
{
	DcWebxdcAppsBar* self;
	self = _data80_->self;
	dc_webxdc_present_app (_data80_->msg_id);
}

static void
___lambda61__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda61_ (self);
}

static void
__lambda62_ (Block80Data* _data80_)
{
	DcWebxdcAppsBar* self;
	self = _data80_->self;
	dc_webxdc_minimize_app (_data80_->msg_id);
}

static void
___lambda62__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda62_ (self);
}

static void
__lambda63_ (Block80Data* _data80_)
{
	DcWebxdcAppsBar* self;
	self = _data80_->self;
	dc_webxdc_stop_app (_data80_->msg_id);
}

static void
___lambda63__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda63_ (self);
}

static void
__lambda64_ (Block80Data* _data80_,
             gint n_press,
             gdouble x,
             gdouble y)
{
	DcWebxdcAppsBar* self;
	GtkBox* _tmp0_;
	self = _data80_->self;
	_tmp0_ = _data80_->box;
	dc_webxdc_apps_bar_show_context_menu (self, (GtkWidget*) _tmp0_, _data80_->msg_id, x, y);
}

static void
___lambda64__gtk_gesture_click_pressed (GtkGestureClick* _sender,
                                        gint n_press,
                                        gdouble x,
                                        gdouble y,
                                        gpointer self)
{
	__lambda64_ (self, n_press, x, y);
}

static GtkWidget*
dc_webxdc_apps_bar_build_row (DcWebxdcAppsBar* self,
                              gint msg_id,
                              DcWebxdcCardInfo* info)
{
	Block80Data* _data80_;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkBox* _tmp2_;
	GtkBox* _tmp3_;
	GtkBox* _tmp4_;
	GtkImage* icon = NULL;
	GtkImage* _tmp5_;
	GtkImage* _tmp6_;
	GdkTexture* _tmp7_;
	const gchar* _tmp11_ = NULL;
	const gchar* _tmp12_;
	GtkLabel* name_lbl = NULL;
	GtkLabel* _tmp13_;
	GtkButton* name_btn = NULL;
	GtkButton* _tmp14_;
	GtkBox* name_box = NULL;
	GtkBox* _tmp15_;
	GtkImage* _tmp16_;
	GtkBox* _tmp17_;
	GtkButton* minimize = NULL;
	GtkButton* _tmp18_;
	GtkBox* _tmp19_;
	GtkButton* stop = NULL;
	GtkButton* _tmp20_;
	GtkBox* _tmp21_;
	GtkGestureClick* context = NULL;
	GtkGestureClick* _tmp22_;
	GtkBox* _tmp23_;
	GtkEventController* _tmp24_;
	GtkBox* _tmp25_;
	GtkWidget* _tmp26_;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (info != NULL, NULL);
	_data80_ = g_slice_new0 (Block80Data);
	_data80_->_ref_count_ = 1;
	_data80_->self = g_object_ref (self);
	_data80_->msg_id = msg_id;
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp0_);
	_data80_->box = _tmp0_;
	_tmp1_ = _data80_->box;
	gtk_widget_set_margin_start ((GtkWidget*) _tmp1_, 8);
	_tmp2_ = _data80_->box;
	gtk_widget_set_margin_end ((GtkWidget*) _tmp2_, 8);
	_tmp3_ = _data80_->box;
	gtk_widget_set_margin_top ((GtkWidget*) _tmp3_, 3);
	_tmp4_ = _data80_->box;
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp4_, 3);
	_tmp5_ = (GtkImage*) gtk_image_new ();
	g_object_ref_sink (_tmp5_);
	icon = _tmp5_;
	_tmp6_ = icon;
	gtk_image_set_pixel_size (_tmp6_, 20);
	_tmp7_ = info->icon;
	if (_tmp7_ != NULL) {
		GtkImage* _tmp8_;
		GdkTexture* _tmp9_;
		_tmp8_ = icon;
		_tmp9_ = info->icon;
		g_object_set (_tmp8_, "paintable", (GdkPaintable*) _tmp9_, NULL);
	} else {
		GtkImage* _tmp10_;
		_tmp10_ = icon;
		g_object_set (_tmp10_, "icon-name", "application-x-executable-symbolic", NULL);
	}
	_tmp12_ = info->name;
	_tmp11_ = _tmp12_;
	if (_tmp11_ == NULL) {
		_tmp11_ = "Webxdc app";
	}
	_tmp13_ = (GtkLabel*) gtk_label_new (_tmp11_);
	g_object_ref_sink (_tmp13_);
	name_lbl = _tmp13_;
	gtk_widget_set_halign ((GtkWidget*) name_lbl, GTK_ALIGN_START);
	gtk_label_set_ellipsize (name_lbl, PANGO_ELLIPSIZE_END);
	gtk_label_set_max_width_chars (name_lbl, 30);
	_tmp14_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp14_);
	name_btn = _tmp14_;
	gtk_widget_add_css_class ((GtkWidget*) name_btn, "flat");
	gtk_widget_set_hexpand ((GtkWidget*) name_btn, TRUE);
	_tmp15_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	g_object_ref_sink (_tmp15_);
	name_box = _tmp15_;
	_tmp16_ = icon;
	gtk_box_append (name_box, (GtkWidget*) _tmp16_);
	gtk_box_append (name_box, (GtkWidget*) name_lbl);
	gtk_button_set_child (name_btn, (GtkWidget*) name_box);
	gtk_widget_set_tooltip_text ((GtkWidget*) name_btn, "Raise app window");
	g_signal_connect_data (name_btn, "clicked", (GCallback) ___lambda61__gtk_button_clicked, block80_data_ref (_data80_), (GClosureNotify) block80_data_unref, 0);
	_tmp17_ = _data80_->box;
	gtk_box_append (_tmp17_, (GtkWidget*) name_btn);
	_tmp18_ = dc_webxdc_apps_bar_bar_button ("window-minimize-symbolic", "Minimize or restore app window");
	minimize = _tmp18_;
	g_signal_connect_data (minimize, "clicked", (GCallback) ___lambda62__gtk_button_clicked, block80_data_ref (_data80_), (GClosureNotify) block80_data_unref, 0);
	_tmp19_ = _data80_->box;
	gtk_box_append (_tmp19_, (GtkWidget*) minimize);
	_tmp20_ = dc_webxdc_apps_bar_bar_button ("media-playback-stop-symbolic", "Stop app");
	stop = _tmp20_;
	g_signal_connect_data (stop, "clicked", (GCallback) ___lambda63__gtk_button_clicked, block80_data_ref (_data80_), (GClosureNotify) block80_data_unref, 0);
	_tmp21_ = _data80_->box;
	gtk_box_append (_tmp21_, (GtkWidget*) stop);
	_tmp22_ = (GtkGestureClick*) gtk_gesture_click_new ();
	context = _tmp22_;
	gtk_gesture_single_set_button ((GtkGestureSingle*) context, (guint) GDK_BUTTON_SECONDARY);
	g_signal_connect_data (context, "pressed", (GCallback) ___lambda64__gtk_gesture_click_pressed, block80_data_ref (_data80_), (GClosureNotify) block80_data_unref, 0);
	_tmp23_ = _data80_->box;
	_tmp24_ = _g_object_ref0 ((GtkEventController*) context);
	gtk_widget_add_controller ((GtkWidget*) _tmp23_, _tmp24_);
	_tmp25_ = _data80_->box;
	_tmp26_ = _g_object_ref0 ((GtkWidget*) _tmp25_);
	result = _tmp26_;
	_g_object_unref0 (context);
	_g_object_unref0 (stop);
	_g_object_unref0 (minimize);
	_g_object_unref0 (name_box);
	_g_object_unref0 (name_btn);
	_g_object_unref0 (name_lbl);
	_g_object_unref0 (icon);
	block80_data_unref (_data80_);
	_data80_ = NULL;
	return result;
}

static Block81Data*
block81_data_ref (Block81Data* _data81_)
{
	g_atomic_int_inc (&_data81_->_ref_count_);
	return _data81_;
}

static void
block81_data_unref (void * _userdata_)
{
	Block81Data* _data81_;
	_data81_ = (Block81Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data81_->_ref_count_)) {
		DcWebxdcAppsBar* self;
		self = _data81_->self;
		_g_object_unref0 (self);
		g_slice_free (Block81Data, _data81_);
	}
}

static void
__lambda67_ (Block81Data* _data81_)
{
	DcWebxdcAppsBar* self;
	self = _data81_->self;
	g_signal_emit (self, dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_SCROLL_REQUESTED_SIGNAL], 0, _data81_->msg_id);
}

static void
___lambda67__dc_popover_button_selected (DcPopoverButton* _sender,
                                         gpointer self)
{
	__lambda67_ (self);
}

static void
__lambda68_ (Block81Data* _data81_)
{
	DcWebxdcAppsBar* self;
	self = _data81_->self;
	g_signal_emit (self, dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_FORWARD_REQUESTED_SIGNAL], 0, _data81_->msg_id);
}

static void
___lambda68__dc_popover_button_selected (DcPopoverButton* _sender,
                                         gpointer self)
{
	__lambda68_ (self);
}

static void
__lambda69_ (Block81Data* _data81_)
{
	DcWebxdcAppsBar* self;
	self = _data81_->self;
	g_signal_emit (self, dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_SAVE_REQUESTED_SIGNAL], 0, _data81_->msg_id);
}

static void
___lambda69__dc_popover_button_selected (DcPopoverButton* _sender,
                                         gpointer self)
{
	__lambda69_ (self);
}

static void
___lambda70_ (Block81Data* _data81_)
{
	DcWebxdcAppsBar* self;
	DcPinnedMessagesManager* _tmp0_;
	self = _data81_->self;
	_tmp0_ = self->priv->pinned;
	dc_pinned_messages_manager_toggle_pin (_tmp0_, _data81_->msg_id, NULL, NULL);
}

static void
____lambda70__dc_popover_button_selected (DcPopoverButton* _sender,
                                          gpointer self)
{
	___lambda70_ (self);
}

static void
__lambda71_ (Block81Data* _data81_)
{
	DcWebxdcAppsBar* self;
	self = _data81_->self;
	dc_webxdc_stop_app (_data81_->msg_id);
}

static void
___lambda71__dc_popover_button_selected (DcPopoverButton* _sender,
                                         gpointer self)
{
	__lambda71_ (self);
}

static void
dc_webxdc_apps_bar_show_context_menu (DcWebxdcAppsBar* self,
                                      GtkWidget* parent,
                                      gint msg_id,
                                      gdouble x,
                                      gdouble y)
{
	Block81Data* _data81_;
	GtkBox* vbox = NULL;
	GtkPopover* popover = NULL;
	GtkBox* _tmp0_ = NULL;
	GtkPopover* _tmp1_;
	DcPopoverButton* view_btn = NULL;
	GtkPopover* _tmp2_;
	DcPopoverButton* _tmp3_;
	DcPopoverButton* _tmp4_;
	GtkBox* _tmp5_;
	DcPopoverButton* _tmp6_;
	DcPopoverButton* forward_btn = NULL;
	GtkPopover* _tmp7_;
	DcPopoverButton* _tmp8_;
	DcPopoverButton* _tmp9_;
	GtkBox* _tmp10_;
	DcPopoverButton* _tmp11_;
	DcPopoverButton* save_btn = NULL;
	GtkPopover* _tmp12_;
	DcPopoverButton* _tmp13_;
	DcPopoverButton* _tmp14_;
	GtkBox* _tmp15_;
	DcPopoverButton* _tmp16_;
	DcPinnedMessagesManager* _tmp17_;
	GtkBox* _tmp25_;
	GtkSeparator* _tmp26_;
	GtkSeparator* _tmp27_;
	DcPopoverButton* stop_btn = NULL;
	GtkPopover* _tmp28_;
	DcPopoverButton* _tmp29_;
	GtkBox* _tmp30_;
	GtkPopover* _tmp31_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (parent != NULL);
	_data81_ = g_slice_new0 (Block81Data);
	_data81_->_ref_count_ = 1;
	_data81_->self = g_object_ref (self);
	_data81_->msg_id = msg_id;
	_tmp1_ = dc_popover_menu (parent, x, y, &_tmp0_);
	_g_object_unref0 (vbox);
	vbox = _tmp0_;
	popover = _tmp1_;
	_tmp2_ = popover;
	_tmp3_ = dc_popover_button_new (_tmp2_, "View in conversation", FALSE, FALSE);
	g_object_ref_sink (_tmp3_);
	view_btn = _tmp3_;
	_tmp4_ = view_btn;
	g_signal_connect_data (_tmp4_, "selected", (GCallback) ___lambda67__dc_popover_button_selected, block81_data_ref (_data81_), (GClosureNotify) block81_data_unref, 0);
	_tmp5_ = vbox;
	_tmp6_ = view_btn;
	gtk_box_append (_tmp5_, (GtkWidget*) _tmp6_);
	_tmp7_ = popover;
	_tmp8_ = dc_popover_button_new (_tmp7_, "Forward…", FALSE, FALSE);
	g_object_ref_sink (_tmp8_);
	forward_btn = _tmp8_;
	_tmp9_ = forward_btn;
	g_signal_connect_data (_tmp9_, "selected", (GCallback) ___lambda68__dc_popover_button_selected, block81_data_ref (_data81_), (GClosureNotify) block81_data_unref, 0);
	_tmp10_ = vbox;
	_tmp11_ = forward_btn;
	gtk_box_append (_tmp10_, (GtkWidget*) _tmp11_);
	_tmp12_ = popover;
	_tmp13_ = dc_popover_button_new (_tmp12_, "Save to disk…", FALSE, FALSE);
	g_object_ref_sink (_tmp13_);
	save_btn = _tmp13_;
	_tmp14_ = save_btn;
	g_signal_connect_data (_tmp14_, "selected", (GCallback) ___lambda69__dc_popover_button_selected, block81_data_ref (_data81_), (GClosureNotify) block81_data_unref, 0);
	_tmp15_ = vbox;
	_tmp16_ = save_btn;
	gtk_box_append (_tmp15_, (GtkWidget*) _tmp16_);
	_tmp17_ = self->priv->pinned;
	if (_tmp17_ != NULL) {
		const gchar* _tmp18_ = NULL;
		DcPinnedMessagesManager* _tmp19_;
		DcPopoverButton* pin_btn = NULL;
		GtkPopover* _tmp20_;
		DcPopoverButton* _tmp21_;
		DcPopoverButton* _tmp22_;
		GtkBox* _tmp23_;
		DcPopoverButton* _tmp24_;
		_tmp19_ = self->priv->pinned;
		if (dc_pinned_messages_manager_is_pinned (_tmp19_, _data81_->msg_id)) {
			_tmp18_ = "Unpin";
		} else {
			_tmp18_ = "Pin";
		}
		_tmp20_ = popover;
		_tmp21_ = dc_popover_button_new (_tmp20_, _tmp18_, FALSE, FALSE);
		g_object_ref_sink (_tmp21_);
		pin_btn = _tmp21_;
		_tmp22_ = pin_btn;
		g_signal_connect_data (_tmp22_, "selected", (GCallback) ____lambda70__dc_popover_button_selected, block81_data_ref (_data81_), (GClosureNotify) block81_data_unref, 0);
		_tmp23_ = vbox;
		_tmp24_ = pin_btn;
		gtk_box_append (_tmp23_, (GtkWidget*) _tmp24_);
		_g_object_unref0 (pin_btn);
	}
	_tmp25_ = vbox;
	_tmp26_ = (GtkSeparator*) gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
	g_object_ref_sink (_tmp26_);
	_tmp27_ = _tmp26_;
	gtk_box_append (_tmp25_, (GtkWidget*) _tmp27_);
	_g_object_unref0 (_tmp27_);
	_tmp28_ = popover;
	_tmp29_ = dc_popover_button_new (_tmp28_, "Stop app", TRUE, FALSE);
	g_object_ref_sink (_tmp29_);
	stop_btn = _tmp29_;
	g_signal_connect_data (stop_btn, "selected", (GCallback) ___lambda71__dc_popover_button_selected, block81_data_ref (_data81_), (GClosureNotify) block81_data_unref, 0);
	_tmp30_ = vbox;
	gtk_box_append (_tmp30_, (GtkWidget*) stop_btn);
	_tmp31_ = popover;
	gtk_popover_popup (_tmp31_);
	_g_object_unref0 (stop_btn);
	_g_object_unref0 (save_btn);
	_g_object_unref0 (forward_btn);
	_g_object_unref0 (view_btn);
	_g_object_unref0 (popover);
	_g_object_unref0 (vbox);
	block81_data_unref (_data81_);
	_data81_ = NULL;
}

void
dc_webxdc_apps_bar_close (DcWebxdcAppsBar* self)
{
	guint _tmp0_;
	g_return_if_fail (self != NULL);
	if (self->priv->closed) {
		return;
	}
	self->priv->closed = TRUE;
	_tmp0_ = self->priv->load_generation;
	self->priv->load_generation = _tmp0_ + 1;
	self->priv->chat_id = 0;
	if (self->priv->monitor_handler != ((gulong) 0)) {
		DcWebxdcMonitor* _tmp1_;
		DcWebxdcMonitor* _tmp2_;
		_tmp1_ = dc_webxdc_monitor_get_default ();
		_tmp2_ = _tmp1_;
		g_signal_handler_disconnect ((GObject*) _tmp2_, self->priv->monitor_handler);
		_g_object_unref0 (_tmp2_);
		self->priv->monitor_handler = (gulong) 0;
	}
	self->priv->rpc = NULL;
	self->priv->pinned = NULL;
	dc_webxdc_apps_bar_hide_bar (self);
}

static void
dc_webxdc_apps_bar_real_dispose (GObject* base)
{
	DcWebxdcAppsBar * self;
	self = (DcWebxdcAppsBar*) base;
	dc_webxdc_apps_bar_close (self);
	G_OBJECT_CLASS (dc_webxdc_apps_bar_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

static GtkButton*
dc_webxdc_apps_bar_bar_button (const gchar* icon_name,
                               const gchar* tooltip)
{
	GtkButton* button = NULL;
	GtkButton* _tmp0_;
	GtkButton* result;
	g_return_val_if_fail (icon_name != NULL, NULL);
	g_return_val_if_fail (tooltip != NULL, NULL);
	_tmp0_ = (GtkButton*) gtk_button_new_from_icon_name (icon_name);
	g_object_ref_sink (_tmp0_);
	button = _tmp0_;
	gtk_widget_add_css_class ((GtkWidget*) button, "flat");
	gtk_widget_set_valign ((GtkWidget*) button, GTK_ALIGN_CENTER);
	gtk_widget_set_tooltip_text ((GtkWidget*) button, tooltip);
	result = button;
	return result;
}

GtkRevealer*
dc_webxdc_apps_bar_get_revealer (DcWebxdcAppsBar* self)
{
	GtkRevealer* result;
	GtkRevealer* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_revealer;
	result = _tmp0_;
	return result;
}

static void
dc_webxdc_apps_bar_set_revealer (DcWebxdcAppsBar* self,
                                 GtkRevealer* value)
{
	GtkRevealer* old_value;
	g_return_if_fail (self != NULL);
	old_value = dc_webxdc_apps_bar_get_revealer (self);
	if (old_value != value) {
		GtkRevealer* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_revealer);
		self->priv->_revealer = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dc_webxdc_apps_bar_properties[DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY]);
	}
}

static void
dc_webxdc_apps_bar_class_init (DcWebxdcAppsBarClass * klass,
                               gpointer klass_data)
{
	dc_webxdc_apps_bar_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcWebxdcAppsBar_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) dc_webxdc_apps_bar_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_dc_webxdc_apps_bar_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dc_webxdc_apps_bar_set_property;
	G_OBJECT_CLASS (klass)->finalize = dc_webxdc_apps_bar_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY, dc_webxdc_apps_bar_properties[DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY] = g_param_spec_object ("revealer", "revealer", "revealer", gtk_revealer_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_SCROLL_REQUESTED_SIGNAL] = g_signal_new ("scroll-requested", DC_TYPE_WEBXDC_APPS_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_FORWARD_REQUESTED_SIGNAL] = g_signal_new ("forward-requested", DC_TYPE_WEBXDC_APPS_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
	dc_webxdc_apps_bar_signals[DC_WEBXDC_APPS_BAR_SAVE_REQUESTED_SIGNAL] = g_signal_new ("save-requested", DC_TYPE_WEBXDC_APPS_BAR, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}

static void
dc_webxdc_apps_bar_instance_init (DcWebxdcAppsBar * self,
                                  gpointer klass)
{
	self->priv = dc_webxdc_apps_bar_get_instance_private (self);
	self->priv->rpc = NULL;
	self->priv->pinned = NULL;
	self->priv->chat_id = 0;
	self->priv->load_generation = (guint) 0;
	self->priv->monitor_handler = (gulong) 0;
	self->priv->closed = FALSE;
}

static void
dc_webxdc_apps_bar_finalize (GObject * obj)
{
	DcWebxdcAppsBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBar);
	_g_object_unref0 (self->priv->_revealer);
	_g_object_unref0 (self->priv->bar_content);
	G_OBJECT_CLASS (dc_webxdc_apps_bar_parent_class)->finalize (obj);
}

/** Per-chat topbar (like the pinned-messages bar) listing the Webxdc
        apps currently RUNNING from this chat — an app that is not running
        has no row, and with nothing running the bar stays hidden. Starting
        an app happens from its message card; this bar controls the open
        window. Each row shows the app with minimize and stop buttons, and
        a right-click menu carries the rest: view in conversation, forward,
        save to disk, pin/unpin the message and stop. Window behavior (independent vs
        follow-chat) is a global choice in Settings → Webxdc Apps. The
        window state itself lives in Dc.Webxdc; this bar is only a view
        over it, kept in sync through Webxdc.Monitor. */
static GType
dc_webxdc_apps_bar_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcWebxdcAppsBarClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_webxdc_apps_bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcWebxdcAppsBar), 0, (GInstanceInitFunc) dc_webxdc_apps_bar_instance_init, NULL };
	GType dc_webxdc_apps_bar_type_id;
	dc_webxdc_apps_bar_type_id = g_type_register_static (G_TYPE_OBJECT, "DcWebxdcAppsBar", &g_define_type_info, 0);
	DcWebxdcAppsBar_private_offset = g_type_add_instance_private (dc_webxdc_apps_bar_type_id, sizeof (DcWebxdcAppsBarPrivate));
	return dc_webxdc_apps_bar_type_id;
}

GType
dc_webxdc_apps_bar_get_type (void)
{
	static volatile gsize dc_webxdc_apps_bar_type_id__once = 0;
	if (g_once_init_enter (&dc_webxdc_apps_bar_type_id__once)) {
		GType dc_webxdc_apps_bar_type_id;
		dc_webxdc_apps_bar_type_id = dc_webxdc_apps_bar_get_type_once ();
		g_once_init_leave (&dc_webxdc_apps_bar_type_id__once, dc_webxdc_apps_bar_type_id);
	}
	return dc_webxdc_apps_bar_type_id__once;
}

static void
_vala_dc_webxdc_apps_bar_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	DcWebxdcAppsBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBar);
	switch (property_id) {
		case DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY:
		g_value_set_object (value, dc_webxdc_apps_bar_get_revealer (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dc_webxdc_apps_bar_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec)
{
	DcWebxdcAppsBar * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DC_TYPE_WEBXDC_APPS_BAR, DcWebxdcAppsBar);
	switch (property_id) {
		case DC_WEBXDC_APPS_BAR_REVEALER_PROPERTY:
		dc_webxdc_apps_bar_set_revealer (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

