[Xfce4-commits] r25761 - in xfce4-panel/trunk: . plugins/clock

Nick Schermer nick at xfce.org
Fri May 25 12:10:40 CEST 2007


Author: nick
Date: 2007-05-25 10:10:40 +0000 (Fri, 25 May 2007)
New Revision: 25761

Modified:
   xfce4-panel/trunk/ChangeLog
   xfce4-panel/trunk/plugins/clock/clock.c
Log:
	* plugins/clock/clock.c: Only update the clock once a minute when
	  seconds are disabled. That should give Auke a couple of minutes
	  extra laptop fun ^_^. (Does not work for the led clock because
	  we always want blinking dots).

Modified: xfce4-panel/trunk/ChangeLog
===================================================================
--- xfce4-panel/trunk/ChangeLog	2007-05-25 09:24:07 UTC (rev 25760)
+++ xfce4-panel/trunk/ChangeLog	2007-05-25 10:10:40 UTC (rev 25761)
@@ -1,3 +1,10 @@
+2007-05-26 12:07 nick
+
+	* plugins/clock/clock.c: Only update the clock once a minute when
+	  seconds are disabled. That should give Auke a couple of minutes
+	  extra laptop fun ^_^. (Does not work for the led clock because
+	  we always want blinking dots).
+
 2007-05-24 20:30 nick
 
 	* panel/panel-item-manager.c: Rewrite some code, internal plugins

Modified: xfce4-panel/trunk/plugins/clock/clock.c
===================================================================
--- xfce4-panel/trunk/plugins/clock/clock.c	2007-05-25 09:24:07 UTC (rev 25760)
+++ xfce4-panel/trunk/plugins/clock/clock.c	2007-05-25 10:10:40 UTC (rev 25761)
@@ -2,7 +2,7 @@
 
 /*  $Id$
  *
- *  Copyright © 2005 The Xfce Development Team
+ *  Copyright © 2005 - 2007 The Xfce Development Team
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Library General Public License as published
@@ -61,6 +61,7 @@
     GtkTooltips *tips;
 
     int timeout_id;
+    int reschedule_id;
     int screen_changed_id;
 
     /* Settings */
@@ -95,7 +96,60 @@
 /* -------------------------------------------------------------------- *
  *                               Clock                                  *
  * -------------------------------------------------------------------- */
+ 
+static gboolean
+clock_reschedule_callback (Clock *clock)
+{
+    g_return_val_if_fail (clock->secs == FALSE, FALSE);
+    
+    /* update the clock every minute */
+    xfce_clock_set_interval (XFCE_CLOCK (clock->clock), 60 * 1000);
+    
+    return FALSE;
+}
 
+static void
+clock_reschedule_callback_destroy (Clock *clock)
+{
+    clock->reschedule_id = 0;
+}
+
+static void
+clock_reschedule (Clock *clock)
+{
+    time_t ticks;
+    struct tm *tm;
+    gint interval;
+    
+    /* stop running reschudule */
+    if (clock->reschedule_id)
+        g_source_remove (clock->reschedule_id);
+        
+    /* update every second if seconds are displayed or the led clock is used */
+    if (clock->secs || clock->mode == XFCE_CLOCK_LEDS)
+    {
+    	/* update every second */
+    	xfce_clock_set_interval (XFCE_CLOCK (clock->clock), 1000);
+    }
+    else
+    {
+        /* get the time */
+        time (&ticks);
+        tm = localtime (&ticks);
+    
+        /* get the interval up to the next minute */
+        interval = ((60 - tm->tm_sec) * 1000) + 500;
+        
+        /* set the new clock timeout (for this minute) */
+        xfce_clock_set_interval (XFCE_CLOCK (clock->clock), interval);
+        
+        /* start a new reschedule event */
+        clock->reschedule_id = 
+            g_timeout_add_full (G_PRIORITY_LOW, interval, (GSourceFunc)clock_reschedule_callback, 
+                                clock, (GDestroyNotify)clock_reschedule_callback_destroy);
+    }
+}
+
 static gboolean
 clock_date_tooltip (Clock *clock)
 {
@@ -237,6 +291,9 @@
     if (dlg)
         gtk_widget_destroy (dlg);
         
+    if (clock->reschedule_id)
+        g_source_remove (clock->reschedule_id);
+        
     g_signal_handler_disconnect (plugin, clock->screen_changed_id);
 
     g_source_remove (clock->timeout_id);
@@ -331,10 +388,11 @@
     gtk_container_add (GTK_CONTAINER (clock->frame), clock->clock);
 
     clock->mday = -1;
-
-    xfce_clock_set_interval (XFCE_CLOCK (clock->clock), 1000);
-
+    
     clock_read_rc_file (clock->plugin, clock);
+    
+    /* set the clock timeout */
+    clock_reschedule (clock);
 }
 
 /* Create widgets and connect to signals */
@@ -345,6 +403,7 @@
     Clock *clock = panel_slice_new0 (Clock);
 
     clock->plugin = plugin;
+    clock->reschedule_id = 0;
 
     g_signal_connect (plugin, "size-changed",
                       G_CALLBACK (clock_set_size), clock);
@@ -371,8 +430,6 @@
     gtk_widget_show (clock->clock);
     gtk_container_add (GTK_CONTAINER (clock->frame), clock->clock);
 
-    xfce_clock_set_interval (XFCE_CLOCK (clock->clock), 1000);
-
     clock_read_rc_file (plugin, clock);
     clock->mday = -1;
 
@@ -381,9 +438,13 @@
     gtk_object_sink (GTK_OBJECT (clock->tips));
 
     clock_date_tooltip (clock);
+    
+    /* set the clock timeout */
+    clock_reschedule (clock);
 
+    /* update the tooltip every minute */
     clock->timeout_id =
-        g_timeout_add (60000, (GSourceFunc) clock_date_tooltip, clock);
+        g_timeout_add (60 * 1000, (GSourceFunc) clock_date_tooltip, clock);
 }
 
 /* -------------------------------------------------------------------- *
@@ -439,6 +500,9 @@
 	cd->clock->secs = active;
 	xfce_clock_show_secs (XFCE_CLOCK (cd->clock->clock),
 	                      active);
+	
+	/* set the clock timeout */
+        clock_reschedule (cd->clock);
     }
 
     clock_update_size (cd->clock,



More information about the Xfce4-commits mailing list