Index: clock.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/applets/clock/clock.c,v
retrieving revision 1.185
diff -u -p -r1.185 clock.c
--- clock.c	29 May 2006 20:47:07 -0000	1.185
+++ clock.c	27 Jul 2006 15:42:27 -0000
@@ -41,6 +41,7 @@
 
 #include "config.h"
 
+#include <math.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -208,31 +209,49 @@ set_tooltip (GtkWidget  *applet,
 	gtk_tooltips_set_tip (tooltips, widget, tip, NULL);
 }
 
-static int
+static gboolean
 clock_timeout_callback (gpointer data)
 {
 	ClockData *cd = data;
-	time_t new_time;
+	float itime;
+	int wakeup;
+
+	time (&cd->current_time);
 
-        time (&new_time);
+	if (cd->showseconds)
+		wakeup = 1;
+	else
+	{
+		switch (cd->format)
+		{
+			case CLOCK_FORMAT_INTERNET:
+				itime = get_itime (cd->current_time);
+				itime = floor (itime) + 1 - itime;
+				/* since time() is only second-accurate
+				 * we wait the extra second to make
+				 * sure the time has really changed when
+				 * we wake up again.
+				 */
+				wakeup = (itime * 86.4) + 1;
+				break;
+
+			case CLOCK_FORMAT_12:
+			case CLOCK_FORMAT_24:
+				wakeup = 60 - (cd->current_time % 60);
+				break;
 
-	if (!cd->showseconds &&
-	    cd->format != CLOCK_FORMAT_UNIX &&
-	    cd->format != CLOCK_FORMAT_CUSTOM) {
-		if (cd->format == CLOCK_FORMAT_INTERNET && 
-		    (long)get_itime (new_time) !=
-		    (long)get_itime (cd->current_time)) {
-			update_clock (cd);
-		} else if ((cd->format == CLOCK_FORMAT_12 ||
-			    cd->format == CLOCK_FORMAT_24) &&
-			   new_time / 60 != cd->current_time / 60) {
-			update_clock (cd);
+			default:
+				wakeup = 1;
 		}
-	} else {
-		update_clock (cd);
 	}
 
-	return TRUE;
+	update_clock (cd);
+
+	cd->timeout = g_timeout_add (wakeup * 1000,
+	                             clock_timeout_callback,
+	                             cd);
+
+	return FALSE;
 }
 
 static float
@@ -394,7 +413,7 @@ update_clock (ClockData * cd)
 		if (cd->showseconds)
 			g_snprintf (hour, sizeof (hour), "@%3.2f", itime);
 		else
-			g_snprintf (hour, sizeof (hour), "@%3.0f", itime);
+			g_snprintf (hour, sizeof (hour), "@%3.0f", floor (itime));
 	} else if (cd->format == CLOCK_FORMAT_CUSTOM) {
 		char *timeformat = g_locale_from_utf8 (cd->custom_format, -1,
 						       NULL, NULL, NULL);
@@ -439,31 +458,13 @@ static void
 refresh_clock (ClockData *cd)
 {
 	unfix_size (cd);
-	update_clock (cd);
-}
-
-static void
-refresh_clock_timeout(ClockData *cd)
-{
-	int timeouttime;
-
-	unfix_size (cd);
 	
 	update_timeformat (cd);
 
 	if (cd->timeout)
 		g_source_remove (cd->timeout);
 
-	update_clock (cd);
-	
-	if (cd->format == CLOCK_FORMAT_INTERNET)
-		timeouttime = INTERNETSECOND;
-	else
-		timeouttime = 1000;
-	
-	cd->timeout = g_timeout_add (timeouttime,
-	                             clock_timeout_callback,
-	                             cd);
+	clock_timeout_callback (cd);
 }
 
 static void
@@ -1710,7 +1711,7 @@ create_clock_widget (ClockData *cd)
 	                          _("Computer Clock"));
 
 	/* Refresh the clock so that it paints its first state */
-	refresh_clock_timeout(cd);
+	refresh_clock (cd);
 }
 
 /* this is when the panel orientation changes */
@@ -1774,7 +1775,7 @@ copy_time (BonoboUIComponent *uic,
 		if (cd->showseconds)
 			g_snprintf (string, sizeof (string), "@%3.2f", itime);
 		else
-			g_snprintf (string, sizeof (string), "@%3.0f", itime);
+			g_snprintf (string, sizeof (string), "@%3.0f", floor (itime));
 	} else {
 		struct tm *tm;
 		char      *format;
@@ -1969,7 +1970,7 @@ format_changed (GConfClient  *client,
 
 	clock->format = new_format;
 	update_timeformat (clock);
-	refresh_clock_timeout (clock);
+	refresh_clock (clock);
 }
 
 static void
@@ -1986,7 +1987,7 @@ show_seconds_changed (GConfClient  *clie
 	value = gconf_value_get_bool (entry->value);
 	
 	clock->showseconds = (value != 0);
-	refresh_clock_timeout (clock);
+	refresh_clock (clock);
 }
 
 static void
@@ -2021,7 +2022,7 @@ gmt_time_changed (GConfClient  *client,
 	value = gconf_value_get_bool (entry->value);
 	
 	clock->gmt_time = (value != 0);
-	refresh_clock_timeout (clock);
+	refresh_clock (clock);
 }
 
 static gboolean
