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

/* vim:set et sts=4 sw=4:
valac --pkg gtk+-2.0 --pkg x11 --pkg gdk-x11-2.0 --pkg gee-1.0 keybinding-manager.vala
*/

#include <glib.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xregion.h>
#include <gdk/gdkx.h>
#include <float.h>
#include <math.h>
#include <gtk/gtk.h>
#include <X11/extensions/XInput2.h>
#include <string.h>
#include <gobject/gvaluecollector.h>


#define TYPE_KEYBINDING_MANAGER (keybinding_manager_get_type ())
#define KEYBINDING_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_KEYBINDING_MANAGER, KeybindingManager))
#define KEYBINDING_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_KEYBINDING_MANAGER, KeybindingManagerClass))
#define IS_KEYBINDING_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_KEYBINDING_MANAGER))
#define IS_KEYBINDING_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_KEYBINDING_MANAGER))
#define KEYBINDING_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_KEYBINDING_MANAGER, KeybindingManagerClass))

typedef struct _KeybindingManager KeybindingManager;
typedef struct _KeybindingManagerClass KeybindingManagerClass;
typedef struct _KeybindingManagerPrivate KeybindingManagerPrivate;

#define KEYBINDING_MANAGER_TYPE_KEYBINDING (keybinding_manager_keybinding_get_type ())
#define KEYBINDING_MANAGER_KEYBINDING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), KEYBINDING_MANAGER_TYPE_KEYBINDING, KeybindingManagerKeybinding))
#define KEYBINDING_MANAGER_KEYBINDING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), KEYBINDING_MANAGER_TYPE_KEYBINDING, KeybindingManagerKeybindingClass))
#define KEYBINDING_MANAGER_IS_KEYBINDING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KEYBINDING_MANAGER_TYPE_KEYBINDING))
#define KEYBINDING_MANAGER_IS_KEYBINDING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), KEYBINDING_MANAGER_TYPE_KEYBINDING))
#define KEYBINDING_MANAGER_KEYBINDING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), KEYBINDING_MANAGER_TYPE_KEYBINDING, KeybindingManagerKeybindingClass))

typedef struct _KeybindingManagerKeybinding KeybindingManagerKeybinding;
typedef struct _KeybindingManagerKeybindingClass KeybindingManagerKeybindingClass;
#define __g_list_free__keybinding_manager_keybinding_unref0_0(var) ((var == NULL) ? NULL : (var = (_g_list_free__keybinding_manager_keybinding_unref0_ (var), NULL)))
#define _keybinding_manager_keybinding_unref0(var) ((var == NULL) ? NULL : (var = (keybinding_manager_keybinding_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define __vala_GdkEventKey_free0(var) ((var == NULL) ? NULL : (var = (_vala_GdkEventKey_free (var), NULL)))
typedef struct _KeybindingManagerKeybindingPrivate KeybindingManagerKeybindingPrivate;
typedef struct _KeybindingManagerParamSpecKeybinding KeybindingManagerParamSpecKeybinding;

struct _KeybindingManager {
	GObject parent_instance;
	KeybindingManagerPrivate * priv;
};

struct _KeybindingManagerClass {
	GObjectClass parent_class;
};

struct _KeybindingManagerPrivate {
	GList* m_bindings;
};

typedef void (*KeybindingManagerKeybindingHandlerFunc) (GdkEvent* event, void* user_data);
struct _KeybindingManagerKeybinding {
	GTypeInstance parent_instance;
	volatile int ref_count;
	KeybindingManagerKeybindingPrivate * priv;
};

struct _KeybindingManagerKeybindingClass {
	GTypeClass parent_class;
	void (*finalize) (KeybindingManagerKeybinding *self);
};

struct _KeybindingManagerKeybindingPrivate {
	guint _keysym;
	GdkModifierType _modifiers;
	KeybindingManagerKeybindingHandlerFunc _handler;
	gpointer _handler_target;
};

struct _KeybindingManagerParamSpecKeybinding {
	GParamSpec parent_instance;
};


static gpointer keybinding_manager_parent_class = NULL;
static KeybindingManager* keybinding_manager_m_instance;
static KeybindingManager* keybinding_manager_m_instance = NULL;
static gpointer keybinding_manager_keybinding_parent_class = NULL;

GType keybinding_manager_get_type (void) G_GNUC_CONST;
static gpointer keybinding_manager_keybinding_ref (gpointer instance);
static void keybinding_manager_keybinding_unref (gpointer instance);
static GParamSpec* keybinding_manager_param_spec_keybinding (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) G_GNUC_UNUSED;
static void keybinding_manager_value_set_keybinding (GValue* value, gpointer v_object) G_GNUC_UNUSED;
static void keybinding_manager_value_take_keybinding (GValue* value, gpointer v_object) G_GNUC_UNUSED;
static gpointer keybinding_manager_value_get_keybinding (const GValue* value) G_GNUC_UNUSED;
static GType keybinding_manager_keybinding_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
#define KEYBINDING_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_KEYBINDING_MANAGER, KeybindingManagerPrivate))
enum  {
	KEYBINDING_MANAGER_DUMMY_PROPERTY
};
static void _keybinding_manager_keybinding_unref0_ (gpointer var);
static void _g_list_free__keybinding_manager_keybinding_unref0_ (GList* self);
#define KEYBINDING_MANAGER_MODIFIER_FILTER ((guint) (GDK_MODIFIER_MASK & (~(((((((((GDK_LOCK_MASK | GDK_MOD2_MASK) | GDK_BUTTON1_MASK) | GDK_BUTTON2_MASK) | GDK_BUTTON3_MASK) | GDK_BUTTON4_MASK) | GDK_BUTTON5_MASK) | GDK_SUPER_MASK) | GDK_HYPER_MASK) | GDK_META_MASK))))
static KeybindingManager* keybinding_manager_new (void);
static KeybindingManager* keybinding_manager_construct (GType object_type);
static void keybinding_manager_event_handler (KeybindingManager* self, GdkEvent* event);
static void _keybinding_manager_event_handler_gdk_event_func (GdkEvent* event, gpointer self);
gboolean keybinding_manager_bind (KeybindingManager* self, guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target);
static gboolean keybinding_manager_grab_keycode (KeybindingManager* self, GdkDisplay* display, guint keyval, guint modifiers);
static KeybindingManagerKeybinding* keybinding_manager_keybinding_new (guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target);
static KeybindingManagerKeybinding* keybinding_manager_keybinding_construct (GType object_type, guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target);
void keybinding_manager_unbind (KeybindingManager* self, guint keysym, GdkModifierType modifiers);
static guint keybinding_manager_keybinding_get_keysym (KeybindingManagerKeybinding* self);
static GdkModifierType keybinding_manager_keybinding_get_modifiers (KeybindingManagerKeybinding* self);
static gboolean keybinding_manager_ungrab_keycode (KeybindingManager* self, GdkDisplay* display, guint keyval, guint modifiers);
KeybindingManager* keybinding_manager_get_instance (void);
GdkModifierType keybinding_manager_get_primary_modifier (guint binding_mask);
gboolean keybinding_manager_primary_modifier_still_pressed (GdkEvent* event, guint primary_modifier);
static GdkEventKey* _vala_GdkEventKey_copy (GdkEventKey* self);
static void _vala_GdkEventKey_free (GdkEventKey* self);
guint keybinding_manager_keyval_to_modifier (guint keyval);
static KeybindingManagerKeybindingHandlerFunc keybinding_manager_keybinding_get_handler (KeybindingManagerKeybinding* self, gpointer* result_target);
static XIGrabModifiers* keybinding_manager_get_grab_modifiers (KeybindingManager* self, guint modifiers, int* result_length1);
static void _vala_array_add10 (gint** array, int* length, int* size, gint value);
static void _vala_array_add11 (gint** array, int* length, int* size, gint value);
static void _vala_array_add12 (gint** array, int* length, int* size, gint value);
static void _vala_array_add13 (XIGrabModifiers** array, int* length, int* size, const XIGrabModifiers* value);
static void _vala_XIGrabModifiers_array_free (XIGrabModifiers* array, gint array_length);
#define KEYBINDING_MANAGER_KEYBINDING_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), KEYBINDING_MANAGER_TYPE_KEYBINDING, KeybindingManagerKeybindingPrivate))
enum  {
	KEYBINDING_MANAGER_KEYBINDING_DUMMY_PROPERTY
};
static void keybinding_manager_keybinding_set_keysym (KeybindingManagerKeybinding* self, guint value);
static void keybinding_manager_keybinding_set_modifiers (KeybindingManagerKeybinding* self, GdkModifierType value);
static void keybinding_manager_keybinding_set_handler (KeybindingManagerKeybinding* self, KeybindingManagerKeybindingHandlerFunc value, gpointer value_target);
static void keybinding_manager_keybinding_finalize (KeybindingManagerKeybinding* obj);
static void keybinding_manager_finalize (GObject* obj);


static void _keybinding_manager_keybinding_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (keybinding_manager_keybinding_unref (var), NULL));
}


static void _g_list_free__keybinding_manager_keybinding_unref0_ (GList* self) {
	g_list_foreach (self, (GFunc) _keybinding_manager_keybinding_unref0_, NULL);
	g_list_free (self);
}


static void _keybinding_manager_event_handler_gdk_event_func (GdkEvent* event, gpointer self) {
	keybinding_manager_event_handler ((KeybindingManager*) self, event);
}


static KeybindingManager* keybinding_manager_construct (GType object_type) {
	KeybindingManager * self = NULL;
	self = (KeybindingManager*) g_object_new (object_type, NULL);
	gdk_event_handler_set (_keybinding_manager_event_handler_gdk_event_func, g_object_ref (self), g_object_unref);
	return self;
}


static KeybindingManager* keybinding_manager_new (void) {
	return keybinding_manager_construct (TYPE_KEYBINDING_MANAGER);
}


/**
     * Bind accelerator to given handler
     *
     * @param keysym
     * @param modifiers
     * @param handler handler called when given accelerator is pressed
     */
static gpointer _keybinding_manager_keybinding_ref0 (gpointer self) {
	return self ? keybinding_manager_keybinding_ref (self) : NULL;
}


gboolean keybinding_manager_bind (KeybindingManager* self, guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target) {
	gboolean result = FALSE;
	Display* display = NULL;
	Display* _tmp0_ = NULL;
	gint keycode = 0;
	Display* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	guchar _tmp3_ = '\0';
	gint _tmp4_ = 0;
	GdkDisplay* _tmp5_ = NULL;
	guint _tmp6_ = 0U;
	GdkModifierType _tmp7_ = 0;
	KeybindingManagerKeybinding* binding = NULL;
	guint _tmp8_ = 0U;
	GdkModifierType _tmp9_ = 0;
	KeybindingManagerKeybindingHandlerFunc _tmp10_ = NULL;
	void* _tmp10__target = NULL;
	KeybindingManagerKeybinding* _tmp11_ = NULL;
	KeybindingManagerKeybinding* _tmp12_ = NULL;
	KeybindingManagerKeybinding* _tmp13_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = gdk_x11_get_default_xdisplay ();
	display = _tmp0_;
	_tmp1_ = display;
	_tmp2_ = keysym;
	_tmp3_ = XKeysymToKeycode (_tmp1_, (gulong) _tmp2_);
	keycode = (gint) _tmp3_;
	_tmp4_ = keycode;
	if (_tmp4_ == 0) {
		result = FALSE;
		return result;
	}
	_tmp5_ = gdk_display_get_default ();
	_tmp6_ = keysym;
	_tmp7_ = modifiers;
	keybinding_manager_grab_keycode (self, _tmp5_, _tmp6_, (guint) _tmp7_);
	_tmp8_ = keysym;
	_tmp9_ = modifiers;
	_tmp10_ = handler;
	_tmp10__target = handler_target;
	_tmp11_ = keybinding_manager_keybinding_new (_tmp8_, _tmp9_, _tmp10_, _tmp10__target);
	binding = _tmp11_;
	_tmp12_ = binding;
	_tmp13_ = _keybinding_manager_keybinding_ref0 (_tmp12_);
	self->priv->m_bindings = g_list_append (self->priv->m_bindings, _tmp13_);
	result = TRUE;
	_keybinding_manager_keybinding_unref0 (binding);
	return result;
}


