call gtk_window_process_updates() so the animation keeps running even if

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.
This commit is contained in:
Michael Natterer 2005-11-16 14:40:41 +00:00 committed by Michael Natterer
parent 6e802acd48
commit 81be0b4311
4 changed files with 83 additions and 5 deletions

View 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

View 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

View 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;

View 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 ();