X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fclock%2Fclock.c;h=79c4266f3b239e86c318033c8a9b38833c2f459b;hb=30ea5428a1a0080d01247458e0b2a8fc63ef582b;hp=273fb818e17991089c391a52a85d1b9dc5ea9924;hpb=f8bebb561d52fa25b320904bb0c6a08347d05611;p=chaz%2Ftint2 diff --git a/src/clock/clock.c b/src/clock/clock.c index 273fb81..79c4266 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -22,17 +22,14 @@ #include #include #include -#include -#include #include #include "window.h" #include "server.h" -#include "area.h" #include "panel.h" -#include "taskbar.h" #include "clock.h" #include "timer.h" +#include "common.h" char *time1_format; @@ -145,45 +142,19 @@ 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.size_mode = SIZE_BY_CONTENT; clock->area._resize = resize_clock; + // check consistency + if (time1_format == 0) + return; + clock->area.resize = 1; - clock->area.redraw = 1; clock->area.on_screen = 1; - 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, 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)); - } - - if (panel_horizontal) { - // panel horizonal => fixed height and posy - 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.bg->border.width + panel->area.paddingxlr; - clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height); - 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; - if (time2_format) { - 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); - 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, clock_gettime_for_tz(time_tooltip_timezone)); @@ -225,69 +196,51 @@ void draw_clock (void *obj, cairo_t *c) } -void resize_clock (void *obj) +int resize_clock (void *obj) { Clock *clock = obj; - PangoLayout *layout; - int time_width, date_width, new_width; + Panel *panel = clock->area.panel; + int time_height_ink, time_height, time_width, date_height_ink, date_height, date_width, ret = 0; clock->area.redraw = 1; - time_width = date_width = 0; + + date_height = date_width = 0; 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, clock_gettime_for_tz(time2_timezone)); - - // vertical panel doen't adjust width - if (!panel_horizontal) return; - - //printf(" resize_clock\n"); - cairo_surface_t *cs; - cairo_t *c; - Pixmap pmap; - pmap = XCreatePixmap (server.dsp, server.root_win, clock->area.width, clock->area.height, server.depth); - - cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, clock->area.width, clock->area.height); - c = cairo_create (cs); - layout = pango_cairo_create_layout (c); - - // check width - pango_layout_set_font_description (layout, time1_font_desc); - pango_layout_set_indent(layout, 0); - pango_layout_set_text (layout, buf_time, strlen(buf_time)); - pango_layout_get_pixel_size (layout, &time_width, NULL); + get_text_size2(time1_font_desc, &time_height_ink, &time_height, &time_width, panel->area.height, panel->area.width, buf_time, strlen(buf_time)); if (time2_format) { - pango_layout_set_font_description (layout, time2_font_desc); - pango_layout_set_indent(layout, 0); - pango_layout_set_text (layout, buf_date, strlen(buf_date)); - pango_layout_get_pixel_size (layout, &date_width, NULL); + strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); + get_text_size2(time2_font_desc, &date_height_ink, &date_height, &date_width, panel->area.height, panel->area.width, buf_date, strlen(buf_date)); } - - if (time_width > date_width) new_width = time_width; - else new_width = date_width; - new_width += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width); - - Panel *panel = ((Area*)obj)->panel; - if (new_width > clock->area.width || new_width < (clock->area.width-6)) { - // resize clock - // we try to limit the number of resize - // printf("clock_width %d, new_width %d\n", clock->area.width, new_width); - clock->area.width = new_width + 1; - - // resize other objects on panel - panel->area.resize = 1; -#ifdef ENABLE_BATTERY - panel->battery.area.resize = 1; -#endif - systray.area.resize = 1; - panel_refresh = 1; + + if (panel_horizontal) { + int new_size = (time_width > date_width) ? time_width : date_width; + new_size += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width); + if (new_size > clock->area.width || new_size < (clock->area.width-6)) { + // we try to limit the number of resize + clock->area.width = new_size + 1; + clock->time1_posy = (clock->area.height - time_height) / 2; + if (time2_format) { + 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; + } + ret = 1; + } + } + else { + int new_size = time_height + date_height + (2 * (clock->area.paddingxlr + clock->area.bg->border.width)); + if (new_size != clock->area.height) { + // we try to limit the number of resize + clock->area.height = new_size; + clock->time1_posy = (clock->area.height - time_height) / 2; + if (time2_format) { + 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; + } + ret = 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); - cairo_surface_destroy (cs); - XFreePixmap (server.dsp, pmap); + return ret; } @@ -302,17 +255,6 @@ void clock_action(int button) command = clock_rclick_command; break; } - if (command) { - 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); - } - } + tint_exec(command); }