[gnome-games] event: Allow to keep hardware info



commit 488180ffb8a455f03b74cce8d2e34abf40f42787
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed May 24 19:48:31 2017 +0200

    event: Allow to keep hardware info
    
    Turn the 'index' field into 'hardware_index' and add fields containing
    the code of the input related to the event.
    
    Also remove the barely useful 'send_event' field.
    
    This avoid loosing information related to the original hardware event,
    whether the event is mapped or not.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782611

 src/event/event.h                     |   16 +++++++---------
 src/event/event.vapi                  |   15 ++++++---------
 src/gamepad/gamepad.c                 |   32 ++++++++++----------------------
 src/gamepad/linux/linux-raw-gamepad.c |   11 ++++++-----
 src/retro/retro-gamepad.vala          |    6 +++---
 5 files changed, 32 insertions(+), 48 deletions(-)
---
diff --git a/src/event/event.h b/src/event/event.h
index 6cc2c05..953ad44 100644
--- a/src/event/event.h
+++ b/src/event/event.h
@@ -29,49 +29,47 @@ typedef enum
 
 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;
+  guint8 hardware_index;
 };
 
 struct _GamesEventGamepadButton {
   GamesEventType type;
-  gint8 send_event;
   guint32 time;
   guint16 hardware_type;
   guint16 hardware_code;
   gint32 hardware_value;
-  guint8 index;
+  guint8 hardware_index;
+  guint16 button;
 };
 
 struct _GamesEventGamepadAxis {
   GamesEventType type;
-  gint8 send_event;
   guint32 time;
   guint16 hardware_type;
   guint16 hardware_code;
   gint32 hardware_value;
-  guint8 index;
+  guint8 hardware_index;
+  guint16 axis;
   gdouble value;
 };
 
 struct _GamesEventGamepadHat {
   GamesEventType type;
-  gint8 send_event;
   guint32 time;
   guint16 hardware_type;
   guint16 hardware_code;
   gint32 hardware_value;
-  guint8 index;
-  guint8 axis;
+  guint8 hardware_index;
+  guint16 axis;
   gint8 value;
 };
 
