[gnome-games/wip/aplazas/781572-remove-vala-macro: 1/6] gamepad: Port GamepadInputType to C



commit 325828b0244dd533c575012a98b2f7fb76deb964
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Apr 28 09:34:34 2017 +0200

    gamepad: Port GamepadInputType to C
    
    This will help to port part of the gamepad handling to C to avoid using
    the Vala preprocessor.
    
    Also makes GamepadInputType.INVALID the first value, hence the value
    associated to 0, so it act as a safe default.

 src/Makefile.am                                    |    4 ++-
 src/gamepad/gamepad-input-type.c                   |   22 ++++++++++++++
 src/gamepad/gamepad-input-type.h                   |   30 ++++++++++++++++++++
 ...pad-input-type.vala => gamepad-input-type.vapi} |    3 +-
 4 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 604ff67..200ff63 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,7 @@ BUILT_SOURCES = \
 
 EXTRA_DIST = \
        $(gresource_file) \
+       gamepad/gamepad-input-type.vapi \
        gamepad/linux/linux-raw-gamepad-monitor.vapi \
        gamepad/raw-gamepad.vapi \
        gamepad/raw-gamepad-monitor.vapi \
@@ -73,7 +74,7 @@ gnome_games_SOURCES = \
        gamepad/gamepad.vala \
        gamepad/gamepad-callbacks.vala \
        gamepad/gamepad-dpad.vala \
-       gamepad/gamepad-input-type.vala \
+       gamepad/gamepad-input-type.c \
        gamepad/gamepad-mapped-event.vala \
        gamepad/gamepad-mapping.vala \
        gamepad/gamepad-mapping-error.vala \
@@ -182,6 +183,7 @@ gnome_games_VALAFLAGS = \
        --pkg retro-gtk-0.10 \
        --pkg linux \
        --pkg posix \
+       --pkg gamepad-input-type \
        --pkg raw-gamepad \
        --pkg raw-gamepad-monitor \
        --pkg standard-gamepad-axis \
diff --git a/src/gamepad/gamepad-input-type.c b/src/gamepad/gamepad-input-type.c
new file mode 100644
index 0000000..caf19a8
--- /dev/null
+++ b/src/gamepad/gamepad-input-type.c
@@ -0,0 +1,22 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#include "gamepad-input-type.h"
+
+GType
+games_gamepad_input_type_get_type (void)
+{
+  static volatile gsize type_id = 0;
+  static const GEnumValue values[] = {
+    { GAMES_GAMEPAD_INPUT_TYPE_INVALID, "GAMES_GAMEPAD_INPUT_TYPE_INVALID", "invalid" },
+    { GAMES_GAMEPAD_INPUT_TYPE_AXIS, "GAMES_GAMEPAD_INPUT_TYPE_AXIS", "axis" },
+    { GAMES_GAMEPAD_INPUT_TYPE_BUTTON, "GAMES_GAMEPAD_INPUT_TYPE_BUTTON", "button" },
+    { 0, NULL, NULL },
+  };
+
+  if (g_once_init_enter (&type_id))
+    g_once_init_leave (&type_id,
+                       g_enum_register_static ("GamesGamepadInputType",
+                                               values));
+
+  return type_id;
+}
diff --git a/src/gamepad/gamepad-input-type.h b/src/gamepad/gamepad-input-type.h
new file mode 100644
index 0000000..d9c802f
--- /dev/null
+++ b/src/gamepad/gamepad-input-type.h
@@ -0,0 +1,30 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#ifndef GAMES_GAMEPAD_INPUT_TYPE_H
+#define GAMES_GAMEPAD_INPUT_TYPE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_GAMEPAD_INPUT_TYPE (games_gamepad_input_type_get_type ())
+
+/**
+ * GamesGamepadInputType:
+ * @GAMES_GAMEPAD_INPUT_TYPE_INVALID: an invalid input type
+ * @GAMES_GAMEPAD_INPUT_TYPE_AXIS: an axis
+ * @GAMES_GAMEPAD_INPUT_TYPE_BUTTON: a button
+ *
+ * The input types of a standard gamepad.
+ **/
+typedef enum {
+  GAMES_GAMEPAD_INPUT_TYPE_INVALID,
+  GAMES_GAMEPAD_INPUT_TYPE_AXIS,
+  GAMES_GAMEPAD_INPUT_TYPE_BUTTON,
+} GamesGamepadInputType;
+
+GType games_gamepad_input_type_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GAMES_GAMEPAD_INPUT_TYPE_H */
diff --git a/src/gamepad/gamepad-input-type.vala b/src/gamepad/gamepad-input-type.vapi
similarity index 70%
rename from src/gamepad/gamepad-input-type.vala
rename to src/gamepad/gamepad-input-type.vapi
index 583d28f..5bc689e 100644
--- a/src/gamepad/gamepad-input-type.vala
+++ b/src/gamepad/gamepad-input-type.vapi
@@ -1,7 +1,8 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
+[CCode (cheader_filename = "gamepad-input-type.h")]
 private enum Games.GamepadInputType {
+       INVALID,
        AXIS,
        BUTTON,
-       INVALID,
 }


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