[gnome-games: 11/20] gamepad: Port GamepadInputType to C



commit e344697cd8b9e4060e43605fc3b5816db901625d
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781572

 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 5181cf2..59e9101 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/libevdev.vapi \
        gamepad/linux/linux-raw-gamepad.vapi \
        gamepad/linux/linux-raw-gamepad-monitor.vapi \
@@ -75,7 +76,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 \
@@ -184,6 +185,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]