diff --git a/src/event/event.vapi b/src/event/event.vapi
index db41661..017812f 100644
--- a/src/event/event.vapi
+++ b/src/event/event.vapi
@@ -19,7 +19,6 @@ public class Games.Event {
 [Compact]
 public class Games.EventAny : Games.Event {
        public Games.EventType type;
-       public int8 send_event;
        public uint32 time;
 }
 
@@ -27,7 +26,6 @@ public class Games.EventAny : Games.Event {
 [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;
@@ -38,24 +36,24 @@ public class Games.EventGamepad : Games.Event {
 [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;
+       public uint8 hardware_index;
+       public uint16 button;
 }
 
 [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 uint8 hardware_index;
+       public uint16 axis;
        public double value;
 }
 
@@ -63,13 +61,12 @@ public class Games.EventGamepadAxis : Games.Event {
 [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 uint8 hardware_index;
+       public uint16 axis;
        public int8 value;
 }
 
diff --git a/src/gamepad/gamepad.c b/src/gamepad/gamepad.c
index 178c16a..3827bf6 100644
--- a/src/gamepad/gamepad.c
+++ b/src/gamepad/gamepad.c
@@ -68,25 +68,21 @@ map_button_event (GamesGamepad            *self,
 
   mapped_event = games_event_copy ((GamesEvent *) games_event);
   games_gamepad_mapping_get_button_mapping (self->mapping,
-                                            games_event->index,
+                                            games_event->hardware_index,
                                             &destination);
 
   pressed = games_event->type == GAMES_EVENT_GAMEPAD_BUTTON_PRESS;
 
-  mapped_event->any.send_event = TRUE;
-  mapped_event->gamepad.hardware_type = destination.type;
-  mapped_event->gamepad.hardware_code = destination.code;
-
   switch (destination.type) {
   case EV_ABS:
     signal = SIGNAL_AXIS_EVENT;
-    mapped_event->gamepad_axis.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_axis.axis = destination.code;
     mapped_event->gamepad_axis.value = pressed ? 1 : 0;
 
     break;
   case EV_KEY:
     signal = pressed ? SIGNAL_BUTTON_PRESS_EVENT : SIGNAL_BUTTON_RELEASE_EVENT;
-    mapped_event->gamepad_button.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_button.button = destination.code;
 
     break;
   default:
@@ -110,23 +106,19 @@ map_axis_event (GamesGamepad          *self,
   gboolean pressed;
 
   mapped_event = games_event_copy ((GamesEvent *) games_event);
-  games_gamepad_mapping_get_axis_mapping (self->mapping, games_event->index, &destination);
+  games_gamepad_mapping_get_axis_mapping (self->mapping, games_event->hardware_index, &destination);
 
   pressed = games_event->value > 0.;
 
-  mapped_event->any.send_event = TRUE;
-  mapped_event->gamepad.hardware_type = destination.type;
-  mapped_event->gamepad.hardware_code = destination.code;
-
   switch (destination.type) {
   case EV_ABS:
     signal = SIGNAL_AXIS_EVENT;
-    mapped_event->gamepad_axis.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_axis.axis = destination.code;
 
     break;
   case EV_KEY:
     signal = pressed ? SIGNAL_BUTTON_PRESS_EVENT : SIGNAL_BUTTON_RELEASE_EVENT;
-    mapped_event->gamepad_button.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_button.button = destination.code;
 
     break;
   default:
@@ -151,27 +143,23 @@ map_hat_event (GamesGamepad         *self,
 
   mapped_event = games_event_copy ((GamesEvent *) games_event);
   games_gamepad_mapping_get_dpad_mapping (self->mapping,
-                                          games_event->index,
-                                          games_event->axis,
+                                          games_event->hardware_index / 2,
+                                          games_event->hardware_index % 2,
                                           games_event->value,
                                           &destination);
 
   pressed = abs (games_event->value);
 
-  mapped_event->any.send_event = TRUE;
-  mapped_event->gamepad.hardware_type = destination.type;
-  mapped_event->gamepad.hardware_code = destination.code;
-
   switch (destination.type) {
   case EV_ABS:
     signal = SIGNAL_AXIS_EVENT;
-    mapped_event->gamepad_axis.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_axis.axis = destination.code;
     mapped_event->gamepad_axis.value = abs (games_event->value);
 
     break;
   case EV_KEY:
     signal = pressed ? SIGNAL_BUTTON_PRESS_EVENT : SIGNAL_BUTTON_RELEASE_EVENT;
-    mapped_event->gamepad_button.index = 0; // FIXME How to set it properly?
+    mapped_event->gamepad_button.button = destination.code;
 
     break;
   default:
diff --git a/src/gamepad/linux/linux-raw-gamepad.c b/src/gamepad/linux/linux-raw-gamepad.c
index b7b8cba..45ccddb 100644
--- a/src/gamepad/linux/linux-raw-gamepad.c
+++ b/src/gamepad/linux/linux-raw-gamepad.c
@@ -138,7 +138,6 @@ handle_evdev_event (GamesLinuxRawGamepad *self)
   if (libevdev_next_event (self->device, (guint) LIBEVDEV_READ_FLAG_NORMAL, &event) != 0)
     return;
 
-  games_event.gamepad.send_event = FALSE;
   games_event.gamepad.time = event.time.tv_sec * 1000 + event.time.tv_usec / 1000;
   games_event.gamepad.hardware_type = event.type;
   games_event.gamepad.hardware_code = event.code;
@@ -149,7 +148,8 @@ handle_evdev_event (GamesLinuxRawGamepad *self)
     games_event.type = event.value ?
       GAMES_EVENT_GAMEPAD_BUTTON_PRESS :
       GAMES_EVENT_GAMEPAD_BUTTON_RELEASE;
-    games_event.gamepad_button.index = self->key_map[event.code - BTN_MISC];
+      games_event.gamepad_button.hardware_index = self->key_map[event.code - BTN_MISC];
+      games_event.gamepad_button.button = event.code;
 
     break;
   case EV_ABS:
@@ -163,8 +163,8 @@ handle_evdev_event (GamesLinuxRawGamepad *self)
     case ABS_HAT3X:
     case ABS_HAT3Y:
       games_event.type = GAMES_EVENT_GAMEPAD_HAT;
-      games_event.gamepad_hat.index = self->key_map[(event.code - ABS_HAT0X) / 2];
-      games_event.gamepad_hat.axis = (event.code - ABS_HAT0X) % 2;
+      games_event.gamepad_hat.hardware_index = self->key_map[(event.code - ABS_HAT0X) / 2] * 2 + (event.code 
- ABS_HAT0X) % 2;
+      games_event.gamepad_hat.axis = event.code;
       games_event.gamepad_hat.value = event.value;
 
       break;
@@ -173,7 +173,8 @@ handle_evdev_event (GamesLinuxRawGamepad *self)
     case ABS_RX:
     case ABS_RY:
       games_event.type = GAMES_EVENT_GAMEPAD_AXIS;
-      games_event.gamepad_axis.index = event.code;
+      games_event.gamepad_axis.hardware_index = event.code;
+      games_event.gamepad_axis.axis = event.code;
       games_event.gamepad_axis.value =
         centered_axis_value (&self->abs_info[self->abs_map[event.code]],
                              event.value);
diff --git a/src/retro/retro-gamepad.vala b/src/retro/retro-gamepad.vala
index 537cc4e..9c619bf 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -15,9 +15,9 @@ private class Games.RetroGamepad: Object, Retro.InputDevice {
                buttons = new bool[EventCode.KEY_MAX + 1];
                axes = new int16[EventCode.ABS_MAX + 1];
 
-               gamepad.button_press_event.connect ((event) => buttons[event.gamepad.hardware_code] = true);
-               gamepad.button_release_event.connect ((event) => buttons[event.gamepad.hardware_code] = 
false);
-               gamepad.axis_event.connect ((event) => axes[event.gamepad.hardware_code] = (int16) 
(event.gamepad_axis.value * int16.MAX));
+               gamepad.button_press_event.connect ((event) => buttons[event.gamepad_button.button] = true);
+               gamepad.button_release_event.connect ((event) => buttons[event.gamepad_button.button] = 
false);
+               gamepad.axis_event.connect ((event) => axes[event.gamepad_axis.axis] = (int16) 
(event.gamepad_axis.value * int16.MAX));
        }
 
        public void poll () {}


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