/**
     * Unbind given accelerator.
     *
     * @param keysym
     * @param modifiers
     */
void keybinding_manager_unbind (KeybindingManager* self, guint keysym, GdkModifierType modifiers) {
	GList* remove_bindings = NULL;
	GList* _tmp0_ = NULL;
	GList* _tmp20_ = NULL;
	g_return_if_fail (self != NULL);
	remove_bindings = NULL;
	_tmp0_ = self->priv->m_bindings;
	{
		GList* binding_collection = NULL;
		GList* binding_it = NULL;
		binding_collection = _tmp0_;
		for (binding_it = binding_collection; binding_it != NULL; binding_it = binding_it->next) {
			KeybindingManagerKeybinding* _tmp1_ = NULL;
			KeybindingManagerKeybinding* binding = NULL;
			_tmp1_ = _keybinding_manager_keybinding_ref0 ((KeybindingManagerKeybinding*) binding_it->data);
			binding = _tmp1_;
			{
				gboolean _tmp2_ = FALSE;
				KeybindingManagerKeybinding* _tmp3_ = NULL;
				guint _tmp4_ = 0U;
				guint _tmp5_ = 0U;
				guint _tmp6_ = 0U;
				_tmp3_ = binding;
				_tmp4_ = keybinding_manager_keybinding_get_keysym (_tmp3_);
				_tmp5_ = _tmp4_;
				_tmp6_ = keysym;
				if (_tmp5_ == _tmp6_) {
					KeybindingManagerKeybinding* _tmp7_ = NULL;
					GdkModifierType _tmp8_ = 0;
					GdkModifierType _tmp9_ = 0;
					GdkModifierType _tmp10_ = 0;
					_tmp7_ = binding;
					_tmp8_ = keybinding_manager_keybinding_get_modifiers (_tmp7_);
					_tmp9_ = _tmp8_;
					_tmp10_ = modifiers;
					_tmp2_ = _tmp9_ == _tmp10_;
				} else {
					_tmp2_ = FALSE;
				}
				if (_tmp2_) {
					GdkDisplay* _tmp11_ = NULL;
					KeybindingManagerKeybinding* _tmp12_ = NULL;
					guint _tmp13_ = 0U;
					guint _tmp14_ = 0U;
					KeybindingManagerKeybinding* _tmp15_ = NULL;
					GdkModifierType _tmp16_ = 0;
					GdkModifierType _tmp17_ = 0;
					KeybindingManagerKeybinding* _tmp18_ = NULL;
					KeybindingManagerKeybinding* _tmp19_ = NULL;
					_tmp11_ = gdk_display_get_default ();
					_tmp12_ = binding;
					_tmp13_ = keybinding_manager_keybinding_get_keysym (_tmp12_);
					_tmp14_ = _tmp13_;
					_tmp15_ = binding;
					_tmp16_ = keybinding_manager_keybinding_get_modifiers (_tmp15_);
					_tmp17_ = _tmp16_;
					keybinding_manager_ungrab_keycode (self, _tmp11_, _tmp14_, (guint) _tmp17_);
					_tmp18_ = binding;
					_tmp19_ = _keybinding_manager_keybinding_ref0 (_tmp18_);
					remove_bindings = g_list_append (remove_bindings, _tmp19_);
				}
				_keybinding_manager_keybinding_unref0 (binding);
			}
		}
	}
	_tmp20_ = remove_bindings;
	{
		GList* binding_collection = NULL;
		GList* binding_it = NULL;
		binding_collection = _tmp20_;
		for (binding_it = binding_collection; binding_it != NULL; binding_it = binding_it->next) {
			KeybindingManagerKeybinding* _tmp21_ = NULL;
			KeybindingManagerKeybinding* binding = NULL;
			_tmp21_ = _keybinding_manager_keybinding_ref0 ((KeybindingManagerKeybinding*) binding_it->data);
			binding = _tmp21_;
			{
				KeybindingManagerKeybinding* _tmp22_ = NULL;
				_tmp22_ = binding;
				self->priv->m_bindings = g_list_remove (self->priv->m_bindings, _tmp22_);
				_keybinding_manager_keybinding_unref0 (binding);
			}
		}
	}
	__g_list_free__keybinding_manager_keybinding_unref0_0 (remove_bindings);
}


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


KeybindingManager* keybinding_manager_get_instance (void) {
	KeybindingManager* result = NULL;
	KeybindingManager* _tmp0_ = NULL;
	KeybindingManager* _tmp2_ = NULL;
	KeybindingManager* _tmp3_ = NULL;
	_tmp0_ = keybinding_manager_m_instance;
	if (_tmp0_ == NULL) {
		KeybindingManager* _tmp1_ = NULL;
		_tmp1_ = keybinding_manager_new ();
		_g_object_unref0 (keybinding_manager_m_instance);
		keybinding_manager_m_instance = _tmp1_;
	}
	_tmp2_ = keybinding_manager_m_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}


GdkModifierType keybinding_manager_get_primary_modifier (guint binding_mask) {
	GdkModifierType result = 0;
	static const GdkModifierType masks[] = {GDK_MOD5_MASK, GDK_MOD4_MASK, GDK_MOD3_MASK, GDK_MOD2_MASK, GDK_MOD1_MASK, GDK_CONTROL_MASK, GDK_SHIFT_MASK, GDK_LOCK_MASK};
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				gint _tmp2_ = 0;
				GdkModifierType mask = 0;
				gint _tmp3_ = 0;
				GdkModifierType _tmp4_ = 0;
				guint _tmp5_ = 0U;
				GdkModifierType _tmp6_ = 0;
				GdkModifierType _tmp7_ = 0;
				if (!_tmp0_) {
					gint _tmp1_ = 0;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = i;
				if (!(_tmp2_ < G_N_ELEMENTS (masks))) {
					break;
				}
				_tmp3_ = i;
				_tmp4_ = masks[_tmp3_];
				mask = _tmp4_;
				_tmp5_ = binding_mask;
				_tmp6_ = mask;
				_tmp7_ = mask;
				if ((_tmp5_ & _tmp6_) == ((guint) _tmp7_)) {
					result = mask;
					return result;
				}
			}
		}
	}
	result = 0;
	return result;
}


