Commit f602e51e authored by Adrien Plazas's avatar Adrien Plazas
Browse files

event: Add Event

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

https://bugzilla.gnome.org/show_bug.cgi?id=782611
parent b4cfcc9f
......@@ -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"\" \
......
// This file is part of GNOME Games. License: GPL-3.0+.
#include "event.h"
#include <string.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 ();
memcpy(copy, self, sizeof (GamesEvent));
return copy;
}
void
games_event_free (GamesEvent *self)
{
g_return_if_fail (self);
g_slice_free (GamesEvent, self);
}
// 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 */
// 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,
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment