[gnome-clocks] Use gesture for Gdk.Key.Escape



commit 4eca08c70be61dd885eea357eda2d4e1f2c9adaf
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Tue Dec 14 00:13:31 2021 +0100

    Use gesture for Gdk.Key.Escape

 data/ui/window.ui |  5 +++++
 src/window.vala   | 18 ++++++++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index ae6509ee..3a5cda86 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="ClocksWindow" parent="AdwApplicationWindow">
+    <child>
+      <object class="GtkEventControllerKey">
+        <signal name="key-pressed" handler="key_press_cb"/>
+      </object>
+    </child>
     <child>
       <object class="AdwLeaflet" id="alarm_leaflet">
         <property name="orientation">vertical</property>
diff --git a/src/window.vala b/src/window.vala
index 1bc781ec..6a14f750 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -82,8 +82,6 @@ public class Window : Adw.ApplicationWindow {
         add_binding_action (Gdk.Key.@4,
                             Gdk.ModifierType.ALT_MASK,
                             "set-page", "(s)", "timer");
-
-        add_binding (Gdk.Key.Escape, 0, escape_key_pressed, null);
     }
 
     public Window (Application app) {
@@ -226,13 +224,17 @@ public class Window : Adw.ApplicationWindow {
         world.add_location (location);
     }
 
-    private bool escape_key_pressed () {
+    [GtkCallback]
+    private bool key_press_cb (Gtk.EventControllerKey controller, uint keyval, uint keycode, 
Gdk.ModifierType mod_state) {
         bool handled = false;
-
-        if (world_leaflet.visible_child == main_view) {
-            handled = ((Clock) stack.visible_child).escape_pressed ();
-        } else {
-            world_leaflet.navigate (Adw.NavigationDirection.BACK);
+        var state = mod_state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK);
+
+        if (keyval == Gdk.Key.Escape && state == 0) {
+            if (world_leaflet.visible_child == main_view) {
+                handled = ((Clock) stack.visible_child).escape_pressed ();
+            } else {
+                world_leaflet.navigate (Adw.NavigationDirection.BACK);
+            }
         }
 
         return handled;


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