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



commit b520483bc507ceca8cddefb9e73f48edef50e88f
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 e6380bd..96da3d1 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -261,11 +261,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 {
@@ -1214,7 +1215,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,
@@ -1424,7 +1425,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,
@@ -1597,7 +1598,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,
@@ -1735,7 +1736,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,
@@ -1797,8 +1798,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);
                 }
 
@@ -2268,7 +2269,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);
         }
 
@@ -2638,7 +2639,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;
         }
 
@@ -2705,7 +2706,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. */
@@ -3038,7 +3039,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) {
@@ -3109,7 +3110,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);
 }
@@ -3344,8 +3345,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]