[gnome-games/wip/aplazas/gamepad: 14/14] gamepad: Make Gamepad derivable
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/gamepad: 14/14] gamepad: Make Gamepad derivable
- Date: Mon, 22 May 2017 09:07:27 +0000 (UTC)
commit c448d4da98dc4d3b4b6cba4091fcd585cbfbb813
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun May 14 08:16:08 2017 +0200
gamepad: Make Gamepad derivable
This is needed to make LinuxRawGamepad a subclass of Gamepad and drop
the now barely useful RawGamepad type.
src/gamepad/gamepad.c | 48 +++++++++++++++++++++++++-----------------------
src/gamepad/gamepad.h | 7 ++++++-
2 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/src/gamepad/gamepad.c b/src/gamepad/gamepad.c
index 178c16a..075907f 100644
--- a/src/gamepad/gamepad.c
+++ b/src/gamepad/gamepad.c
@@ -8,14 +8,13 @@
#include "gamepad-mapping.h"
#include "gamepad-mappings-manager.h"
-struct _GamesGamepad {
- GObject parent_instance;
-
+typedef struct
+{
GamesRawGamepad *raw_gamepad;
GamesGamepadMapping *mapping;
-};
+} GamesGamepadPrivate;
-G_DEFINE_TYPE (GamesGamepad, games_gamepad, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GamesGamepad, games_gamepad, G_TYPE_OBJECT)
enum {
SIGNAL_EVENT,
@@ -61,13 +60,14 @@ static void
map_button_event (GamesGamepad *self,
GamesEventGamepadButton *games_event)
{
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
GamesGamepadInput destination;
GamesEvent *mapped_event;
guint signal;
gboolean pressed;
mapped_event = games_event_copy ((GamesEvent *) games_event);
- games_gamepad_mapping_get_button_mapping (self->mapping,
+ games_gamepad_mapping_get_button_mapping (priv->mapping,
games_event->index,
&destination);
@@ -104,13 +104,14 @@ static void
map_axis_event (GamesGamepad *self,
GamesEventGamepadAxis *games_event)
{
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
GamesGamepadInput destination;
GamesEvent *mapped_event;
guint signal;
gboolean pressed;
mapped_event = games_event_copy ((GamesEvent *) games_event);
- games_gamepad_mapping_get_axis_mapping (self->mapping, games_event->index, &destination);
+ games_gamepad_mapping_get_axis_mapping (priv->mapping, games_event->index, &destination);
pressed = games_event->value > 0.;
@@ -144,13 +145,14 @@ static void
map_hat_event (GamesGamepad *self,
GamesEventGamepadHat *games_event)
{
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
GamesGamepadInput destination;
GamesEvent *mapped_event;
guint signal;
gboolean pressed;
mapped_event = games_event_copy ((GamesEvent *) games_event);
- games_gamepad_mapping_get_dpad_mapping (self->mapping,
+ games_gamepad_mapping_get_dpad_mapping (priv->mapping,
games_event->index,
games_event->axis,
games_event->value,
@@ -213,15 +215,14 @@ on_event (GamesRawGamepad *sender,
GamesEvent *event,
gpointer data)
{
- GamesGamepad *self;
-
- self = GAMES_GAMEPAD (data);
+ GamesGamepad *self = GAMES_GAMEPAD (data);
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
g_return_if_fail (self != NULL);
g_signal_emit (self, signals[SIGNAL_EVENT], 0, event);
- if (self->mapping == NULL)
+ if (priv->mapping == NULL)
forward_event (self, event);
else
map_event (self, event);
@@ -241,7 +242,8 @@ GamesGamepad *
games_gamepad_new (GamesRawGamepad *raw_gamepad,
GError **error)
{
- GamesGamepad *self = NULL;
+ GamesGamepad *self = GAMES_GAMEPAD (data);
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
const gchar *guid;
GamesGamepadMappingsManager *mappings_manager;
const gchar *mapping_string;
@@ -249,16 +251,14 @@ games_gamepad_new (GamesRawGamepad *raw_gamepad,
g_return_val_if_fail (raw_gamepad != NULL, NULL);
- self = (GamesGamepad*) g_object_new (GAMES_TYPE_GAMEPAD, NULL);
-
- self->raw_gamepad = g_object_ref (raw_gamepad);
+ priv->raw_gamepad = g_object_ref (raw_gamepad);
guid = games_raw_gamepad_get_guid (raw_gamepad);
mappings_manager = games_gamepad_mappings_manager_get_instance ();
mapping_string = games_gamepad_mappings_manager_get_mapping (mappings_manager, guid);
g_object_unref (mappings_manager);
- self->mapping = games_gamepad_mapping_new_from_sdl_string (mapping_string, &inner_error);
+ priv->mapping = games_gamepad_mapping_new_from_sdl_string (mapping_string, &inner_error);
if (G_UNLIKELY (inner_error != NULL)) {
g_debug ("%s", inner_error->message);
g_clear_error (&inner_error);
@@ -280,12 +280,14 @@ games_gamepad_new (GamesRawGamepad *raw_gamepad,
/* Type */
-static void finalize (GObject *obj) {
- GamesGamepad *self;
- self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAMEPAD, GamesGamepad);
- g_object_unref (self->raw_gamepad);
- g_object_unref (self->mapping);
- G_OBJECT_CLASS (games_gamepad_parent_class)->finalize (obj);
+static void finalize (GObject *object) {
+ GamesGamepad *self = (GamesGamepad *)object;
+ GamesGamepadPrivate *priv = games_gamepad_get_instance_private (self);
+
+ g_object_unref (priv->raw_gamepad);
+ g_object_unref (priv->mapping);
+
+ G_OBJECT_CLASS (games_gamepad_parent_class)->finalize (object);
}
static void games_gamepad_class_init (GamesGamepadClass *klass) {
diff --git a/src/gamepad/gamepad.h b/src/gamepad/gamepad.h
index cb8c1a0..7053159 100644
--- a/src/gamepad/gamepad.h
+++ b/src/gamepad/gamepad.h
@@ -10,7 +10,12 @@ G_BEGIN_DECLS
#define GAMES_TYPE_GAMEPAD (games_gamepad_get_type())
-G_DECLARE_FINAL_TYPE (GamesGamepad, games_gamepad, GAMES, GAMEPAD, GObject)
+G_DECLARE_DERIVABLE_TYPE (GamesGamepad, games_gamepad, GAMES, GAMEPAD, GObject)
+
+struct _GamesGamepadClass
+{
+ GObjectClass parent;
+};
GamesGamepad *games_gamepad_new (GamesRawGamepad *raw_gamepad,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]