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

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.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 TYPE_WM_DETECTOR (wm_detector_get_type ())
#define WM_DETECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_WM_DETECTOR, WMDetector))
#define WM_DETECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_WM_DETECTOR, WMDetectorClass))
#define IS_WM_DETECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_WM_DETECTOR))
#define IS_WM_DETECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_WM_DETECTOR))
#define WM_DETECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_WM_DETECTOR, WMDetectorClass))

typedef struct _WMDetector WMDetector;
typedef struct _WMDetectorClass WMDetectorClass;
typedef struct _WMDetectorPrivate WMDetectorPrivate;
enum  {
	WM_DETECTOR_0_PROPERTY,
	WM_DETECTOR_NUM_PROPERTIES
};
static GParamSpec* wm_detector_properties[WM_DETECTOR_NUM_PROPERTIES];
typedef enum  {
	WM_DETECTOR_WAYLAND_WM_LABWC,
	WM_DETECTOR_WAYLAND_WM_SWAY,
	WM_DETECTOR_WAYLAND_WM_WAYFIRE,
	WM_DETECTOR_WAYLAND_WM_RIVER,
	WM_DETECTOR_WAYLAND_WM_HYPRLAND,
	WM_DETECTOR_WAYLAND_WM_UNKNOWN
} WMDetectorWaylandWM;

#define WM_DETECTOR_TYPE_WAYLAND_WM (wm_detector_wayland_wm_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))

struct _WMDetector {
	GObject parent_instance;
	WMDetectorPrivate * priv;
};

struct _WMDetectorClass {
	GObjectClass parent_class;
};

static gpointer wm_detector_parent_class = NULL;

VALA_EXTERN GType wm_detector_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WMDetector, g_object_unref)
VALA_EXTERN GType wm_detector_wayland_wm_get_type (void) G_GNUC_CONST ;
VALA_EXTERN WMDetectorWaylandWM wm_detector_detect (void);
VALA_EXTERN gchar* wm_detector_get_name (WMDetectorWaylandWM wm);
VALA_EXTERN gchar* wm_detector_get_config_path (WMDetectorWaylandWM wm);
VALA_EXTERN gboolean wm_detector_config_exists (WMDetectorWaylandWM wm);
VALA_EXTERN WMDetector* wm_detector_new (void);
VALA_EXTERN WMDetector* wm_detector_construct (GType object_type);
static GType wm_detector_get_type_once (void);

static GType
wm_detector_wayland_wm_get_type_once (void)
{
	static const GEnumValue values[] = {{WM_DETECTOR_WAYLAND_WM_LABWC, "WM_DETECTOR_WAYLAND_WM_LABWC", "labwc"}, {WM_DETECTOR_WAYLAND_WM_SWAY, "WM_DETECTOR_WAYLAND_WM_SWAY", "sway"}, {WM_DETECTOR_WAYLAND_WM_WAYFIRE, "WM_DETECTOR_WAYLAND_WM_WAYFIRE", "wayfire"}, {WM_DETECTOR_WAYLAND_WM_RIVER, "WM_DETECTOR_WAYLAND_WM_RIVER", "river"}, {WM_DETECTOR_WAYLAND_WM_HYPRLAND, "WM_DETECTOR_WAYLAND_WM_HYPRLAND", "hyprland"}, {WM_DETECTOR_WAYLAND_WM_UNKNOWN, "WM_DETECTOR_WAYLAND_WM_UNKNOWN", "unknown"}, {0, NULL, NULL}};
	GType wm_detector_wayland_wm_type_id;
	wm_detector_wayland_wm_type_id = g_enum_register_static ("WMDetectorWaylandWM", values);
	return wm_detector_wayland_wm_type_id;
}

GType
wm_detector_wayland_wm_get_type (void)
{
	static volatile gsize wm_detector_wayland_wm_type_id__once = 0;
	if (g_once_init_enter (&wm_detector_wayland_wm_type_id__once)) {
		GType wm_detector_wayland_wm_type_id;
		wm_detector_wayland_wm_type_id = wm_detector_wayland_wm_get_type_once ();
		g_once_init_leave (&wm_detector_wayland_wm_type_id__once, wm_detector_wayland_wm_type_id);
	}
	return wm_detector_wayland_wm_type_id__once;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

WMDetectorWaylandWM
wm_detector_detect (void)
{
	gchar* desktop = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* session = NULL;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	WMDetectorWaylandWM result;
	_tmp0_ = g_getenv ("XDG_CURRENT_DESKTOP");
	_tmp1_ = g_strdup (_tmp0_);
	desktop = _tmp1_;
	_tmp2_ = desktop;
	if (_tmp2_ != NULL) {
		gchar* lower = NULL;
		const gchar* _tmp3_;
		gchar* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		const gchar* _tmp9_;
		_tmp3_ = desktop;
		_tmp4_ = g_utf8_strdown (_tmp3_, (gssize) -1);
		lower = _tmp4_;
		_tmp5_ = lower;
		if (string_contains (_tmp5_, "labwc")) {
			result = WM_DETECTOR_WAYLAND_WM_LABWC;
			_g_free0 (lower);
			_g_free0 (desktop);
			return result;
		}
		_tmp6_ = lower;
		if (string_contains (_tmp6_, "sway")) {
			result = WM_DETECTOR_WAYLAND_WM_SWAY;
			_g_free0 (lower);
			_g_free0 (desktop);
			return result;
		}
		_tmp7_ = lower;
		if (string_contains (_tmp7_, "wayfire")) {
			result = WM_DETECTOR_WAYLAND_WM_WAYFIRE;
			_g_free0 (lower);
			_g_free0 (desktop);
			return result;
		}
		_tmp8_ = lower;
		if (string_contains (_tmp8_, "river")) {
			result = WM_DETECTOR_WAYLAND_WM_RIVER;
			_g_free0 (lower);
			_g_free0 (desktop);
			return result;
		}
		_tmp9_ = lower;
		if (string_contains (_tmp9_, "hyprland")) {
			result = WM_DETECTOR_WAYLAND_WM_HYPRLAND;
			_g_free0 (lower);
			_g_free0 (desktop);
			return result;
		}
		_g_free0 (lower);
	}
	_tmp10_ = g_getenv ("DESKTOP_SESSION");
	_tmp11_ = g_strdup (_tmp10_);
	session = _tmp11_;
	_tmp12_ = session;
	if (_tmp12_ != NULL) {
		gchar* lower = NULL;
		const gchar* _tmp13_;
		gchar* _tmp14_;
		const gchar* _tmp15_;
		const gchar* _tmp16_;
		const gchar* _tmp17_;
		const gchar* _tmp18_;
		const gchar* _tmp19_;
		_tmp13_ = session;
		_tmp14_ = g_utf8_strdown (_tmp13_, (gssize) -1);
		lower = _tmp14_;
		_tmp15_ = lower;
		if (string_contains (_tmp15_, "labwc")) {
			result = WM_DETECTOR_WAYLAND_WM_LABWC;
			_g_free0 (lower);
			_g_free0 (session);
			_g_free0 (desktop);
			return result;
		}
		_tmp16_ = lower;
		if (string_contains (_tmp16_, "sway")) {
			result = WM_DETECTOR_WAYLAND_WM_SWAY;
			_g_free0 (lower);
			_g_free0 (session);
			_g_free0 (desktop);
			return result;
		}
		_tmp17_ = lower;
		if (string_contains (_tmp17_, "wayfire")) {
			result = WM_DETECTOR_WAYLAND_WM_WAYFIRE;
			_g_free0 (lower);
			_g_free0 (session);
			_g_free0 (desktop);
			return result;
		}
		_tmp18_ = lower;
		if (string_contains (_tmp18_, "river")) {
			result = WM_DETECTOR_WAYLAND_WM_RIVER;
			_g_free0 (lower);
			_g_free0 (session);
			_g_free0 (desktop);
			return result;
		}
		_tmp19_ = lower;
		if (string_contains (_tmp19_, "hyprland")) {
			result = WM_DETECTOR_WAYLAND_WM_HYPRLAND;
			_g_free0 (lower);
			_g_free0 (session);
			_g_free0 (desktop);
			return result;
		}
		_g_free0 (lower);
	}
	result = WM_DETECTOR_WAYLAND_WM_UNKNOWN;
	_g_free0 (session);
	_g_free0 (desktop);
	return result;
}

gchar*
wm_detector_get_name (WMDetectorWaylandWM wm)
{
	gchar* result;
	switch (wm) {
		case WM_DETECTOR_WAYLAND_WM_LABWC:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("labwc");
			result = _tmp0_;
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_SWAY:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("sway");
			result = _tmp1_;
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_WAYFIRE:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("wayfire");
			result = _tmp2_;
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_RIVER:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("river");
			result = _tmp3_;
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_HYPRLAND:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("hyprland");
			result = _tmp4_;
			return result;
		}
		default:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("unknown");
			result = _tmp5_;
			return result;
		}
	}
}

