[Xfce4-commits] <xfce4-weather-plugin:master> Scrollbox: Pause processing when invisible.

Harald Judt noreply at xfce.org
Sat Dec 15 21:22:08 CET 2012


Updating branch refs/heads/master
         to 0f00bd2ab0980a2d907f1bd755ad063c7b8db680 (commit)
       from 2a25b43b5ef1c50209f33e99a4e0f52be96373bf (commit)

commit 0f00bd2ab0980a2d907f1bd755ad063c7b8db680
Author: Harald Judt <h.judt at gmx.at>
Date:   Fri Dec 14 23:10:03 2012 +0100

    Scrollbox: Pause processing when invisible.
    
    Stop processing when the scrollbox becomes hidden and save CPU power.

 panel-plugin/weather-scrollbox.c |   25 ++++++++++++++++++++++---
 panel-plugin/weather-scrollbox.h |    4 ++++
 panel-plugin/weather.c           |    2 ++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index b764101..b9714f7 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -72,6 +72,7 @@ gtk_scrollbox_init(GtkScrollbox *self)
     self->offset = 0;
     self->fade = FADE_UNSET;
     self->active = NULL;
+    self->visible = FALSE;
     self->orientation = GTK_ORIENTATION_HORIZONTAL;
     self->fontname = NULL;
     self->pattr_list = pango_attr_list_new();
@@ -296,7 +297,9 @@ gtk_scrollbox_fade_in(gpointer user_data)
         return TRUE;
 
     self->fade = FADE_OUT;
-    self->timeout_id = g_timeout_add(LABEL_REFRESH, gtk_scrollbox_sleep, self);
+    if (self->visible)
+        self->timeout_id = g_timeout_add(LABEL_REFRESH,
+                                         gtk_scrollbox_sleep, self);
     return FALSE;
 }
 
@@ -327,8 +330,9 @@ gtk_scrollbox_fade_out(gpointer user_data)
             self->active = self->labels;
 
         gtk_scrollbox_swap_labels(self);
-        self->timeout_id = g_timeout_add(LABEL_SPEED,
-                                         gtk_scrollbox_fade_in, self);
+        if (self->visible)
+            self->timeout_id = g_timeout_add(LABEL_SPEED,
+                                             gtk_scrollbox_fade_in, self);
     }
     return FALSE;
 }
@@ -397,6 +401,21 @@ gtk_scrollbox_set_animate(GtkScrollbox *self,
 
 
 void
+gtk_scrollbox_set_visible(GtkScrollbox *self,
+                          gboolean visible)
+{
+    g_return_if_fail(GTK_IS_SCROLLBOX(self));
+
+    self->visible = visible;
+    gtk_widget_set_visible(GTK_WIDGET(self), visible);
+    if (visible) {
+        gtk_scrollbox_swap_labels(self);
+        gtk_scrollbox_start_fade(self);
+    }
+}
+
+
+void
 gtk_scrollbox_prev_label(GtkScrollbox *self)
 {
     g_return_if_fail(GTK_IS_SCROLLBOX(self));
diff --git a/panel-plugin/weather-scrollbox.h b/panel-plugin/weather-scrollbox.h
index 1b0d80f..80d7d7b 100644
--- a/panel-plugin/weather-scrollbox.h
+++ b/panel-plugin/weather-scrollbox.h
@@ -55,6 +55,7 @@ struct _GtkScrollbox {
     guint timeout_id;
     gint offset;
     gboolean animate;
+    gboolean visible;
     fade_states fade;
     GtkOrientation orientation;
     gchar *fontname;
@@ -82,6 +83,9 @@ void gtk_scrollbox_clear(GtkScrollbox *self);
 void gtk_scrollbox_set_animate(GtkScrollbox *self,
                                gboolean animate);
 
+void gtk_scrollbox_set_visible(GtkScrollbox *self,
+                               gboolean visible);
+
 void gtk_scrollbox_prev_label(GtkScrollbox *self);
 
 void gtk_scrollbox_next_label(GtkScrollbox *self);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 3711944..2b143e2 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -271,6 +271,8 @@ scrollbox_set_visible(plugin_data *data)
         gtk_widget_show_all(GTK_WIDGET(data->vbox_center_scrollbox));
     else
         gtk_widget_hide_all(GTK_WIDGET(data->vbox_center_scrollbox));
+    gtk_scrollbox_set_visible(GTK_SCROLLBOX(data->scrollbox),
+                              data->show_scrollbox);
 }
 
 


More information about the Xfce4-commits mailing list