static GdkEventKey* _vala_GdkEventKey_copy (GdkEventKey* self) {
	return g_boxed_copy (gdk_event_get_type (), self);
}


static gpointer __vala_GdkEventKey_copy0 (gpointer self) {
	return self ? _vala_GdkEventKey_copy (self) : NULL;
}


static void _vala_GdkEventKey_free (GdkEventKey* self) {
	g_boxed_free (gdk_event_get_type (), self);
}


gboolean keybinding_manager_primary_modifier_still_pressed (GdkEvent* event, guint primary_modifier) {
	gboolean result = FALSE;
	GdkEventKey* keyevent = NULL;
	GdkEvent* _tmp0_ = NULL;
	GdkEventKey* _tmp1_ = NULL;
	GdkEventKey* _tmp2_ = NULL;
	GdkEventKey* _tmp3_ = NULL;
	guint _tmp4_ = 0U;
	GdkDevice* device = NULL;
	GdkEvent* _tmp5_ = NULL;
	GdkDevice* _tmp6_ = NULL;
	GdkDevice* _tmp7_ = NULL;
	GdkDevice* pointer = NULL;
	GdkDevice* _tmp8_ = NULL;
	GdkInputSource _tmp9_ = 0;
	gdouble* axes = NULL;
	gint axes_length1 = 0;
	gint _axes_size_ = 0;
	guint modifier = 0U;
	GdkDevice* _tmp15_ = NULL;
	GdkEventKey* _tmp16_ = NULL;
	GdkWindow* _tmp17_ = NULL;
	gdouble* _tmp18_ = NULL;
	gint _tmp18__length1 = 0;
	GdkModifierType _tmp19_ = 0;
	guint _tmp20_ = 0U;
	guint _tmp21_ = 0U;
	guint _tmp22_ = 0U;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = event;
	_tmp1_ = (GdkEventKey *) (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = __vala_GdkEventKey_copy0 (_tmp2_);
	keyevent = _tmp3_;
	_tmp4_ = primary_modifier;
	if (_tmp4_ == ((guint) 0)) {
		result = FALSE;
		__vala_GdkEventKey_free0 (keyevent);
		return result;
	}
	_tmp5_ = event;
	_tmp6_ = gdk_event_get_device (_tmp5_);
	_tmp7_ = _g_object_ref0 (_tmp6_);
	device = _tmp7_;
	_tmp8_ = device;
	_tmp9_ = gdk_device_get_source (_tmp8_);
	if (_tmp9_ == GDK_SOURCE_KEYBOARD) {
		GdkDevice* _tmp10_ = NULL;
		GdkDevice* _tmp11_ = NULL;
		GdkDevice* _tmp12_ = NULL;
		_tmp10_ = device;
		_tmp11_ = gdk_device_get_associated_device (_tmp10_);
		_tmp12_ = _g_object_ref0 (_tmp11_);
		_g_object_unref0 (pointer);
		pointer = _tmp12_;
	} else {
		GdkDevice* _tmp13_ = NULL;
		GdkDevice* _tmp14_ = NULL;
		_tmp13_ = device;
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_g_object_unref0 (pointer);
		pointer = _tmp14_;
	}
	axes = NULL;
	axes_length1 = 0;
	_axes_size_ = axes_length1;
	modifier = (guint) 0;
	_tmp15_ = pointer;
	_tmp16_ = keyevent;
	_tmp17_ = _tmp16_->window;
	_tmp18_ = axes;
	_tmp18__length1 = axes_length1;
	gdk_device_get_state (_tmp15_, _tmp17_, _tmp18_, &_tmp19_);
	modifier = (guint) _tmp19_;
	_tmp20_ = primary_modifier;
	_tmp21_ = modifier;
	_tmp22_ = primary_modifier;
	if ((_tmp20_ & _tmp21_) == _tmp22_) {
		result = TRUE;
		axes = (g_free (axes), NULL);
		_g_object_unref0 (pointer);
		_g_object_unref0 (device);
		__vala_GdkEventKey_free0 (keyevent);
		return result;
	}
	result = FALSE;
	axes = (g_free (axes), NULL);
	_g_object_unref0 (pointer);
	_g_object_unref0 (device);
	__vala_GdkEventKey_free0 (keyevent);
	return result;
}


guint keybinding_manager_keyval_to_modifier (guint keyval) {
	guint result = 0U;
	guint _tmp0_ = 0U;
	_tmp0_ = keyval;
	switch (_tmp0_) {
		case 0xffe3:
		case 0xffe4:
		{
			result = (guint) GDK_CONTROL_MASK;
			return result;
		}
		case 0xffe1:
		case 0xffe2:
		{
			result = (guint) GDK_SHIFT_MASK;
			return result;
		}
		case 0xffe5:
		{
			result = (guint) GDK_LOCK_MASK;
			return result;
		}
		case 0xffe9:
		case 0xffea:
		{
			result = (guint) GDK_MOD1_MASK;
			return result;
		}
		case 0xffe7:
		case 0xffe8:
		{
			result = (guint) GDK_META_MASK;
			return result;
		}
		case 0xffeb:
		case 0xffec:
		{
			result = (guint) GDK_SUPER_MASK;
			return result;
		}
		case 0xffed:
		case 0xffee:
		{
			result = (guint) GDK_HYPER_MASK;
			return result;
		}
		default:
		{
			result = (guint) 0;
			return result;
		}
	}
}


static void keybinding_manager_event_handler (KeybindingManager* self, GdkEvent* event) {
	GdkEvent* _tmp30_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (event != NULL);
	{
		gboolean _tmp0_ = FALSE;
		_tmp0_ = TRUE;
		while (TRUE) {
			GdkEvent* _tmp1_ = NULL;
			GdkEventAny* _tmp2_ = NULL;
			GdkEventAny* _tmp3_ = NULL;
			GdkWindow* _tmp4_ = NULL;
			GdkWindow* _tmp5_ = NULL;
			GdkEvent* _tmp6_ = NULL;
			GdkEventType _tmp7_ = 0;
			if (!_tmp0_) {
				if (!FALSE) {
					break;
				}
			}
			_tmp0_ = FALSE;
			_tmp1_ = event;
			_tmp2_ = (GdkEventAny *) (_tmp1_);
			_tmp3_ = _tmp2_;
			_tmp4_ = _tmp3_->window;
			_tmp5_ = gdk_get_default_root_window ();
			if (_tmp4_ != _tmp5_) {
				break;
			}
			_tmp6_ = event;
			_tmp7_ = _tmp6_->type;
			if (_tmp7_ == GDK_KEY_PRESS) {
				guint modifiers = 0U;
				GdkEvent* _tmp8_ = NULL;
				GdkEventKey* _tmp9_ = NULL;
				GdkEventKey* _tmp10_ = NULL;
				GdkModifierType _tmp11_ = 0;
				GList* _tmp12_ = NULL;
				_tmp8_ = event;
				_tmp9_ = (GdkEventKey *) (_tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = _tmp10_->state;
				modifiers = (guint) (_tmp11_ & KEYBINDING_MANAGER_MODIFIER_FILTER);
				_tmp12_ = self->priv->m_bindings;
				{
					GList* binding_collection = NULL;
					GList* binding_it = NULL;
					binding_collection = _tmp12_;
					for (binding_it = binding_collection; binding_it != NULL; binding_it = binding_it->next) {
						KeybindingManagerKeybinding* _tmp13_ = NULL;
						KeybindingManagerKeybinding* binding = NULL;
						_tmp13_ = _keybinding_manager_keybinding_ref0 ((KeybindingManagerKeybinding*) binding_it->data);
						binding = _tmp13_;
						{
							gboolean _tmp14_ = FALSE;
							GdkEvent* _tmp15_ = NULL;
							GdkEventKey* _tmp16_ = NULL;
							GdkEventKey* _tmp17_ = NULL;
							guint _tmp18_ = 0U;
							KeybindingManagerKeybinding* _tmp19_ = NULL;
							guint _tmp20_ = 0U;
							guint _tmp21_ = 0U;
							KeybindingManagerKeybinding* _tmp26_ = NULL;
							KeybindingManagerKeybindingHandlerFunc _tmp27_ = NULL;
							void* _tmp27__target = NULL;
							KeybindingManagerKeybindingHandlerFunc _tmp28_ = NULL;
							void* _tmp28__target = NULL;
							GdkEvent* _tmp29_ = NULL;
							_tmp15_ = event;
							_tmp16_ = (GdkEventKey *) (_tmp15_);
							_tmp17_ = _tmp16_;
							_tmp18_ = _tmp17_->keyval;
							_tmp19_ = binding;
							_tmp20_ = keybinding_manager_keybinding_get_keysym (_tmp19_);
							_tmp21_ = _tmp20_;
							if (_tmp18_ != _tmp21_) {
								_tmp14_ = TRUE;
							} else {
								guint _tmp22_ = 0U;
								KeybindingManagerKeybinding* _tmp23_ = NULL;
								GdkModifierType _tmp24_ = 0;
								GdkModifierType _tmp25_ = 0;
								_tmp22_ = modifiers;
								_tmp23_ = binding;
								_tmp24_ = keybinding_manager_keybinding_get_modifiers (_tmp23_);
								_tmp25_ = _tmp24_;
								_tmp14_ = _tmp22_ != ((guint) _tmp25_);
							}
							if (_tmp14_) {
								_keybinding_manager_keybinding_unref0 (binding);
								continue;
							}
							_tmp26_ = binding;
							_tmp27_ = keybinding_manager_keybinding_get_handler (_tmp26_, &_tmp27__target);
							_tmp28_ = _tmp27_;
							_tmp28__target = _tmp27__target;
							_tmp29_ = event;
							_tmp28_ (_tmp29_, _tmp28__target);
							_keybinding_manager_keybinding_unref0 (binding);
							return;
						}
					}
				}
			}
		}
	}
	_tmp30_ = event;
	gtk_main_do_event (_tmp30_);
}


static void _vala_array_add10 (gint** array, int* length, int* size, gint value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}


static void _vala_array_add11 (gint** array, int* length, int* size, gint value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}


static void _vala_array_add12 (gint** array, int* length, int* size, gint value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gint, *array, *size);
	}
	(*array)[(*length)++] = value;
}


