[gnome-games] swell-foop: prevent keyboard focus from going to the toolbar Before the keyevents were comming from
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] swell-foop: prevent keyboard focus from going to the toolbar Before the keyevents were comming from
- Date: Fri, 28 Sep 2012 23:13:07 +0000 (UTC)
commit 3fc877b2d4ebe0aacce473cc736e0cbb2a844d37
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date: Sat Sep 29 01:01:01 2012 +0200
swell-foop: prevent keyboard focus from going to the toolbar Before the keyevents were comming from the clutter stage. Pressing up-arrow would move focus to the toolbar's new-game button. This commit moves the keyevents to the main window.
The game will now always react to keypresses regardless of wether
the stage has focus.
Note: The space-key is reserved for playing the game. If the toolbar
has focus we need to prevent accidentially pressing the new-game
button.
The return-key is still free to allow users of the keyboard to
activate button.
swell-foop/src/swell-foop.vala | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
---
diff --git a/swell-foop/src/swell-foop.vala b/swell-foop/src/swell-foop.vala
index fe7b90f..998233b 100644
--- a/swell-foop/src/swell-foop.vala
+++ b/swell-foop/src/swell-foop.vala
@@ -54,6 +54,7 @@ public class SwellFoop : Gtk.Application
window = new Gtk.ApplicationWindow (this);
window.set_title (_("Swell Foop"));
window.resizable = false;
+ window.set_events (window.get_events () | Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK);
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
vbox.show ();
@@ -144,35 +145,34 @@ public class SwellFoop : Gtk.Application
/* When the mouse leaves the window we need to update the view */
clutter_embed.leave_notify_event.connect (view.board_left_cb);
- stage.key_release_event.connect (key_release_event_cb);
-
history = new History (Path.build_filename (Environment.get_user_data_dir (), "swell-foop", "history"));
history.load ();
+
+ window.key_press_event.connect (key_press_event_cb);
}
- private bool key_release_event_cb (Clutter.Actor actor, Clutter.KeyEvent event)
+ private bool key_press_event_cb (Gtk.Widget widget, Gdk.EventKey event)
{
switch (event.keyval)
{
- case Clutter.Key.F2:
+ case Gdk.Key.F2:
new_game ();
break;
- case Clutter.Key.Up:
+ case Gdk.Key.Up:
view.cursor_move (0, 1);
break;
- case Clutter.Key.Down:
+ case Gdk.Key.Down:
view.cursor_move (0, -1);
break;
- case Clutter.Key.Left:
+ case Gdk.Key.Left:
view.cursor_move (-1, 0);
break;
- case Clutter.Key.Right:
+ case Gdk.Key.Right:
view.cursor_move (1, 0);
break;
case Clutter.Key.space:
- case Clutter.Key.Return:
view.cursor_click ();
- break;
+ return true; //handle this one to avoid activating the toolbar button
default:
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]