[gnome-games/wip/aplazas/gamepad-event: 1/11] event: Add Event



commit 9d2a5929eba7e25e574fe7ea49c8d9982e294dcc
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 11 22:58:24 2017 +0200

    event: Add Event
    
    This will be used to propagate gamepad events and to replace the current
    gamepad event system by a simpler one.

 src/Makefile.am      |    6 +++
 src/event/event.c    |   35 ++++++++++++++++++
 src/event/event.h    |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/event/event.vapi |   84 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 222 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index bf6f067..8830be5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,7 @@ BUILT_SOURCES = \
 
 EXTRA_DIST = \
        $(gresource_file) \
+       event/event.vapi \
        gamepad/gamepad.vapi \
        gamepad/gamepad-monitor.vapi \
        gamepad/raw-gamepad.vapi \
@@ -67,6 +68,8 @@ gnome_games_SOURCES = \
        dummy/dummy-icon.vala \
        dummy/dummy-runner.vala \
        \
+       event/event.c \
+       \
        gameinfo/gameinfo-doc.vala \
        gameinfo/gameinfo-error.vala \
        gameinfo/gameinfo-disc-id-disc-title.vala \
@@ -188,6 +191,7 @@ gnome_games_VALAFLAGS = \
        --pkg retro-gtk-0.10 \
        --pkg linux \
        --pkg posix \
+       --pkg event \
        --pkg gamepad \
        --pkg gamepad-monitor \
        --pkg raw-gamepad \
@@ -195,6 +199,7 @@ gnome_games_VALAFLAGS = \
        --pkg standard-gamepad-button \
        --gresources $(gresource_file) \
        --vapi $(vapi_file) \
+       --vapidir=event/ \
        --vapidir=gamepad/ \
        -H $(header_file) \
        $(NULL)
@@ -203,6 +208,7 @@ gnome_games_CFLAGS = \
        $(GNOME_GAMES_CFLAGS) \
        $(GAMEPADS_CFLAGS) \
        $(UDEV_CFLAGS) \
+       -I$(srcdir)/event \
        -I$(srcdir)/gamepad \
        -I$(srcdir)/gamepad/linux \
        -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