static void _vala_array_add13 (XIGrabModifiers** array, int* length, int* size, const XIGrabModifiers* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (XIGrabModifiers, *array, *size);
	}
	(*array)[(*length)++] = *value;
}


static void _vala_XIGrabModifiers_array_free (XIGrabModifiers* array, gint array_length) {
	if (array != NULL) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			 (&array[i]);
		}
	}
	g_free (array);
}


static XIGrabModifiers* keybinding_manager_get_grab_modifiers (KeybindingManager* self, guint modifiers, int* result_length1) {
	XIGrabModifiers* result = NULL;
	static const gint ignored_modifiers[] = {(gint) LockMask, (gint) Mod2Mask, (gint) Mod5Mask};
	gint* masks = NULL;
	gint* _tmp0_ = NULL;
	gint masks_length1 = 0;
	gint _masks_size_ = 0;
	gint* _tmp18_ = NULL;
	gint _tmp18__length1 = 0;
	XIGrabModifiers* ximodifiers = NULL;
	XIGrabModifiers* _tmp19_ = NULL;
	gint ximodifiers_length1 = 0;
	gint _ximodifiers_size_ = 0;
	gint* _tmp20_ = NULL;
	gint _tmp20__length1 = 0;
	XIGrabModifiers* _tmp25_ = NULL;
	gint _tmp25__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_new0 (gint, 0);
	masks = _tmp0_;
	masks_length1 = 0;
	_masks_size_ = masks_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gint _tmp3_ = 0;
				gint modifier = 0;
				gint _tmp4_ = 0;
				gint _tmp5_ = 0;
				gint* _tmp6_ = NULL;
				gint _tmp6__length1 = 0;
				gint _tmp7_ = 0;
				gint length = 0;
				gint* _tmp8_ = NULL;
				gint _tmp8__length1 = 0;
				if (!_tmp1_) {
					gint _tmp2_ = 0;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				_tmp3_ = i;
				if (!(_tmp3_ < G_N_ELEMENTS (ignored_modifiers))) {
					break;
				}
				_tmp4_ = i;
				_tmp5_ = ignored_modifiers[_tmp4_];
				modifier = _tmp5_;
				_tmp6_ = masks;
				_tmp6__length1 = masks_length1;
				_tmp7_ = modifier;
				_vala_array_add10 (&masks, &masks_length1, &_masks_size_, _tmp7_);
				_tmp8_ = masks;
				_tmp8__length1 = masks_length1;
				length = _tmp8__length1;
				{
					gint j = 0;
					j = 0;
					{
						gboolean _tmp9_ = FALSE;
						_tmp9_ = TRUE;
						while (TRUE) {
							gint _tmp11_ = 0;
							gint _tmp12_ = 0;
							gint* _tmp13_ = NULL;
							gint _tmp13__length1 = 0;
							gint* _tmp14_ = NULL;
							gint _tmp14__length1 = 0;
							gint _tmp15_ = 0;
							gint _tmp16_ = 0;
							gint _tmp17_ = 0;
							if (!_tmp9_) {
								gint _tmp10_ = 0;
								_tmp10_ = j;
								j = _tmp10_ + 1;
							}
							_tmp9_ = FALSE;
							_tmp11_ = j;
							_tmp12_ = length;
							if (!(_tmp11_ < (_tmp12_ - 1))) {
								break;
							}
							_tmp13_ = masks;
							_tmp13__length1 = masks_length1;
							_tmp14_ = masks;
							_tmp14__length1 = masks_length1;
							_tmp15_ = j;
							_tmp16_ = _tmp14_[_tmp15_];
							_tmp17_ = modifier;
							_vala_array_add11 (&masks, &masks_length1, &_masks_size_, _tmp16_ | _tmp17_);
						}
					}
				}
			}
		}
	}
	_tmp18_ = masks;
	_tmp18__length1 = masks_length1;
	_vala_array_add12 (&masks, &masks_length1, &_masks_size_, 0);
	_tmp19_ = g_new0 (XIGrabModifiers, 0);
	ximodifiers = _tmp19_;
	ximodifiers_length1 = 0;
	_ximodifiers_size_ = ximodifiers_length1;
	_tmp20_ = masks;
	_tmp20__length1 = masks_length1;
	{
		gint* mask_collection = NULL;
		gint mask_collection_length1 = 0;
		gint _mask_collection_size_ = 0;
		gint mask_it = 0;
		mask_collection = _tmp20_;
		mask_collection_length1 = _tmp20__length1;
		for (mask_it = 0; mask_it < _tmp20__length1; mask_it = mask_it + 1) {
			gint mask = 0;
			mask = mask_collection[mask_it];
			{
				XIGrabModifiers* _tmp21_ = NULL;
				gint _tmp21__length1 = 0;
				gint _tmp22_ = 0;
				guint _tmp23_ = 0U;
				XIGrabModifiers _tmp24_ = {0};
				_tmp21_ = ximodifiers;
				_tmp21__length1 = ximodifiers_length1;
				_tmp22_ = mask;
				_tmp23_ = modifiers;
				memset (&_tmp24_, 0, sizeof (XIGrabModifiers));
				_tmp24_.modifiers = _tmp22_ | _tmp23_;
				_tmp24_.status = 0;
				_vala_array_add13 (&ximodifiers, &ximodifiers_length1, &_ximodifiers_size_, &_tmp24_);
			}
		}
	}
	_tmp25_ = ximodifiers;
	_tmp25__length1 = ximodifiers_length1;
	if (result_length1) {
		*result_length1 = _tmp25__length1;
	}
	result = _tmp25_;
	masks = (g_free (masks), NULL);
	return result;
}


