[gnome-games] shortcuts-window: specify icons in xml



commit f2d0f15b96e474794e9c855968951d2c4612b868
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Mon Aug 19 03:52:10 2019 +0500

    shortcuts-window: specify icons in xml
    
    Since we cannot subclass GtkShortcutsWindow in GTK4, set gamepad icons via
    xml instead of programmatically.

 data/ui/shortcuts-window.ui  | 48 +++++++++++++++++++++++++++++++++++---------
 src/ui/application.vala      |  3 +++
 src/ui/shortcuts-window.vala | 36 ---------------------------------
 3 files changed, 42 insertions(+), 45 deletions(-)
---
diff --git a/data/ui/shortcuts-window.ui b/data/ui/shortcuts-window.ui
index cc86abdd..76a42e38 100644
--- a/data/ui/shortcuts-window.ui
+++ b/data/ui/shortcuts-window.ui
@@ -35,41 +35,46 @@
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="collection_shortcut_left_stick">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">stick_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Navigate</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Left analog 
stick</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="collection_shortcut_dpad">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">dpad_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Navigate</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Directional 
pad</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="collection_shortcut_shoulders_front">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">shoulders_front_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Select view</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Front shoulder 
buttons</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="collection_shortcut_start">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">button_start_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Start game</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Start 
button</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="collection_shortcut_south">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">button_south_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Start game</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Bottom action 
button</property>
               </object>
@@ -102,25 +107,28 @@
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="ingame_shortcut_home">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">button_home_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Go back to the 
collection</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Home button</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="ingame_shortcut_south">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">button_south_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Accept</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Bottom action 
button</property>
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="ingame_shortcut_east">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">button_east_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Cancel</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Right action 
button</property>
               </object>
@@ -190,9 +198,10 @@
               </object>
             </child>
             <child>
-              <object class="GtkShortcutsShortcut" id="nintendo_ds_shortcut_right_stick">
+              <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
                 <property name="shortcut-type">gesture</property>
+                <property name="icon">stick_icon</property>
                 <property name="title" translatable="yes" context="shortcut window">Toggle screen</property>
                 <property name="subtitle" translatable="yes" context="shortcut window">Press right analog 
stick</property>
               </object>
@@ -223,5 +232,26 @@
       </object>
     </child>
   </template>
+  <object class="GThemedIcon" id="button_home_icon">
+    <property name="name">button-home-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="button_start_icon">
+    <property name="name">button-start-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="button_east_icon">
+    <property name="name">button-east-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="button_south_icon">
+    <property name="name">button-south-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="dpad_icon">
+    <property name="name">dpad-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="stick_icon">
+    <property name="name">stick-symbolic</property>
+  </object>
+  <object class="GThemedIcon" id="shoulders_front_icon">
+    <property name="name">shoulders-front-symbolic</property>
+  </object>
 </interface>
 
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 3795364d..f32340ef 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -201,6 +201,9 @@ public class Games.Application : Gtk.Application {
        }
 
        protected override void activate () {
+               var icon_theme = Gtk.IconTheme.get_default ();
+               icon_theme.add_resource_path ("/org/gnome/Games/gesture");
+
                Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = true;
 
                var screen = Gdk.Screen.get_default ();
diff --git a/src/ui/shortcuts-window.vala b/src/ui/shortcuts-window.vala
index b3d37c66..b4dc2c0f 100644
--- a/src/ui/shortcuts-window.vala
+++ b/src/ui/shortcuts-window.vala
@@ -2,47 +2,11 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/shortcuts-window.ui")]
 private class Games.ShortcutsWindow : Gtk.ShortcutsWindow {
-       [GtkChild]
-       private Gtk.ShortcutsShortcut collection_shortcut_left_stick;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut collection_shortcut_dpad;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut collection_shortcut_shoulders_front;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut collection_shortcut_start;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut collection_shortcut_south;
        [GtkChild]
        private Gtk.ShortcutsShortcut ingame_shortcut_alt_left;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut ingame_shortcut_home;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut ingame_shortcut_south;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut ingame_shortcut_east;
-       [GtkChild]
-       private Gtk.ShortcutsShortcut nintendo_ds_shortcut_right_stick;
 
        construct {
                update_direction ();
-
-               var stick_icon = icon_for_uri ("resource:///org/gnome/Games/gesture/stick-symbolic.svg");
-
-               collection_shortcut_left_stick.icon = stick_icon;
-               collection_shortcut_dpad.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/dpad-symbolic.svg");
-               collection_shortcut_shoulders_front.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/shoulders-front-symbolic.svg");
-               collection_shortcut_start.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/button-start-symbolic.svg");
-               collection_shortcut_south.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/button-south-symbolic.svg");
-               ingame_shortcut_home.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/button-home-symbolic.svg");
-               ingame_shortcut_south.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/button-south-symbolic.svg");
-               ingame_shortcut_east.icon = icon_for_uri 
("resource:///org/gnome/Games/gesture/button-east-symbolic.svg");
-               nintendo_ds_shortcut_right_stick.icon = stick_icon;
-       }
-
-       static GLib.Icon icon_for_uri (string uri) {
-               var file = File.new_for_uri (uri);
-
-               return new FileIcon (file);
        }
 
        [GtkCallback]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]