[retro-gtk/wip/aplazas/gamepad: 3/6] input: Make GamepadConfiguration use Linux event codes
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/gamepad: 3/6] input: Make GamepadConfiguration use Linux event codes
- Date: Tue, 5 Sep 2017 06:12:58 +0000 (UTC)
commit ec5824311e5d407560822cde04f6823a20c6621d
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Jul 30 16:44:23 2017 +0100
input: Make GamepadConfiguration use Linux event codes
Partially ports GamepadConfiguration in the process.
This helps reducing the public usage of JoypadId.
retro-gtk/Makefile.am | 1 +
retro-gtk/input/gamepad-configuration.vala | 26 ++-------------
retro-gtk/input/retro-gamepad-configuration.c | 44 +++++++++++++++++++++++++
3 files changed, 48 insertions(+), 23 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index d8d69f5..48d3fc6 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -38,6 +38,7 @@ libretro_gtk_la_SOURCES = \
input/keyboard-state.vala \
input/mouse.vala \
input/retro-gamepad-input.c \
+ input/retro-gamepad-configuration.c \
input/retro-keyboard-key.c \
input/virtual-gamepad.vala \
\
diff --git a/retro-gtk/input/gamepad-configuration.vala b/retro-gtk/input/gamepad-configuration.vala
index d7709c0..3263361 100644
--- a/retro-gtk/input/gamepad-configuration.vala
+++ b/retro-gtk/input/gamepad-configuration.vala
@@ -1,34 +1,14 @@
// This file is part of retro-gtk. License: GPL-3.0+.
public class Retro.GamepadConfiguration : Object {
- private uint16[] gamepad_keys;
+ internal uint16[] gamepad_keys;
construct {
gamepad_keys = new uint16[JoypadId.COUNT];
}
- public void set_to_default () {
- set_button_key (JoypadId.B, 39); // QWERTY S
- set_button_key (JoypadId.Y, 38); // QWERTY A
- set_button_key (JoypadId.SELECT, 22); // Backspace
- set_button_key (JoypadId.START, 36); // Enter
- set_button_key (JoypadId.UP, 111); // Up arrow
- set_button_key (JoypadId.DOWN, 116); // Down arrow
- set_button_key (JoypadId.LEFT, 113); // Left arrow
- set_button_key (JoypadId.RIGHT, 114); // Right arrow
- set_button_key (JoypadId.A, 40); // QWERTY D
- set_button_key (JoypadId.X, 25); // QWERTY W
- set_button_key (JoypadId.L, 24); // QWERTY Q
- set_button_key (JoypadId.R, 26); // QWERTY E
- set_button_key (JoypadId.L2, 52); // QWERTY Z
- set_button_key (JoypadId.R2, 54); // QWERTY C
- set_button_key (JoypadId.L3, 10); // QWERTY 1
- set_button_key (JoypadId.R3, 12); // QWERTY 3
- }
-
- public void set_button_key (JoypadId button, uint16 key) {
- gamepad_keys[button] = key;
- }
+ public extern void set_to_default ();
+ public extern void set_button_key (uint16 button, uint16 key);
public uint16 get_button_key (JoypadId button) {
return gamepad_keys[button];
diff --git a/retro-gtk/input/retro-gamepad-configuration.c b/retro-gtk/input/retro-gamepad-configuration.c
new file mode 100644
index 0000000..145b532
--- /dev/null
+++ b/retro-gtk/input/retro-gamepad-configuration.c
@@ -0,0 +1,44 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-gamepad-input.h"
+
+void
+retro_gamepad_configuration_set_to_default (RetroGamepadConfiguration *self)
+{
+ g_return_if_fail (self != NULL);
+
+ retro_gamepad_configuration_set_button_key (self, BTN_A, KEY_S);
+ retro_gamepad_configuration_set_button_key (self, BTN_Y, KEY_A);
+ retro_gamepad_configuration_set_button_key (self, BTN_SELECT, KEY_BACKSPACE);
+ retro_gamepad_configuration_set_button_key (self, BTN_START, KEY_ENTER);
+ retro_gamepad_configuration_set_button_key (self, BTN_DPAD_UP, KEY_UP);
+ retro_gamepad_configuration_set_button_key (self, BTN_DPAD_DOWN, KEY_DOWN);
+ retro_gamepad_configuration_set_button_key (self, BTN_DPAD_LEFT, KEY_LEFT);
+ retro_gamepad_configuration_set_button_key (self, BTN_DPAD_RIGHT, KEY_RIGHT);
+ retro_gamepad_configuration_set_button_key (self, BTN_B, KEY_D);
+ retro_gamepad_configuration_set_button_key (self, BTN_X, KEY_W);
+ retro_gamepad_configuration_set_button_key (self, BTN_TL, KEY_Q);
+ retro_gamepad_configuration_set_button_key (self, BTN_TR, KEY_E);
+ retro_gamepad_configuration_set_button_key (self, BTN_TL2, KEY_Z);
+ retro_gamepad_configuration_set_button_key (self, BTN_TR2, KEY_C);
+ retro_gamepad_configuration_set_button_key (self, BTN_THUMBL, KEY_1);
+ retro_gamepad_configuration_set_button_key (self, BTN_THUMBR, KEY_3);
+}
+
+void
+retro_gamepad_configuration_set_button_key (RetroGamepadConfiguration *self,
+ guint16 button,
+ guint16 key)
+{
+ RetroJoypadId retro_button;
+
+ g_return_if_fail (self != NULL);
+
+ retro_button = retro_gamepad_button_converter (button);
+
+ if (retro_button == RETRO_JOYPAD_ID_COUNT)
+ return;
+
+ // GDK adds 8 to the Linux input event codes to create the hardware keycode.
+ self->gamepad_keys[retro_button] = key + 8;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]