[gnome-settings-daemon] power: Fix non-transient notifications sticking around



commit 487ab6cf4fa7fcb6d0921a4d53bee6288fe783ff
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 12 13:34:24 2013 +0200

    power: Fix non-transient notifications sticking around
    
    When replacing an existing notification with a more up-to-date one,
    we were closing the existing notification, and creating a new one in its
    place. As, to clean up when a notification is dismissed by hand, we hook
    up to the "closed" signal, we ended up zero'ing the pointer to the just
    shown notification and making it impossible to remove later.
    
    eg.
    - 1st notification created
    - updated state comes in
    - notify_close() called
    - notification pointer is replaced with newer notification
    - main loop returns
    - "closed" signal is received for the 1st notification (ah!)
    - original notification is unref'ed, and its location is zero'd
      by weak pointer call.
    
    That location is that of the new notification as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=702047

 plugins/power/gsd-power-manager.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index fd4c904..f052bac 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -258,11 +258,12 @@ gsd_power_manager_error_quark (void)
 }
 
 static void
-notify_close_if_showing (NotifyNotification *notification)
+notify_close_if_showing (NotifyNotification **notification)
 {
-        if (notification == NULL)
+        if (*notification == NULL)
                 return;
-        notify_notification_close (notification, NULL);
+        notify_notification_close (*notification, NULL);
+        g_clear_object (notification);
 }
 
 typedef enum {
@@ -1211,7 +1212,7 @@ engine_ups_discharging (GsdPowerManager *manager, UpDevice *device)
         icon = gpm_upower_get_device_icon (device, TRUE);
 
         /* close any existing notification of this class */
-        notify_close_if_showing (manager->priv->notification_ups_discharging);
+        notify_close_if_showing (&manager->priv->notification_ups_discharging);
 
         /* create a new notification */
         create_notification (title, message->str,
@@ -1421,7 +1422,7 @@ engine_charge_low (GsdPowerManager *manager, UpDevice *device)
         icon = gpm_upower_get_device_icon (device, TRUE);
 
         /* close any existing notification of this class */
-        notify_close_if_showing (manager->priv->notification_low);
+        notify_close_if_showing (&manager->priv->notification_low);
 
         /* create a new notification */
         create_notification (title, message,
@@ -1594,7 +1595,7 @@ engine_charge_critical (GsdPowerManager *manager, UpDevice *device)
         icon = gpm_upower_get_device_icon (device, TRUE);
 
         /* close any existing notification of this class */
-        notify_close_if_showing (manager->priv->notification_low);
+        notify_close_if_showing (&manager->priv->notification_low);
 
         /* create a new notification */
         create_notification (title, message,
@@ -1732,7 +1733,7 @@ engine_charge_action (GsdPowerManager *manager, UpDevice *device)
         icon = gpm_upower_get_device_icon (device, TRUE);
 
         /* close any existing notification of this class */
-        notify_close_if_showing (manager->priv->notification_low);
+        notify_close_if_showing (&manager->priv->notification_low);
 
         /* create a new notification */
         create_notification (title, message,
@@ -1794,8 +1795,8 @@ engine_device_changed_cb (UpClient *client, UpDevice *device, GsdPowerManager *m
                 } else if (state == UP_DEVICE_STATE_FULLY_CHARGED ||
                            state == UP_DEVICE_STATE_CHARGING) {
                         g_debug ("fully charged or charging, hiding notifications if any");
-                        notify_close_if_showing (manager->priv->notification_low);
-                        notify_close_if_showing (manager->priv->notification_ups_discharging);
+                        notify_close_if_showing (&manager->priv->notification_low);
+                        notify_close_if_showing (&manager->priv->notification_ups_discharging);
                         main_battery_or_ups_low_changed (manager, FALSE);
                 }
 
@@ -2277,7 +2278,7 @@ up_client_changed_cb (UpClient *client, GsdPowerManager *manager)
         if (!up_client_get_on_battery (client)) {
             /* if we are playing a critical charge sound loop on AC, stop it */
             play_loop_stop (&manager->priv->critical_alert_timeout_id);
-            notify_close_if_showing (manager->priv->notification_low);
+            notify_close_if_showing (&manager->priv->notification_low);
             main_battery_or_ups_low_changed (manager, FALSE);
         }
 
@@ -2653,7 +2654,7 @@ idle_configure (GsdPowerManager *manager)
                                   &manager->priv->idle_dim_id);
                 clear_idle_watch (manager->priv->idle_monitor,
                                   &manager->priv->idle_sleep_warning_id);
-                notify_close_if_showing (manager->priv->notification_sleep_warning);
+                notify_close_if_showing (&manager->priv->notification_sleep_warning);
                 return;
         }
 
@@ -2720,7 +2721,7 @@ idle_configure (GsdPowerManager *manager)
         }
 
         if (manager->priv->idle_sleep_warning_id == 0)
-                notify_close_if_showing (manager->priv->notification_sleep_warning);
+                notify_close_if_showing (&manager->priv->notification_sleep_warning);
 
         /* set up dim callback for when the screen lock is not active,
          * but only if we actually want to dim. */
@@ -3053,7 +3054,7 @@ static void
 show_sleep_warning (GsdPowerManager *manager)
 {
         /* close any existing notification of this class */
-        notify_close_if_showing (manager->priv->notification_sleep_warning);
+        notify_close_if_showing (&manager->priv->notification_sleep_warning);
 
         /* create a new notification */
         switch (manager->priv->sleep_action_type) {
@@ -3124,7 +3125,7 @@ idle_became_active_cb (GnomeIdleMonitor *monitor,
         set_temporary_unidle_on_ac (manager, FALSE);
 
         /* close any existing notification about idleness */
-        notify_close_if_showing (manager->priv->notification_sleep_warning);
+        notify_close_if_showing (&manager->priv->notification_sleep_warning);
 
         idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL);
 }
@@ -3352,8 +3353,8 @@ handle_resume_actions (GsdPowerManager *manager)
 {
         /* close existing notifications on resume, the system power
          * state is probably different now */
-        notify_close_if_showing (manager->priv->notification_low);
-        notify_close_if_showing (manager->priv->notification_ups_discharging);
+        notify_close_if_showing (&manager->priv->notification_low);
+        notify_close_if_showing (&manager->priv->notification_ups_discharging);
         main_battery_or_ups_low_changed (manager, FALSE);
 
         /* ensure we turn the panel back on after resume */


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