]> Pileus Git - ~andy/gtk/commitdiff
call gtk_window_process_updates() so the animation keeps running even if
authorMichael Natterer <mitch@imendio.com>
Wed, 16 Nov 2005 14:40:41 +0000 (14:40 +0000)
committerMichael Natterer <mitch@src.gnome.org>
Wed, 16 Nov 2005 14:40:41 +0000 (14:40 +0000)
2005-11-16  Michael Natterer  <mitch@imendio.com>

* gtk/gtkimage.c (animation_timeout): call
gtk_window_process_updates() so the animation keeps running even
if the main loop is busy with sources that eat a lot of cpu with
high priority. Fixes bug #321444.

(gtk_image_new_from_animation): document the fact that the
animation will stop running if the main loop is busy with sources
that have priorities higher than G_PRIORITY_DEFAULT.

* tests/testimage.c: added test case that shows an animation even
though a cpu-eating idle function is running.

ChangeLog
ChangeLog.pre-2-10
gtk/gtkimage.c
tests/testimage.c

index 0566c99a95aa9d21315fbc9fcc56905c3dde2189..8e55301e2212670e76e338270f9bdbde57f21b85 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2005-11-16  Michael Natterer  <mitch@imendio.com>
+
+       * gtk/gtkimage.c (animation_timeout): call
+       gtk_window_process_updates() so the animation keeps running even
+       if the main loop is busy with sources that eat a lot of cpu with
+       high priority. Fixes bug #321444.
+
+       (gtk_image_new_from_animation): document the fact that the
+       animation will stop running if the main loop is busy with sources
+       that have priorities higher than G_PRIORITY_DEFAULT.
+
+       * tests/testimage.c: added test case that shows an animation even
+       though a cpu-eating idle function is running.
+
 2005-11-16  Michael Natterer  <mitch@imendio.com>
 
        * gdk/x11/gdkevents-x11.c (_gdk_events_uninit): new internal
index 0566c99a95aa9d21315fbc9fcc56905c3dde2189..8e55301e2212670e76e338270f9bdbde57f21b85 100644 (file)
@@ -1,3 +1,17 @@
+2005-11-16  Michael Natterer  <mitch@imendio.com>
+
+       * gtk/gtkimage.c (animation_timeout): call
+       gtk_window_process_updates() so the animation keeps running even
+       if the main loop is busy with sources that eat a lot of cpu with
+       high priority. Fixes bug #321444.
+
+       (gtk_image_new_from_animation): document the fact that the
+       animation will stop running if the main loop is busy with sources
+       that have priorities higher than G_PRIORITY_DEFAULT.
+
+       * tests/testimage.c: added test case that shows an animation even
+       though a cpu-eating idle function is running.
+
 2005-11-16  Michael Natterer  <mitch@imendio.com>
 
        * gdk/x11/gdkevents-x11.c (_gdk_events_uninit): new internal
index 1061253e18e44c0805eb5e5b8b0ca25d8861aa53..a2f18baca7bc3fe7c2b7f79901df2d18221c333f 100644 (file)
@@ -671,7 +671,12 @@ gtk_image_new_from_icon_set (GtkIconSet     *icon_set,
  * The #GtkImage does not assume a reference to the
  * animation; you still need to unref it if you own references.
  * #GtkImage will add its own reference rather than adopting yours.
- * 
+ *
+ * Note that the animation frames are shown using a timeout with
+ * #G_PRIORITY_DEFAULT. When using animations to indicate busyness,
+ * keep in mind that the animation will only be shown if the main loop
+ * is not busy with something that has a higher priority.
+ *
  * Return value: a new #GtkImage widget
  **/
 GtkWidget*
@@ -1396,9 +1401,12 @@ animation_timeout (gpointer data)
       g_timeout_add (gdk_pixbuf_animation_iter_get_delay_time (image->data.anim.iter),
                      animation_timeout,
                      image);
-  
+
   gtk_widget_queue_draw (GTK_WIDGET (image));
 
+  if (GTK_WIDGET_DRAWABLE (image))
+    gdk_window_process_updates (GTK_WIDGET (image)->window, TRUE);
+
   GDK_THREADS_LEAVE ();
 
   return FALSE;
index b9ade1d1f2213d0aba5baa15ddb9af515064199d..0e40f247b87c04b9012acc060a9afdf972519e4e 100644 (file)
@@ -68,6 +68,30 @@ drag_data_received (GtkWidget        *widget,
   gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
 }
 
+static gboolean
+idle_func (gpointer data)
+{
+  g_print ("keep me busy\n");
+
+  return TRUE;
+}
+
+static gboolean
+anim_image_expose (GtkWidget      *widget,
+                   GdkEventExpose *eevent,
+                   gpointer        data)
+{
+  g_print ("start busyness\n");
+
+  g_signal_handlers_disconnect_by_func (widget, anim_image_expose, data);
+
+  /* produce high load */
+  g_idle_add_full (G_PRIORITY_DEFAULT,
+                   idle_func, NULL, NULL);
+
+  return FALSE;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -78,14 +102,18 @@ main (int argc, char **argv)
   GtkIconSet *iconset;
   GtkIconSource *iconsource;
   gchar *icon_name = "gnome-terminal";
-  
+  gchar *anim_filename = NULL;
+
   gtk_init (&argc, &argv);
 
   if (argc > 1)
     icon_name = argv[1];
 
+  if (argc > 2)
+    anim_filename = argv[2];
+
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  table = gtk_table_new (4, 3, FALSE);
+  table = gtk_table_new (6, 3, FALSE);
   gtk_container_add (GTK_CONTAINER (window), table);
 
   label = gtk_label_new ("symbolic size");
@@ -144,7 +172,21 @@ main (int argc, char **argv)
   image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
   gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
   gtk_table_attach_defaults (GTK_TABLE (table), image, 2, 3, 4, 5);
-                  
+
+  if (anim_filename)
+    {
+      label = gtk_label_new ("GTK_IMAGE_ANIMATION (from file)");
+      gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6);
+      image = gtk_image_new_from_file (anim_filename);
+      gtk_image_set_pixel_size (GTK_IMAGE (image), 30);
+      gtk_table_attach_defaults (GTK_TABLE (table), image, 2, 3, 5, 6);
+
+      /* produce high load */
+      g_signal_connect_after (image, "expose-event",
+                              G_CALLBACK (anim_image_expose),
+                              NULL);
+    }
+
   gtk_widget_show_all (window);
 
   gtk_main ();