[gnome-games/wip/abhinavsingh/gamepad-config: 19/25] gamepad: Add set_mapping() to Gamepad



commit 409e4c73ed1b5b6ee5a60f6c4efaffc12c7587b9
Author: theawless <theawless gmail com>
Date:   Wed Jun 21 02:00:46 2017 +0530

    gamepad: Add set_mapping() to Gamepad
    
    This will allow us to change mappings of Gamepad even after
    construction.

 src/gamepad/gamepad.c    |   11 ++++++++++-
 src/gamepad/gamepad.h    |    3 +++
 src/gamepad/gamepad.vapi |    1 +
 3 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/gamepad/gamepad.c b/src/gamepad/gamepad.c
index 8a543fd..e586341 100644
--- a/src/gamepad/gamepad.c
+++ b/src/gamepad/gamepad.c
@@ -5,7 +5,6 @@
 #include <linux/input-event-codes.h>
 #include <stdlib.h>
 #include "../event/event.h"
-#include "gamepad-mapping.h"
 #include "gamepad-mappings-manager.h"
 
 struct _GamesGamepad {
@@ -236,6 +235,16 @@ games_gamepad_get_name (GamesGamepad *self)
   return games_raw_gamepad_get_name (self->raw_gamepad);
 }
 
+void
+games_gamepad_set_mapping (GamesGamepad        *self,
+                           GamesGamepadMapping *mapping)
+{
+  if (self->mapping != NULL)
+    g_object_unref (self->mapping);
+
+  self->mapping = mapping ? g_object_ref (mapping) : NULL;
+}
+
 // FIXME
 GamesGamepad *
 games_gamepad_new (GamesRawGamepad  *raw_gamepad,
diff --git a/src/gamepad/gamepad.h b/src/gamepad/gamepad.h
index 16d0db4..c854eda 100644
--- a/src/gamepad/gamepad.h
+++ b/src/gamepad/gamepad.h
@@ -5,6 +5,7 @@
 
 #include <glib-object.h>
 #include "raw-gamepad.h"
+#include "gamepad-mapping.h"
 
 G_BEGIN_DECLS
 
@@ -16,6 +17,8 @@ GamesGamepad *games_gamepad_new (GamesRawGamepad  *raw_gamepad,
                                  GError          **error);
 const gchar *games_gamepad_get_guid (GamesGamepad *self);
 const gchar *games_gamepad_get_name (GamesGamepad *self);
+void games_gamepad_set_mapping (GamesGamepad        *self,
+                                GamesGamepadMapping *mapping);
 
 G_END_DECLS
 
diff --git a/src/gamepad/gamepad.vapi b/src/gamepad/gamepad.vapi
index 52006a0..24c366d 100644
--- a/src/gamepad/gamepad.vapi
+++ b/src/gamepad/gamepad.vapi
@@ -11,4 +11,5 @@ private class Games.Gamepad : GLib.Object {
        public string guid { get; }
        public string name { get; }
        public Gamepad (RawGamepad raw_gamepad) throws GLib.Error;
+       public void set_mapping (GamepadMapping mapping);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]