X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Fclock%2Fclock.c;h=876536cbca6407c147908210f1f075ed5ea67f15;hb=35e206acc0a7b9dca7611fe4a7e17c7acc381ad0;hp=b7a3966c71f586d75612583425f8fbbe08493564;hpb=f3f6ab62e3242c62e129d56b2a44c19c09303a16;p=chaz%2Ftint2 diff --git a/src/clock/clock.c b/src/clock/clock.c index b7a3966..876536c 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -23,92 +23,132 @@ #include #include #include +#include #include "window.h" #include "server.h" -#include "taskbar.h" -#include "panel.h" #include "area.h" +#include "panel.h" +#include "taskbar.h" #include "clock.h" +#include "timer.h" -char *time1_format; -char *time2_format; -char *clock_lclick_command; -char *clock_rclick_command; +char *time1_format=0; +char *time2_format=0; +char *time_tooltip_format=0; +char *clock_lclick_command=0; +char *clock_rclick_command=0; struct timeval time_clock; -int time_precision; -PangoFontDescription *time1_font_desc; -PangoFontDescription *time2_font_desc; +PangoFontDescription *time1_font_desc=0; +PangoFontDescription *time2_font_desc=0; 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; + + +void update_clocks() +{ + gettimeofday(&time_clock, 0); + int i; + if (time1_format) { + for (i=0 ; i < nb_panel ; i++) + panel1[i].clock.area.resize = 1; + } + panel_refresh = 1; +} -void init_precision() +const char* clock_get_tooltip(void* obj) { - if (!time1_format) time_precision = 60; - else if (strchr(time1_format, 'S')) time_precision = 1; - else if (strchr(time1_format, 'T')) time_precision = 1; - else if (strchr(time1_format, 'r')) time_precision = 1; - else time_precision = 60; + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec)); + return buf_tooltip; } void init_clock() { - Panel *panel; - Clock *clock; - int i, time_height, time_height_ink, date_height, date_height_ink; - - init_precision(); - // 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; - - for (i=0 ; i < nb_panel ; i++) { - panel = &panel1[i]; - clock = &panel->clock; - - if (!clock->area.on_screen) continue; - - clock->area.parent = panel; - clock->area.panel = panel; - clock->area._draw_foreground = draw_clock; - clock->area._resize = resize_clock; - clock->area.resize = 1; - clock->area.redraw = 1; - - strftime(buf_time, sizeof(buf_time), time1_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)); - if (time2_format) { - strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); - get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); - } + 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); + else + clock_timeout = add_timeout(10, 60000, update_clocks); + } +} - if (panel_horizontal) { - // panel horizonal => fixed height and posy - clock->area.posy = panel->area.pix.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.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->time1_posy = (clock->area.height - time_height) / 2; - if (time2_format) { - strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); - get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); +void init_clock_panel(void *p) +{ + Panel *panel =(Panel*)p; + Clock *clock = &panel->clock; + int time_height, time_height_ink, date_height, date_height_ink; + + clock->area.parent = p; + clock->area.panel = p; + clock->area._draw_foreground = draw_clock; + clock->area._resize = resize_clock; + clock->area.resize = 1; + clock->area.redraw = 1; + clock->area.on_screen = 1; - 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; - } + strftime(buf_time, sizeof(buf_time), time1_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)); + if (time2_format) { + strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); + } + + if (panel_horizontal) { + // panel horizonal => fixed height and posy + clock->area.posy = panel->area.pix.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.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->time1_posy = (clock->area.height - time_height) / 2; + if (time2_format) { + strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + 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; + } + + if (time_tooltip_format) { + clock->area._get_tooltip_text = clock_get_tooltip; + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec)); + } +} + + +void cleanup_clock() +{ + clock_enabled = 0; + if (time1_font_desc) + pango_font_description_free(time1_font_desc); + if (time2_font_desc) + pango_font_description_free(time2_font_desc); + if (time1_format) + g_free(time1_format); + if (time2_format) + g_free(time2_format); + if (time_tooltip_format) + g_free(time_tooltip_format); + if (clock_lclick_command) + g_free(clock_lclick_command); + if (clock_rclick_command) + g_free(clock_rclick_command); + time1_font_desc = time2_font_desc = 0; + time1_format = time2_format = 0; + clock_lclick_command = clock_rclick_command = 0; } @@ -227,6 +267,10 @@ void clock_action(int button) pid_t pid; pid = fork(); if (pid == 0) { + // change for the fork the signal mask + sigset_t sigset; + sigprocmask(SIG_SETMASK, &sigset, 0); + sigprocmask(SIG_UNBLOCK, &sigset, 0); execl("/bin/sh", "/bin/sh", "-c", command, NULL); _exit(0); }