gchar*
wm_detector_get_config_path (WMDetectorWaylandWM wm)
{
	gchar* home = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	_tmp0_ = g_get_home_dir ();
	_tmp1_ = g_strdup (_tmp0_);
	home = _tmp1_;
	switch (wm) {
		case WM_DETECTOR_WAYLAND_WM_LABWC:
		{
			const gchar* _tmp2_;
			gchar* _tmp3_;
			_tmp2_ = home;
			_tmp3_ = g_build_filename (_tmp2_, ".config", "labwc", "autostart", NULL);
			result = _tmp3_;
			_g_free0 (home);
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_SWAY:
		{
			const gchar* _tmp4_;
			gchar* _tmp5_;
			_tmp4_ = home;
			_tmp5_ = g_build_filename (_tmp4_, ".config", "sway", "config", NULL);
			result = _tmp5_;
			_g_free0 (home);
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_WAYFIRE:
		{
			const gchar* _tmp6_;
			gchar* _tmp7_;
			_tmp6_ = home;
			_tmp7_ = g_build_filename (_tmp6_, ".config", "wayfire.ini", NULL);
			result = _tmp7_;
			_g_free0 (home);
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_RIVER:
		{
			const gchar* _tmp8_;
			gchar* _tmp9_;
			_tmp8_ = home;
			_tmp9_ = g_build_filename (_tmp8_, ".config", "river", "init", NULL);
			result = _tmp9_;
			_g_free0 (home);
			return result;
		}
		case WM_DETECTOR_WAYLAND_WM_HYPRLAND:
		{
			const gchar* _tmp10_;
			gchar* _tmp11_;
			_tmp10_ = home;
			_tmp11_ = g_build_filename (_tmp10_, ".config", "hypr", "hyprland.conf", NULL);
			result = _tmp11_;
			_g_free0 (home);
			return result;
		}
		default:
		{
			gchar* _tmp12_;
			_tmp12_ = g_strdup ("");
			result = _tmp12_;
			_g_free0 (home);
			return result;
		}
	}
}

gboolean
wm_detector_config_exists (WMDetectorWaylandWM wm)
{
	gchar* path = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp2_;
	gboolean result;
	_tmp0_ = wm_detector_get_config_path (wm);
	path = _tmp0_;
	_tmp2_ = path;
	if (g_strcmp0 (_tmp2_, "") != 0) {
		const gchar* _tmp3_;
		_tmp3_ = path;
		_tmp1_ = g_file_test (_tmp3_, G_FILE_TEST_EXISTS);
	} else {
		_tmp1_ = FALSE;
	}
	result = _tmp1_;
	_g_free0 (path);
	return result;
}

WMDetector*
wm_detector_construct (GType object_type)
{
	WMDetector * self = NULL;
	self = (WMDetector*) g_object_new (object_type, NULL);
	return self;
}

WMDetector*
wm_detector_new (void)
{
	return wm_detector_construct (TYPE_WM_DETECTOR);
}

static void
wm_detector_class_init (WMDetectorClass * klass,
                        gpointer klass_data)
{
	wm_detector_parent_class = g_type_class_peek_parent (klass);
}

static void
wm_detector_instance_init (WMDetector * self,
                           gpointer klass)
{
}

static GType
wm_detector_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WMDetectorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) wm_detector_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WMDetector), 0, (GInstanceInitFunc) wm_detector_instance_init, NULL };
	GType wm_detector_type_id;
	wm_detector_type_id = g_type_register_static (G_TYPE_OBJECT, "WMDetector", &g_define_type_info, 0);
	return wm_detector_type_id;
}

GType
wm_detector_get_type (void)
{
	static volatile gsize wm_detector_type_id__once = 0;
	if (g_once_init_enter (&wm_detector_type_id__once)) {
		GType wm_detector_type_id;
		wm_detector_type_id = wm_detector_get_type_once ();
		g_once_init_leave (&wm_detector_type_id__once, wm_detector_type_id);
	}
	return wm_detector_type_id__once;
}

