[gnome-games] ui: Add KeyboardTester
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Add KeyboardTester
- Date: Fri, 22 Jun 2018 20:43:46 +0000 (UTC)
commit a8e728dbc89d31fed98a1e19189f12514efaa1c7
Author: theawless <theawless gmail com>
Date: Mon Feb 19 18:58:13 2018 +0530
ui: Add KeyboardTester
This allows the user to test their keyboard by highlighting GamepadView
widget on user inputs.
https://bugzilla.gnome.org/show_bug.cgi?id=780755
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/keyboard-tester.ui | 18 ++++++++++++
src/Makefile.am | 1 +
src/ui/keyboard-tester.vala | 60 ++++++++++++++++++++++++++++++++++++++
5 files changed, 81 insertions(+)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index dc36d38..3d0915a 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-tester.ui \
ui/media-menu-button.ui \
ui/media-selector.ui \
ui/preferences-page-controllers.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 1387e5f..e9f252e 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-tester.ui</file>
<file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
<file preprocess="xml-stripblanks">ui/media-selector.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-controllers.ui</file>
diff --git a/data/ui/keyboard-tester.ui b/data/ui/keyboard-tester.ui
new file mode 100644
index 0000000..4320ee7
--- /dev/null
+++ b/data/ui/keyboard-tester.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GamesKeyboardTester" 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="can_focus">False</property>
+ <property name="halign">fill</property>
+ <property name="valign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 65e3328..49bbeec 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-tester.vala \
ui/media-selector.vala \
ui/media-menu-button.vala \
ui/preferences-page.vala \
diff --git a/src/ui/keyboard-tester.vala b/src/ui/keyboard-tester.vala
new file mode 100644
index 0000000..932c900
--- /dev/null
+++ b/src/ui/keyboard-tester.vala
@@ -0,0 +1,60 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/keyboard-tester.ui")]
+private class Games.KeyboardTester : Gtk.Box {
+ [GtkChild]
+ private GamepadView gamepad_view;
+
+ public Retro.KeyJoypadMapping mapping { set; get; }
+
+ public KeyboardTester (GamepadViewConfiguration configuration) {
+ try {
+ gamepad_view.set_configuration (configuration);
+ }
+ catch (Error e) {
+ critical ("Could not set up gamepad view: %s", e.message);
+ }
+ }
+
+ public void start () {
+ gamepad_view.reset ();
+ connect_to_keyboard ();
+ }
+
+ public void stop () {
+ disconnect_from_keyboard ();
+ }
+
+ private void connect_to_keyboard () {
+ var window = get_toplevel ();
+ window.key_press_event.connect (on_key_press_event);
+ window.key_release_event.connect (on_key_release_event);
+ }
+
+ private void disconnect_from_keyboard () {
+ var window = get_toplevel ();
+ window.key_press_event.disconnect (on_key_press_event);
+ window.key_release_event.disconnect (on_key_release_event);
+ }
+
+ private bool on_key_press_event (Gdk.EventKey key) {
+ update_gamepad_view (key, true);
+
+ return true;
+ }
+
+ private bool on_key_release_event (Gdk.EventKey key) {
+ update_gamepad_view (key, false);
+
+ return true;
+ }
+
+ private void update_gamepad_view (Gdk.EventKey key, bool highlight) {
+ for (Retro.JoypadId joypad_id = 0; joypad_id < Retro.JoypadId.COUNT; joypad_id += 1) {
+ if (mapping.get_button_key (joypad_id) == key.hardware_keycode) {
+ var code = joypad_id.to_button_code ();
+ gamepad_view.highlight ({ EventCode.EV_KEY, code }, highlight);
+ }
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]