X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fclock%2Fclock.c;h=115ba9fe1bf5a4794984f1db33e0863147249142;hb=21dcd195642692401f855ef07b239364b5ef0c1b;hp=200996ebd4263c3d95516930cbc7bde578380cd4;hpb=2cccd91fa633d9bfefd46073981276cb29fda5e7;p=chaz%2Ftint2 diff --git a/src/clock/clock.c b/src/clock/clock.c index 200996e..115ba9f 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "window.h" #include "server.h" @@ -34,8 +36,11 @@ char *time1_format=0; +char *time1_timezone=0; char *time2_format=0; +char *time2_timezone=0; char *time_tooltip_format=0; +char *time_tooltip_timezone=0; char *clock_lclick_command=0; char *clock_rclick_command=0; struct timeval time_clock; @@ -45,6 +50,7 @@ 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() @@ -58,19 +64,32 @@ void update_clocks() panel_refresh = 1; } +struct tm* clock_gettime_for_tz(const char* timezone) { + if (timezone) { + const char* old_tz = getenv("TZ"); + setenv("TZ", timezone, 1); + struct tm* result = localtime(&time_clock.tv_sec); + if (old_tz) setenv("TZ", old_tz, 1); + else unsetenv("TZ"); + return result; + } + else return localtime(&time_clock.tv_sec); +} const char* clock_get_tooltip(void* obj) { + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone)); return buf_tooltip; } void init_clock() { - if(time1_format) { + if(time1_format && clock_timeout==0) { 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); + clock_timeout = add_timeout(10, 1000, update_clocks); + else + clock_timeout = add_timeout(10, 60000, update_clocks); } } @@ -89,10 +108,10 @@ void init_clock_panel(void *p) clock->area.redraw = 1; clock->area.on_screen = 1; - strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); + strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone)); 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)); + strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); } @@ -111,7 +130,7 @@ void init_clock_panel(void *p) 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)); + strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); 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); @@ -120,7 +139,7 @@ void init_clock_panel(void *p) 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)); + strftime(buf_tooltip, sizeof(buf_tooltip), time_tooltip_format, clock_gettime_for_tz(time_tooltip_timezone)); } } @@ -132,18 +151,17 @@ void cleanup_clock() 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); + g_free(time1_format); + g_free(time2_format); + g_free(time_tooltip_format); + g_free(time1_timezone); + g_free(time2_timezone); + g_free(time_tooltip_timezone); + g_free(clock_lclick_command); + g_free(clock_rclick_command); time1_font_desc = time2_font_desc = 0; - time1_format = time2_format = 0; + time1_format = time2_format = time_tooltip_format = 0; + time1_timezone = time2_timezone = time_tooltip_timezone = 0; clock_lclick_command = clock_rclick_command = 0; } @@ -190,9 +208,9 @@ void resize_clock (void *obj) clock->area.redraw = 1; time_width = date_width = 0; - strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); + strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone)); if (time2_format) - strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); // vertical panel doen't adjust width if (!panel_horizontal) return; @@ -263,6 +281,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); }