From 7002637e69617e796b90099c9b9295c358fd2ab7 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Thu, 17 Dec 2009 18:39:57 +0100 Subject: Refactor clock update logic to avoid jumping clock position Signed-off-by: Nikias Bassen --- src/sbmanager.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/sbmanager.c b/src/sbmanager.c index 65afd6d..cb69606 100644 --- a/src/sbmanager.c +++ b/src/sbmanager.c @@ -264,16 +264,20 @@ leave_cleanup: return FALSE; } -static void clock_cb (ClutterTimeline *timeline, gint msecs, SBManagerApp *app) +static void clock_set_time(ClutterActor *label, time_t t) { - time_t t = time(NULL); struct tm *curtime = localtime(&t); gchar *ctext = g_strdup_printf("%02d:%02d", curtime->tm_hour, curtime->tm_min); - clutter_text_set_text(CLUTTER_TEXT(clock_label), ctext); - clutter_actor_set_position(clock_label, (clutter_actor_get_width(stage)-clutter_actor_get_width(clock_label)) / 2, 2); + clutter_text_set_text(CLUTTER_TEXT(label), ctext); + clutter_actor_set_position(label, (clutter_actor_get_width(stage)-clutter_actor_get_width(label)) / 2, 2); g_free(ctext); } +static void clock_update_cb (ClutterTimeline *timeline, gint msecs, SBManagerApp *app) +{ + clock_set_time(clock_label, time(NULL)); +} + static void actor_get_abs_center(ClutterActor *actor, gfloat *center_x, gfloat *center_y) { *center_x = 0.0; @@ -623,9 +627,6 @@ int main(int argc, char **argv) /* clock widget */ actor = clutter_text_new_full (CLOCK_FONT, "00:00", &clock_text_color); - gint xpos = (clutter_actor_get_width(stage)-clutter_actor_get_width(actor))/2; - clutter_actor_set_position(actor, xpos, 2); - clutter_actor_show(actor); clutter_group_add (CLUTTER_GROUP (stage), actor); clock_label = actor; @@ -637,14 +638,11 @@ int main(int argc, char **argv) clutter_timeline_set_loop(timeline, TRUE); /* have it loop */ /* fire a callback for frame change */ - g_signal_connect(timeline, "completed", G_CALLBACK (clock_cb), app); + g_signal_connect(timeline, "completed", G_CALLBACK (clock_update_cb), app); /* and start it */ clutter_timeline_start (timeline); - /* Show the window: */ - gtk_widget_show_all (GTK_WIDGET (app->window)); - g_signal_connect(stage, "motion-event", G_CALLBACK (stage_motion), app); g_signal_connect( G_OBJECT(app->window), "map-event", G_CALLBACK (form_map), app); @@ -654,6 +652,13 @@ int main(int argc, char **argv) selected_mutex = g_mutex_new(); + /* Show the window. This also sets the stage's bounding box. */ + gtk_widget_show_all (GTK_WIDGET (app->window)); + + /* Position and update the clock */ + clock_set_time(actor, time(NULL)); + clutter_actor_show(clock_label); + /* Load icons in an idle loop */ g_idle_add((GSourceFunc)get_icons, app); -- cgit v1.1-32-gdbae