[gnome-games/wip/abhinavsingh/gamepad-config: 23/23] ui: Add preferences page for inputs
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 23/23] ui: Add preferences page for inputs
- Date: Sat, 22 Jul 2017 20:04:33 +0000 (UTC)
commit 50ff4b4f94afafa46aa36cf452a10365c0fe99a5
Author: theawless <theawless gmail com>
Date: Tue May 23 20:13:26 2017 +0530
ui: Add preferences page for inputs
This screen will allow the users to edit the settings related to inputs
like gamepads and keyboard.
data/Makefile.am | 1 +
data/org.gnome.Games.gresource.xml | 1 +
data/ui/preferences-page-inputs.ui | 71 +++++++++++++++++++++++++
data/ui/preferences-window.ui | 9 +++
src/Makefile.am | 1 +
src/ui/preferences-page-inputs.vala | 100 +++++++++++++++++++++++++++++++++++
6 files changed, 183 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 947b80e..90c21b6 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -43,6 +43,7 @@ EXTRA_DIST = \
ui/game-icon-view.ui \
ui/media-menu-button.ui \
ui/media-selector.ui \
+ ui/preferences-page-inputs.ui \
ui/preferences-page-plugins-item.ui \
ui/preferences-page-plugins.ui \
ui/preferences-page-video.ui \
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index a9e846d..ed0986a 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -22,6 +22,7 @@
<file preprocess="xml-stripblanks">ui/game-icon-view.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-inputs.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
<file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
diff --git a/data/ui/preferences-page-inputs.ui b/data/ui/preferences-page-inputs.ui
new file mode 100644
index 0000000..6cfc237
--- /dev/null
+++ b/data/ui/preferences-page-inputs.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GamesPreferencesPageInputs" parent="GtkStack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="visible-child">main_stack_child_holder</property>
+ <property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
+ <child>
+ <object class="GtkBox" id="extra_stack_child_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="name">extra_stack_child</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="main_stack_child_holder">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="can_focus">False</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="valign">start</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkAlignment">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="top_padding">12</property>
+ <child>
+ <object class="GtkListBox" id="gamepads_list_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="selection_mode">none</property>
+ <signal name="row-activated" handler="gamepads_list_box_row_activated"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Gamepads</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="name">main_stack_child</property>
+ </packing>
+ </child>
+ </template>
+ <object class="GtkHeaderBar" id="default_header_bar">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Inputs</property>
+ </object>
+</interface>
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 77f10e2..10d6251 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -77,6 +77,15 @@
</packing>
</child>
<child>
+ <object class="GamesPreferencesPageInputs" id="inputs_page">
+ <property name="visible">True</property>
+ </object>
+ <packing>
+ <property name="name">inputs</property>
+ <property name="title" translatable="yes">Inputs</property>
+ </packing>
+ </child>
+ <child>
<object class="GamesPreferencesPagePlugins" id="plugins_page">
<property name="visible">True</property>
</object>
diff --git a/src/Makefile.am b/src/Makefile.am
index 0bfd623..c19e07e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -156,6 +156,7 @@ gnome_games_SOURCES = \
ui/media-selector.vala \
ui/media-menu-button.vala \
ui/preferences-page.vala \
+ ui/preferences-page-inputs.vala \
ui/preferences-page-plugins.vala \
ui/preferences-page-plugins-item.vala \
ui/preferences-page-video.vala \
diff --git a/src/ui/preferences-page-inputs.vala b/src/ui/preferences-page-inputs.vala
new file mode 100644
index 0000000..696a11d
--- /dev/null
+++ b/src/ui/preferences-page-inputs.vala
@@ -0,0 +1,100 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-inputs.ui")]
+private class Games.PreferencesPageInputs: Gtk.Stack, PreferencesPage {
+ private Gtk.HeaderBar _header_bar;
+ public Gtk.HeaderBar header_bar {
+ protected set { _header_bar = value; }
+ get { return _header_bar; }
+ }
+
+ private bool _immersive_mode;
+ public bool immersive_mode {
+ protected set { _immersive_mode = value; }
+ get { return _immersive_mode; }
+ }
+
+ [GtkChild]
+ private Gtk.ListBox gamepads_list_box;
+ [GtkChild]
+ private Gtk.Box extra_stack_child_holder;
+ [GtkChild]
+ private Gtk.HeaderBar default_header_bar;
+
+ private GamepadMonitor gamepad_monitor;
+ private Binding header_bar_binding;
+ private Binding immersive_mode_binding;
+ private ulong back_handler_id;
+
+ construct {
+ header_bar = default_header_bar;
+ immersive_mode = false;
+
+ gamepad_monitor = GamepadMonitor.get_instance ();
+ gamepad_monitor.gamepad_unplugged.connect (rebuild_gamepad_list);
+ gamepad_monitor.gamepad_plugged.connect (rebuild_gamepad_list);
+ build_gamepad_list ();
+ }
+
+ public void visible_page_changed () {
+ on_back (null);
+ }
+
+ private void rebuild_gamepad_list () {
+ clear_gamepad_list ();
+ build_gamepad_list ();
+ }
+
+ private void build_gamepad_list () {
+ var i = 0;
+ gamepad_monitor.foreach_gamepad ((gamepad) => {
+ i += 1;
+ var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+ box.pack_start (new Gtk.Label (gamepad.name), false, false);
+ box.margin = 6;
+ box.show_all ();
+ gamepads_list_box.add (box);
+ });
+ }
+
+ private void clear_gamepad_list () {
+ gamepads_list_box.foreach ((child) => child.destroy ());
+ }
+
+ [GtkCallback]
+ private void gamepads_list_box_row_activated (Gtk.ListBoxRow row_item) {
+ Gamepad? gamepad = null;
+ var i = 0;
+ var row_index = row_item.get_index ();
+ gamepad_monitor.foreach_gamepad ((gamepad_) => {
+ if (i++ == row_index)
+ gamepad = gamepad_;
+ });
+
+ if (gamepad == null)
+ return;
+ var configurer = new GamepadConfigurer(gamepad);
+ back_handler_id = configurer.back.connect (on_back);
+ header_bar_binding = configurer.bind_property ("header-bar", this, "header-bar",
+ BindingFlags.SYNC_CREATE);
+ immersive_mode_binding = configurer.bind_property ("immersive-mode", this, "immersive-mode",
+ BindingFlags.SYNC_CREATE);
+ extra_stack_child_holder.pack_start (configurer);
+ set_visible_child_name ("extra_stack_child");
+ }
+
+ private void on_back (Object? emitter) {
+ header_bar_binding = null;
+ immersive_mode_binding = null;
+ if (back_handler_id != 0) {
+ if (emitter != null)
+ emitter.disconnect (back_handler_id);
+ back_handler_id = 0;
+ }
+
+ header_bar = default_header_bar;
+ immersive_mode = false;
+ set_visible_child_name ("main_stack_child");
+ extra_stack_child_holder.foreach ((child) => child.destroy ());
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]