Updating branch refs/heads/xfce-4.8 to 0f1f3c0bb965bc12794432182c571f5eb8d67e42 (commit) from ed25d312fdf930b06c2ebffe639169d780d44f7b (commit)
commit 0f1f3c0bb965bc12794432182c571f5eb8d67e42 Author: Nick Schermer <n...@xfce.org> Date: Sat Jun 11 22:13:17 2011 +0200 Idle XfcePanelImage loading. Delay loading of images in the panel. This will improve the overall response of the panel and menus. (cherry picked from commit 0fcce195482cfd1a3e925014d9a81a4b5e7676b8) libxfce4panel/xfce-panel-image.c | 110 ++++++++++++++++++++++++++------------ 1 files changed, 76 insertions(+), 34 deletions(-) diff --git a/libxfce4panel/xfce-panel-image.c b/libxfce4panel/xfce-panel-image.c index 1126d1e..f483787 100644 --- a/libxfce4panel/xfce-panel-image.c +++ b/libxfce4panel/xfce-panel-image.c @@ -90,6 +90,9 @@ struct _XfcePanelImagePrivate /* cached width and height */ gint width; gint height; + + /* idle load timeout */ + guint idle_load_id; }; enum @@ -119,6 +122,8 @@ static gboolean xfce_panel_image_expose_event (GtkWidget *widget, GdkEventExpose *event); static void xfce_panel_image_style_set (GtkWidget *widget, GtkStyle *previous_style); +static gboolean xfce_panel_image_load (gpointer data); +static void xfce_panel_image_load_destroy (gpointer data); static GdkPixbuf *xfce_panel_image_scale_pixbuf (GdkPixbuf *source, gint dest_width, gint dest_height); @@ -305,10 +310,7 @@ xfce_panel_image_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv; - GdkPixbuf *pixbuf; - GdkScreen *screen; - GtkIconTheme *icon_theme = NULL; - gint size; + widget->allocation = *allocation; @@ -326,38 +328,16 @@ xfce_panel_image_size_allocate (GtkWidget *widget, /* free cache */ xfce_panel_image_unref_null (priv->cache); - size = MIN (priv->width, priv->height); - if (G_UNLIKELY (priv->force_icon_sizes && size < 32)) + if (priv->pixbuf == NULL) { - /* we use some hardcoded values here for convienence, - * above 32 pixels svg icons will kick in */ - if (size > 16 && size < 22) - size = 16; - else if (size > 22 && size < 24) - size = 22; - else if (size > 24 && size < 32) - size = 24; - } - - if (priv->pixbuf != NULL) - { - /* use the pixbuf set by the user */ - pixbuf = g_object_ref (G_OBJECT (priv->pixbuf)); - - if (G_LIKELY (pixbuf != NULL)) - { - /* scale the icon to the correct size */ - priv->cache = xfce_panel_image_scale_pixbuf (pixbuf, size, size); - g_object_unref (G_OBJECT (pixbuf)); - } + /* delay icon loading */ + priv->idle_load_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, xfce_panel_image_load, + widget, xfce_panel_image_load_destroy); } else { - screen = gtk_widget_get_screen (widget); - if (G_LIKELY (screen != NULL)) - icon_theme = gtk_icon_theme_get_for_screen (screen); - - priv->cache = xfce_panel_pixbuf_from_source (priv->source, icon_theme, size); + /* directly render pixbufs */ + xfce_panel_image_load (widget); } } } @@ -378,8 +358,8 @@ xfce_panel_image_expose_event (GtkWidget *widget, if (G_LIKELY (pixbuf != NULL)) { /* get the size of the cache pixbuf */ - source_width = gdk_pixbuf_get_width (priv->cache); - source_height = gdk_pixbuf_get_height (priv->cache); + source_width = gdk_pixbuf_get_width (pixbuf); + source_height = gdk_pixbuf_get_height (pixbuf); /* position */ dest_x = widget->allocation.x + (priv->width - source_width) / 2; @@ -451,6 +431,65 @@ xfce_panel_image_style_set (GtkWidget *widget, +static gboolean +xfce_panel_image_load (gpointer data) +{ + XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (data)->priv; + GdkPixbuf *pixbuf; + GdkScreen *screen; + GtkIconTheme *icon_theme = NULL; + gint size; + + size = MIN (priv->width, priv->height); + if (G_UNLIKELY (priv->force_icon_sizes && size < 32)) + { + /* we use some hardcoded values here for convienence, + * above 32 pixels svg icons will kick in */ + if (size > 16 && size < 22) + size = 16; + else if (size > 22 && size < 24) + size = 22; + else if (size > 24 && size < 32) + size = 24; + } + + if (priv->pixbuf != NULL) + { + /* use the pixbuf set by the user */ + pixbuf = g_object_ref (G_OBJECT (priv->pixbuf)); + + if (G_LIKELY (pixbuf != NULL)) + { + /* scale the icon to the correct size */ + priv->cache = xfce_panel_image_scale_pixbuf (pixbuf, size, size); + g_object_unref (G_OBJECT (pixbuf)); + } + } + else + { + screen = gtk_widget_get_screen (GTK_WIDGET (data)); + if (G_LIKELY (screen != NULL)) + icon_theme = gtk_icon_theme_get_for_screen (screen); + + priv->cache = xfce_panel_pixbuf_from_source (priv->source, icon_theme, size); + } + + if (G_LIKELY (priv->cache != NULL)) + gtk_widget_queue_draw (GTK_WIDGET (data)); + + return FALSE; +} + + + +static void +xfce_panel_image_load_destroy (gpointer data) +{ + XFCE_PANEL_IMAGE (data)->priv->idle_load_id = 0; +} + + + static GdkPixbuf * xfce_panel_image_scale_pixbuf (GdkPixbuf *source, gint dest_width, @@ -673,6 +712,9 @@ xfce_panel_image_clear (XfcePanelImage *image) g_return_if_fail (XFCE_IS_PANEL_IMAGE (image)); + if (priv->idle_load_id != 0) + g_source_remove (priv->idle_load_id); + if (priv->source != NULL) { g_free (priv->source); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits