+
+int resize_clock (void *obj)
+{
+ Clock *clock = obj;
+ 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;
+
+ date_height = date_width = 0;
+ strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
+ 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) {
+ 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 (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;
+ }
+ }
+
+ return ret;