X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fclock%2Fclock.c;h=288ed942e601181bdb2792fe7fe9f7889c4ea32f;hb=6f9e73f8f0b88d1258e99397d9ca8b1afca5085e;hp=e7bb32f66699544ca09c60c1a94194bc113343b2;hpb=bf2fd3cf8c96d2a747ba4ea3bd8bd9b0a0d7e0e7;p=chaz%2Ftint2 diff --git a/src/clock/clock.c b/src/clock/clock.c index e7bb32f..288ed94 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -41,53 +41,60 @@ static char buf_time[40]; static char buf_date[40]; -void init_clock(Clock *clock, Area *parent) +void init_clock() { - Panel *panel = (Panel *)parent; - int time_height, time_height_ink, date_height, date_height_ink; - - clock->area.parent = parent; - clock->area.panel = panel; - clock->area._draw_foreground = draw_foreground_clock; - clock->area._resize = resize_clock; - if (!time1_format) return; - - if (strchr(time1_format, 'S') == NULL) time_precision = 60; - else time_precision = 1; - - // update clock to force update (-time_precision) - struct timeval stv; - gettimeofday(&stv, 0); - time_clock.tv_sec = stv.tv_sec - time_precision; - time_clock.tv_sec -= time_clock.tv_sec % time_precision; - - clock->area.posy = parent->pix.border.width + parent->paddingy; - clock->area.height = parent->height - (2 * clock->area.posy); - clock->area.resize = 1; - clock->area.redraw = 1; + Panel *panel; + Clock *clock; + int i, time_height, time_height_ink, date_height, date_height_ink; - strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); - if (time2_format) - strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + for (i=0 ; i < nb_panel ; i++) { + panel = &panel1[i]; + clock = &panel->clock; - get_text_size(time1_font_desc, &time_height_ink, &time_height, parent->height, buf_time, strlen(buf_time)); - clock->time1_posy = (clock->area.height - time_height) / 2; + clock->area.parent = panel; + clock->area.panel = panel; + clock->area._draw_foreground = draw_clock; + clock->area._resize = resize_clock; - if (time2_format) { - get_text_size(time2_font_desc, &date_height_ink, &date_height, parent->height, buf_date, strlen(buf_date)); + if (!clock->area.on_screen) continue; - clock->time1_posy -= ((date_height_ink + 2) / 2); - clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; - } + if (strchr(time1_format, 'S') == NULL) time_precision = 60; + else time_precision = 1; + + // update clock to force update (-time_precision) + struct timeval stv; + gettimeofday(&stv, 0); + time_clock.tv_sec = stv.tv_sec - time_precision; + time_clock.tv_sec -= time_clock.tv_sec % time_precision; + + clock->area.posy = panel->area.pix.border.width + panel->area.paddingy; + clock->area.height = panel->area.height - (2 * clock->area.posy); + clock->area.resize = 1; + clock->area.redraw = 1; + + strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); + if (time2_format) + strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + + get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time)); + clock->time1_posy = (clock->area.height - time_height) / 2; + + if (time2_format) { + get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); + + clock->time1_posy -= ((date_height_ink + 2) / 2); + clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; + } + } } -void draw_foreground_clock (void *obj, cairo_t *c, int active) +void draw_clock (void *obj, cairo_t *c, int active) { Clock *clock = obj; PangoLayout *layout; - //printf(" draw_foreground_clock : %s en (%d, %d)\n", buf_time, clock->area.posx, clock->area.width); + //printf(" draw_clock : %s en (%d, %d)\n", buf_time, clock->area.posx, clock->area.width); layout = pango_cairo_create_layout (c); // draw layout @@ -119,12 +126,13 @@ void draw_foreground_clock (void *obj, cairo_t *c, int active) void resize_clock (void *obj) { - Area *parent = ((Area*)obj)->parent; Clock *clock = obj; PangoLayout *layout; int time_width, date_width, new_width; time_width = date_width = 0; + clock->area.redraw = 1; + strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); if (time2_format) strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); @@ -155,12 +163,22 @@ void resize_clock (void *obj) else new_width = date_width; new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.width); - if (new_width > clock->area.width || new_width < (clock->area.width-3)) { + if (new_width > clock->area.width || new_width < (clock->area.width-6)) { + int i; + Panel *panel = ((Area*)obj)->panel; + + printf("clock_width %d, new_width %d\n", clock->area.width, new_width); // resize clock - //printf("clock_width %d, new_width %d\n", clock->area.width, new_width); - clock->area.width = new_width; - clock->area.posx = parent->width - clock->area.width - parent->paddingxlr - parent->pix.border.width; - set_resize(parent); + // we try to limit the number of resize + clock->area.width = new_width + 1; + clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width; + + // resize other objects on panel + for (i=0 ; i < nb_panel ; i++) { + panel1[i].area.resize = 1; + } + systray.area.resize = 1; + panel_refresh = 1; } g_object_unref (layout);