[Xfce4-commits] r25762 - in xfce4-panel/branches/xfce_4_4: . plugins/clock

Nick Schermer nick at xfce.org
Fri May 25 12:19:52 CEST 2007


Author: nick
Date: 2007-05-25 10:19:51 +0000 (Fri, 25 May 2007)
New Revision: 25762

Modified:
   xfce4-panel/branches/xfce_4_4/ChangeLog
   xfce4-panel/branches/xfce_4_4/NEWS
   xfce4-panel/branches/xfce_4_4/plugins/clock/clock.c
Log:
	* plugins/clock/clock.c: Backport rev 25761.

Modified: xfce4-panel/branches/xfce_4_4/ChangeLog
===================================================================
--- xfce4-panel/branches/xfce_4_4/ChangeLog	2007-05-25 10:10:40 UTC (rev 25761)
+++ xfce4-panel/branches/xfce_4_4/ChangeLog	2007-05-25 10:19:51 UTC (rev 25762)
@@ -1,3 +1,7 @@
+2007-05-25 12:16 nick
+
+	* plugins/clock/clock.c: Backport rev 25761.
+
 2007-05-24 20:37  nick
 
 	* panel/panel-item-manager.c, NEWS: Fix loading internal plugins 

Modified: xfce4-panel/branches/xfce_4_4/NEWS
===================================================================
--- xfce4-panel/branches/xfce_4_4/NEWS	2007-05-25 10:10:40 UTC (rev 25761)
+++ xfce4-panel/branches/xfce_4_4/NEWS	2007-05-25 10:19:51 UTC (rev 25762)
@@ -8,6 +8,7 @@
   Xinerama setup with differently sized monitors (Bug #3097). (Jasper)
 - Fix loading internal plugins if a similar file exists in the start directory
   (Bug #3279). (Nick)
+- Only update the clock once a minute when seconds are disabled. (Nick)
 
 4.4.1
 =====

Modified: xfce4-panel/branches/xfce_4_4/plugins/clock/clock.c
===================================================================
--- xfce4-panel/branches/xfce_4_4/plugins/clock/clock.c	2007-05-25 10:10:40 UTC (rev 25761)
+++ xfce4-panel/branches/xfce_4_4/plugins/clock/clock.c	2007-05-25 10:19:51 UTC (rev 25762)
@@ -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);
@@ -332,9 +389,10 @@
 
     clock->mday = -1;
 
-    xfce_clock_set_interval (XFCE_CLOCK (clock->clock), 1000);
+    clock_read_rc_file (clock->plugin, clock);
     
-    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;
@@ -382,9 +439,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);
 }
 
 /* -------------------------------------------------------------------- *
@@ -440,6 +501,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