[gnome-utils] flash: make sure to keep a self reference while fading out



commit 8e9279c8ebdf9ffd132899990f001faaa4f7c79a
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 26 16:54:09 2011 -0400

    flash: make sure to keep a self reference while fading out
    
    This way we can unref the flash object immediately instead of waiting
    after the mainloop has quit.

 gnome-screenshot/cheese-flash.c     |   16 ++++++++++++----
 gnome-screenshot/gnome-screenshot.c |    3 ++-
 2 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/gnome-screenshot/cheese-flash.c b/gnome-screenshot/cheese-flash.c
index 9e3ec4d..131c9b3 100644
--- a/gnome-screenshot/cheese-flash.c
+++ b/gnome-screenshot/cheese-flash.c
@@ -165,8 +165,8 @@ cheese_flash_opacity_fade (gpointer data)
 static gboolean
 cheese_flash_start_fade (gpointer data)
 {
-  CheeseFlashPrivate *flash_priv = CHEESE_FLASH_GET_PRIVATE (CHEESE_FLASH (data));
-
+  CheeseFlash *self = data;
+  CheeseFlashPrivate *flash_priv = CHEESE_FLASH_GET_PRIVATE (self);
   GtkWindow *flash_window = flash_priv->window;
 
   /* If the screen is non-composited, just hide and finish up */
@@ -176,7 +176,11 @@ cheese_flash_start_fade (gpointer data)
     return FALSE;
   }
 
-  flash_priv->fade_timeout_tag = g_timeout_add (1000.0 / FLASH_ANIMATION_RATE, cheese_flash_opacity_fade, data);
+  flash_priv->fade_timeout_tag = 
+    g_timeout_add_full (G_PRIORITY_DEFAULT,
+                        1000.0 / FLASH_ANIMATION_RATE,
+                        cheese_flash_opacity_fade,
+                        g_object_ref (self), g_object_unref);
   return FALSE;
 }
 
@@ -197,7 +201,11 @@ cheese_flash_fire (CheeseFlash  *flash,
 
   gtk_window_set_opacity (flash_window, 0.99);
   gtk_widget_show_all (GTK_WIDGET (flash_window));
-  flash_priv->flash_timeout_tag = g_timeout_add (FLASH_DURATION, cheese_flash_start_fade, (gpointer) flash);
+  flash_priv->flash_timeout_tag = 
+    g_timeout_add_full (G_PRIORITY_DEFAULT,
+                        FLASH_DURATION,
+                        cheese_flash_start_fade,
+                        g_object_ref (flash), g_object_unref);
 }
 
 CheeseFlash *
diff --git a/gnome-screenshot/gnome-screenshot.c b/gnome-screenshot/gnome-screenshot.c
index 60f20ec..6a83ef2 100644
--- a/gnome-screenshot/gnome-screenshot.c
+++ b/gnome-screenshot/gnome-screenshot.c
@@ -507,6 +507,8 @@ finish_prepare_screenshot (GdkRectangle *rectangle)
   cheese_flash_fire (flash, &rect);
   play_sound_effect (window);
 
+  g_object_unref (flash);
+
   if (screenshot_config->copy_to_clipboard)
     {
       screenshot_save_to_clipboard ();
@@ -721,7 +723,6 @@ main (int argc, char *argv[])
 
   gtk_main ();
 
-  g_clear_object (&flash);
   g_clear_object (&connection);
 
   return EXIT_SUCCESS;



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