static gboolean keybinding_manager_grab_keycode (KeybindingManager* self, GdkDisplay* display, guint keyval, guint modifiers) {
	gboolean result = FALSE;
	Display* xdisplay = NULL;
	GdkDisplay* _tmp0_ = NULL;
	Display* _tmp1_ = NULL;
	gint keycode = 0;
	Display* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	guchar _tmp4_ = '\0';
	gint _tmp5_ = 0;
	XIEventMask evmask = {0};
	guchar* _tmp7_ = NULL;
	XIEventMask _tmp8_ = {0};
	XIEventMask _tmp9_ = {0};
	guchar* _tmp10_ = NULL;
	gint _tmp10__length1 = 0;
	XIEventMask _tmp11_ = {0};
	guchar* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	gint retval = 0;
	Display* _tmp13_ = NULL;
	gint _tmp14_ = 0;
	Display* _tmp15_ = NULL;
	Window _tmp16_ = 0;
	XIEventMask _tmp17_ = {0};
	guint _tmp18_ = 0U;
	gint _tmp19_ = 0;
	XIGrabModifiers* _tmp20_ = NULL;
	XIGrabModifiers* _tmp21_ = NULL;
	gint _tmp21__length1 = 0;
	gint _tmp22_ = 0;
	gint _tmp23_ = 0;
	gint _tmp24_ = 0;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (display != NULL, FALSE);
	_tmp0_ = display;
	_tmp1_ = gdk_x11_display_get_xdisplay (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gdk_x11_display_get_type ()) ? ((GdkX11Display*) _tmp0_) : NULL);
	xdisplay = _tmp1_;
	_tmp2_ = xdisplay;
	_tmp3_ = keyval;
	_tmp4_ = XKeysymToKeycode (_tmp2_, (gulong) _tmp3_);
	keycode = (gint) _tmp4_;
	_tmp5_ = keycode;
	if (_tmp5_ == 0) {
		guint _tmp6_ = 0U;
		_tmp6_ = keyval;
		g_warning ("keybindingmanager.vala:255: Can not convert keyval=%u to keycode!", _tmp6_);
		result = FALSE;
		return result;
	}
	_tmp7_ = g_new0 (guchar, (XI_LASTEVENT + 7) / 8);
	memset (&_tmp8_, 0, sizeof (XIEventMask));
	_tmp8_.deviceid = XIAllMasterDevices;
	_tmp8_.mask = (g_free (_tmp8_.mask), NULL);
	_tmp8_.mask = _tmp7_;
	_tmp8_.mask_len = (XI_LASTEVENT + 7) / 8;
	evmask = _tmp8_;
	_tmp9_ = evmask;
	_tmp10_ = _tmp9_.mask;
	_tmp10__length1 = _tmp9_.mask_len;
	XISetMask (_tmp10_, XI_KeyPress);
	_tmp11_ = evmask;
	_tmp12_ = _tmp11_.mask;
	_tmp12__length1 = _tmp11_.mask_len;
	XISetMask (_tmp12_, XI_KeyRelease);
	_tmp13_ = xdisplay;
	_tmp14_ = keycode;
	_tmp15_ = xdisplay;
	_tmp16_ = DefaultRootWindow (_tmp15_);
	_tmp17_ = evmask;
	_tmp18_ = modifiers;
	_tmp20_ = keybinding_manager_get_grab_modifiers (self, _tmp18_, &_tmp19_);
	_tmp21_ = _tmp20_;
	_tmp21__length1 = _tmp19_;
	_tmp22_ = XIGrabKeycode (_tmp13_, XIAllMasterDevices, _tmp14_, _tmp16_, (gint) GrabModeAsync, (gint) GrabModeAsync, TRUE, &_tmp17_, _tmp19_, _tmp21_);
	_tmp23_ = _tmp22_;
	_tmp21_ = (_vala_XIGrabModifiers_array_free (_tmp21_, _tmp21__length1), NULL);
	retval = _tmp23_;
	_tmp24_ = retval;
	result = _tmp24_ == 0;
	 (&evmask);
	return result;
}


