[gnome-games/wip/aplazas/781572-remove-vala-macro: 1/19] gamepad: Port RawGamepad to C
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/781572-remove-vala-macro: 1/19] gamepad: Port RawGamepad to C
- Date: Tue, 2 May 2017 12:10:16 +0000 (UTC)
commit d3e94be5f24c2e5527018e2cd8f9c21054d988ac
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Apr 20 13:59:51 2017 +0200
gamepad: Port RawGamepad to C
This will help to port part of the gamepad handling to C to avoid using
the Vala preprocessor.
https://bugzilla.gnome.org/show_bug.cgi?id=781572
src/Makefile.am | 4 +-
src/gamepad/raw-gamepad.c | 158 ++++++++++++++++++++++++++++++++++++++++++
src/gamepad/raw-gamepad.h | 27 +++++++
src/gamepad/raw-gamepad.vala | 43 -----------
src/gamepad/raw-gamepad.vapi | 12 +++
5 files changed, 200 insertions(+), 44 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d86f402..1896848 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,7 @@ BUILT_SOURCES = \
EXTRA_DIST = \
$(gresource_file) \
gamepad/linux/libevdev.vapi \
+ gamepad/raw-gamepad.vapi \
gamepad/standard-gamepad-axis.vapi \
gamepad/standard-gamepad-button.vapi \
$(NULL)
@@ -77,7 +78,7 @@ gnome_games_SOURCES = \
gamepad/gamepad-mapping-error.vala \
gamepad/gamepad-mappings-manager.vala \
gamepad/gamepad-monitor.vala \
- gamepad/raw-gamepad.vala \
+ gamepad/raw-gamepad.c \
gamepad/raw-gamepad-monitor.vala \
gamepad/standard-gamepad-axis.c \
gamepad/standard-gamepad-button.c \
@@ -180,6 +181,7 @@ gnome_games_VALAFLAGS = \
--pkg retro-gtk-0.10 \
--pkg linux \
--pkg posix \
+ --pkg raw-gamepad \
--pkg standard-gamepad-axis \
--pkg standard-gamepad-button \
--gresources $(gresource_file) \
diff --git a/src/gamepad/raw-gamepad.c b/src/gamepad/raw-gamepad.c
new file mode 100644
index 0000000..b79893d
--- /dev/null
+++ b/src/gamepad/raw-gamepad.c
@@ -0,0 +1,158 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#include "raw-gamepad.h"
+
+#include "standard-gamepad-axis.h"
+#include "standard-gamepad-button.h"
+
+/**
+ * SECTION:raw-gamepad
+ * @Short_description: Low-level representation of a gamepad
+ * @Title: GamesRawGamepad
+ */
+
+G_DEFINE_INTERFACE (GamesRawGamepad, games_raw_gamepad, G_TYPE_OBJECT)
+
+/* Signals */
+enum {
+ SIGNAL_STANDARD_BUTTON_EVENT,
+ SIGNAL_BUTTON_EVENT,
+ SIGNAL_STANDARD_AXIS_EVENT,
+ SIGNAL_AXIS_EVENT,
+ SIGNAL_DPAD_EVENT,
+ SIGNAL_UNPLUGGED,
+ LAST_SIGNAL,
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/* Public */
+
+/**
+ * games_raw_gamepad_get_guid:
+ * @self: a #GamesRawGamepad
+ *
+ * Returns the GUID reprensenting this gamepad for SDL2 mappings.
+ *
+ * Return value: %TRUE if a menu is displayed, %FALSE otherwise
+ **/
+const gchar *
+games_raw_gamepad_get_guid (GamesRawGamepad *self)
+{
+ g_return_val_if_fail (self != NULL, NULL);
+
+ return GAMES_RAW_GAMEPAD_GET_IFACE (self)->get_guid (self);
+}
+
+/* Type */
+
+static void
+games_raw_gamepad_default_init (GamesRawGamepadInterface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ if (initialized)
+ return;
+
+ initialized = TRUE;
+
+ /**
+ * GamesRawGamepad::standard-button-event:
+ * @button: the standard button emitting the event
+ * @value: %TRUE if the button is pressed, %FALSE otherwise
+ *
+ * Emitted when a standard button is pressed/released.
+ **/
+ signals[SIGNAL_STANDARD_BUTTON_EVENT] =
+ g_signal_new ("standard-button-event",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ GAMES_TYPE_STANDARD_GAMEPAD_BUTTON,
+ G_TYPE_BOOLEAN);
+
+ /**
+ * GamesRawGamepad::button-event:
+ * @button: the code representing the button
+ * @value: %TRUE if the button is pressed, %FALSE otherwise
+ *
+ * Emitted when a button is pressed/released.
+ **/
+ signals[SIGNAL_BUTTON_EVENT] =
+ g_signal_new ("button-event",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_INT,
+ G_TYPE_BOOLEAN);
+
+ /**
+ * GamesRawGamepad::standard-axis-event:
+ * @axis: the standard axis emitting the event
+ * @value: the value of the axis ranging from -1 to 1
+ *
+ * Emitted when a standard axis' value changes.
+ **/
+ signals[SIGNAL_STANDARD_AXIS_EVENT] =
+ g_signal_new ("standard-axis-event",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ GAMES_TYPE_STANDARD_GAMEPAD_AXIS,
+ G_TYPE_DOUBLE);
+
+ /**
+ * GamesRawGamepad::axis-event:
+ * @axis: the code representing the axis
+ * @value: the value of the axis ranging from -1 to 1
+ *
+ * Emitted when an axis' value changes.
+ **/
+ signals[SIGNAL_AXIS_EVENT] =
+ g_signal_new ("axis-event",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_INT,
+ G_TYPE_DOUBLE);
+
+ /**
+ * GamesRawGamepad::dpad-event:
+ * @dpad: the code representing the dpad
+ * @axis: the axis: 0 for X, 1 for Y
+ * @value: the value of the axis ranging from -1 to 1
+ *
+ * Emitted when a dpad's axis value changes.
+ **/
+ signals[SIGNAL_DPAD_EVENT] =
+ g_signal_new ("dpad-event",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 3,
+ G_TYPE_INT,
+ G_TYPE_INT,
+ G_TYPE_INT);
+
+ /**
+ * GamesRawGamepad::unplugged:
+ *
+ * Emitted when the gamepad is unplugged.
+ **/
+ signals[SIGNAL_UNPLUGGED] =
+ g_signal_new ("unplugged",
+ GAMES_TYPE_RAW_GAMEPAD,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
diff --git a/src/gamepad/raw-gamepad.h b/src/gamepad/raw-gamepad.h
new file mode 100644
index 0000000..aaf4fda
--- /dev/null
+++ b/src/gamepad/raw-gamepad.h
@@ -0,0 +1,27 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#ifndef GAMES_RAW_GAMEPAD_H
+#define GAMES_RAW_GAMEPAD_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_RAW_GAMEPAD (games_raw_gamepad_get_type ())
+
+G_DECLARE_INTERFACE (GamesRawGamepad, games_raw_gamepad, GAMES, RAW_GAMEPAD, GObject)
+
+struct _GamesRawGamepadInterface {
+ GTypeInterface parent;
+
+ const gchar *(*get_guid) (GamesRawGamepad *self);
+};
+
+// FIXME Remove this once every piece using it has been moved to C.
+typedef struct _GamesRawGamepadInterface GamesRawGamepadIface;
+
+const gchar *games_raw_gamepad_get_guid (GamesRawGamepad *self);
+
+G_END_DECLS
+
+#endif /* GAMES_RAW_GAMEPAD_H */
diff --git a/src/gamepad/raw-gamepad.vapi b/src/gamepad/raw-gamepad.vapi
new file mode 100644
index 0000000..dde4c8e
--- /dev/null
+++ b/src/gamepad/raw-gamepad.vapi
@@ -0,0 +1,12 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[CCode (cheader_filename = "raw-gamepad.h")]
+private interface Games.RawGamepad : GLib.Object {
+ public abstract signal void standard_button_event (StandardGamepadButton button, bool value);
+ public abstract signal void button_event (int code, bool value);
+ public abstract signal void standard_axis_event (StandardGamepadAxis axis, double value);
+ public abstract signal void axis_event (int axis, double value);
+ public abstract signal void dpad_event (int dpad, int axis, int value);
+ public abstract signal void unplugged ();
+ public abstract string guid { get; }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]