[Xfce4-commits] <xfce4-weather-plugin:master> Scrollbox: Do not abort or reset transition animation when not desired.

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


Updating branch refs/heads/master
         to 960304f93aee86f1123b693ff1895acf053ef0fc (commit)
       from 0f00bd2ab0980a2d907f1bd755ad063c7b8db680 (commit)

commit 960304f93aee86f1123b693ff1895acf053ef0fc
Author: Harald Judt <h.judt at gmx.at>
Date:   Sat Dec 15 10:50:53 2012 +0100

    Scrollbox: Do not abort or reset transition animation when not desired.
    
    When the scrollbox should change due to a weather data update, the
    current animation will be aborted or reset. We do not want this on
    regular updates or configuration changes regarding the labels, so
    let the current animation end and apply the changes after that.

 panel-plugin/weather-scrollbox.c |  110 +++++++++++++++++++++++++++-----------
 panel-plugin/weather-scrollbox.h |    4 +-
 panel-plugin/weather.c           |    7 ---
 3 files changed, 81 insertions(+), 40 deletions(-)

diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index b9714f7..b2d9949 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -27,8 +27,10 @@
 #include <libxfce4panel/libxfce4panel.h>
 
 #include "weather-scrollbox.h"
-#define LABEL_REFRESH 3000
-#define LABEL_SPEED   25
+
+#define LABEL_REFRESH (3000)
+#define LABEL_REFRESH_NO_ANIMATION (5000)
+#define LABEL_SPEED (25)
 
 
 static void gtk_scrollbox_finalize(GObject *object);
@@ -39,8 +41,6 @@ static void gtk_scrollbox_size_request(GtkWidget *widget,
 static gboolean gtk_scrollbox_expose_event(GtkWidget *widget,
                                            GdkEventExpose *event);
 
-static void gtk_scrollbox_start_fade(GtkScrollbox *self);
-
 static gboolean gtk_scrollbox_fade_out(gpointer user_data);
 
 G_DEFINE_TYPE(GtkScrollbox, gtk_scrollbox, GTK_TYPE_DRAWING_AREA)
@@ -70,8 +70,9 @@ gtk_scrollbox_init(GtkScrollbox *self)
     self->labels_new = NULL;
     self->timeout_id = 0;
     self->offset = 0;
-    self->fade = FADE_UNSET;
+    self->fade = FADE_NONE;
     self->active = NULL;
+    self->animate = FALSE;
     self->visible = FALSE;
     self->orientation = GTK_ORIENTATION_HORIZONTAL;
     self->fontname = NULL;
@@ -200,12 +201,12 @@ gtk_scrollbox_expose_event(GtkWidget *widget,
             height = widget->allocation.y
                 + (widget->allocation.height
                    - PANGO_PIXELS(logical_rect.height)) / 2
-                + (self->animate ? self->offset : 0);
+                + (self->animate || self->fade == FADE_OUT ? self->offset : 0);
         } else {
             width = widget->allocation.x
                 + (widget->allocation.width
                    - PANGO_PIXELS(logical_rect.height)) / 2
-                + (self->animate ? self->offset : 0);
+                + (self->animate || self->fade == FADE_OUT ? self->offset : 0);
             height = widget->allocation.y
                 + (widget->allocation.height
                    - PANGO_PIXELS(logical_rect.width)) / 2;
@@ -263,8 +264,42 @@ gtk_scrollbox_swap_labels(GtkScrollbox *self)
     self->labels_new = NULL;
 
     gtk_widget_queue_resize(GTK_WIDGET(self));
-    if (self->fade == FADE_UNSET)
-        gtk_scrollbox_start_fade(self);
+}
+
+
+static gboolean
+gtk_scrollbox_fade_none(gpointer user_data)
+{
+    GtkScrollbox *self = GTK_SCROLLBOX(user_data);
+
+    if (!self->visible)
+        return FALSE;
+
+    /* start fading out if animation has been enabled */
+    if (self->animate) {
+        self->fade = FADE_OUT;
+        self->offset = 0;
+        self->timeout_id = g_timeout_add(LABEL_SPEED,
+                                         gtk_scrollbox_fade_out, self);
+        return FALSE;
+    }
+
+    if (self->timeout_id != 0) {
+        g_source_remove(self->timeout_id);
+        self->timeout_id = 0;
+    }
+
+    if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
+        self->offset = GTK_WIDGET(self)->allocation.height;
+    else
+        self->offset = GTK_WIDGET(self)->allocation.width;
+
+    gtk_scrollbox_swap_labels(self);
+    gtk_scrollbox_next_label(self);
+
+    self->timeout_id = g_timeout_add(LABEL_REFRESH_NO_ANIMATION,
+                                     gtk_scrollbox_fade_none, self);
+    return FALSE;
 }
 
 
@@ -296,10 +331,16 @@ gtk_scrollbox_fade_in(gpointer user_data)
         (self->orientation == GTK_ORIENTATION_VERTICAL && self->offset < 0))
         return TRUE;
 
-    self->fade = FADE_OUT;
     if (self->visible)