static gboolean keybinding_manager_ungrab_keycode (KeybindingManager* self, GdkDisplay* display, guint keyval, guint modifiers) {
	gboolean result = FALSE;
	Display* xdisplay = NULL;
	GdkDisplay* _tmp0_ = NULL;
	Display* _tmp1_ = NULL;
	gint keycode = 0;
	Display* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	guchar _tmp4_ = '\0';
	gint _tmp5_ = 0;
	gint retval = 0;
	Display* _tmp7_ = NULL;
	gint _tmp8_ = 0;
	Display* _tmp9_ = NULL;
	Window _tmp10_ = 0;
	guint _tmp11_ = 0U;
	gint _tmp12_ = 0;
	XIGrabModifiers* _tmp13_ = NULL;
	XIGrabModifiers* _tmp14_ = NULL;
	gint _tmp14__length1 = 0;
	gint _tmp15_ = 0;
	gint _tmp16_ = 0;
	gint _tmp17_ = 0;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (display != NULL, FALSE);
	_tmp0_ = display;
	_tmp1_ = gdk_x11_display_get_xdisplay (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gdk_x11_display_get_type ()) ? ((GdkX11Display*) _tmp0_) : NULL);
	xdisplay = _tmp1_;
	_tmp2_ = xdisplay;
	_tmp3_ = keyval;
	_tmp4_ = XKeysymToKeycode (_tmp2_, (gulong) _tmp3_);
	keycode = (gint) _tmp4_;
	_tmp5_ = keycode;
	if (_tmp5_ == 0) {
		guint _tmp6_ = 0U;
		_tmp6_ = keyval;
		g_warning ("keybindingmanager.vala:288: Can not convert keyval=%u to keycode!", _tmp6_);
		result = FALSE;
		return result;
	}
	_tmp7_ = xdisplay;
	_tmp8_ = keycode;
	_tmp9_ = xdisplay;
	_tmp10_ = DefaultRootWindow (_tmp9_);
	_tmp11_ = modifiers;
	_tmp13_ = keybinding_manager_get_grab_modifiers (self, _tmp11_, &_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp14__length1 = _tmp12_;
	_tmp15_ = XIUngrabKeycode (_tmp7_, XIAllMasterDevices, _tmp8_, _tmp10_, _tmp12_, _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp14_ = (_vala_XIGrabModifiers_array_free (_tmp14_, _tmp14__length1), NULL);
	retval = _tmp16_;
	_tmp17_ = retval;
	result = _tmp17_ == 0;
	return result;
}


static KeybindingManagerKeybinding* keybinding_manager_keybinding_construct (GType object_type, guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target) {
	KeybindingManagerKeybinding* self = NULL;
	guint _tmp0_ = 0U;
	GdkModifierType _tmp1_ = 0;
	KeybindingManagerKeybindingHandlerFunc _tmp2_ = NULL;
	void* _tmp2__target = NULL;
	self = (KeybindingManagerKeybinding*) g_type_create_instance (object_type);
	_tmp0_ = keysym;
	keybinding_manager_keybinding_set_keysym (self, _tmp0_);
	_tmp1_ = modifiers;
	keybinding_manager_keybinding_set_modifiers (self, _tmp1_);
	_tmp2_ = handler;
	_tmp2__target = handler_target;
	keybinding_manager_keybinding_set_handler (self, _tmp2_, _tmp2__target);
	return self;
}


static KeybindingManagerKeybinding* keybinding_manager_keybinding_new (guint keysym, GdkModifierType modifiers, KeybindingManagerKeybindingHandlerFunc handler, void* handler_target) {
	return keybinding_manager_keybinding_construct (KEYBINDING_MANAGER_TYPE_KEYBINDING, keysym, modifiers, handler, handler_target);
}


static guint keybinding_manager_keybinding_get_keysym (KeybindingManagerKeybinding* self) {
	guint result;
	guint _tmp0_ = 0U;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->_keysym;
	result = _tmp0_;
	return result;
}


static void keybinding_manager_keybinding_set_keysym (KeybindingManagerKeybinding* self, guint value) {
	guint _tmp0_ = 0U;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_keysym = _tmp0_;
}


static GdkModifierType keybinding_manager_keybinding_get_modifiers (KeybindingManagerKeybinding* self) {
	GdkModifierType result;
	GdkModifierType _tmp0_ = 0;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_modifiers;
	result = _tmp0_;
	return result;
}


static void keybinding_manager_keybinding_set_modifiers (KeybindingManagerKeybinding* self, GdkModifierType value) {
	GdkModifierType _tmp0_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_modifiers = _tmp0_;
}


static KeybindingManagerKeybindingHandlerFunc keybinding_manager_keybinding_get_handler (KeybindingManagerKeybinding* self, gpointer* result_target) {
	KeybindingManagerKeybindingHandlerFunc result;
	KeybindingManagerKeybindingHandlerFunc _tmp0_ = NULL;
	void* _tmp0__target = NULL;
	KeybindingManagerKeybindingHandlerFunc _tmp1_ = NULL;
	void* _tmp1__target = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_handler;
	_tmp0__target = self->priv->_handler_target;
	_tmp1_ = _tmp0_;
	_tmp1__target = _tmp0__target;
	*result_target = _tmp1__target;
	result = _tmp1_;
	return result;
}


static void keybinding_manager_keybinding_set_handler (KeybindingManagerKeybinding* self, KeybindingManagerKeybindingHandlerFunc value, gpointer value_target) {
	KeybindingManagerKeybindingHandlerFunc _tmp0_ = NULL;
	void* _tmp0__target = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp0__target = value_target;
	self->priv->_handler = _tmp0_;
	self->priv->_handler_target = _tmp0__target;
}


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


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


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


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


static gchar* keybinding_manager_value_keybinding_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		KeybindingManagerKeybinding* 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 = keybinding_manager_keybinding_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* keybinding_manager_value_keybinding_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	KeybindingManagerKeybinding** 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 = keybinding_manager_keybinding_ref (value->data[0].v_pointer);
	}
	return NULL;
}


static GParamSpec* keybinding_manager_param_spec_keybinding (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	KeybindingManagerParamSpecKeybinding* spec;
	g_return_val_if_fail (g_type_is_a (object_type, KEYBINDING_MANAGER_TYPE_KEYBINDING), 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);
}


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


static void keybinding_manager_value_set_keybinding (GValue* value, gpointer v_object) {
	KeybindingManagerKeybinding* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KEYBINDING_MANAGER_TYPE_KEYBINDING));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KEYBINDING_MANAGER_TYPE_KEYBINDING));
		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;
		keybinding_manager_keybinding_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		keybinding_manager_keybinding_unref (old);
	}
}


static void keybinding_manager_value_take_keybinding (GValue* value, gpointer v_object) {
	KeybindingManagerKeybinding* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, KEYBINDING_MANAGER_TYPE_KEYBINDING));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, KEYBINDING_MANAGER_TYPE_KEYBINDING));
		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) {
		keybinding_manager_keybinding_unref (old);
	}
}


static void keybinding_manager_keybinding_class_init (KeybindingManagerKeybindingClass * klass) {
	keybinding_manager_keybinding_parent_class = g_type_class_peek_parent (klass);
	((KeybindingManagerKeybindingClass *) klass)->finalize = keybinding_manager_keybinding_finalize;
	g_type_class_add_private (klass, sizeof (KeybindingManagerKeybindingPrivate));
}


static void keybinding_manager_keybinding_instance_init (KeybindingManagerKeybinding * self) {
	self->priv = KEYBINDING_MANAGER_KEYBINDING_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void keybinding_manager_keybinding_finalize (KeybindingManagerKeybinding* obj) {
	KeybindingManagerKeybinding * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KEYBINDING_MANAGER_TYPE_KEYBINDING, KeybindingManagerKeybinding);
	g_signal_handlers_destroy (self);
}


/**
     * Helper class to store keybinding
     */
static GType keybinding_manager_keybinding_get_type (void) {
	static volatile gsize keybinding_manager_keybinding_type_id__volatile = 0;
	if (g_once_init_enter (&keybinding_manager_keybinding_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { keybinding_manager_value_keybinding_init, keybinding_manager_value_keybinding_free_value, keybinding_manager_value_keybinding_copy_value, keybinding_manager_value_keybinding_peek_pointer, "p", keybinding_manager_value_keybinding_collect_value, "p", keybinding_manager_value_keybinding_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (KeybindingManagerKeybindingClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) keybinding_manager_keybinding_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KeybindingManagerKeybinding), 0, (GInstanceInitFunc) keybinding_manager_keybinding_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) };
		GType keybinding_manager_keybinding_type_id;
		keybinding_manager_keybinding_type_id = g_type_register_fundamental (g_type_fundamental_next (), "KeybindingManagerKeybinding", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&keybinding_manager_keybinding_type_id__volatile, keybinding_manager_keybinding_type_id);
	}
	return keybinding_manager_keybinding_type_id__volatile;
}


static gpointer keybinding_manager_keybinding_ref (gpointer instance) {
	KeybindingManagerKeybinding* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


static void keybinding_manager_keybinding_unref (gpointer instance) {
	KeybindingManagerKeybinding* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		KEYBINDING_MANAGER_KEYBINDING_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void keybinding_manager_class_init (KeybindingManagerClass * klass) {
	keybinding_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (KeybindingManagerPrivate));
	G_OBJECT_CLASS (klass)->finalize = keybinding_manager_finalize;
}


static void keybinding_manager_instance_init (KeybindingManager * self) {
	self->priv = KEYBINDING_MANAGER_GET_PRIVATE (self);
	self->priv->m_bindings = NULL;
}


static void keybinding_manager_finalize (GObject* obj) {
	KeybindingManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_KEYBINDING_MANAGER, KeybindingManager);
	__g_list_free__keybinding_manager_keybinding_unref0_0 (self->priv->m_bindings);
	G_OBJECT_CLASS (keybinding_manager_parent_class)->finalize (obj);
}


/**
 * This class is in charge to grab keybindings on the X11 display
 * and filter X11-events and passing on such events to the registed
 * handler methods.
 *
 * @author Oliver Sauder <os@esite.ch>
 */
GType keybinding_manager_get_type (void) {
	static volatile gsize keybinding_manager_type_id__volatile = 0;
	if (g_once_init_enter (&keybinding_manager_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (KeybindingManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) keybinding_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KeybindingManager), 0, (GInstanceInitFunc) keybinding_manager_instance_init, NULL };
		GType keybinding_manager_type_id;
		keybinding_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "KeybindingManager", &g_define_type_info, 0);
		g_once_init_leave (&keybinding_manager_type_id__volatile, keybinding_manager_type_id);
	}
	return keybinding_manager_type_id__volatile;
}



