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

/*
 * This file is part of budgie-desktop
 *
 * Copyright Budgie Desktop Developers
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include "icontasklistapplet.h"
#include <libxfce4windowing/libxfce4windowing.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include "budgie-windowing.h"
#include "budgie-private.h"
#include <glib-object.h>
#include <gobject/gvaluecollector.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

enum  {
	BUDGIE_APPLICATION_MATCHER_0_PROPERTY,
	BUDGIE_APPLICATION_MATCHER_NUM_PROPERTIES
};
static GParamSpec* budgie_application_matcher_properties[BUDGIE_APPLICATION_MATCHER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _budgie_application_matcher_match_result_unref0(var) ((var == NULL) ? NULL : (var = (budgie_application_matcher_match_result_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _BudgieApplicationMatcherParamSpecMatchResult BudgieApplicationMatcherParamSpecMatchResult;

struct _BudgieApplicationMatcherMatchResultPrivate {
	gchar* _desktop_id;
};

struct _BudgieApplicationMatcherParamSpecMatchResult {
	GParamSpec parent_instance;
};

static gpointer budgie_application_matcher_parent_class = NULL;
static gint BudgieApplicationMatcherMatchResult_private_offset;
static gpointer budgie_application_matcher_match_result_parent_class = NULL;
static GType budgie_application_matcher_match_result_type_id = 0;
static GType budgie_application_matcher_type_id = 0;

static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
static gchar** budgie_application_matcher_extract_name_variants (BudgieApplicationMatcher* self,
                                                          const gchar* instance,
                                                          gint* result_length1);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_try_startup_wm_class (BudgieApplicationMatcher* self,
                                                                                      GDesktopAppInfo* desktop_info,
                                                                                      const gchar* desktop_id,
                                                                                      const gchar* instance,
                                                                                      const gchar* class_name,
                                                                                      gchar** variants,
                                                                                      gint variants_length1);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_try_desktop_id_match (BudgieApplicationMatcher* self,
                                                                                      GDesktopAppInfo* desktop_info,
                                                                                      const gchar* desktop_id,
                                                                                      const gchar* instance,
                                                                                      const gchar* class_name,
                                                                                      gchar** variants,
                                                                                      gint variants_length1);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_try_reverse_dns_match (BudgieApplicationMatcher* self,
                                                                                       GDesktopAppInfo* desktop_info,
                                                                                       const gchar* desktop_id,
                                                                                       const gchar* instance,
                                                                                       const gchar* class_name,
                                                                                       gchar** variants,
                                                                                       gint variants_length1);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_try_snap_pattern_match (BudgieApplicationMatcher* self,
                                                                                        GDesktopAppInfo* desktop_info,
                                                                                        const gchar* desktop_id,
                                                                                        const gchar* instance,
                                                                                        const gchar* class_name,
                                                                                        gchar** variants,
                                                                                        gint variants_length1);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_try_instance_to_exec_match (BudgieApplicationMatcher* self,
                                                                                            GDesktopAppInfo* desktop_info,
                                                                                            const gchar* desktop_id,
                                                                                            const gchar* instance);
static gboolean budgie_application_matcher_matches_any_variant (BudgieApplicationMatcher* self,
                                                         const gchar* target,
                                                         const gchar* original,
                                                         gchar** variants,
                                                         gint variants_length1);
static BudgieApplicationMatcherMatchResult* budgie_application_matcher_create_match_result (BudgieApplicationMatcher* self,
                                                                                     const gchar* desktop_id);
static void _vala_array_add1 (gchar** * array,
                       gint* length,
                       gint* size,
                       gchar* value);
static void budgie_application_matcher_add_unique (BudgieApplicationMatcher* self,
                                            gchar*** array,
                                            gint* array_length1,
                                            const gchar* value);
static gchar** _vala_array_dup2 (gchar** self,
                          gssize length);
static void budgie_application_matcher_match_result_finalize (BudgieApplicationMatcherMatchResult * obj);
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 gssize _vala_array_length (gpointer array);

/**
 * Find the desktop ID that matches a window.
 *
 * @param window The window to match
 * @return MatchResult containing the desktop ID, if found. If not found, the desktop ID will be null
 */
static gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

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

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

