[gnome-games/wip/abhinavsingh/gamepad-config: 22/22] ui: Add preferences page for inputs



commit b4b04d209b5184dfa8cad39a66071a258bedd37e
Author: theawless <theawless gmail com>
Date:   Thu Jul 27 00:52:08 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-controllers.ui  |   71 +++++++++++++++++++++++
 data/ui/preferences-window.ui            |    9 +++
 src/Makefile.am                          |    1 +
 src/ui/preferences-page-controllers.vala |   92 ++++++++++++++++++++++++++++++
 6 files changed, 175 insertions(+), 0 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 947b80e..fff2a95 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-controllers.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..b8ba7b5 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-controllers.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-controllers.ui b/data/ui/preferences-page-controllers.ui
new file mode 100644
index 0000000..09bd294
--- /dev/null
+++ b/data/ui/preferences-page-controllers.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GamesPreferencesPageControllers" 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">Controllers</property>
+  </object>
+</interface>
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 320f4bb..5cdaecb 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -77,6 +77,15 @@
               </packing>
             </child>
             <child>
+              <object class="GamesPreferencesPageControllers" id="controllers_page">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="name">controllers</property>
+                <property name="title" translatable="yes">Controllers</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..645eb45 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-controllers.vala \
        ui/preferences-page-plugins.vala \
        ui/preferences-page-plugins-item.vala \
        ui/preferences-page-video.vala \
diff --git a/src/ui/preferences-page-controllers.vala b/src/ui/preferences-page-controllers.vala
new file mode 100644
index 0000000..9ce50c3
--- /dev/null
+++ b/src/ui/preferences-page-controllers.vala
@@ -0,0 +1,92 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-controllers.ui")]
+private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
+       public Gtk.HeaderBar header_bar { protected set; get; }
+
+       public bool immersive_mode { protected set; get; }
+
+       [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]