[gnome-clocks] app: Move withraw_notification callback



commit 801323b7b5db0e55c1bf0fb80a35f8f0efcc1a99
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Tue Dec 14 00:43:44 2021 +0100

    app: Move withraw_notification callback
    
    The window returned by ensure_window() may already exist, we don't want
    to add more controllers/callbacks to it.

 data/ui/window.ui    | 5 +++++
 src/application.vala | 8 +-------
 src/window.vala      | 5 +++++
 3 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 99cc7f70..80d5b4a2 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -6,6 +6,11 @@
         <signal name="key-pressed" handler="key_press_cb"/>
       </object>
     </child>
+    <child>
+      <object class="GtkEventControllerFocus">
+        <signal name="enter" handler="enter_cb"/>
+      </object>
+    </child>
     <child>
       <object class="AdwLeaflet" id="alarm_leaflet">
         <property name="orientation">vertical</property>
diff --git a/src/application.vala b/src/application.vala
index 4d8f942c..0b04764e 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -98,12 +98,6 @@ public class Application : Adw.Application {
 
         var win = ensure_window ();
         win.present ();
-
-        var controller = new Gtk.EventControllerFocus ();
-        controller.enter.connect (() => {
-                withdraw_notifications ();
-            });
-        ((Gtk.Widget) win).add_controller (controller);
     }
 
     protected override void startup () {
@@ -152,7 +146,7 @@ public class Application : Adw.Application {
         system_notifications.append (notification_id);
     }
 
-    private void withdraw_notifications () {
+    public void withdraw_notifications () {
         foreach (var notification in system_notifications) {
             withdraw_notification (notification);
         }
diff --git a/src/window.vala b/src/window.vala
index d7fc5a59..acbf42fc 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -223,6 +223,11 @@ public class Window : Adw.ApplicationWindow {
         world.add_location (location);
     }
 
+    [GtkCallback]
+    private void enter_cb (Gtk.EventControllerFocus controller) {
+        ((Application) application).withdraw_notifications ();
+    }
+
     [GtkCallback]
     private bool key_press_cb (Gtk.EventControllerKey controller, uint keyval, uint keycode, 
Gdk.ModifierType mod_state) {
         bool handled = false;


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