[gnome-2048/app-menu: 4/5] Allow to use arrows for UI navigation.



commit c73c21512f68a5a54bf9415c994510b9a868037a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jan 8 22:22:31 2019 +0100

    Allow to use arrows for UI navigation.
    
    Without that, the game understands every use of one of the
    arrow keys as a move even when that was for UI navigation.

 data/mainwindow.ui   |  3 +++
 src/application.vala | 14 +++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/data/mainwindow.ui b/data/mainwindow.ui
index d1ccf7e..330ce82 100644
--- a/data/mainwindow.ui
+++ b/data/mainwindow.ui
@@ -23,6 +23,7 @@
             <property name="action_name">app.undo</property>
             <property name="tooltip_text" translatable="yes">Undo</property>
             <property name="always_show_image">True</property>
+            <property name="focus-on-click">False</property>
             <style>
               <class name="image-button"/>
             </style>
@@ -46,6 +47,7 @@
             <property name="receives_default">True</property>
             <property name="action_name">app.new-game</property>
             <property name="use_underline">True</property>
+            <property name="focus-on-click">False</property>
           </object>
           <packing>
             <property name="position">2</property>
@@ -57,6 +59,7 @@
             <property name="halign">end</property>
             <property name="valign">center</property>
             <property name="menu-model">hamburger-menu</property>
+            <property name="focus-on-click">False</property>
             <style>
               <class name="image-button"/>
             </style>
diff --git a/src/application.vala b/src/application.vala
index 9f97e55..24f958b 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -44,6 +44,8 @@ public class Application : Gtk.Application
     private ComboBoxText _grid_size_combo;
     private MenuButton _hamburger_button;
 
+    private GtkClutter.Embed embed;
+
     private Scores.Context _scores_ctx;
     private Scores.Category _grid4_cat;
     private Scores.Category _grid5_cat;
@@ -144,6 +146,7 @@ public class Application : Gtk.Application
         set_accels_for_action ("app.toggle-hamburger",  {                 "F10",
                                                                           "Menu"    });
 
+        _window.notify ["has-toplevel-focus"].connect (() => embed.grab_focus ());
         _window.show_all ();
 
         _game_restored = _game.restore_game ();
@@ -251,11 +254,15 @@ public class Application : Gtk.Application
         _new_game_button = (Button) builder.get_object ("new-game-button");
 
         _hamburger_button = (MenuButton) builder.get_object ("hamburger-button");
+        _hamburger_button.notify ["active"].connect (() => {
+                if (!_hamburger_button.active)
+                    embed.grab_focus ();
+            });
     }
 
     private void _create_game_view (Builder builder)
     {
-        GtkClutter.Embed embed = new GtkClutter.Embed ();
+        embed = new GtkClutter.Embed ();
         AspectFrame frame = (AspectFrame) builder.get_object ("aspectframe");
         frame.add (embed);
         _game.view = embed.get_stage ();
@@ -360,6 +367,8 @@ public class Application : Gtk.Application
         _game_restored = false;
 
         _game.new_game ();
+
+        embed.grab_focus ();
     }
 
     private void scores_cb ()
@@ -416,6 +425,9 @@ public class Application : Gtk.Application
     {
         _game_restored = false;
 
+        if (_hamburger_button.active || (_window.focus_visible && !embed.is_focus))
+            return false;
+
         return _game.key_pressed (event);
     }
 


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