]> Dogcows Code - chaz/tint2/blobdiff - src/clock/clock.c
fixed resize_clock() and snapshot
[chaz/tint2] / src / clock / clock.c
index 3eef5a427b61b11ea919dc3e000219090ca97b0f..e29c138a687cf82825a38d24c2321ce669aebe83 100644 (file)
@@ -50,10 +50,10 @@ static char buf_time[40];
 static char buf_date[40];
 static char buf_tooltip[40];
 int clock_enabled;
-static const struct timeout* clock_timeout=0;
+static timeout* clock_timeout=0;
 
 
-void update_clocks(void* arg)
+void update_clocks_sec(void* arg)
 {
        gettimeofday(&time_clock, 0);
        int i;
@@ -64,6 +64,22 @@ void update_clocks(void* arg)
        panel_refresh = 1;
 }
 
+void update_clocks_min(void* arg)
+{
+       // remember old_sec because after suspend/hibernate the clock should be updated directly, and not
+       // on next minute change
+       time_t old_sec = time_clock.tv_sec;
+       gettimeofday(&time_clock, 0);
+       if (time_clock.tv_sec % 60 == 0 || time_clock.tv_sec - old_sec > 60) {
+               int i;
+               if (time1_format) {
+                       for (i=0 ; i < nb_panel ; i++)
+                               panel1[i].clock.area.resize = 1;
+               }
+               panel_refresh = 1;
+       }
+}
+
 struct tm* clock_gettime_for_tz(const char* timezone) {
        if (timezone) {
                const char* old_tz = getenv("TZ");
@@ -87,9 +103,9 @@ void init_clock()
 {
        if(time1_format && clock_timeout==0) {
                if (strchr(time1_format, 'S') || strchr(time1_format, 'T') || strchr(time1_format, 'r'))
-                       clock_timeout = add_timeout(10, 1000, update_clocks, 0);
+                       clock_timeout = add_timeout(10, 1000, update_clocks_sec, 0);
                else
-                       clock_timeout = add_timeout(10, 60000, update_clocks, 0);
+                       clock_timeout = add_timeout(10, 1000, update_clocks_min, 0);
        }
 }
 
@@ -117,15 +133,15 @@ void init_clock_panel(void *p)
 
        if (panel_horizontal) {
                // panel horizonal => fixed height and posy
-               clock->area.posy = panel->area.pix.border.width + panel->area.paddingy;
+               clock->area.posy = panel->area.bg->border.width + panel->area.paddingy;
                clock->area.height = panel->area.height - (2 * clock->area.posy);
        }
        else {
                // panel vertical => fixed width, height, posy and posx
-               clock->area.posy = panel->area.pix.border.width + panel->area.paddingxlr;
+               clock->area.posy = panel->area.bg->border.width + panel->area.paddingxlr;
                clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height);
-               clock->area.posx = panel->area.pix.border.width + panel->area.paddingy;
-               clock->area.width = panel->area.width - (2 * panel->area.pix.border.width) - (2 * panel->area.paddingy);
+               clock->area.posx = panel->area.bg->border.width + panel->area.paddingy;
+               clock->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy);
        }
 
        clock->time1_posy = (clock->area.height - time_height) / 2;
@@ -166,7 +182,7 @@ void cleanup_clock()
 }
 
 
-void draw_clock (void *obj, cairo_t *c, int active)
+void draw_clock (void *obj, cairo_t *c)
 {
        Clock *clock = obj;
        PangoLayout *layout;
@@ -239,11 +255,9 @@ void resize_clock (void *obj)
 
        if (time_width > date_width) new_width = time_width;
        else new_width = date_width;
-       new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.width);
+       new_width += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width);
 
        Panel *panel = ((Area*)obj)->panel;
-       clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width;
-
        if (new_width > clock->area.width || new_width < (clock->area.width-6)) {
                // resize clock
                // we try to limit the number of resize
@@ -258,6 +272,8 @@ void resize_clock (void *obj)
                systray.area.resize = 1;
                panel_refresh = 1;
        }
+       clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.bg->border.width;
+
 
        g_object_unref (layout);
        cairo_destroy (c);
This page took 0.022852 seconds and 4 git commands to generate.