[lightsoff] Use eventcontroller for keyboard handling



commit d49b6ab70337f0538b04aaa0c1d4f0c1fdc84b49
Author: Robert Roth <robert roth bee-tf ro>
Date:   Tue May 12 08:59:29 2020 +0300

    Use eventcontroller for keyboard handling

 meson.build               |  2 +-
 src/lightsoff-window.vala | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/meson.build b/meson.build
index 782a929..bc810c2 100644
--- a/meson.build
+++ b/meson.build
@@ -20,7 +20,7 @@ glib_min_version = '2.38'
 glib_dep = dependency('glib-2.0', version: '>= ' + glib_min_version)
 gmodule_dep = dependency('gmodule-2.0')
 gio_dep = dependency('gio-2.0', version: '>= ' + glib_min_version)
-gtk_dep = dependency('gtk+-3.0', version: '>= 3.13.4')
+gtk_dep = dependency('gtk+-3.0', version: '>= 3.24')
 clutter_dep = dependency('clutter-1.0', version: '>= 1.14.0')
 clutter_gtk_dep = dependency('clutter-gtk-1.0', version: '>= 1.5.0')
 librsvg_dep = dependency('librsvg-2.0', version: '>= 2.32.0')
diff --git a/src/lightsoff-window.vala b/src/lightsoff-window.vala
index abc4cb1..06b5d78 100644
--- a/src/lightsoff-window.vala
+++ b/src/lightsoff-window.vala
@@ -21,6 +21,7 @@ public class LightsoffWindow : ApplicationWindow
     private GLib.Settings settings;
     private GameView game_view;
     private SimpleAction previous_level;
+    private EventControllerKey key_controller;
 
     private const GLib.ActionEntry[] window_actions =
     {
@@ -29,6 +30,12 @@ public class LightsoffWindow : ApplicationWindow
         { "next-level",     next_level_cb }
     };
 
+    private inline void init_keyboard ()
+    {
+        key_controller = new EventControllerKey (this);
+        key_controller.key_pressed.connect (on_key_pressed);
+    }
+
     public Gtk.Widget build_clutter_game_container (int level, out GameView out_game_view)
     {
         var clutter_embed = new GtkClutter.Embed ();
@@ -76,6 +83,7 @@ public class LightsoffWindow : ApplicationWindow
         add_action_entries (window_actions, this);
         previous_level = (SimpleAction) this.lookup_action ("previous-level");
 
+        init_keyboard ();
         int level = settings.get_int ("level");
         level_changed_cb (level);
 
@@ -85,7 +93,6 @@ public class LightsoffWindow : ApplicationWindow
             this.add (build_clutter_game_container (level, out game_view));
 
         this.set_resizable (gtk);
-        this.key_release_event.connect (key_release_event_cb);
         game_view.level_changed.connect (level_changed_cb);
         game_view.moves_changed.connect (update_subtitle);
 
@@ -127,9 +134,11 @@ public class LightsoffWindow : ApplicationWindow
             settings.set_int ("level", level);
     }
 
-    private bool key_release_event_cb (Gtk.Widget widget, Gdk.EventKey event)
+    private inline bool on_key_pressed (EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)
     {
-        switch (event.keyval)
+        if (menu_button.get_active())
+            return false;
+        switch (keyval)
         {
         case Gdk.Key.Escape:
             set_focus_visible (false);


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