[gnome-games] ui: Add KeyboardConfigurer
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Add KeyboardConfigurer
- Date: Fri, 22 Jun 2018 20:44:01 +0000 (UTC)
commit 3b83a1954ad7c07563c87521c339ad6caaa87144
Author: theawless <theawless gmail com>
Date: Mon Feb 19 19:07:33 2018 +0530
ui: Add KeyboardConfigurer
Allows the user to create, save, and reset keyboard mapping.
https://bugzilla.gnome.org/show_bug.cgi?id=780755
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/keyboard-configurer.ui | 106 ++++++++++++++++++++++
src/Makefile.am | 1 +
src/ui/keyboard-configurer.vala | 181 +++++++++++++++++++++++++++++++++++++
5 files changed, 290 insertions(+)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index cc7fb35..0887658 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-configurer.ui \
ui/keyboard-mapper.ui \
ui/keyboard-tester.ui \
ui/media-menu-button.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 2443a7c..8efd288 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-configurer.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>
diff --git a/data/ui/keyboard-configurer.ui b/data/ui/keyboard-configurer.ui
new file mode 100644
index 0000000..88fcecd
--- /dev/null
+++ b/data/ui/keyboard-configurer.ui
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GamesKeyboardConfigurer" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkStack" id="stack">
+ <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>
+ <child>
+ <object class="GtkBox" id="keyboard_mapper_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="name">keyboard_mapper</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="keyboard_tester_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="name">keyboard_tester</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkActionBar" id="action_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="reset_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes" context="Keyboard configuration factory
reset">Reset</property>
+ <signal name="clicked" handler="on_reset_clicked"/>
+ <style>
+ <class name="destructive-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="configure_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Configure</property>
+ <signal name="clicked" handler="on_configure_clicked"/>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+ <object class="GtkHeaderBar" id="header_bar">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkButton" id="back_button">
+ <property name="visible">True</property>
+ <signal name="clicked" handler="on_back_clicked"/>
+ <style>
+ <class name="image-button"/>
+ </style>
+ <child internal-child="accessible">
+ <object class="AtkObject" id="a11y-back">
+ <property name="accessible-name" translatable="yes">Back</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage" id="back_image">
+ <property name="visible">True</property>
+ <property name="icon-name">go-previous-symbolic</property>
+ <property name="icon-size">1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="cancel_button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Cancel</property>
+ <signal name="clicked" handler="on_cancel_clicked"/>
+ <style>
+ <class name="destructive-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 4a20ccf..bd576d2 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-configurer.vala \
ui/keyboard-mapper.vala \
ui/keyboard-tester.vala \
ui/media-selector.vala \
diff --git a/src/ui/keyboard-configurer.vala b/src/ui/keyboard-configurer.vala
new file mode 100644
index 0000000..990a915
--- /dev/null
+++ b/src/ui/keyboard-configurer.vala
@@ -0,0 +1,181 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/keyboard-configurer.ui")]
+private class Games.KeyboardConfigurer : Gtk.Box {
+ private const GamepadInput[] KEYBOARD_GAMEPAD_INPUTS = {
+ { EventCode.EV_KEY, EventCode.BTN_A },
+ { EventCode.EV_KEY, EventCode.BTN_B },
+ { EventCode.EV_KEY, EventCode.BTN_X },
+ { EventCode.EV_KEY, EventCode.BTN_Y },
+ { EventCode.EV_KEY, EventCode.BTN_START },
+ { EventCode.EV_KEY, EventCode.BTN_SELECT },
+ { EventCode.EV_KEY, EventCode.BTN_THUMBL },
+ { EventCode.EV_KEY, EventCode.BTN_THUMBR },
+ { EventCode.EV_KEY, EventCode.BTN_TL },
+ { EventCode.EV_KEY, EventCode.BTN_TR },
+ { EventCode.EV_KEY, EventCode.BTN_DPAD_UP },
+ { EventCode.EV_KEY, EventCode.BTN_DPAD_LEFT },
+ { EventCode.EV_KEY, EventCode.BTN_DPAD_DOWN },
+ { EventCode.EV_KEY, EventCode.BTN_DPAD_RIGHT },
+ { EventCode.EV_KEY, EventCode.BTN_TL2 },
+ { EventCode.EV_KEY, EventCode.BTN_TR2 },
+ };
+
+ private const GamepadInputPath[] KEYBOARD_GAMEPAD_INPUT_PATHS = {
+ { { EventCode.EV_KEY, EventCode.BTN_A }, "a" },
+ { { EventCode.EV_KEY, EventCode.BTN_B }, "b" },
+ { { EventCode.EV_KEY, EventCode.BTN_DPAD_DOWN }, "dpdown" },
+ { { EventCode.EV_KEY, EventCode.BTN_DPAD_LEFT }, "dpleft" },
+ { { EventCode.EV_KEY, EventCode.BTN_DPAD_RIGHT }, "dpright" },
+ { { EventCode.EV_KEY, EventCode.BTN_DPAD_UP }, "dpup" },
+ { { EventCode.EV_KEY, EventCode.BTN_SELECT }, "back" },
+ { { EventCode.EV_KEY, EventCode.BTN_TL }, "leftshoulder" },
+ { { EventCode.EV_KEY, EventCode.BTN_TR }, "rightshoulder" },
+ { { EventCode.EV_KEY, EventCode.BTN_START }, "start" },
+ { { EventCode.EV_KEY, EventCode.BTN_THUMBL }, "leftstick" },
+ { { EventCode.EV_KEY, EventCode.BTN_THUMBR }, "rightstick" },
+ { { EventCode.EV_KEY, EventCode.BTN_TL2 }, "lefttrigger" },
+ { { EventCode.EV_KEY, EventCode.BTN_TR2 }, "righttrigger" },
+ { { EventCode.EV_KEY, EventCode.BTN_Y }, "x" },
+ { { EventCode.EV_KEY, EventCode.BTN_X }, "y" },
+ };
+
+ private const GamepadViewConfiguration KEYBOARD_GAMEPAD_VIEW_CONFIGURATION = {
+ "resource:///org/gnome/Games/gamepads/standard-gamepad.svg", KEYBOARD_GAMEPAD_INPUT_PATHS
+ };
+
+ private enum State {
+ TEST,
+ CONFIGURE,
+ }
+
+ public signal void back ();
+
+ private State _state;
+ private State state {
+ set {
+ _state = value;
+ immersive_mode = (state == State.CONFIGURE);
+
+ switch (value) {
+ case State.TEST:
+ reset_button.set_sensitive (!mapping_manager.is_default ());
+
+ back_button.show ();
+ cancel_button.hide ();
+ action_bar.show ();
+ header_bar.title = _("Testing Keyboard");
+ header_bar.get_style_context ().remove_class ("selection-mode");
+ stack.set_visible_child_name ("keyboard_tester");
+
+ tester.start ();
+ mapper.stop ();
+ mapper.finished.disconnect (on_mapper_finished);
+
+ break;
+ case State.CONFIGURE:
+ back_button.hide ();
+ cancel_button.show ();
+ action_bar.hide ();
+ header_bar.title = _("Configuring Keyboard");
+ header_bar.get_style_context ().add_class ("selection-mode");
+ stack.set_visible_child_name ("keyboard_mapper");
+
+ tester.stop ();
+ mapper.start ();
+ mapper.finished.connect (on_mapper_finished);
+
+ break;
+ }
+ }
+ get { return _state; }
+ }
+
+ [GtkChild (name = "header_bar")]
+ private Gtk.HeaderBar _header_bar;
+ public Gtk.HeaderBar header_bar {
+ private set {}
+ get { return _header_bar; }
+ }
+
+ public bool immersive_mode { private set; get; }
+
+ [GtkChild]
+ private Gtk.Stack stack;
+ [GtkChild]
+ private Gtk.Box keyboard_mapper_holder;
+ [GtkChild]
+ private Gtk.Box keyboard_tester_holder;
+ [GtkChild]
+ private Gtk.ActionBar action_bar;
+ [GtkChild]
+ private Gtk.Button reset_button;
+ [GtkChild]
+ private Gtk.Button back_button;
+ [GtkChild]
+ private Gtk.Button cancel_button;
+
+ private KeyboardMapper mapper;
+ private KeyboardTester tester;
+ private KeyboardMappingManager mapping_manager;
+
+ public KeyboardConfigurer () {
+ mapper = new KeyboardMapper (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION, KEYBOARD_GAMEPAD_INPUTS);
+ keyboard_mapper_holder.pack_start (mapper);
+ tester = new KeyboardTester (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION);
+ keyboard_tester_holder.pack_start (tester);
+ mapping_manager = new KeyboardMappingManager ();
+
+ tester.mapping = mapping_manager.mapping;
+ mapping_manager.changed.connect (() => {
+ tester.mapping = mapping_manager.mapping;
+ });
+
+ state = State.TEST;
+ }
+
+ [GtkCallback]
+ private void on_reset_clicked () {
+ reset_mapping ();
+ }
+
+ [GtkCallback]
+ private void on_configure_clicked () {
+ state = State.CONFIGURE;
+ }
+
+ [GtkCallback]
+ private void on_back_clicked () {
+ back ();
+ }
+
+ [GtkCallback]
+ private void on_cancel_clicked () {
+ state = State.TEST;
+ }
+
+ private void reset_mapping () {
+ var message_dialog = new ResetControllerMappingDialog ();
+ message_dialog.set_transient_for ((Gtk.Window) get_toplevel ());
+ message_dialog.response.connect ((response) => {
+ switch (response) {
+ case Gtk.ResponseType.ACCEPT:
+ mapping_manager.delete_mapping ();
+ reset_button.set_sensitive (false);
+
+ break;
+ default:
+ break;
+ }
+
+ message_dialog.destroy();
+ });
+ message_dialog.show ();
+ }
+
+ private void on_mapper_finished (Retro.KeyJoypadMapping mapping) {
+ mapping_manager.save_mapping (mapping);
+
+ state = State.TEST;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]