[Xfce4-commits] <xfce4-panel:devel> Add a guess size property to the systray box to reduce flickering.

Nick Schermer nick at xfce.org
Tue Aug 11 20:30:59 CEST 2009


Updating branch refs/heads/devel
         to e9007087049da7f28d8e202996687bbb178f7b6c (commit)
       from 9ffa1b2f3de38cd462870fb6ff16732bb19fc445 (commit)

commit e9007087049da7f28d8e202996687bbb178f7b6c
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Mar 26 22:04:50 2009 +0100

    Add a guess size property to the systray box to reduce flickering.
    
    This value is used to reduce the maximum icon size, so the systray
    does not resize that often.

 plugins/systray/systray-box.c |   30 +++++++++++++++++++++++++++---
 plugins/systray/systray-box.h |    9 ++++++---
 plugins/systray/systray.c     |   13 ++++++++++---
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/plugins/systray/systray-box.c b/plugins/systray/systray-box.c
index b4e8501..e264e86 100644
--- a/plugins/systray/systray-box.c
+++ b/plugins/systray/systray-box.c
@@ -92,6 +92,9 @@ struct _SystrayBox
 
   /* number of rows */
   gint          rows;
+
+  /* guess size, this is a value used to reduce the tray flickering */
+  gint          guess_size;
 };
 
 typedef struct
@@ -152,6 +155,7 @@ systray_box_init (SystrayBox *box)
   box->n_hidden_childeren = 0;
   box->arrow_type = GTK_ARROW_LEFT;
   box->show_hidden = FALSE;
+  box->guess_size = 128;
 
   /* create hash table */
   box->names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -202,10 +206,15 @@ systray_box_size_request (GtkWidget      *widget,
   GtkRequisition   child_req;
   gint             n_visible_childeren = 0;
   gint             swap;
+  gint             guess_size, icon_size;
 
   panel_return_if_fail (XFCE_IS_SYSTRAY_BOX (widget));
   panel_return_if_fail (requisition != NULL);
 
+  /* get the guess size */
+  guess_size = box->guess_size - (SPACING * (box->rows - 1));
+  guess_size /= box->rows;
+
   /* check if we need to hide or show any childeren */
   for (li = box->childeren; li != NULL; li = li->next)
     {
@@ -243,11 +252,14 @@ systray_box_size_request (GtkWidget      *widget,
           /* count the number of visible childeren */
           if (child_info->auto_hide == FALSE || box->show_hidden == TRUE)
             {
+              /* get the icon size */
+              icon_size = MIN (guess_size, MAX (child_req.width, child_req.height));
+
               /* pick largest icon */
-              if (child_size == -1)
-                child_size = MAX (child_req.width, child_req.height);
+              if (G_UNLIKELY (child_size == -1))
+                child_size = icon_size;
               else
-                child_size = MAX (child_size, MAX (child_req.width, child_req.height));
+                child_size = MAX (child_size, icon_size);
 
               /* increase number of visible childeren */
               n_visible_childeren++;
@@ -605,6 +617,18 @@ systray_box_new (void)
 
 
 void
+systray_box_set_guess_size (SystrayBox *box,
+                            gint        guess_size)
+{
+  panel_return_if_fail (XFCE_IS_SYSTRAY_BOX (box));
+
+  /* set the systray guess size */
+  box->guess_size = guess_size;
+}
+
+
+
+void
 systray_box_set_arrow_type (SystrayBox   *box,
                             GtkArrowType  arrow_type)
 {
diff --git a/plugins/systray/systray-box.h b/plugins/systray/systray-box.h
index a704bfa..4076bf1 100644
--- a/plugins/systray/systray-box.h
+++ b/plugins/systray/systray-box.h
@@ -36,13 +36,16 @@ void       systray_box_register_type   (GTypeModule  *module);
 
 GtkWidget *systray_box_new             (void) G_GNUC_MALLOC;
 
-void       systray_box_set_arrow_type  (SystrayBox   *tray,
+void       systray_box_set_guess_size  (SystrayBox   *box,
+                                        gint          guess_size);
+
+void       systray_box_set_arrow_type  (SystrayBox   *box,
                                         GtkArrowType  arrow_type);
 
-void       systray_box_set_rows        (SystrayBox   *tray,
+void       systray_box_set_rows        (SystrayBox   *box,
                                         gint          rows);
 
-gint       systray_box_get_rows        (SystrayBox   *tray);
+gint       systray_box_get_rows        (SystrayBox   *box);
 
 void       systray_box_add_with_name   (SystrayBox   *box,
                                         GtkWidget    *child,
diff --git a/plugins/systray/systray.c b/plugins/systray/systray.c
index f3e8d73..bdbac93 100644
--- a/plugins/systray/systray.c
+++ b/plugins/systray/systray.c
@@ -429,10 +429,17 @@ systray_plugin_size_changed (XfcePanelPlugin *panel_plugin,
                              gint             size)
 {
   SystrayPlugin *plugin = XFCE_SYSTRAY_PLUGIN (panel_plugin);
+  GtkWidget     *frame = plugin->frame;
+  gint           border;
 
-  /* set border sizes */
-  gtk_container_set_border_width (GTK_CONTAINER (plugin->frame),
-    (size > 26 && plugin->show_frame) ? 1 : 0);
+  /* set frame border */
+  border = (size > 26 && plugin->show_frame) ? 1 : 0;
+  gtk_container_set_border_width (GTK_CONTAINER (frame), border);
+
+  /* set the guess size this is used to get the initial icon size request
+   * correct to avoid flickering in the system tray for new applications */
+  border += MAX (frame->style->xthickness, frame->style->ythickness);
+  systray_box_set_guess_size (XFCE_SYSTRAY_BOX (plugin->box), size - 2 * border);
 
   return TRUE;
 }



More information about the Xfce4-commits mailing list