[gnome-games/wip/aplazas/781572-remove-vala-macro: 14/19] gamepad: Port GamepadDPad to C
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781572-remove-vala-macro: 14/19] gamepad: Port GamepadDPad to C
- Date: Tue, 2 May 2017 12:11:22 +0000 (UTC)
commit 8b21d6f1138f0b523656faa492d854b3a8a0c89b
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Apr 28 14:19:37 2017 +0200
gamepad: Port GamepadDPad to C
This will help to port part of the gamepad handling to C to avoid using
the Vala preprocessor.
src/Makefile.am | 4 ++-
src/gamepad/gamepad-dpad.c | 36 ++++++++++++++++++++
src/gamepad/gamepad-dpad.h | 25 ++++++++++++++
.../{gamepad-dpad.vala => gamepad-dpad.vapi} | 1 +
4 files changed, 65 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 19766ee..ead8089 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,7 @@ BUILT_SOURCES = \
EXTRA_DIST = \
$(gresource_file) \
+ gamepad/gamepad-dpad.vapi \
gamepad/gamepad-input-type.vapi \
gamepad/gamepad-mapped-event.vapi \
gamepad/gamepad-mapping-error.vapi \
@@ -75,7 +76,7 @@ gnome_games_SOURCES = \
\
gamepad/gamepad.vala \
gamepad/gamepad-callbacks.vala \
- gamepad/gamepad-dpad.vala \
+ gamepad/gamepad-dpad.c \
gamepad/gamepad-input-type.c \
gamepad/gamepad-mapped-event.c \
gamepad/gamepad-mapping.vala \
@@ -185,6 +186,7 @@ gnome_games_VALAFLAGS = \
--pkg retro-gtk-0.10 \
--pkg linux \
--pkg posix \
+ --pkg gamepad-dpad \
--pkg gamepad-input-type \
--pkg gamepad-mapped-event \
--pkg gamepad-mapping-error \
diff --git a/src/gamepad/gamepad-dpad.c b/src/gamepad/gamepad-dpad.c
new file mode 100644
index 0000000..1748243
--- /dev/null
+++ b/src/gamepad/gamepad-dpad.c
@@ -0,0 +1,36 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#include "gamepad-dpad.h"
+
+#include <string.h>
+
+GamesGamepadDPad *
+games_gamepad_dpad_dup (const GamesGamepadDPad *self)
+{
+ GamesGamepadDPad *dup;
+
+ dup = g_new0 (GamesGamepadDPad, 1);
+ memcpy (dup, self, sizeof (GamesGamepadDPad));
+
+ return dup;
+}
+
+void
+games_gamepad_dpad_free (GamesGamepadDPad *self)
+{
+ g_free (self);
+}
+
+GType
+games_gamepad_dpad_get_type (void)
+{
+ static volatile gsize type_id = 0;
+
+ if (g_once_init_enter (&type_id))
+ g_once_init_leave (&type_id,
+ g_boxed_type_register_static ("GamesGamepadDPad",
+ (GBoxedCopyFunc) games_gamepad_dpad_dup,
+ (GBoxedFreeFunc) games_gamepad_dpad_free));
+
+ return type_id;
+}
diff --git a/src/gamepad/gamepad-dpad.h b/src/gamepad/gamepad-dpad.h
new file mode 100644
index 0000000..bfc0a2c
--- /dev/null
+++ b/src/gamepad/gamepad-dpad.h
@@ -0,0 +1,25 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#ifndef GAMES_GAMEPAD_DPAD_H
+#define GAMES_GAMEPAD_DPAD_H
+
+#include <glib-object.h>
+#include "gamepad-input-type.h"
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_GAMEPAD_DPAD (games_gamepad_dpad_get_type ())
+
+typedef struct {
+ GamesGamepadInputType types[4];
+ gint values[4];
+ gint axis_values[2];
+} GamesGamepadDPad;
+
+GType games_gamepad_dpad_get_type (void) G_GNUC_CONST;
+GamesGamepadDPad *games_gamepad_dpad_dup (const GamesGamepadDPad *self);
+void games_gamepad_dpad_free (GamesGamepadDPad *self);
+
+G_END_DECLS
+
+#endif /* GAMES_GAMEPAD_DPAD_H */
diff --git a/src/gamepad/gamepad-dpad.vala b/src/gamepad/gamepad-dpad.vapi
similarity index 77%
rename from src/gamepad/gamepad-dpad.vala
rename to src/gamepad/gamepad-dpad.vapi
index ae2355e..08b06b6 100644
--- a/src/gamepad/gamepad-dpad.vala
+++ b/src/gamepad/gamepad-dpad.vapi
@@ -1,5 +1,6 @@
// This file is part of GNOME Games. License: GPL-3.0+.
+[CCode (cheader_filename = "gamepad-dpad.h")]
private struct Games.GamepadDPad {
GamepadInputType types[4];
int values[4];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]