snippet gobject
- scope c
- desc Create GObject
	#include "${1:$filename|stripsuffix}.h"

	typedef struct
	{
		$0
	} ${2:$1|camelize}Private;

	G_DEFINE_TYPE_WITH_PRIVATE ($2, ${3:$1|functify}, ${4:G_TYPE_OBJECT})

	enum {
		PROP_0,
		N_PROPS
	};

	static GParamSpec *properties [N_PROPS];

	$2 *
	$3_new (void)
	{
		return g_object_new (${$1|namespace|functify|upper}_TYPE_${$1|class|functify|upper}, NULL);
	}

	static void
	$3_finalize (GObject *object)
	{
		$2 *self = ($2 *)object;
		$2Private *priv = $3_get_instance_private (self);

		G_OBJECT_CLASS ($3_parent_class)->finalize (object);
	}

	static void
	$3_get_property (GObject    *object,
	${$3|space}               guint       prop_id,
	${$3|space}               GValue     *value,
	${$3|space}               GParamSpec *pspec)
	{
		$2 *self = ${$3|upper} (object);

		switch (prop_id)
		  {
		  default:
		    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		  }
	}

	static void
	$3_set_property (GObject      *object,
	${$3|space}               guint         prop_id,
	${$3|space}               const GValue *value,
	${$3|space}               GParamSpec   *pspec)
	{
		$2 *self = ${$3|upper} (object);

		switch (prop_id)
		  {
		  default:
		    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		  }
	}

	static void
	$3_class_init ($2Class *klass)
	{
		GObjectClass *object_class = G_OBJECT_CLASS (klass);

		object_class->finalize = $3_finalize;
		object_class->get_property = $3_get_property;
		object_class->set_property = $3_set_property;
	}

	static void
	$3_init ($2 *self)
	{
	}
- scope chdr
- desc Create GObject header
	#ifndef ${$1|functify|upper}_H
	#define ${$1|functify|upper}_H

	#include ${3:<glib-object.h>}

	G_BEGIN_DECLS

	#define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper} (${$1|functify}_get_type())

	G_DECLARE_DERIVABLE_TYPE (${1:$filename|stripsuffix|camelize}, ${$1|functify}, ${$1|functify|namespace|upper}, ${$1|class|functify|upper}, ${2:GObject})

	struct _$1Class
	{
		$2Class parent;
	};

	$1 *${$1|functify}_new (void);
	$0
	G_END_DECLS

	#endif /* ${$1|functify|upper}_H */
snippet gobj_guard
- scope chdr
	#ifndef ${1:$filename|stripsuffix|functify|upper}_H
	#define $1_H

	#include <glib.h>

	G_BEGIN_DECLS

	$0

	G_END_DECLS

	#endif /* $1_H */
snippet gobj_interface
- scope c
- desc Create GObject Interface
	#include "${1:$filename|stripsuffix}.h"

	G_DEFINE_INTERFACE (${2:$1|camelize}, ${3:$1|functify}, ${4:G_TYPE_OBJECT})

	static void
	$3_default_init ($2Interface *iface)
	{
	}
- scope chdr
- desc Create GObject Interface header
	#ifndef ${$1|functify|upper}_H
	#define ${$1|functify|upper}_H

	#include ${3:<glib-object.h>}

	G_BEGIN_DECLS

	#define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper} (${$1|functify}_get_type ())

	G_DECLARE_INTERFACE ($1, ${$1|functify}, ${$1|functify|namespace|upper}, ${$1|class|functify|upper}, ${2:GObject})

	struct _${1:$filename|stripsuffix|functify|camelize}Interface
	{
		GTypeInterface parent;

		$0
	};

	G_END_DECLS

	#endif /* ${$1|functify|upper}_H */
snippet gobj_ref
- scope c
- desc GObject ref
	g_object_ref (${1});$0
snippet gobj_unref
- scope c
- desc GObject unref
	g_object_unref (${1});$0
snippet gobj_clear
- scope c
- desc GObject clear
	g_clear_object (&${1});$0
snippet gproperty
- scope c
- desc Add GObject property
	properties [PROP_${1:NAME}] =
		g_param_spec_${2:object} ("${3:$1|lower}",
		             ${$2|space}  "${4:$3|camelize}",
		             ${$2|space}  "${5:$3|camelize}",
		             ${$2|space}  ${6}
		             ${$2|space}  (G_PARAM_${7:READWRITE} |
		             ${$2|space}   G_PARAM_STATIC_STRINGS));
	g_object_class_install_property (object_class, PROP_$1,
	                                 properties [PROP_$1]);
snippet gsignal
- scope c
- desc Add GObject signal
	signals [${$1|functify|upper}] =
		g_signal_new ("${1:name}",
		              G_TYPE_FROM_CLASS (klass),
		              ${2:G_SIGNAL_RUN_LAST},
		              ${3:0},
		              ${4:NULL},
		              ${5:NULL},
		              ${6:g_cclosure_marshal_generic},
		              ${7:G_TYPE_NONE},
		              ${8:0});
snippet async
- scope c
	void
	${$2|functify}_${1:do_something}_async (${2:$filename|stripsuffix|camelize} *self,
	${$2|space} ${$1|space}          GCancellable *cancellable,
	${$2|space} ${$1|space}          GAsyncReadyCallback callback,
	${$2|space} ${$1|space}          gpointer user_data)
	{
		g_autoptr(GTask) task = NULL;

		g_return_if_fail (${$filename|stripsuffix|functify|namespace|upper}_IS_${$filename|stripsuffix|class|functify|upper} (self));
		g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));

		task = g_task_new (self, cancellable, callback, user_data);

		$0
	}
snippet finish
- scope c
	gboolean
	${$2|functify}_${1:do_something}_finish (${2:$filename|stripsuffix|camelize} *self,
	${$2|space} ${$1|space}           GAsyncResult *result,
	${$2|space} ${$1|space}           GError **error)
	{
		GTask *task = (GTask *)result;

		g_return_val_if_fail (${$filename|stripsuffix|functify|namespace|upper}_IS_${$filename|stripsuffix|class|functify|upper} (self), ${3:FALSE});

		return g_task_propagate_${4:boolean} (task, error);
	}
snippet Private
- desc Define a local for the GObject's private data.
- scope c, chdr
	${$filename|stripsuffix|functify|camelize}Private *priv = ${$filename|stripsuffix|functify}_get_instance_private (self);$0
snippet doc
- scope c, chdr
	/**
	 * ${$filename|stripsuffix|functify}_${1:func}:
	 *
	 * ${3}
	 *
	 * Returns: ${2}
	 */$0
snippet fail
- desc Snippet for g_return_if_fail()
- scope c, chdr
	g_return_if_fail (${1:`$filename|stripsuffix|functify|namespace|upper`_IS_`$filename|stripsuffix|class|functify|upper` (self)});$0
snippet vfail
- desc Snippet for g_return_val_if_fail()
- scope c, chdr
	g_return_val_if_fail (${1:`$filename|stripsuffix|functify|namespace|upper`_IS_`$filename|stripsuffix|class|functify|upper` (self)}, ${2:NULL});$0
