[gnome-nibbles] Handle key pressed event in gnome-nibbles.vala



commit 2f73feab3153c97038da37703644d9e3c5fec385
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Mon Feb 15 18:39:38 2016 +0200

    Handle key pressed event in gnome-nibbles.vala
    
    The reason I am moving this from nibbles-view.vala to gnome-nibbles.vala
    is to avoid a weird behavior of having your first key press ignored
    everytime by the start of a new level, thus making your worm
    unresponsive to your command.
    
    As unlikey as it may seem that there is any difference of behavior
    by connecting to the signal in gnome-nibbles.vala rather than
    nibbles-view.vala, this actually provides a fix for the bug that states
    a worm is uncontrollable briefly after spawn.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758467

 src/gnome-nibbles.vala |   11 +++++++++++
 src/nibbles-view.vala  |    9 ---------
 2 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 24546a8..1b52044 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -156,6 +156,7 @@ public class Nibbles : Gtk.Application
         window = builder.get_object ("nibbles-window") as Gtk.ApplicationWindow;
         window.size_allocate.connect (size_allocate_cb);
         window.window_state_event.connect (window_state_event_cb);
+        window.key_press_event.connect (key_press_event_cb);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-maximized"))
             window.maximize ();
@@ -258,6 +259,16 @@ public class Nibbles : Gtk.Application
     * * Window events
     \*/
 
+    /* The reason this event handler is found here (and not in nibbles-view.vala
+     * which would be a more suitable place) is to avoid a weird behavior of having
+     * your first key press ignored everytime by the start of a new level, thus
+     * making your worm unresponsive to your command.
+     */
+    private bool key_press_event_cb (Gtk.Widget widget, Gdk.EventKey event)
+    {
+        return game.handle_keypress (event.keyval);
+    }
+
     private void size_allocate_cb (Gtk.Allocation allocation)
     {
         if (is_maximized || is_tiled)
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index e7f780a..b9d82d4 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -895,15 +895,6 @@ public class NibblesView : GtkClutter.Embed
     }
 
     /*\
-    * * Input handling
-    \*/
-
-    public override bool key_press_event (Gdk.EventKey event)
-    {
-        return game.handle_keypress (event.keyval);
-    }
-
-    /*\
     * * Sound
     \*/
 


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