[gnome-games] ui: Add KeyboardMapper
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Add KeyboardMapper
- Date: Fri, 22 Jun 2018 20:43:51 +0000 (UTC)
commit 9b268f0e7adf5d45ce5bd6e1c1a111a745afceff
Author: theawless <theawless gmail com>
Date: Mon Feb 19 19:03:17 2018 +0530
ui: Add KeyboardMapper
Use GamepadView to get the user input and KeyboardMappingBuilder to
build the configuration from those inputs.
https://bugzilla.gnome.org/show_bug.cgi?id=780755
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/keyboard-mapper.ui | 37 +++++++++++++++++++
src/Makefile.am | 1 +
src/ui/keyboard-mapper.vala | 74 ++++++++++++++++++++++++++++++++++++++
5 files changed, 114 insertions(+)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 3d0915a..98790c7 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -40,6 +40,7 @@ EXTRA_DIST = \
ui/gamepad-mapper.ui \
ui/gamepad-tester.ui \
ui/game-icon-view.ui \
+ ui/keyboard-mapper.ui \
ui/keyboard-tester.ui \
ui/media-menu-button.ui \
ui/media-selector.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index e9f252e..7be7b6a 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -19,6 +19,7 @@
<file preprocess="xml-stripblanks">ui/gamepad-mapper.ui</file>
<file preprocess="xml-stripblanks">ui/gamepad-tester.ui</file>
<file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
+ <file preprocess="xml-stripblanks">ui/keyboard-mapper.ui</file>
<file preprocess="xml-stripblanks">ui/keyboard-tester.ui</file>
<file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
<file preprocess="xml-stripblanks">ui/media-selector.ui</file>
diff --git a/data/ui/keyboard-mapper.ui b/data/ui/keyboard-mapper.ui
new file mode 100644
index 0000000..9f83161
--- /dev/null
+++ b/data/ui/keyboard-mapper.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GamesKeyboardMapper" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GamesGamepadView" id="gamepad_view">
+ <property name="visible">True</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkActionBar" id="action_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="skip_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Skip</property>
+ <signal name="clicked" handler="on_skip_clicked"/>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child type="center">
+ <object class="GtkLabel" id="info_message">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 49bbeec..2d1b776 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -127,6 +127,7 @@ gnome_games_SOURCES = \
ui/game-icon-view.vala \
ui/game-thumbnail.vala \
ui/gamepad-view-configuration.vala \
+ ui/keyboard-mapper.vala \
ui/keyboard-tester.vala \
ui/media-selector.vala \
ui/media-menu-button.vala \
diff --git a/src/ui/keyboard-mapper.vala b/src/ui/keyboard-mapper.vala
new file mode 100644
index 0000000..382219b
--- /dev/null
+++ b/src/ui/keyboard-mapper.vala
@@ -0,0 +1,74 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/keyboard-mapper.ui")]
+private class Games.KeyboardMapper : Gtk.Box {
+ public signal void finished (Retro.KeyJoypadMapping mapping);
+
+ [GtkChild]
+ private GamepadView gamepad_view;
+ [GtkChild]
+ private Gtk.Label info_message;
+
+ private KeyboardMappingBuilder mapping_builder;
+ private GamepadInput[] mapping_inputs;
+ private GamepadInput input;
+ private uint current_input_index;
+
+ construct {
+ info_message.label = _("Press suitable key on your keyboard");
+ }
+
+ public KeyboardMapper (GamepadViewConfiguration configuration, GamepadInput[] mapping_inputs) {
+ this.mapping_inputs = mapping_inputs;
+ try {
+ gamepad_view.set_configuration (configuration);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
+ }
+
+ public void start () {
+ mapping_builder = new KeyboardMappingBuilder ();
+ current_input_index = 0;
+ connect_to_keyboard ();
+
+ next_input ();
+ }
+
+ public void stop () {
+ disconnect_from_keyboard ();
+ }
+
+ [GtkCallback]
+ private void on_skip_clicked () {
+ next_input ();
+ }
+
+ private void connect_to_keyboard () {
+ get_toplevel ().key_release_event.connect (on_keyboard_event);
+ }
+
+ private void disconnect_from_keyboard () {
+ get_toplevel ().key_release_event.disconnect (on_keyboard_event);
+ }
+
+ private bool on_keyboard_event (Gdk.EventKey key) {
+ if (mapping_builder.set_input_mapping (input, key.hardware_keycode))
+ next_input ();
+
+ return true;
+ }
+
+ private void next_input () {
+ if (current_input_index == mapping_inputs.length) {
+ finished (mapping_builder.mapping);
+
+ return;
+ }
+
+ gamepad_view.reset ();
+ input = mapping_inputs[current_input_index++];
+ gamepad_view.highlight (input, true);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]