-        self->timeout_id = g_timeout_add(LABEL_REFRESH,
-                                         gtk_scrollbox_sleep, self);
+        if (self->animate) {
+            self->fade = FADE_OUT;
+            self->timeout_id = g_timeout_add(LABEL_REFRESH,
+                                             gtk_scrollbox_sleep, self);
+        } else {
+            self->fade = FADE_NONE;
+            self->timeout_id = g_timeout_add(LABEL_REFRESH_NO_ANIMATION,
+                                             gtk_scrollbox_fade_none, self);
+        }
     return FALSE;
 }
 
@@ -323,16 +364,11 @@ gtk_scrollbox_fade_out(gpointer user_data)
          self->offset > 0 - GTK_WIDGET(self)->allocation.width))
         return TRUE;
 
-    if (self->active != NULL) {
-        if (self->active->next != NULL)
-            self->active = self->active->next;
-        else
-            self->active = self->labels;
-
-        gtk_scrollbox_swap_labels(self);
-        if (self->visible)
-            self->timeout_id = g_timeout_add(LABEL_SPEED,
-                                             gtk_scrollbox_fade_in, self);
+    gtk_scrollbox_swap_labels(self);
+    gtk_scrollbox_next_label(self);
+    if (self->visible) {
+        self->timeout_id = g_timeout_add(LABEL_SPEED,
+                                         gtk_scrollbox_fade_in, self);
     }
     return FALSE;
 }
@@ -346,7 +382,9 @@ gtk_scrollbox_start_fade(GtkScrollbox *self)
         self->timeout_id = 0;
     }
 
-    if (g_list_length(self->labels) > 1) {
+    gtk_scrollbox_swap_labels(self);
+
+    if (self->animate && g_list_length(self->labels) > 1) {
         if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
             self->offset = GTK_WIDGET(self)->allocation.height;
         else
@@ -354,8 +392,7 @@ gtk_scrollbox_start_fade(GtkScrollbox *self)
 
         self->fade = FADE_IN;
         self->timeout_id = g_timeout_add(LABEL_SPEED,
-                                         gtk_scrollbox_fade_in,
-                                         self);
+                                         gtk_scrollbox_fade_in, self);
     } else
         self->offset = 0;
 }
@@ -406,12 +443,23 @@ gtk_scrollbox_set_visible(GtkScrollbox *self,
 {
     g_return_if_fail(GTK_IS_SCROLLBOX(self));
 
-    self->visible = visible;
     gtk_widget_set_visible(GTK_WIDGET(self), visible);
+    self->visible = visible;
     if (visible) {
-        gtk_scrollbox_swap_labels(self);
-        gtk_scrollbox_start_fade(self);
-    }
+        if (self->timeout_id == 0)
+            if (self->animate)
+                gtk_scrollbox_start_fade(self);
+            else {
+                self->fade = FADE_NONE;
+                self->timeout_id = g_timeout_add(1000,
+                                                 gtk_scrollbox_fade_none,
+                                                 self);
+            }
+    } else
+        if (self->timeout_id != 0) {
+            g_source_remove(self->timeout_id);
+            self->timeout_id = 0;
+        }
 }
 
 
@@ -425,7 +473,7 @@ gtk_scrollbox_prev_label(GtkScrollbox *self)
             self->active = self->active->prev;
         else
             self->active = g_list_last(self->labels);
-        gtk_widget_queue_resize(GTK_WIDGET(self));
+        gtk_widget_queue_draw(GTK_WIDGET(self));
     }
 }
 
@@ -440,7 +488,7 @@ gtk_scrollbox_next_label(GtkScrollbox *self)
             self->active = self->active->next;
         else
             self->active = self->labels;
-        gtk_widget_queue_resize(GTK_WIDGET(self));
+        gtk_widget_queue_draw(GTK_WIDGET(self));
     }
 }
 
diff --git a/panel-plugin/weather-scrollbox.h b/panel-plugin/weather-scrollbox.h
index 80d7d7b..63dd371 100644
--- a/panel-plugin/weather-scrollbox.h
+++ b/panel-plugin/weather-scrollbox.h
@@ -38,9 +38,9 @@ GType gtk_scrollbox_get_type(void);
 
 
 typedef enum {
-    FADE_UNSET,
     FADE_IN,
-    FADE_OUT
+    FADE_OUT,
+    FADE_NONE
 } fade_states;
 
 typedef struct _GtkScrollbox GtkScrollbox;
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 2b143e2..b612fec 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -284,9 +284,6 @@ update_scrollbox(plugin_data *data)
     data_types type;
     gint i = 0, j = 0;
 
-    gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
-                              data->scrollbox_animate);
-
     if (data->weatherdata && data->weatherdata->current_conditions) {
         while (i < data->labels->len) {
             j = 0;
@@ -314,11 +311,7 @@ update_scrollbox(plugin_data *data)
         weather_debug("No weather data available, set single label '%s'.",
                       _("No Data"));
     }
-
-    /* show or hide scrollbox */
     scrollbox_set_visible(data);
-    gtk_scrollbox_swap_labels(GTK_SCROLLBOX(data->scrollbox));
-
     weather_debug("Updated scrollbox.");
 }
 


More information about the Xfce4-commits mailing list