[gnome-clocks/wip/sophie-h/fix-no-notification: 2/2] window: Fix notification is emediately withdrawn




commit d3c9aefa2464f2e3725bb088c9dc01c5db8a1bc2
Author: Sophie Herold <sophie hemio de>
Date:   Thu Aug 4 17:24:24 2022 +0200

    window: Fix notification is emediately withdrawn
    
    The previously used GtkEventControllerFocus::enter signal
    did also fire if the window was not in focus and the ui changed.
    
    This patch also fixes two issues with notifications getting
    withdrawn multiple times.
    
    Closes #237

 data/ui/window.ui    | 6 +-----
 src/application.vala | 6 +++++-
 src/window.vala      | 6 ++++--
 3 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/data/ui/window.ui b/data/ui/window.ui
index 8cd9e797..99c80529 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -2,16 +2,12 @@
 <interface>
   <template class="ClocksWindow" parent="AdwApplicationWindow">
     <property name="hide-on-close">True</property>
+    <signal name="notify::is-active" handler="on_window_active"/>
     <child>
       <object class="GtkEventControllerKey">
         <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 6c1e39af..589f13c5 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -144,13 +144,17 @@ public class Application : Adw.Application {
     public new void send_notification (string notification_id, GLib.Notification notification) {
         base.send_notification (notification_id, notification);
 
-        system_notifications.append (notification_id);
+        if (system_notifications.find (notification_id) == null) {
+            system_notifications.append (notification_id);
+        }
     }
 
     public void withdraw_notifications () {
         foreach (var notification in system_notifications) {
             withdraw_notification (notification);
         }
+
+        system_notifications = new List<string> ();
     }
 
     public override void shutdown () {
diff --git a/src/window.vala b/src/window.vala
index 0f2cfbab..c6eb9d17 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -229,8 +229,10 @@ public class Window : Adw.ApplicationWindow {
     }
 
     [GtkCallback]
-    private void enter_cb (Gtk.EventControllerFocus controller) {
-        ((Application) application).withdraw_notifications ();
+    private void on_window_active () {
+        if (is_active) {
+            ((Application) application).withdraw_notifications ();
+        }
     }
 
     [GtkCallback]


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