[gnome-2048] Allow WASD keys.



commit 77fe183673cd79173322345d1f5e1bc12febfe3c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jan 30 14:53:50 2019 +0100

    Allow WASD keys.
    
    Uses the hardware keycodes, as it
    should. This patch copies the one
    of the bug, by Ricardo Borges Jr.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795056

 src/application.vala | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index 0385f46..fd8ac14 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -419,6 +419,11 @@ public class Application : Gtk.Application
     * * window management callbacks
     \*/
 
+    private const uint16 KEYCODE_W = 25;
+    private const uint16 KEYCODE_A = 38;
+    private const uint16 KEYCODE_S = 39;
+    private const uint16 KEYCODE_D = 40;
+
     private bool key_press_event_cb (Widget widget, Gdk.EventKey event)
     {
         if (_hamburger_button.active || (_window.focus_visible && !_embed.is_focus))
@@ -426,14 +431,21 @@ public class Application : Gtk.Application
         if (_game.cannot_move ())
             return false;
 
+        switch (event.hardware_keycode)
+        {
+            case KEYCODE_W:     _request_move (MoveRequest.UP);     return true;    // or KEYCODE_UP    = 
111;
+            case KEYCODE_A:     _request_move (MoveRequest.LEFT);   return true;    // or KEYCODE_LEFT  = 
113;
+            case KEYCODE_S:     _request_move (MoveRequest.DOWN);   return true;    // or KEYCODE_DOWN  = 
116;
+            case KEYCODE_D:     _request_move (MoveRequest.RIGHT);  return true;    // or KEYCODE_RIGHT = 
114;
+        }
         switch (_upper_key (event.keyval))
         {
-            case Gdk.Key.Down:  _request_move (MoveRequest.DOWN);   return true;
             case Gdk.Key.Up:    _request_move (MoveRequest.UP);     return true;
             case Gdk.Key.Left:  _request_move (MoveRequest.LEFT);   return true;
+            case Gdk.Key.Down:  _request_move (MoveRequest.DOWN);   return true;
             case Gdk.Key.Right: _request_move (MoveRequest.RIGHT);  return true;
-            default: return false;
         }
+        return false;
     }
     private static inline uint _upper_key (uint keyval)
     {


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