diff --git a/src/event/event.c b/src/event/event.c
new file mode 100644
index 0000000..758465e
--- /dev/null
+++ b/src/event/event.c
@@ -0,0 +1,35 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#include "event.h"
+
+G_DEFINE_BOXED_TYPE (GamesEvent, games_event, games_event_copy, games_event_free)
+
+GamesEvent *
+games_event_new (void)
+{
+  GamesEvent *self;
+
+  self = g_slice_new0 (GamesEvent);
+
+  return self;
+}
+
+GamesEvent *
+games_event_copy (GamesEvent *self)
+{
+  GamesEvent *copy;
+
+  g_return_val_if_fail (self, NULL);
+
+  copy = games_event_new ();
+
+  return copy;
+}
+
+void
+games_event_free (GamesEvent *self)
+{
+  g_return_if_fail (self);
+
+  g_slice_free (GamesEvent, self);
+}
diff --git a/src/event/event.h b/src/event/event.h
new file mode 100644
index 0000000..6cc2c05
--- /dev/null
+++ b/src/event/event.h
@@ -0,0 +1,97 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+#ifndef GAMES_EVENT_H
+#define GAMES_EVENT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_EVENT (games_event_get_type())
+
+typedef struct _GamesEventAny GamesEventAny;
+typedef struct _GamesEventGamepad GamesEventGamepad;
+typedef struct _GamesEventGamepadButton GamesEventGamepadButton;
+typedef struct _GamesEventGamepadAxis GamesEventGamepadAxis;
+typedef struct _GamesEventGamepadHat GamesEventGamepadHat;
+
+typedef union  _GamesEvent GamesEvent;
+
+typedef enum
+{
+  GAMES_EVENT_NOTHING = -1,
+  GAMES_EVENT_GAMEPAD_BUTTON_PRESS = 0,
+  GAMES_EVENT_GAMEPAD_BUTTON_RELEASE = 1,
+  GAMES_EVENT_GAMEPAD_AXIS = 2,
+  GAMES_EVENT_GAMEPAD_HAT = 3,
+  GAMES_LAST_EVENT,
+} GamesEventType;
+
+struct _GamesEventAny {
+  GamesEventType type;
+  gint8 send_event;
+  guint32 time;
+};
+
+struct _GamesEventGamepad {
+  GamesEventType type;
+  gint8 send_event;
+  guint32 time;
+  guint16 hardware_type;
+  guint16 hardware_code;
+  gint32 hardware_value;
+};
+
+struct _GamesEventGamepadButton {
+  GamesEventType type;
+  gint8 send_event;
+  guint32 time;
+  guint16 hardware_type;
+  guint16 hardware_code;
+  gint32 hardware_value;
+  guint8 index;
+};
+
+struct _GamesEventGamepadAxis {
+  GamesEventType type;
+  gint8 send_event;
+  guint32 time;
+  guint16 hardware_type;
+  guint16 hardware_code;
+  gint32 hardware_value;
+  guint8 index;
+  gdouble value;
+};
+
+struct _GamesEventGamepadHat {
+  GamesEventType type;
+  gint8 send_event;
+  guint32 time;
+  guint16 hardware_type;
+  guint16 hardware_code;
+  gint32 hardware_value;
+  guint8 index;
+  guint8 axis;
+  gint8 value;
+};
+
+union _GamesEvent {
+  GamesEventType type;
+  GamesEventAny any;
+  GamesEventGamepad gamepad;
+  GamesEventGamepadButton gamepad_button;
+  GamesEventGamepadAxis gamepad_axis;
+  GamesEventGamepadHat gamepad_hat;
+};
+
+GType games_event_get_type (void) G_GNUC_CONST;
+
+GamesEvent *games_event_new (void);
+GamesEvent *games_event_copy (GamesEvent *self);
+void games_event_free (GamesEvent *self);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GamesEvent, games_event_free)
+
+G_END_DECLS
+
+#endif /* GAMES_EVENT_H */
diff --git a/src/event/event.vapi b/src/event/event.vapi
new file mode 100644
index 0000000..db41661
--- /dev/null
+++ b/src/event/event.vapi
@@ -0,0 +1,84 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.Event {
+       public Games.EventType type;
+       [CCode (has_construct_function = false)]
+       public Event (Games.EventType type);
+       public Games.Event copy ();
+       public void free ();
+       public Games.EventAny any {[CCode (cname = "(GamesEventAny *)")] get; }
+       public Games.EventGamepad gamepad {[CCode (cname = "(GamesEventGamepad *)")] get; }
+       public Games.EventGamepadButton gamepad_button {[CCode (cname = "(GamesEventGamepadButton *)")] get; }
+       public Games.EventGamepadAxis gamepad_axis {[CCode (cname = "(GamesEventGamepadAxis *)")] get; }
+       public Games.EventGamepadHat gamepad_hat {[CCode (cname = "(GamesEventGamepadHat *)")] get; }
+}
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.EventAny : Games.Event {
+       public Games.EventType type;
+       public int8 send_event;
+       public uint32 time;
+}
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.EventGamepad : Games.Event {
+       public Games.EventType type;
+       public int8 send_event;
+       public uint32 time;
+       public uint16 hardware_type;
+       public uint16 hardware_code;
+       public int32 hardware_value;
+}
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.EventGamepadButton : Games.Event {
+       public Games.EventType type;
+       public int8 send_event;
+       public uint32 time;
+       public uint16 hardware_type;
+       public uint16 hardware_code;
+       public int32 hardware_value;
+       public uint8 index;
+}
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.EventGamepadAxis : Games.Event {
+       public Games.EventType type;
+       public int8 send_event;
+       public uint32 time;
+       public uint16 hardware_type;
+       public uint16 hardware_code;
+       public int32 hardware_value;
+       public uint8 index;
+       public double value;
+}
+
+[CCode (cheader_filename = "event.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", 
type_id = "games_event_get_type ()")]
+[Compact]
+public class Games.EventGamepadHat : Games.Event {
+       public Games.EventType type;
+       public int8 send_event;
+       public uint32 time;
+       public uint16 hardware_type;
+       public uint16 hardware_code;
+       public int32 hardware_value;
+       public uint8 index;
+       public uint8 axis;
+       public int8 value;
+}
+
+[CCode (cheader_filename = "event.h", cprefix = "GAMES_")]
+public enum Games.EventType {
+       EVENT_NOTHING,
+       EVENT_GAMEPAD_BUTTON_PRESS,
+       EVENT_GAMEPAD_BUTTON_RELEASE,
+       EVENT_GAMEPAD_AXIS,
+       EVENT_GAMEPAD_HAT,
+       LAST_EVENT,
+}


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