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

/*
 * SPDX-License-Identifier: GPL-2.0-or-later
 * SPDX-FileCopyrightText: 2018-2025 elementary, Inc. (https://elementary.io)
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <granite.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#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 GREETER_TYPE_CAPS_LOCK_REVEALER (greeter_caps_lock_revealer_get_type ())
#define GREETER_CAPS_LOCK_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer))
#define GREETER_CAPS_LOCK_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealerClass))
#define GREETER_IS_CAPS_LOCK_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER))
#define GREETER_IS_CAPS_LOCK_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GREETER_TYPE_CAPS_LOCK_REVEALER))
#define GREETER_CAPS_LOCK_REVEALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealerClass))

typedef struct _GreeterCapsLockRevealer GreeterCapsLockRevealer;
typedef struct _GreeterCapsLockRevealerClass GreeterCapsLockRevealerClass;
typedef struct _GreeterCapsLockRevealerPrivate GreeterCapsLockRevealerPrivate;
enum  {
	GREETER_CAPS_LOCK_REVEALER_0_PROPERTY,
	GREETER_CAPS_LOCK_REVEALER_NUM_PROPERTIES
};
static GParamSpec* greeter_caps_lock_revealer_properties[GREETER_CAPS_LOCK_REVEALER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GreeterCapsLockRevealer {
	GtkBin parent_instance;
	GreeterCapsLockRevealerPrivate * priv;
};

struct _GreeterCapsLockRevealerClass {
	GtkBinClass parent_class;
};

struct _GreeterCapsLockRevealerPrivate {
	GtkImage* caps_lock_image;
	GtkImage* num_lock_image;
	GtkLabel* lock_label;
	GtkRevealer* revealer;
};

static gint GreeterCapsLockRevealer_private_offset;
static gpointer greeter_caps_lock_revealer_parent_class = NULL;

VALA_EXTERN GType greeter_caps_lock_revealer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GreeterCapsLockRevealer, g_object_unref)
static void greeter_caps_lock_revealer_update_visibility (GreeterCapsLockRevealer* self,
                                                   GdkKeymap* keymap);
VALA_EXTERN GreeterCapsLockRevealer* greeter_caps_lock_revealer_new (void);
VALA_EXTERN GreeterCapsLockRevealer* greeter_caps_lock_revealer_construct (GType object_type);
static GObject * greeter_caps_lock_revealer_constructor (GType type,
                                                  guint n_construct_properties,
                                                  GObjectConstructParam * construct_properties);
static void _greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed (GdkKeymap* _sender,
                                                                             gpointer self);
static void greeter_caps_lock_revealer_finalize (GObject * obj);
static GType greeter_caps_lock_revealer_get_type_once (void);

static inline gpointer
greeter_caps_lock_revealer_get_instance_private (GreeterCapsLockRevealer* self)
{
	return G_STRUCT_MEMBER_P (self, GreeterCapsLockRevealer_private_offset);
}

static void
greeter_caps_lock_revealer_update_visibility (GreeterCapsLockRevealer* self,
                                              GdkKeymap* keymap)
{
	gboolean caps_lock = FALSE;
	gboolean num_lock = FALSE;
	gboolean _tmp0_ = FALSE;
	GtkRevealer* _tmp1_;
	GtkImage* _tmp2_;
	GtkImage* _tmp3_;
	GtkImage* _tmp4_;
	GtkImage* _tmp5_;
	gboolean _tmp6_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (keymap != NULL);
	caps_lock = gdk_keymap_get_caps_lock_state (keymap);
	num_lock = gdk_keymap_get_num_lock_state (keymap);
	if (caps_lock) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = num_lock;
	}
	_tmp1_ = self->priv->revealer;
	gtk_revealer_set_reveal_child (_tmp1_, _tmp0_);
	_tmp2_ = self->priv->caps_lock_image;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp2_, !caps_lock);
	_tmp3_ = self->priv->num_lock_image;
	gtk_widget_set_no_show_all ((GtkWidget*) _tmp3_, !num_lock);
	_tmp4_ = self->priv->caps_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp4_, caps_lock);
	_tmp5_ = self->priv->num_lock_image;
	gtk_widget_set_visible ((GtkWidget*) _tmp5_, num_lock);
	if (caps_lock) {
		_tmp6_ = num_lock;
	} else {
		_tmp6_ = FALSE;
	}
	if (_tmp6_) {
		GtkLabel* _tmp7_;
		_tmp7_ = self->priv->lock_label;
		gtk_label_set_label (_tmp7_, _ ("Caps Lock & Num Lock are on"));
	} else {
		if (caps_lock) {
			GtkLabel* _tmp8_;
			_tmp8_ = self->priv->lock_label;
			gtk_label_set_label (_tmp8_, _ ("Caps Lock is on"));
		} else {
			if (num_lock) {
				GtkLabel* _tmp9_;
				_tmp9_ = self->priv->lock_label;
				gtk_label_set_label (_tmp9_, _ ("Num Lock is on"));
			} else {
				GtkLabel* _tmp10_;
				_tmp10_ = self->priv->lock_label;
				gtk_label_set_label (_tmp10_, NULL);
			}
		}
	}
}

GreeterCapsLockRevealer*
greeter_caps_lock_revealer_construct (GType object_type)
{
	GreeterCapsLockRevealer * self = NULL;
	self = (GreeterCapsLockRevealer*) g_object_new (object_type, NULL);
	return self;
}

GreeterCapsLockRevealer*
greeter_caps_lock_revealer_new (void)
{
	return greeter_caps_lock_revealer_construct (GREETER_TYPE_CAPS_LOCK_REVEALER);
}

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

static void
_greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed (GdkKeymap* _sender,
                                                                        gpointer self)
{
	greeter_caps_lock_revealer_update_visibility ((GreeterCapsLockRevealer*) self, _sender);
}

static GObject *
greeter_caps_lock_revealer_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GreeterCapsLockRevealer * self;
	GtkImage* _tmp0_;
	GtkImage* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkStyleContext* _tmp4_;
	GtkBox* caps_lock_box = NULL;
	GtkBox* _tmp5_ = NULL;
	GtkBox* _tmp6_;
	GtkStyleContext* _tmp7_;
	GtkBox* _tmp8_;
	GtkImage* _tmp9_;
	GtkBox* _tmp10_;
	GtkImage* _tmp11_;
	GtkBox* _tmp12_;
	GtkLabel* _tmp13_;
	GtkBox* _tmp14_;
	GtkWidget* _tmp15_;
	GtkRevealer* _tmp16_ = NULL;
	GtkRevealer* _tmp17_;
	GdkKeymap* keymap = NULL;
	GdkDisplay* _tmp18_;
	GdkKeymap* _tmp19_;
	GdkKeymap* _tmp20_;
	GdkKeymap* _tmp21_;
	GdkKeymap* _tmp22_;
	parent_class = G_OBJECT_CLASS (greeter_caps_lock_revealer_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("input-keyboard-capslock-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->caps_lock_image);
	self->priv->caps_lock_image = _tmp0_;
	_tmp1_ = (GtkImage*) gtk_image_new_from_icon_name ("input-keyboard-numlock-symbolic", (GtkIconSize) GTK_ICON_SIZE_MENU);
	g_object_ref_sink (_tmp1_);
	_g_object_unref0 (self->priv->num_lock_image);
	self->priv->num_lock_image = _tmp1_;
	_tmp2_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->lock_label);
	self->priv->lock_label = _tmp2_;
	_tmp3_ = self->priv->lock_label;
	_tmp4_ = gtk_widget_get_style_context ((GtkWidget*) _tmp3_);
	gtk_style_context_add_class (_tmp4_, GRANITE_STYLE_CLASS_SMALL_LABEL);
	_tmp5_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
	gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp5_);
	caps_lock_box = _tmp5_;
	_tmp6_ = caps_lock_box;
	_tmp7_ = gtk_widget_get_style_context ((GtkWidget*) _tmp6_);
	gtk_style_context_add_class (_tmp7_, GTK_STYLE_CLASS_DIM_LABEL);
	_tmp8_ = caps_lock_box;
	_tmp9_ = self->priv->caps_lock_image;
	gtk_container_add ((GtkContainer*) _tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = caps_lock_box;
	_tmp11_ = self->priv->num_lock_image;
	gtk_container_add ((GtkContainer*) _tmp10_, (GtkWidget*) _tmp11_);
	_tmp12_ = caps_lock_box;
	_tmp13_ = self->priv->lock_label;
	gtk_container_add ((GtkContainer*) _tmp12_, (GtkWidget*) _tmp13_);
	_tmp14_ = caps_lock_box;
	_tmp15_ = _g_object_ref0 ((GtkWidget*) _tmp14_);
	_tmp16_ = (GtkRevealer*) gtk_revealer_new ();
	g_object_set ((GtkContainer*) _tmp16_, "child", _tmp15_, NULL);
	_g_object_unref0 (_tmp15_);
	gtk_revealer_set_transition_type (_tmp16_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->priv->revealer);
	self->priv->revealer = _tmp16_;
	_tmp17_ = self->priv->revealer;
	g_object_set ((GtkContainer*) self, "child", (GtkWidget*) _tmp17_, NULL);
	_tmp18_ = gdk_display_get_default ();
	_tmp19_ = gdk_keymap_get_for_display (_tmp18_);
	_tmp20_ = _g_object_ref0 (_tmp19_);
	keymap = _tmp20_;
	_tmp21_ = keymap;
	g_signal_connect_object (_tmp21_, "state-changed", (GCallback) _greeter_caps_lock_revealer_update_visibility_gdk_keymap_state_changed, self, 0);
	_tmp22_ = keymap;
	greeter_caps_lock_revealer_update_visibility (self, _tmp22_);
	_g_object_unref0 (keymap);
	_g_object_unref0 (caps_lock_box);
	return obj;
}

static void
greeter_caps_lock_revealer_class_init (GreeterCapsLockRevealerClass * klass,
                                       gpointer klass_data)
{
	greeter_caps_lock_revealer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GreeterCapsLockRevealer_private_offset);
	G_OBJECT_CLASS (klass)->constructor = greeter_caps_lock_revealer_constructor;
	G_OBJECT_CLASS (klass)->finalize = greeter_caps_lock_revealer_finalize;
}

static void
greeter_caps_lock_revealer_instance_init (GreeterCapsLockRevealer * self,
                                          gpointer klass)
{
	self->priv = greeter_caps_lock_revealer_get_instance_private (self);
}

static void
greeter_caps_lock_revealer_finalize (GObject * obj)
{
	GreeterCapsLockRevealer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GREETER_TYPE_CAPS_LOCK_REVEALER, GreeterCapsLockRevealer);
	_g_object_unref0 (self->priv->caps_lock_image);
	_g_object_unref0 (self->priv->num_lock_image);
	_g_object_unref0 (self->priv->lock_label);
	_g_object_unref0 (self->priv->revealer);
	G_OBJECT_CLASS (greeter_caps_lock_revealer_parent_class)->finalize (obj);
}

static GType
greeter_caps_lock_revealer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GreeterCapsLockRevealerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) greeter_caps_lock_revealer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GreeterCapsLockRevealer), 0, (GInstanceInitFunc) greeter_caps_lock_revealer_instance_init, NULL };
	GType greeter_caps_lock_revealer_type_id;
	greeter_caps_lock_revealer_type_id = g_type_register_static (gtk_bin_get_type (), "GreeterCapsLockRevealer", &g_define_type_info, 0);
	GreeterCapsLockRevealer_private_offset = g_type_add_instance_private (greeter_caps_lock_revealer_type_id, sizeof (GreeterCapsLockRevealerPrivate));
	return greeter_caps_lock_revealer_type_id;
}

GType
greeter_caps_lock_revealer_get_type (void)
{
	static volatile gsize greeter_caps_lock_revealer_type_id__once = 0;
	if (g_once_init_enter (&greeter_caps_lock_revealer_type_id__once)) {
		GType greeter_caps_lock_revealer_type_id;
		greeter_caps_lock_revealer_type_id = greeter_caps_lock_revealer_get_type_once ();
		g_once_init_leave (&greeter_caps_lock_revealer_type_id__once, greeter_caps_lock_revealer_type_id);
	}
	return greeter_caps_lock_revealer_type_id__once;
}

