[gnome-games] gamepad: Allow incomplete mappings
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gamepad: Allow incomplete mappings
- Date: Mon, 7 Aug 2017 19:47:42 +0000 (UTC)
commit 8d5d0cbd3ca13e5643ec8c8bcc5c1bac4ca654ba
Author: theawless <theawless gmail com>
Date: Thu Jul 27 01:27:16 2017 +0530
gamepad: Allow incomplete mappings
Ignore a gamepad input if the mapping doesn't contain it.
https://bugzilla.gnome.org/show_bug.cgi?id=780754
src/gamepad/gamepad-mapping.c | 34 +++++++++++++++++++++++++---------
1 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/src/gamepad/gamepad-mapping.c b/src/gamepad/gamepad-mapping.c
index ea4b1c9..8e4e332 100644
--- a/src/gamepad/gamepad-mapping.c
+++ b/src/gamepad/gamepad-mapping.c
@@ -266,6 +266,8 @@ games_gamepad_mapping_get_dpad_mapping (GamesGamepadMapping *self,
GamesGamepadInput *destination)
{
GamesGamepadDPad *dpad;
+ GamesGamepadInput *dpad_input;
+
gint dpad_changed_value;
gint dpad_position;
@@ -274,14 +276,26 @@ games_gamepad_mapping_get_dpad_mapping (GamesGamepadMapping *self,
memset (destination, 0, sizeof (GamesGamepadInput));
+ destination->type = EV_MAX;
+ if (dpad_index >= self->dpads->len)
+ return;
+
dpad = &g_array_index (self->dpads, GamesGamepadDPad, dpad_index);
+ if (dpad == NULL)
+ return;
+
dpad_changed_value = (dpad_value == 0) ?
dpad->axis_values[dpad_axis] :
dpad_value;
// We add 4 so that the remainder is always positive.
dpad_position = (dpad_changed_value + dpad_axis + 4) % 4;
dpad->axis_values[dpad_axis] = dpad_value;
- *destination = dpad->inputs[dpad_position];
+ if (dpad_position >= 4)
+ return;
+
+ dpad_input = &dpad->inputs[dpad_position];
+ if (dpad_input != NULL)
+ *destination = *dpad_input;
}
void
@@ -294,10 +308,11 @@ games_gamepad_mapping_get_axis_mapping (GamesGamepadMapping *self,
memset (destination, 0, sizeof (GamesGamepadInput));
- destination->type = (axis_number < self->axes->len) ?
- g_array_index (self->axes, GamesGamepadInput, axis_number).type :
- EV_MAX;
- destination->code = g_array_index (self->axes, GamesGamepadInput, axis_number).code;
+ destination->type = EV_MAX;
+ if (axis_number >= self->axes->len)
+ return;
+
+ *destination = g_array_index (self->axes, GamesGamepadInput, axis_number);
}
void
@@ -310,10 +325,11 @@ games_gamepad_mapping_get_button_mapping (GamesGamepadMapping *self,
memset (destination, 0, sizeof (GamesGamepadInput));
- destination->type = (button_number < self->buttons->len) ?
- g_array_index (self->buttons, GamesGamepadInput, button_number).type :
- EV_MAX;
- destination->code = g_array_index (self->buttons, GamesGamepadInput, button_number).code;
+ destination->type = EV_MAX;
+ if (button_number >= self->buttons->len)
+ return;
+
+ *destination = g_array_index (self->buttons, GamesGamepadInput, button_number);
}
/* Type */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]