[gnome-games/wip/abhinavsingh/gamepad-config: 16/22] gamepad: Allow incomplete mappings
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 16/22] gamepad: Allow incomplete mappings
- Date: Fri, 21 Jul 2017 13:17:33 +0000 (UTC)
commit f4f14f1fea3ae9c69af14357cb377b5a72fb66dd
Author: theawless <theawless gmail com>
Date: Fri Jul 21 11:24:05 2017 +0530
gamepad: Allow incomplete mappings
Ignore a gamepad input if the mapping doesn't contain it.
src/gamepad/gamepad-mapping.c | 51 ++++++++++++++++++++++++++++-------------
1 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/src/gamepad/gamepad-mapping.c b/src/gamepad/gamepad-mapping.c
index ea4b1c9..0a1525f 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,23 @@ games_gamepad_mapping_get_dpad_mapping (GamesGamepadMapping *self,
memset (destination, 0, sizeof (GamesGamepadInput));
- dpad = &g_array_index (self->dpads, GamesGamepadDPad, dpad_index);
- 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];
+ destination->type = EV_MAX;
+ if (dpad_index < self->dpads->len) {
+ dpad = &g_array_index (self->dpads, GamesGamepadDPad, dpad_index);
+ if (dpad != NULL) {
+ dpad_changed_value = (dpad_value == 0) ?
+ dpad->axis_values[dpad_axis] :
+ dpad_value;
+ // 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;
+ if (dpad_position < 4) {
+ dpad_input = &dpad->inputs[dpad_position];
+ if (dpad_input != NULL)
+ *destination = *dpad_input;
+ }
+ }
+ }
}
void
@@ -289,15 +300,19 @@ games_gamepad_mapping_get_axis_mapping (GamesGamepadMapping *self,
gint axis_number,
GamesGamepadInput *destination)
{
+ GamesGamepadInput *axis;
+
g_return_if_fail (self != NULL);
g_return_if_fail (destination != NULL);
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) {
+ axis = &g_array_index (self->axes, GamesGamepadInput, axis_number);
+ if (axis != NULL)
+ *destination = *axis;
+ }
}
void
@@ -305,15 +320,19 @@ games_gamepad_mapping_get_button_mapping (GamesGamepadMapping *self,
gint button_number,
GamesGamepadInput *destination)
{
+ GamesGamepadInput *button;
+
g_return_if_fail (self != NULL);
g_return_if_fail (destination != NULL);
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) {
+ button = &g_array_index (self->buttons, GamesGamepadInput, button_number);
+ if (button != NULL)
+ *destination = *button;
+ }
}
/* Type */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]