BudgieApplicationMatcherMatchResult*
budgie_application_matcher_match_window (BudgieApplicationMatcher* self,
                                         XfwWindow* window)
{
	BudgieApplicationMatcherMatchResult* match_result = NULL;
	BudgieApplicationMatcherMatchResult* _tmp0_;
	gchar** class_ids = NULL;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gchar** _tmp3_;
	gint _tmp3__length1;
	gint class_ids_length1;
	gint _class_ids_size_;
	gboolean _tmp4_ = FALSE;
	gchar** _tmp5_;
	gint _tmp5__length1;
	gchar* instance = NULL;
	gchar** _tmp11_;
	gint _tmp11__length1;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* class_name = NULL;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp15_ = FALSE;
	gchar** _tmp16_;
	gint _tmp16__length1;
	const gchar* _tmp26_ = NULL;
	const gchar* _tmp27_;
	const gchar* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_;
	gchar* _tmp31_;
	gchar* _tmp32_;
	gchar** variants = NULL;
	const gchar* _tmp33_;
	gint _tmp34_ = 0;
	gchar** _tmp35_;
	gint variants_length1;
	gint _variants_size_;
	GList* apps = NULL;
	GList* _tmp36_;
	GList* _tmp37_;
	const gchar* _tmp79_;
	const gchar* _tmp80_;
	gchar* _tmp81_;
	gchar* _tmp82_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (window != NULL, NULL);
	_tmp0_ = budgie_application_matcher_match_result_new ();
	match_result = _tmp0_;
	_tmp2_ = _tmp1_ = xfw_window_get_class_ids (window);
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup1 (_tmp2_, _vala_array_length (_tmp1_)) : _tmp2_;
	_tmp3__length1 = _vala_array_length (_tmp1_);
	class_ids = _tmp3_;
	class_ids_length1 = _tmp3__length1;
	_class_ids_size_ = class_ids_length1;
	_tmp5_ = class_ids;
	_tmp5__length1 = class_ids_length1;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		gchar** _tmp6_;
		gint _tmp6__length1;
		_tmp6_ = class_ids;
		_tmp6__length1 = class_ids_length1;
		_tmp4_ = _tmp6__length1 == 0;
	}
	if (_tmp4_) {
		const gchar* _tmp7_;
		const gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp7_ = xfw_window_get_name (window);
		_tmp8_ = string_to_string (_tmp7_);
		_tmp9_ = g_strconcat ("Got no class_ids for window='", _tmp8_, NULL);
		_tmp10_ = _tmp9_;
		g_debug ("ApplicationMatcher.vala:46: %s", _tmp10_);
		_g_free0 (_tmp10_);
		result = match_result;
		class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
		return result;
	}
	_tmp11_ = class_ids;
	_tmp11__length1 = class_ids_length1;
	_tmp12_ = _tmp11_[0];
	_tmp13_ = g_strdup (_tmp12_);
	instance = _tmp13_;
	class_name = NULL;
	_tmp16_ = class_ids;
	_tmp16__length1 = class_ids_length1;
	if (_tmp16__length1 > 1) {
		gchar** _tmp17_;
		gint _tmp17__length1;
		const gchar* _tmp18_;
		_tmp17_ = class_ids;
		_tmp17__length1 = class_ids_length1;
		_tmp18_ = _tmp17_[1];
		_tmp15_ = _tmp18_ != NULL;
	} else {
		_tmp15_ = FALSE;
	}
	if (_tmp15_) {
		gchar** _tmp19_;
		gint _tmp19__length1;
		const gchar* _tmp20_;
		gint _tmp21_;
		gint _tmp22_;
		_tmp19_ = class_ids;
		_tmp19__length1 = class_ids_length1;
		_tmp20_ = _tmp19_[1];
		_tmp21_ = strlen (_tmp20_);
		_tmp22_ = _tmp21_;
		_tmp14_ = _tmp22_ > 0;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		gchar** _tmp23_;
		gint _tmp23__length1;
		const gchar* _tmp24_;
		gchar* _tmp25_;
		_tmp23_ = class_ids;
		_tmp23__length1 = class_ids_length1;
		_tmp24_ = _tmp23_[1];
		_tmp25_ = g_strdup (_tmp24_);
		_g_free0 (class_name);
		class_name = _tmp25_;
	}
	_tmp27_ = class_name;
	_tmp26_ = _tmp27_;
	if (_tmp26_ == NULL) {
		_tmp26_ = "";
	}
	_tmp28_ = instance;
	_tmp29_ = string_to_string (_tmp28_);
	_tmp30_ = string_to_string (_tmp26_);
	_tmp31_ = g_strconcat ("Matching WM_CLASS instance='", _tmp29_, "', class='", _tmp30_, "'", NULL);
	_tmp32_ = _tmp31_;
	g_debug ("ApplicationMatcher.vala:57: %s", _tmp32_);
	_g_free0 (_tmp32_);
	_tmp33_ = instance;
	_tmp35_ = budgie_application_matcher_extract_name_variants (self, _tmp33_, &_tmp34_);
	variants = _tmp35_;
	variants_length1 = _tmp34_;
	_variants_size_ = variants_length1;
	_tmp36_ = g_app_info_get_all ();
	apps = _tmp36_;
	_tmp37_ = apps;
	{
		GList* app_info_collection = NULL;
		GList* app_info_it = NULL;
		app_info_collection = _tmp37_;
		for (app_info_it = app_info_collection; app_info_it != NULL; app_info_it = app_info_it->next) {
			GAppInfo* _tmp38_;
			GAppInfo* app_info = NULL;
			_tmp38_ = _g_object_ref0 ((GAppInfo*) app_info_it->data);
			app_info = _tmp38_;
			{
				GAppInfo* _tmp39_;
				GDesktopAppInfo* desktop_info = NULL;
				GAppInfo* _tmp40_;
				GDesktopAppInfo* _tmp41_;
				gchar* desktop_id = NULL;
				GDesktopAppInfo* _tmp42_;
				const gchar* _tmp43_;
				gchar* _tmp44_;
				const gchar* _tmp45_;
				GDesktopAppInfo* _tmp46_;
				const gchar* _tmp47_;
				const gchar* _tmp48_;
				const gchar* _tmp49_;
				gchar** _tmp50_;
				gint _tmp50__length1;
				BudgieApplicationMatcherMatchResult* _tmp51_;
				BudgieApplicationMatcherMatchResult* _tmp52_;
				GDesktopAppInfo* _tmp53_;
				const gchar* _tmp54_;
				const gchar* _tmp55_;
				const gchar* _tmp56_;
				gchar** _tmp57_;
				gint _tmp57__length1;
				BudgieApplicationMatcherMatchResult* _tmp58_;
				BudgieApplicationMatcherMatchResult* _tmp59_;
				GDesktopAppInfo* _tmp60_;
				const gchar* _tmp61_;
				const gchar* _tmp62_;
				const gchar* _tmp63_;
				gchar** _tmp64_;
				gint _tmp64__length1;
				BudgieApplicationMatcherMatchResult* _tmp65_;
				BudgieApplicationMatcherMatchResult* _tmp66_;
				GDesktopAppInfo* _tmp67_;
				const gchar* _tmp68_;
				const gchar* _tmp69_;
				const gchar* _tmp70_;
				gchar** _tmp71_;
				gint _tmp71__length1;
				BudgieApplicationMatcherMatchResult* _tmp72_;
				BudgieApplicationMatcherMatchResult* _tmp73_;
				GDesktopAppInfo* _tmp74_;
				const gchar* _tmp75_;
				const gchar* _tmp76_;
				BudgieApplicationMatcherMatchResult* _tmp77_;
				BudgieApplicationMatcherMatchResult* _tmp78_;
				_tmp39_ = app_info;
				if (!G_TYPE_CHECK_INSTANCE_TYPE (_tmp39_, G_TYPE_DESKTOP_APP_INFO)) {
					_g_object_unref0 (app_info);
					continue;
				}
				_tmp40_ = app_info;
				_tmp41_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp40_, G_TYPE_DESKTOP_APP_INFO) ? ((GDesktopAppInfo*) _tmp40_) : NULL);
				desktop_info = _tmp41_;
				_tmp42_ = desktop_info;
				_tmp43_ = g_app_info_get_id ((GAppInfo*) _tmp42_);
				_tmp44_ = g_strdup (_tmp43_);
				desktop_id = _tmp44_;
				_tmp45_ = desktop_id;
				if (_tmp45_ == NULL) {
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					continue;
				}
				_tmp46_ = desktop_info;
				_tmp47_ = desktop_id;
				_tmp48_ = instance;
				_tmp49_ = class_name;
				_tmp50_ = variants;
				_tmp50__length1 = variants_length1;
				_tmp51_ = budgie_application_matcher_try_startup_wm_class (self, _tmp46_, _tmp47_, _tmp48_, _tmp49_, _tmp50_, (gint) _tmp50__length1);
				_budgie_application_matcher_match_result_unref0 (match_result);
				match_result = _tmp51_;
				_tmp52_ = match_result;
				if (budgie_application_matcher_match_result_matched (_tmp52_)) {
					result = match_result;
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
					variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (class_name);
					_g_free0 (instance);
					class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_tmp53_ = desktop_info;
				_tmp54_ = desktop_id;
				_tmp55_ = instance;
				_tmp56_ = class_name;
				_tmp57_ = variants;
				_tmp57__length1 = variants_length1;
				_tmp58_ = budgie_application_matcher_try_desktop_id_match (self, _tmp53_, _tmp54_, _tmp55_, _tmp56_, _tmp57_, (gint) _tmp57__length1);
				_budgie_application_matcher_match_result_unref0 (match_result);
				match_result = _tmp58_;
				_tmp59_ = match_result;
				if (budgie_application_matcher_match_result_matched (_tmp59_)) {
					result = match_result;
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
					variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (class_name);
					_g_free0 (instance);
					class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_tmp60_ = desktop_info;
				_tmp61_ = desktop_id;
				_tmp62_ = instance;
				_tmp63_ = class_name;
				_tmp64_ = variants;
				_tmp64__length1 = variants_length1;
				_tmp65_ = budgie_application_matcher_try_reverse_dns_match (self, _tmp60_, _tmp61_, _tmp62_, _tmp63_, _tmp64_, (gint) _tmp64__length1);
				_budgie_application_matcher_match_result_unref0 (match_result);
				match_result = _tmp65_;
				_tmp66_ = match_result;
				if (budgie_application_matcher_match_result_matched (_tmp66_)) {
					result = match_result;
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
					variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (class_name);
					_g_free0 (instance);
					class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_tmp67_ = desktop_info;
				_tmp68_ = desktop_id;
				_tmp69_ = instance;
				_tmp70_ = class_name;
				_tmp71_ = variants;
				_tmp71__length1 = variants_length1;
				_tmp72_ = budgie_application_matcher_try_snap_pattern_match (self, _tmp67_, _tmp68_, _tmp69_, _tmp70_, _tmp71_, (gint) _tmp71__length1);
				_budgie_application_matcher_match_result_unref0 (match_result);
				match_result = _tmp72_;
				_tmp73_ = match_result;
				if (budgie_application_matcher_match_result_matched (_tmp73_)) {
					result = match_result;
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
					variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (class_name);
					_g_free0 (instance);
					class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_tmp74_ = desktop_info;
				_tmp75_ = desktop_id;
				_tmp76_ = instance;
				_tmp77_ = budgie_application_matcher_try_instance_to_exec_match (self, _tmp74_, _tmp75_, _tmp76_);
				_budgie_application_matcher_match_result_unref0 (match_result);
				match_result = _tmp77_;
				_tmp78_ = match_result;
				if (budgie_application_matcher_match_result_matched (_tmp78_)) {
					result = match_result;
					_g_free0 (desktop_id);
					_g_object_unref0 (desktop_info);
					_g_object_unref0 (app_info);
					(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
					variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (class_name);
					_g_free0 (instance);
					class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
					return result;
				}
				_g_free0 (desktop_id);
				_g_object_unref0 (desktop_info);
				_g_object_unref0 (app_info);
			}
		}
	}
	_tmp79_ = instance;
	_tmp80_ = string_to_string (_tmp79_);
	_tmp81_ = g_strconcat ("No match found for instance='", _tmp80_, "'", NULL);
	_tmp82_ = _tmp81_;
	g_debug ("ApplicationMatcher.vala:88: %s", _tmp82_);
	_g_free0 (_tmp82_);
	result = match_result;
	(apps == NULL) ? NULL : (apps = (_g_list_free__g_object_unref0_ (apps), NULL));
	variants = (_vala_array_free (variants, variants_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (class_name);
	_g_free0 (instance);
	class_ids = (_vala_array_free (class_ids, class_ids_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

/**
 * Find the desktop ID that matches a window group.
 *
 * @param group The window group to match
 * @return MatchResult with the result of the match
 */
BudgieApplicationMatcherMatchResult*
budgie_application_matcher_match_window_group (BudgieApplicationMatcher* self,
                                               BudgieWindowingWindowGroup* group)
{
	XfwWindow* window = NULL;
	XfwWindow* _tmp0_;
	XfwWindow* _tmp1_;
	XfwWindow* _tmp3_;
	BudgieApplicationMatcherMatchResult* _tmp4_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (group != NULL, NULL);
	_tmp0_ = budgie_windowing_window_group_get_first_window (group);
	window = _tmp0_;
	_tmp1_ = window;
	if (_tmp1_ == NULL) {
		BudgieApplicationMatcherMatchResult* _tmp2_;
		_tmp2_ = budgie_application_matcher_match_result_new ();
		result = _tmp2_;
		_g_object_unref0 (window);
		return result;
	}
	_tmp3_ = window;
	_tmp4_ = budgie_application_matcher_match_window (self, _tmp3_);
	result = _tmp4_;
	_g_object_unref0 (window);
	return result;
}

/**
 * Create a Budgie.Application from a desktop ID.
 *
 * @param desktop_id The desktop file ID (e.g., "firefox.desktop")
 * @return Application object or null if creation failed
 */
BudgieApplication*
budgie_application_matcher_create_application (BudgieApplicationMatcher* self,
                                               const gchar* desktop_id)
{
	GDesktopAppInfo* app_info = NULL;
	GDesktopAppInfo* _tmp0_;
	GDesktopAppInfo* _tmp1_;
	GDesktopAppInfo* _tmp5_;
	BudgieApplication* _tmp6_;
	BudgieApplication* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	_tmp0_ = g_desktop_app_info_new (desktop_id);
	app_info = _tmp0_;
	_tmp1_ = app_info;
	if (_tmp1_ == NULL) {
		const gchar* _tmp2_;
		gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp2_ = string_to_string (desktop_id);
		_tmp3_ = g_strconcat ("Failed to create DesktopAppInfo for '", _tmp2_, "'", NULL);
		_tmp4_ = _tmp3_;
		g_warning ("ApplicationMatcher.vala:116: %s", _tmp4_);
		_g_free0 (_tmp4_);
		result = NULL;
		_g_object_unref0 (app_info);
		return result;
	}
	_tmp5_ = app_info;
	_tmp6_ = budgie_application_new (_tmp5_);
	result = _tmp6_;
	_g_object_unref0 (app_info);
	return result;
}

/**
 * Check StartupWMClass field in desktop file.
 */
static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_try_startup_wm_class (BudgieApplicationMatcher* self,
                                                 GDesktopAppInfo* desktop_info,
                                                 const gchar* desktop_id,
                                                 const gchar* instance,
                                                 const gchar* class_name,
                                                 gchar** variants,
                                                 gint variants_length1)
{
	gchar* wm_class = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_ = FALSE;
	const gchar* _tmp3_;
	const gchar* _tmp8_;
	gboolean _tmp13_ = FALSE;
	BudgieApplicationMatcherMatchResult* _tmp23_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_info != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	_tmp0_ = g_desktop_app_info_get_startup_wm_class (desktop_info);
	_tmp1_ = g_strdup (_tmp0_);
	wm_class = _tmp1_;
	_tmp3_ = wm_class;
	if (_tmp3_ == NULL) {
		_tmp2_ = TRUE;
	} else {
		const gchar* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		_tmp4_ = wm_class;
		_tmp5_ = strlen (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp2_ = _tmp6_ == 0;
	}
	if (_tmp2_) {
		BudgieApplicationMatcherMatchResult* _tmp7_;
		_tmp7_ = budgie_application_matcher_match_result_new ();
		result = _tmp7_;
		_g_free0 (wm_class);
		return result;
	}
	_tmp8_ = wm_class;
	if (budgie_application_matcher_matches_any_variant (self, _tmp8_, instance, variants, (gint) variants_length1)) {
		const gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		BudgieApplicationMatcherMatchResult* _tmp12_;
		_tmp9_ = string_to_string (desktop_id);
		_tmp10_ = g_strconcat ("Matched via StartupWMClass: ", _tmp9_, NULL);
		_tmp11_ = _tmp10_;
		g_debug ("ApplicationMatcher.vala:139: %s", _tmp11_);
		_g_free0 (_tmp11_);
		_tmp12_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp12_;
		_g_free0 (wm_class);
		return result;
	}
	if (class_name != NULL) {
		const gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		_tmp14_ = wm_class;
		_tmp15_ = g_utf8_strdown (_tmp14_, (gssize) -1);
		_tmp16_ = _tmp15_;
		_tmp17_ = g_utf8_strdown (class_name, (gssize) -1);
		_tmp18_ = _tmp17_;
		_tmp13_ = g_strcmp0 (_tmp16_, _tmp18_) == 0;
		_g_free0 (_tmp18_);
		_g_free0 (_tmp16_);
	} else {
		_tmp13_ = FALSE;
	}
	if (_tmp13_) {
		const gchar* _tmp19_;
		gchar* _tmp20_;
		gchar* _tmp21_;
		BudgieApplicationMatcherMatchResult* _tmp22_;
		_tmp19_ = string_to_string (desktop_id);
		_tmp20_ = g_strconcat ("Matched via StartupWMClass (class): ", _tmp19_, NULL);
		_tmp21_ = _tmp20_;
		g_debug ("ApplicationMatcher.vala:144: %s", _tmp21_);
		_g_free0 (_tmp21_);
		_tmp22_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp22_;
		_g_free0 (wm_class);
		return result;
	}
	_tmp23_ = budgie_application_matcher_match_result_new ();
	result = _tmp23_;
	_g_free0 (wm_class);
	return result;
}

/**
 * Check if desktop file ID matches WM_CLASS.
 */
static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_try_desktop_id_match (BudgieApplicationMatcher* self,
                                                 GDesktopAppInfo* desktop_info,
                                                 const gchar* desktop_id,
                                                 const gchar* instance,
                                                 const gchar* class_name,
                                                 gchar** variants,
                                                 gint variants_length1)
{
	gchar* _tmp0_ = NULL;
	gchar* id_base = NULL;
	gchar* _tmp5_;
	const gchar* _tmp6_;
	gboolean _tmp11_ = FALSE;
	BudgieApplicationMatcherMatchResult* _tmp21_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_info != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	if (g_str_has_suffix (desktop_id, ".desktop")) {
		gint _tmp1_;
		gint _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = strlen (desktop_id);
		_tmp2_ = _tmp1_;
		_tmp3_ = string_substring (desktop_id, (glong) 0, (glong) (_tmp2_ - 8));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup (desktop_id);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = g_strdup (_tmp0_);
	id_base = _tmp5_;
	_tmp6_ = id_base;
	if (budgie_application_matcher_matches_any_variant (self, _tmp6_, instance, variants, (gint) variants_length1)) {
		const gchar* _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		BudgieApplicationMatcherMatchResult* _tmp10_;
		_tmp7_ = string_to_string (desktop_id);
		_tmp8_ = g_strconcat ("Matched via desktop ID: ", _tmp7_, NULL);
		_tmp9_ = _tmp8_;
		g_debug ("ApplicationMatcher.vala:166: %s", _tmp9_);
		_g_free0 (_tmp9_);
		_tmp10_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp10_;
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	if (class_name != NULL) {
		const gchar* _tmp12_;
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		_tmp12_ = id_base;
		_tmp13_ = g_utf8_strdown (_tmp12_, (gssize) -1);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_utf8_strdown (class_name, (gssize) -1);
		_tmp16_ = _tmp15_;
		_tmp11_ = g_strcmp0 (_tmp14_, _tmp16_) == 0;
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		const gchar* _tmp17_;
		gchar* _tmp18_;
		gchar* _tmp19_;
		BudgieApplicationMatcherMatchResult* _tmp20_;
		_tmp17_ = string_to_string (desktop_id);
		_tmp18_ = g_strconcat ("Matched via desktop ID (class): ", _tmp17_, NULL);
		_tmp19_ = _tmp18_;
		g_debug ("ApplicationMatcher.vala:171: %s", _tmp19_);
		_g_free0 (_tmp19_);
		_tmp20_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp20_;
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	_tmp21_ = budgie_application_matcher_match_result_new ();
	result = _tmp21_;
	_g_free0 (id_base);
	_g_free0 (_tmp0_);
	return result;
}

/**
 * Handle reverse-DNS naming (com.example.App).
 */
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;
}

static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_try_reverse_dns_match (BudgieApplicationMatcher* self,
                                                  GDesktopAppInfo* desktop_info,
                                                  const gchar* desktop_id,
                                                  const gchar* instance,
                                                  const gchar* class_name,
                                                  gchar** variants,
                                                  gint variants_length1)
{
	gchar* _tmp0_ = NULL;
	gchar* id_base = NULL;
	gchar* _tmp5_;
	BudgieApplicationMatcherMatchResult* match_result = NULL;
	BudgieApplicationMatcherMatchResult* _tmp6_;
	const gchar* _tmp7_;
	gchar** parts = NULL;
	const gchar* _tmp8_;
	gchar** _tmp9_;
	gchar** _tmp10_;
	gint parts_length1;
	gint _parts_size_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gchar* last_part = NULL;
	gchar** _tmp12_;
	gint _tmp12__length1;
	gchar** _tmp13_;
	gint _tmp13__length1;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	gboolean _tmp16_ = FALSE;
	const gchar* _tmp17_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_info != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	if (g_str_has_suffix (desktop_id, ".desktop")) {
		gint _tmp1_;
		gint _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = strlen (desktop_id);
		_tmp2_ = _tmp1_;
		_tmp3_ = string_substring (desktop_id, (glong) 0, (glong) (_tmp2_ - 8));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup (desktop_id);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = g_strdup (_tmp0_);
	id_base = _tmp5_;
	_tmp6_ = budgie_application_matcher_match_result_new ();
	match_result = _tmp6_;
	_tmp7_ = id_base;
	if (!string_contains (_tmp7_, ".")) {
		result = match_result;
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	_tmp8_ = id_base;
	_tmp10_ = _tmp9_ = g_strsplit (_tmp8_, ".", 0);
	parts = _tmp10_;
	parts_length1 = _vala_array_length (_tmp9_);
	_parts_size_ = parts_length1;
	_tmp11_ = parts;
	_tmp11__length1 = parts_length1;
	if (_tmp11__length1 <= 1) {
		result = match_result;
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	_tmp12_ = parts;
	_tmp12__length1 = parts_length1;
	_tmp13_ = parts;
	_tmp13__length1 = parts_length1;
	_tmp14_ = _tmp12_[_tmp13__length1 - 1];
	_tmp15_ = g_strdup (_tmp14_);
	last_part = _tmp15_;
	_tmp17_ = last_part;
	if (budgie_application_matcher_matches_any_variant (self, _tmp17_, instance, variants, (gint) variants_length1)) {
		_tmp16_ = TRUE;
	} else {
		gboolean _tmp18_ = FALSE;
		if (class_name != NULL) {
			const gchar* _tmp19_;
			gchar* _tmp20_;
			gchar* _tmp21_;
			gchar* _tmp22_;
			gchar* _tmp23_;
			_tmp19_ = last_part;
			_tmp20_ = g_utf8_strdown (_tmp19_, (gssize) -1);
			_tmp21_ = _tmp20_;
			_tmp22_ = g_utf8_strdown (class_name, (gssize) -1);
			_tmp23_ = _tmp22_;
			_tmp18_ = g_strcmp0 (_tmp21_, _tmp23_) == 0;
			_g_free0 (_tmp23_);
			_g_free0 (_tmp21_);
		} else {
			_tmp18_ = FALSE;
		}
		_tmp16_ = _tmp18_;
	}
	if (_tmp16_) {
		const gchar* _tmp24_;
		gchar* _tmp25_;
		gchar* _tmp26_;
		BudgieApplicationMatcherMatchResult* _tmp27_;
		_tmp24_ = string_to_string (desktop_id);
		_tmp25_ = g_strconcat ("Matched via reverse-DNS: ", _tmp24_, NULL);
		_tmp26_ = _tmp25_;
		g_debug ("ApplicationMatcher.vala:204: %s", _tmp26_);
		_g_free0 (_tmp26_);
		_tmp27_ = match_result;
		budgie_application_matcher_match_result_set_desktop_id (_tmp27_, desktop_id);
	}
	result = match_result;
	_g_free0 (last_part);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (id_base);
	_g_free0 (_tmp0_);
	return result;
}

/**
 * Handle snap naming pattern (snap-name_app-name).
 */
static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_try_snap_pattern_match (BudgieApplicationMatcher* self,
                                                   GDesktopAppInfo* desktop_info,
                                                   const gchar* desktop_id,
                                                   const gchar* instance,
                                                   const gchar* class_name,
                                                   gchar** variants,
                                                   gint variants_length1)
{
	gchar* _tmp0_ = NULL;
	gchar* id_base = NULL;
	gchar* _tmp5_;
	BudgieApplicationMatcherMatchResult* match_result = NULL;
	BudgieApplicationMatcherMatchResult* _tmp6_;
	const gchar* _tmp7_;
	gchar** snap_parts = NULL;
	const gchar* _tmp8_;
	gchar** _tmp9_;
	gchar** _tmp10_;
	gint snap_parts_length1;
	gint _snap_parts_size_;
	gchar** _tmp11_;
	gint _tmp11__length1;
	gchar* snap_name = NULL;
	gchar** _tmp12_;
	gint _tmp12__length1;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_info != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	if (g_str_has_suffix (desktop_id, ".desktop")) {
		gint _tmp1_;
		gint _tmp2_;
		gchar* _tmp3_;
		_tmp1_ = strlen (desktop_id);
		_tmp2_ = _tmp1_;
		_tmp3_ = string_substring (desktop_id, (glong) 0, (glong) (_tmp2_ - 8));
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp3_;
	} else {
		gchar* _tmp4_;
		_tmp4_ = g_strdup (desktop_id);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp4_;
	}
	_tmp5_ = g_strdup (_tmp0_);
	id_base = _tmp5_;
	_tmp6_ = budgie_application_matcher_match_result_new ();
	match_result = _tmp6_;
	_tmp7_ = id_base;
	if (!string_contains (_tmp7_, "_")) {
		result = match_result;
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	_tmp8_ = id_base;
	_tmp10_ = _tmp9_ = g_strsplit (_tmp8_, "_", 0);
	snap_parts = _tmp10_;
	snap_parts_length1 = _vala_array_length (_tmp9_);
	_snap_parts_size_ = snap_parts_length1;
	_tmp11_ = snap_parts;
	_tmp11__length1 = snap_parts_length1;
	if (_tmp11__length1 < 2) {
		result = match_result;
		snap_parts = (_vala_array_free (snap_parts, snap_parts_length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (id_base);
		_g_free0 (_tmp0_);
		return result;
	}
	_tmp12_ = snap_parts;
	_tmp12__length1 = snap_parts_length1;
	_tmp13_ = _tmp12_[0];
	_tmp14_ = g_strdup (_tmp13_);
	snap_name = _tmp14_;
	_tmp15_ = snap_name;
	if (budgie_application_matcher_matches_any_variant (self, _tmp15_, instance, variants, (gint) variants_length1)) {
		const gchar* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		BudgieApplicationMatcherMatchResult* _tmp19_;
		_tmp16_ = string_to_string (desktop_id);
		_tmp17_ = g_strconcat ("Matched via snap pattern: ", _tmp16_, NULL);
		_tmp18_ = _tmp17_;
		g_debug ("ApplicationMatcher.vala:235: %s", _tmp18_);
		_g_free0 (_tmp18_);
		_tmp19_ = match_result;
		budgie_application_matcher_match_result_set_desktop_id (_tmp19_, desktop_id);
	}
	result = match_result;
	_g_free0 (snap_name);
	snap_parts = (_vala_array_free (snap_parts, snap_parts_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (id_base);
	_g_free0 (_tmp0_);
	return result;
}

/**
* Handle attempting to match the instance name and transformations of it to the exec in the desktop file
 	*/
static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_try_instance_to_exec_match (BudgieApplicationMatcher* self,
                                                       GDesktopAppInfo* desktop_info,
                                                       const gchar* desktop_id,
                                                       const gchar* instance)
{
	gchar* exec = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* instance_dash = NULL;
	gchar* _tmp8_;
	gchar* instance_dot = NULL;
	gchar* _tmp9_;
	gboolean _tmp10_ = FALSE;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	BudgieApplicationMatcherMatchResult* _tmp19_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_info != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	_tmp0_ = g_app_info_get_executable ((GAppInfo*) desktop_info);
	_tmp1_ = g_path_get_basename (_tmp0_);
	exec = _tmp1_;
	_tmp2_ = exec;
	if (g_strcmp0 (instance, _tmp2_) == 0) {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		gchar* _tmp5_;
		BudgieApplicationMatcherMatchResult* _tmp6_;
		_tmp3_ = string_to_string (desktop_id);
		_tmp4_ = g_strconcat ("Matched via InstanceToExec: ", _tmp3_, NULL);
		_tmp5_ = _tmp4_;
		g_debug ("ApplicationMatcher.vala:252: %s", _tmp5_);
		_g_free0 (_tmp5_);
		_tmp6_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp6_;
		_g_free0 (exec);
		return result;
	}
	if (!string_contains (instance, " ")) {
		BudgieApplicationMatcherMatchResult* _tmp7_;
		_tmp7_ = budgie_application_matcher_match_result_new ();
		result = _tmp7_;
		_g_free0 (exec);
		return result;
	}
	_tmp8_ = string_replace (instance, " ", "-");
	instance_dash = _tmp8_;
	_tmp9_ = string_replace (instance, " ", ".");
	instance_dot = _tmp9_;
	_tmp11_ = instance_dash;
	_tmp12_ = exec;
	if (g_strcmp0 (_tmp11_, _tmp12_) == 0) {
		_tmp10_ = TRUE;
	} else {
		const gchar* _tmp13_;
		const gchar* _tmp14_;
		_tmp13_ = instance_dot;
		_tmp14_ = exec;
		_tmp10_ = g_strcmp0 (_tmp13_, _tmp14_) == 0;
	}
	if (_tmp10_) {
		const gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		BudgieApplicationMatcherMatchResult* _tmp18_;
		_tmp15_ = string_to_string (desktop_id);
		_tmp16_ = g_strconcat ("Matched via InstanceToExec: ", _tmp15_, NULL);
		_tmp17_ = _tmp16_;
		g_debug ("ApplicationMatcher.vala:267: %s", _tmp17_);
		_g_free0 (_tmp17_);
		_tmp18_ = budgie_application_matcher_create_match_result (self, desktop_id);
		result = _tmp18_;
		_g_free0 (instance_dot);
		_g_free0 (instance_dash);
		_g_free0 (exec);
		return result;
	}
	_tmp19_ = budgie_application_matcher_match_result_new ();
	result = _tmp19_;
	_g_free0 (instance_dot);
	_g_free0 (instance_dash);
	_g_free0 (exec);
	return result;
}

/**
 * Extract all possible name variants from a WM_CLASS instance.
 *
 * Handles:
 * - Reverse-DNS: com.example.App → ["com.example.App", "App"]
 * - Java packages: org-gjt-sp-jedit-jEdit → ["org-gjt-sp-jedit-jEdit", "jEdit", "jedit", "org"]
 * - Dashed names: brave-browser → ["brave-browser", "browser", "brave"]
 *
 * @param instance The WM_CLASS instance string
 * @return Array of possible name variants
 */
static void
_vala_array_add1 (gchar** * array,
                  gint* length,
                  gint* size,
                  gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gchar**
_vala_array_dup2 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
budgie_application_matcher_extract_name_variants (BudgieApplicationMatcher* self,
                                                  const gchar* instance,
                                                  gint* result_length1)
{
	gchar** variants = NULL;
	gchar** _tmp0_;
	gint variants_length1;
	gint _variants_size_;
	gchar* _tmp1_;
	gchar** _tmp18_;
	gint _tmp18__length1;
	gchar** _tmp25_;
	gint _tmp25__length1;
	gchar** result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (instance != NULL, NULL);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	variants = _tmp0_;
	variants_length1 = 0;
	_variants_size_ = variants_length1;
	_tmp1_ = g_strdup (instance);
	_vala_array_add1 (&variants, &variants_length1, &_variants_size_, _tmp1_);
	if (string_contains (instance, ".")) {
		gchar** parts = NULL;
		gchar** _tmp2_;
		gchar** _tmp3_;
		gint parts_length1;
		gint _parts_size_;
		gchar** _tmp4_;
		gint _tmp4__length1;
		_tmp3_ = _tmp2_ = g_strsplit (instance, ".", 0);
		parts = _tmp3_;
		parts_length1 = _vala_array_length (_tmp2_);
		_parts_size_ = parts_length1;
		_tmp4_ = parts;
		_tmp4__length1 = parts_length1;
		if (_tmp4__length1 > 1) {
			gchar* last = NULL;
			gchar** _tmp5_;
			gint _tmp5__length1;
			gchar** _tmp6_;
			gint _tmp6__length1;
			const gchar* _tmp7_;
			gchar* _tmp8_;
			const gchar* _tmp9_;
			_tmp5_ = parts;
			_tmp5__length1 = parts_length1;
			_tmp6_ = parts;
			_tmp6__length1 = parts_length1;
			_tmp7_ = _tmp5_[_tmp6__length1 - 1];
			_tmp8_ = g_strdup (_tmp7_);
			last = _tmp8_;
			_tmp9_ = last;
			budgie_application_matcher_add_unique (self, &variants, (gint*) (&variants_length1), _tmp9_);
			_variants_size_ = variants_length1;
			_g_free0 (last);
		}
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	}
	if (string_contains (instance, "-")) {
		gchar** parts = NULL;
		gchar** _tmp10_;
		gchar** _tmp11_;
		gint parts_length1;
		gint _parts_size_;
		gchar** _tmp12_;
		gint _tmp12__length1;
		_tmp11_ = _tmp10_ = g_strsplit (instance, "-", 0);
		parts = _tmp11_;
		parts_length1 = _vala_array_length (_tmp10_);
		_parts_size_ = parts_length1;
		_tmp12_ = parts;
		_tmp12__length1 = parts_length1;
		if (_tmp12__length1 > 1) {
			gchar** _tmp13_;
			gint _tmp13__length1;
			gchar** _tmp14_;
			gint _tmp14__length1;
			const gchar* _tmp15_;
			gchar** _tmp16_;
			gint _tmp16__length1;
			const gchar* _tmp17_;
			_tmp13_ = parts;
			_tmp13__length1 = parts_length1;
			_tmp14_ = parts;
			_tmp14__length1 = parts_length1;
			_tmp15_ = _tmp13_[_tmp14__length1 - 1];
			budgie_application_matcher_add_unique (self, &variants, (gint*) (&variants_length1), _tmp15_);
			_variants_size_ = variants_length1;
			_tmp16_ = parts;
			_tmp16__length1 = parts_length1;
			_tmp17_ = _tmp16_[0];
			budgie_application_matcher_add_unique (self, &variants, (gint*) (&variants_length1), _tmp17_);
			_variants_size_ = variants_length1;
		}
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp18_ = (variants != NULL) ? _vala_array_dup2 (variants, variants_length1) : variants;
	_tmp18__length1 = variants_length1;
	{
		gchar** variant_collection = NULL;
		gint variant_collection_length1 = 0;
		gint _variant_collection_size_ = 0;
		gint variant_it = 0;
		variant_collection = _tmp18_;
		variant_collection_length1 = _tmp18__length1;
		for (variant_it = 0; variant_it < variant_collection_length1; variant_it = variant_it + 1) {
			gchar* _tmp19_;
			gchar* variant = NULL;
			_tmp19_ = g_strdup (variant_collection[variant_it]);
			variant = _tmp19_;
			{
				gchar* lower = NULL;
				const gchar* _tmp20_;
				gchar* _tmp21_;
				const gchar* _tmp22_;
				const gchar* _tmp23_;
				_tmp20_ = variant;
				_tmp21_ = g_utf8_strdown (_tmp20_, (gssize) -1);
				lower = _tmp21_;
				_tmp22_ = lower;
				_tmp23_ = variant;
				if (g_strcmp0 (_tmp22_, _tmp23_) != 0) {
					const gchar* _tmp24_;
					_tmp24_ = lower;
					budgie_application_matcher_add_unique (self, &variants, (gint*) (&variants_length1), _tmp24_);
					_variants_size_ = variants_length1;
				}
				_g_free0 (lower);
				_g_free0 (variant);
			}
		}
		variant_collection = (_vala_array_free (variant_collection, variant_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp25_ = variants;
	_tmp25__length1 = variants_length1;
	if (result_length1) {
		*result_length1 = _tmp25__length1;
	}
	result = _tmp25_;
	return result;
}

/**
 * Check if target matches any variant (case-insensitive).
 */
static gboolean
budgie_application_matcher_matches_any_variant (BudgieApplicationMatcher* self,
                                                const gchar* target,
                                                const gchar* original,
                                                gchar** variants,
                                                gint variants_length1)
{
	gchar* target_lower = NULL;
	gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gboolean _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (target != NULL, FALSE);
	g_return_val_if_fail (original != NULL, FALSE);
	_tmp0_ = g_utf8_strdown (target, (gssize) -1);
	target_lower = _tmp0_;
	_tmp1_ = target_lower;
	_tmp2_ = g_utf8_strdown (original, (gssize) -1);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strcmp0 (_tmp1_, _tmp3_) == 0;
	_g_free0 (_tmp3_);
	if (_tmp4_) {
		result = TRUE;
		_g_free0 (target_lower);
		return result;
	}
	{
		gchar** variant_collection = NULL;
		gint variant_collection_length1 = 0;
		gint _variant_collection_size_ = 0;
		gint variant_it = 0;
		variant_collection = variants;
		variant_collection_length1 = variants_length1;
		for (variant_it = 0; variant_it < variant_collection_length1; variant_it = variant_it + 1) {
			gchar* _tmp5_;
			gchar* variant = NULL;
			_tmp5_ = g_strdup (variant_collection[variant_it]);
			variant = _tmp5_;
			{
				const gchar* _tmp6_;
				const gchar* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				gboolean _tmp10_;
				_tmp6_ = target_lower;
				_tmp7_ = variant;
				_tmp8_ = g_utf8_strdown (_tmp7_, (gssize) -1);
				_tmp9_ = _tmp8_;
				_tmp10_ = g_strcmp0 (_tmp6_, _tmp9_) == 0;
				_g_free0 (_tmp9_);
				if (_tmp10_) {
					result = TRUE;
					_g_free0 (variant);
					_g_free0 (target_lower);
					return result;
				}
				_g_free0 (variant);
			}
		}
	}
	result = FALSE;
	_g_free0 (target_lower);
	return result;
}

/**
 * Add string to array if not already present.
 */
static void
budgie_application_matcher_add_unique (BudgieApplicationMatcher* self,
                                       gchar*** array,
                                       gint* array_length1,
                                       const gchar* value)
{
	gint old_length = 0;
	gint _tmp2_;
	gchar* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (value != NULL);
	{
		gchar** item_collection = NULL;
		gint item_collection_length1 = 0;
		gint _item_collection_size_ = 0;
		gint item_it = 0;
		item_collection = *array;
		item_collection_length1 = *array_length1;
		for (item_it = 0; item_it < item_collection_length1; item_it = item_it + 1) {
			gchar* _tmp0_;
			gchar* item = NULL;
			_tmp0_ = g_strdup (item_collection[item_it]);
			item = _tmp0_;
			{
				const gchar* _tmp1_;
				_tmp1_ = item;
				if (g_strcmp0 (_tmp1_, value) == 0) {
					_g_free0 (item);
					return;
				}
				_g_free0 (item);
			}
		}
	}
	old_length = *array_length1;
	_tmp2_ = old_length + 1;
	*array = g_renew (gchar*, *array, old_length + 1);
	(_tmp2_ > (*array_length1)) ? memset ((*array) + (*array_length1), 0, sizeof (gchar*) * (_tmp2_ - (*array_length1))) : NULL;
	*array_length1 = _tmp2_;
	_tmp3_ = g_strdup (value);
	_g_free0 ((*array)[old_length]);
	(*array)[old_length] = _tmp3_;
}

/**
 * Create a MatchResult object.
 */
static BudgieApplicationMatcherMatchResult*
budgie_application_matcher_create_match_result (BudgieApplicationMatcher* self,
                                                const gchar* desktop_id)
{
	BudgieApplicationMatcherMatchResult* _result_ = NULL;
	BudgieApplicationMatcherMatchResult* _tmp0_;
	BudgieApplicationMatcherMatchResult* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (desktop_id != NULL, NULL);
	_tmp0_ = budgie_application_matcher_match_result_new ();
	_result_ = _tmp0_;
	budgie_application_matcher_match_result_set_desktop_id (_result_, desktop_id);
	result = _result_;
	return result;
}

BudgieApplicationMatcher*
budgie_application_matcher_construct (GType object_type)
{
	BudgieApplicationMatcher * self = NULL;
	self = (BudgieApplicationMatcher*) g_object_new (object_type, NULL);
	return self;
}

BudgieApplicationMatcher*
budgie_application_matcher_new (void)
{
	return budgie_application_matcher_construct (BUDGIE_TYPE_APPLICATION_MATCHER);
}

static inline gpointer
budgie_application_matcher_match_result_get_instance_private (BudgieApplicationMatcherMatchResult* self)
{
	return G_STRUCT_MEMBER_P (self, BudgieApplicationMatcherMatchResult_private_offset);
}

gboolean
budgie_application_matcher_match_result_matched (BudgieApplicationMatcherMatchResult* self)
{
	const gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_desktop_id;
	result = _tmp0_ != NULL;
	return result;
}

BudgieApplicationMatcherMatchResult*
budgie_application_matcher_match_result_construct (GType object_type)
{
	BudgieApplicationMatcherMatchResult* self = NULL;
	self = (BudgieApplicationMatcherMatchResult*) g_type_create_instance (object_type);
	return self;
}

BudgieApplicationMatcherMatchResult*
budgie_application_matcher_match_result_new (void)
{
	return budgie_application_matcher_match_result_construct (BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT);
}

const gchar*
budgie_application_matcher_match_result_get_desktop_id (BudgieApplicationMatcherMatchResult* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_desktop_id;
	result = _tmp0_;
	return result;
}

void
budgie_application_matcher_match_result_set_desktop_id (BudgieApplicationMatcherMatchResult* self,
                                                        const gchar* value)
{
	gchar* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_strdup (value);
	_g_free0 (self->priv->_desktop_id);
	self->priv->_desktop_id = _tmp0_;
}

static void
budgie_application_matcher_value_match_result_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
budgie_application_matcher_value_match_result_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		budgie_application_matcher_match_result_unref (value->data[0].v_pointer);
	}
}

static void
budgie_application_matcher_value_match_result_copy_value (const GValue* src_value,
                                                          GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = budgie_application_matcher_match_result_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
budgie_application_matcher_value_match_result_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
budgie_application_matcher_value_match_result_collect_value (GValue* value,
                                                             guint n_collect_values,
                                                             GTypeCValue* collect_values,
                                                             guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		BudgieApplicationMatcherMatchResult * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = budgie_application_matcher_match_result_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
budgie_application_matcher_value_match_result_lcopy_value (const GValue* value,
                                                           guint n_collect_values,
                                                           GTypeCValue* collect_values,
                                                           guint collect_flags)
{
	BudgieApplicationMatcherMatchResult ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = budgie_application_matcher_match_result_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
budgie_application_matcher_param_spec_match_result (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags)
{
	BudgieApplicationMatcherParamSpecMatchResult* spec;
	g_return_val_if_fail (g_type_is_a (object_type, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
budgie_application_matcher_value_get_match_result (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT), NULL);
	return value->data[0].v_pointer;
}

void
budgie_application_matcher_value_set_match_result (GValue* value,
                                                   gpointer v_object)
{
	BudgieApplicationMatcherMatchResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		budgie_application_matcher_match_result_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		budgie_application_matcher_match_result_unref (old);
	}
}

void
budgie_application_matcher_value_take_match_result (GValue* value,
                                                    gpointer v_object)
{
	BudgieApplicationMatcherMatchResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		budgie_application_matcher_match_result_unref (old);
	}
}

static void
budgie_application_matcher_match_result_class_init (BudgieApplicationMatcherMatchResultClass * klass,
                                                    gpointer klass_data)
{
	budgie_application_matcher_match_result_parent_class = g_type_class_peek_parent (klass);
	((BudgieApplicationMatcherMatchResultClass *) klass)->finalize = budgie_application_matcher_match_result_finalize;
	g_type_class_adjust_private_offset (klass, &BudgieApplicationMatcherMatchResult_private_offset);
}

static void
budgie_application_matcher_match_result_instance_init (BudgieApplicationMatcherMatchResult * self,
                                                       gpointer klass)
{
	self->priv = budgie_application_matcher_match_result_get_instance_private (self);
	self->ref_count = 1;
}

static void
budgie_application_matcher_match_result_finalize (BudgieApplicationMatcherMatchResult * obj)
{
	BudgieApplicationMatcherMatchResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BUDGIE_APPLICATION_MATCHER_TYPE_MATCH_RESULT, BudgieApplicationMatcherMatchResult);
	g_signal_handlers_destroy (self);
	_g_free0 (self->priv->_desktop_id);
}

/**
 * Result of a matching operation.
 */
GType
budgie_application_matcher_match_result_get_type (void)
{
	return budgie_application_matcher_match_result_type_id;
}

GType
budgie_application_matcher_match_result_register_type (GTypeModule * module)
{
	static const GTypeValueTable g_define_type_value_table = { budgie_application_matcher_value_match_result_init, budgie_application_matcher_value_match_result_free_value, budgie_application_matcher_value_match_result_copy_value, budgie_application_matcher_value_match_result_peek_pointer, "p", budgie_application_matcher_value_match_result_collect_value, "p", budgie_application_matcher_value_match_result_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (BudgieApplicationMatcherMatchResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_application_matcher_match_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgieApplicationMatcherMatchResult), 0, (GInstanceInitFunc) budgie_application_matcher_match_result_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	budgie_application_matcher_match_result_type_id = g_type_register_fundamental (g_type_fundamental_next (), "BudgieApplicationMatcherMatchResult", &g_define_type_info, &g_define_type_fundamental_info, 0);
	BudgieApplicationMatcherMatchResult_private_offset = sizeof (BudgieApplicationMatcherMatchResultPrivate);
	return budgie_application_matcher_match_result_type_id;
}

gpointer
budgie_application_matcher_match_result_ref (gpointer instance)
{
	BudgieApplicationMatcherMatchResult * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
budgie_application_matcher_match_result_unref (gpointer instance)
{
	BudgieApplicationMatcherMatchResult * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		BUDGIE_APPLICATION_MATCHER_MATCH_RESULT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
budgie_application_matcher_class_init (BudgieApplicationMatcherClass * klass,
                                       gpointer klass_data)
{
	budgie_application_matcher_parent_class = g_type_class_peek_parent (klass);
}

static void
budgie_application_matcher_instance_init (BudgieApplicationMatcher * self,
                                          gpointer klass)
{
}

/**
 * Handles matching windows to desktop application files.
 *
 * This class implements the window-to-desktop-ID matching methods
 * inspired by GNOME Shell, KDE Plasma, and BAMF. It handles:
 * - StartupWMClass matching (primary method)
 * - Reverse-DNS naming (com.example.App)
 * - Java package naming (org-gjt-sp-jedit-jEdit)
 * - Snap naming patterns (snap-name_app-name)
 * - Case-insensitive fallbacks
 */
GType
budgie_application_matcher_get_type (void)
{
	return budgie_application_matcher_type_id;
}

GType
budgie_application_matcher_register_type (GTypeModule * module)
{
	static const GTypeInfo g_define_type_info = { sizeof (BudgieApplicationMatcherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) budgie_application_matcher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BudgieApplicationMatcher), 0, (GInstanceInitFunc) budgie_application_matcher_instance_init, NULL };
	budgie_application_matcher_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "BudgieApplicationMatcher", &g_define_type_info, 0);
	return budgie_application_matcher_type_id;
}

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

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

