[gnome-games] gamepad: Merge GamepadInput and input_t
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gamepad: Merge GamepadInput and input_t
- Date: Sun, 14 May 2017 17:06:49 +0000 (UTC)
commit fea45fa7dac8f4db769b936e279fef2b31da44a8
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sat May 13 21:38:29 2017 +0200
gamepad: Merge GamepadInput and input_t
As event codes use generic types now there is no need to have two fields
to distinguish their types in GamepadInput. Merging the various type
specific values make GamepadInput similar to input_t, the later can then
be replaced.
https://bugzilla.gnome.org/show_bug.cgi?id=782611
src/gamepad/gamepad-input.h | 3 +-
src/gamepad/gamepad-mapping.c | 73 +++++++++--------------------------------
src/gamepad/gamepad.c | 12 +++---
3 files changed, 23 insertions(+), 65 deletions(-)
---
diff --git a/src/gamepad/gamepad-input.h b/src/gamepad/gamepad-input.h
index c76d7c5..7f6d9b8 100644
--- a/src/gamepad/gamepad-input.h
+++ b/src/gamepad/gamepad-input.h
@@ -11,8 +11,7 @@ G_BEGIN_DECLS
typedef struct {
guint16 type;
- guint16 axis;
- guint16 button;
+ guint16 code;
} GamesGamepadInput;
GType games_gamepad_input_get_type (void) G_GNUC_CONST;
diff --git a/src/gamepad/gamepad-mapping.c b/src/gamepad/gamepad-mapping.c
index 85807c3..d9df094 100644
--- a/src/gamepad/gamepad-mapping.c
+++ b/src/gamepad/gamepad-mapping.c
@@ -8,11 +8,6 @@
#include "gamepad-dpad.h"
#include "gamepad-mapping-error.h"
-typedef struct {
- guint16 type;
- guint16 value;
-} input_t;
-
struct _GamesGamepadMapping {
GObject parent_instance;
@@ -28,7 +23,7 @@ G_DEFINE_TYPE (GamesGamepadMapping, games_gamepad_mapping, G_TYPE_OBJECT)
static void
parse_dpad_value (GamesGamepadMapping *self,
const gchar *mapping_value,
- input_t input)
+ GamesGamepadInput input)
{
const gchar *mapping_value_number;
gchar **dpad_parse_array;
@@ -67,13 +62,13 @@ parse_dpad_value (GamesGamepadMapping *self,
if (self->dpads->len <= dpad_index)
g_array_set_size (self->dpads, dpad_index + 1);
g_array_index (self->dpads, GamesGamepadDPad, dpad_index).types[dpad_position] = input.type;
- g_array_index (self->dpads, GamesGamepadDPad, dpad_index).values[dpad_position] = input.value;
+ g_array_index (self->dpads, GamesGamepadDPad, dpad_index).values[dpad_position] = input.code;
}
static void
parse_button_value (GamesGamepadMapping *self,
const gchar *mapping_value,
- input_t input)
+ GamesGamepadInput input)
{
// g_array_append_val() requires a l-value.
const gchar *mapping_value_number;
@@ -92,13 +87,13 @@ parse_button_value (GamesGamepadMapping *self,
if (self->buttons->len <= button)
g_array_set_size (self->buttons, button + 1);
- g_array_index (self->buttons, input_t, button) = input;
+ g_array_index (self->buttons, GamesGamepadInput, button) = input;
}
static void
parse_axis_value (GamesGamepadMapping *self,
const gchar *mapping_value,
- input_t input)
+ GamesGamepadInput input)
{
const gchar *mapping_value_number;
gint axis;
@@ -116,7 +111,7 @@ parse_axis_value (GamesGamepadMapping *self,
if (self->axes->len <= axis)
g_array_set_size (self->axes, axis + 1);
- g_array_index (self->axes, input_t, axis) = input;
+ g_array_index (self->axes, GamesGamepadInput, axis) = input;
}
static guint16
@@ -227,7 +222,7 @@ set_from_sdl_string (GamesGamepadMapping *self,
gchar **splitted_mapping;
gchar *mapping_key;
gchar *mapping_value;
- input_t input;
+ GamesGamepadInput input;
gint parsed_key;
mappings = g_strsplit (mapping_string, ",", 0);
@@ -250,11 +245,11 @@ set_from_sdl_string (GamesGamepadMapping *self,
switch (input.type) {
case EV_KEY:
- input.value = (gint) parse_button (mapping_key);
+ input.code = parse_button (mapping_key);
break;
case EV_ABS:
- input.value = (gint) parse_axis (mapping_key);
+ input.code = parse_axis (mapping_key);
break;
case EV_MAX:
@@ -325,8 +320,8 @@ games_gamepad_mapping_new_from_sdl_string (const gchar *mapping_string,
self = (GamesGamepadMapping*) g_object_new (GAMES_TYPE_GAMEPAD_MAPPING, NULL);
- self->buttons = g_array_new (FALSE, TRUE, sizeof (input_t));
- self->axes = g_array_new (FALSE, TRUE, sizeof (input_t));
+ self->buttons = g_array_new (FALSE, TRUE, sizeof (GamesGamepadInput));
+ self->axes = g_array_new (FALSE, TRUE, sizeof (GamesGamepadInput));
self->dpads = g_array_new (FALSE, TRUE, sizeof (GamesGamepadDPad));
set_from_sdl_string (self, mapping_string);
@@ -358,19 +353,7 @@ games_gamepad_mapping_get_dpad_mapping (GamesGamepadMapping *self,
dpad_position = (dpad_changed_value + dpad_axis + 4) % 4;
dpad->axis_values[dpad_axis] = dpad_value;
event->type = dpad->types[dpad_position];
-
- switch (event->type) {
- case EV_ABS:
- event->axis = dpad->values[dpad_position];
-
- break;
- case EV_KEY:
- event->button = dpad->values[dpad_position];
-
- break;
- default:
- break;
- }
+ event->code = dpad->values[dpad_position];
}
void
@@ -384,21 +367,9 @@ games_gamepad_mapping_get_axis_mapping (GamesGamepadMapping *self,
memset (event, 0, sizeof (GamesGamepadInput));
event->type = (axis_number < self->axes->len) ?
- g_array_index (self->axes, input_t, axis_number).type :
+ g_array_index (self->axes, GamesGamepadInput, axis_number).type :
EV_MAX;
-
- switch (event->type) {
- case EV_ABS:
- event->axis = g_array_index (self->axes, input_t, axis_number).value;
-
- break;
- case EV_KEY:
- event->button = g_array_index (self->axes, input_t, axis_number).value;
-
- break;
- default:
- break;
- }
+ event->code = g_array_index (self->axes, GamesGamepadInput, axis_number).code;
}
void
@@ -412,21 +383,9 @@ games_gamepad_mapping_get_button_mapping (GamesGamepadMapping *self,
memset (event, 0, sizeof (GamesGamepadInput));
event->type = (button_number < self->buttons->len) ?
- g_array_index (self->buttons, input_t, button_number).type :
+ g_array_index (self->buttons, GamesGamepadInput, button_number).type :
EV_MAX;
-
- switch (event->type) {
- case EV_ABS:
- event->axis = g_array_index (self->buttons, input_t, button_number).value;
-
- break;
- case EV_KEY:
- event->button = g_array_index (self->buttons, input_t, button_number).value;
-
- break;
- default:
- break;
- }
+ event->code = g_array_index (self->buttons, GamesGamepadInput, button_number).code;
}
/* Type */
diff --git a/src/gamepad/gamepad.c b/src/gamepad/gamepad.c
index ddbacef..196be99 100644
--- a/src/gamepad/gamepad.c
+++ b/src/gamepad/gamepad.c
@@ -67,13 +67,13 @@ on_button_event (GamesRawGamepad *sender,
case EV_ABS:
g_signal_emit (self,
signals[SIGNAL_AXIS_EVENT],
- 0, event.axis, value ? 1 : 0);
+ 0, event.code, value ? 1 : 0);
break;
case EV_KEY:
g_signal_emit (self,
signals[SIGNAL_BUTTON_EVENT],
- 0, event.button, value);
+ 0, event.code, value);
break;
default:
break;
@@ -99,11 +99,11 @@ on_axis_event (GamesRawGamepad *sender,
switch (event.type) {
case EV_ABS:
g_signal_emit (self, signals[SIGNAL_AXIS_EVENT],
- 0, event.axis, games_event->value);
+ 0, event.code, games_event->value);
break;
case EV_KEY:
g_signal_emit (self, signals[SIGNAL_BUTTON_EVENT],
- 0, event.button, games_event->value > 0.);
+ 0, event.code, games_event->value > 0.);
break;
default:
@@ -155,12 +155,12 @@ on_hat_event (GamesRawGamepad *sender,
switch (event.type) {
case EV_ABS:
g_signal_emit (self, signals[SIGNAL_AXIS_EVENT],
- 0, event.axis, (gdouble) abs (games_event->value));
+ 0, event.code, (gdouble) abs (games_event->value));
break;
case EV_KEY:
g_signal_emit (self, signals[SIGNAL_BUTTON_EVENT],
- 0, event.button, (gboolean) abs (games_event->value));
+ 0, event.code, (gboolean) abs (games_event->value));
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]