From 8c6512f91dc5cfd30a5520747537d03e5d55c970 Mon Sep 17 00:00:00 2001 From: tanya Date: Fri, 9 Apr 2010 16:16:56 +0300 Subject: [PATCH] split to two timeout (long and short) --- applet/src/livewp-common.h | 6 ++-- applet/src/livewp-home-widget.c | 68 +++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/applet/src/livewp-common.h b/applet/src/livewp-common.h index 972c146..5d6be56 100644 --- a/applet/src/livewp-common.h +++ b/applet/src/livewp-common.h @@ -32,7 +32,8 @@ #define THEME_PATH "/usr/share/livewp/theme" #define SHORT_TIMER 100 /* 100 milisecond */ -#define LONG_TIMER 10*60*1000 /* 10 minutes */ +//#define LONG_TIMER 10*60*1000 /* 10 minutes */ +#define LONG_TIMER 20*1000 /* 10 minutes */ enum { SHORT_TIMER_TYPE, LONG_TIMER_TYPE }; @@ -42,7 +43,8 @@ typedef struct _Animation_WallpaperPrivate Animation_WallpaperPrivate; struct _Animation_WallpaperPrivate { - gint timer; + gint long_timer; + gint short_timer; gchar *theme; gboolean visible; AWallpaperPlugin *desktop_plugin; diff --git a/applet/src/livewp-home-widget.c b/applet/src/livewp-home-widget.c index 7815088..b9be927 100644 --- a/applet/src/livewp-home-widget.c +++ b/applet/src/livewp-home-widget.c @@ -449,15 +449,13 @@ change_background(GtkWidget * actor, gpointer data) } static gint -get_time(gint t) -{ +get_time(gint t){ // уравнение изменения времени return t*1.1; } static void -destroy_scene(void) -{ +destroy_scene(void){ GSList * tmp = scene.actors; while (tmp != NULL){ if (tmp->data){ @@ -683,7 +681,45 @@ change_actor(GtkWidget * actor) } #endif static gboolean -plugin_on_timeout (AWallpaperPlugin *desktop_plugin) +short_timeout (AWallpaperPlugin *desktop_plugin) +{ + gint daytime = get_daytime(); + GSList * tmp; + gchar * name; + void (*pfunc)(gpointer, gpointer); + time_t now; + gint t; + Actor *actor; + gboolean stop_flag = TRUE; + + now = time(NULL); +fprintf(stderr, "Short timer %d\n", now); + tmp = scene.actors; + while (tmp != NULL){ + actor = tmp->data; + if (now >= actor->time_start_animation + && actor->time_start_animation > 0 + /* && now - actor->time_start_animation <= actor->duration_animation*/){ + pfunc = actor->func_change; + if (pfunc){ + (*pfunc)(actor, desktop_plugin); + stop_flag = FALSE; + } + } + tmp = g_slist_next(tmp); + } + + scene.daytime = daytime; + if (stop_flag){ + desktop_plugin->priv->short_timer = 0; + return FALSE; + }else + return TRUE; /* keep running this event */ +} + + +static gboolean +long_timeout (AWallpaperPlugin *desktop_plugin) { gint daytime = get_daytime(); GSList * tmp; @@ -716,10 +752,10 @@ fprintf(stderr, "timer daytime=%d\n", daytime); actor = tmp->data; if (now >= actor->time_start_animation && actor->time_start_animation > 0 - /* && now - actor->time_start_animation <= actor->duration_animation*/){ - pfunc = actor->func_change; - if (pfunc) - (*pfunc)(actor, desktop_plugin); + && desktop_plugin->priv->short_timer == 0){ + fprintf(stderr, "start shor timer act = %s\n", actor->name); + actor->time_start_animation = now; + desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, short_timeout, desktop_plugin); } tmp = g_slist_next(tmp); } @@ -770,7 +806,8 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin) init_scene(desktop_plugin); else if (!strcmp(priv->theme,"Berlin")) init_scene(desktop_plugin); - priv->timer = g_timeout_add(LONG_TIMER, plugin_on_timeout, desktop_plugin); + priv->long_timer = g_timeout_add(LONG_TIMER, long_timeout, desktop_plugin); + priv->short_timer = 0; /* TODO Move scene to priv */ scene.timer_type = LONG_TIMER_TYPE; } @@ -781,10 +818,15 @@ lw_applet_finalize (GObject *object) AWallpaperPlugin *desktop_plugin = Animation_Wallpaper_HOME_PLUGIN (object); Animation_WallpaperPrivate *priv = desktop_plugin->priv; - if (priv->timer){ - g_source_remove(priv->timer); - priv->timer = NULL; + if (priv->long_timer){ + g_source_remove(priv->long_timer); + priv->long_timer = 0; } + if (priv->short_timer){ + g_source_remove(priv->short_timer); + priv->short_timer = 0; + } + destroy_scene(); } -- 1.7.9.5