[gnome-games/gnome-3-6] swell-foop: prevent keyboard focus from going to the toolbar
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/gnome-3-6] swell-foop: prevent keyboard focus from going to the toolbar
- Date: Fri, 28 Sep 2012 22:56:16 +0000 (UTC)
commit dc8d781d7e49f985edfe54fc3707d6529c03b91c
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date: Sat Sep 29 00:50:50 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 active button.
swell-foop/src/swell-foop.vala | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/swell-foop/src/swell-foop.vala b/swell-foop/src/swell-foop.vala
index b4bb76e..7ff5551 100644
--- a/swell-foop/src/swell-foop.vala
+++ b/swell-foop/src/swell-foop.vala
@@ -53,6 +53,7 @@ public class SwellFoop : Gtk.Application
main_window = new Gtk.ApplicationWindow (this);
main_window.set_title (_("Swell Foop"));
main_window.resizable = false;
+ main_window.set_events (main_window.get_events () | Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK);
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
vbox.show ();
@@ -151,32 +152,31 @@ public class SwellFoop : Gtk.Application
high_scores.add_category ("normal", _("Normal"));
high_scores.add_category ("large", _("Large"));
- stage.key_release_event.connect (key_release_event_cb);
+ main_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]