[gnome-games] keyboard: Add KeyboardMappingBuilder



commit e1b5cf776f574632b855b89d144f483e84bdd5fb
Author: theawless <theawless gmail com>
Date:   Mon Feb 19 18:48:53 2018 +0530

    keyboard: Add KeyboardMappingBuilder
    
    This enables us to build keyboard mappings conrresonding to given
    inputs of a gamepad.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780755

 src/Makefile.am                            |  1 +
 src/keyboard/keyboard-mapping-builder.vala | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5b13649..65e3328 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,6 +89,7 @@ gnome_games_SOURCES = \
        grilo/grilo-cover.vala \
        grilo/grilo-media.vala \
        \
+       keyboard/keyboard-mapping-builder.vala \
        keyboard/keyboard-mapping-manager.vala \
        \
        retro/retro-core-source.vala \
diff --git a/src/keyboard/keyboard-mapping-builder.vala b/src/keyboard/keyboard-mapping-builder.vala
new file mode 100644
index 0000000..dd52a05
--- /dev/null
+++ b/src/keyboard/keyboard-mapping-builder.vala
@@ -0,0 +1,22 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.KeyboardMappingBuilder : Object {
+       public Retro.KeyJoypadMapping mapping { private set; get; }
+
+       construct {
+               mapping = new Retro.KeyJoypadMapping ();
+       }
+
+       public bool set_input_mapping (GamepadInput input, uint16 keycode) {
+               var joypad_id = Retro.JoypadId.from_button_code (input.code);
+               if (joypad_id == Retro.JoypadId.COUNT)
+                       return false;
+
+               for (Retro.JoypadId i = 0; i < Retro.JoypadId.COUNT; i += 1)
+                       if (mapping.get_button_key (i) == keycode)
+                               return false;
+               mapping.set_button_key (joypad_id, keycode);
+
+               return true;
+       }
+}


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