X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=inline;f=src%2Fclock%2Fclock.c;h=b5c3e41920bc271a36e7a857718c84dd289c0c31;hb=0a43eba2b74224ce55ff7ea3cfaaf25758f2e582;hp=c1504bea8202272c553d243918ca2a374230b6f7;hpb=83f23be9b6b5c2f1ae39d7d045353036b07f872d;p=chaz%2Ftint2 diff --git a/src/clock/clock.c b/src/clock/clock.c index c1504be..b5c3e41 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "window.h" #include "server.h" @@ -30,40 +31,49 @@ #include "panel.h" #include "taskbar.h" #include "clock.h" +#include "timer.h" 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=0; PangoFontDescription *time2_font_desc=0; static char buf_time[40]; static char buf_date[40]; +static char buf_tooltip[40]; int clock_enabled; -void init_precision() +void update_clocks() { - 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; + 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_clock() +const char* clock_get_tooltip(void* obj) { - init_precision(); + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, localtime(&time_clock.tv_sec)); + return buf_tooltip; +} - // 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; + +void init_clock() +{ + if(time1_format) { + if (strchr(time1_format, 'S') || strchr(time1_format, 'T') || strchr(time1_format, 'r')) + install_timer(0, 1000000, 1, 0, update_clocks); + else install_timer(0, 1000000, 60, 0, update_clocks); + } } @@ -109,6 +119,11 @@ void init_clock_panel(void *p) 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)); + } } @@ -123,6 +138,8 @@ void cleanup_clock() 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) @@ -246,7 +263,11 @@ void clock_action(int button) } if (command) { pid_t pid; + sigset_t sigset; + sigprocmask(SIG_SETMASK, &sigset, 0); + sigprocmask(SIG_UNBLOCK, &sigset, 0); pid = fork(); + sigprocmask(SIG_BLOCK, &sigset, 0); if (pid == 0) { execl("/bin/sh", "/bin/sh", "-c", command, NULL); _exit(0);