int resize_taskbarname(void* obj) { Taskbarname* taskbar_name = obj; Panel* panel = taskbar_name->area.panel; int name_height, name_width, name_height_ink; int ret = 0; taskbar_name->area.redraw = 1; get_text_size2(taskbarname_font_desc, &name_height_ink, &name_height, &name_width, panel->area.height, panel->area.width, taskbar_name->name, strlen(taskbar_name->name)); if (panel_horizontal) { int new_size = name_width + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width)); if (new_size != taskbar_name->area.width) { taskbar_name->area.width = new_size; taskbar_name->posy = (taskbar_name->area.height - name_height) / 2; ret = 1; } } else { int new_size = name_height + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width)); if (new_size != taskbar_name->area.height) { taskbar_name->area.height = new_size; taskbar_name->posy = (taskbar_name->area.height - name_height) / 2; ret = 1; } } return ret; }
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)/2; clock->time2_posy = clock->time1_posy + time_height; } 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)/2; clock->time2_posy = clock->time1_posy + time_height; } ret = 1; } } return ret; }
void clock_compute_text_geometry(Panel *panel, int *time_height_ink, int *time_height, int *time_width, int *date_height_ink, int *date_height, int *date_width) { *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), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, FALSE); 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), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, FALSE); } }
gboolean resize_execp(void *obj) { Execp *execp = (Execp *)obj; Panel *panel = (Panel *)execp->area.panel; int horiz_padding = (panel_horizontal ? execp->area.paddingxlr : execp->area.paddingy); int vert_padding = (panel_horizontal ? execp->area.paddingy : execp->area.paddingxlr); int interior_padding = execp->area.paddingx; int icon_w, icon_h; if (reload_icon(execp)) { if (execp->backend->icon) { imlib_context_set_image(execp->backend->icon); icon_w = imlib_image_get_width(); icon_h = imlib_image_get_height(); } else { icon_w = icon_h = 0; } } else { icon_w = icon_h = 0; } int text_next_line = !panel_horizontal && icon_w > execp->area.width / 2; int txt_height_ink, txt_height, txt_width; if (panel_horizontal) { get_text_size2(execp->backend->font_desc, &txt_height_ink, &txt_height, &txt_width, panel->area.height, panel->area.width, execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, execp->backend->has_markup); } else { get_text_size2(execp->backend->font_desc, &txt_height_ink, &txt_height, &txt_width, panel->area.height, !text_next_line ? execp->area.width - icon_w - (icon_w ? interior_padding : 0) - 2 * horiz_padding - left_right_border_width(&execp->area) : execp->area.width - 2 * horiz_padding - left_right_border_width(&execp->area), execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, execp->backend->has_markup); } gboolean result = FALSE; if (panel_horizontal) { int new_size = txt_width; if (icon_w) new_size += interior_padding + icon_w; new_size += 2 * horiz_padding + left_right_border_width(&execp->area); if (new_size > execp->area.width || new_size < (execp->area.width - 6)) { // we try to limit the number of resize execp->area.width = new_size + 1; result = TRUE; } } else { int new_size; if (!text_next_line) { new_size = txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area); new_size = MAX(new_size, icon_h + 2 * vert_padding + top_bottom_border_width(&execp->area)); } else { new_size = icon_h + interior_padding + txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area); } if (new_size != execp->area.height) { execp->area.height = new_size; result = TRUE; } } execp->frontend->textw = txt_width; execp->frontend->texth = txt_height; if (execp->backend->centered) { if (icon_w) { if (!text_next_line) { execp->frontend->icony = (execp->area.height - icon_h) / 2; execp->frontend->iconx = (execp->area.width - txt_width - interior_padding - icon_w) / 2; execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->textx = execp->frontend->iconx + icon_w + interior_padding; } else { execp->frontend->icony = (execp->area.height - icon_h - interior_padding - txt_height) / 2; execp->frontend->iconx = (execp->area.width - icon_w) / 2; execp->frontend->texty = execp->frontend->icony + icon_h + interior_padding; execp->frontend->textx = (execp->area.width - txt_width) / 2; } } else { execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->textx = (execp->area.width - txt_width) / 2; } } else { if (icon_w) { if (!text_next_line) { execp->frontend->icony = (execp->area.height - icon_h) / 2; execp->frontend->iconx = left_border_width(&execp->area) + horiz_padding; execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->textx = execp->frontend->iconx + icon_w + interior_padding; } else { execp->frontend->icony = (execp->area.height - icon_h - interior_padding - txt_height) / 2; execp->frontend->iconx = left_border_width(&execp->area) + horiz_padding; execp->frontend->texty = execp->frontend->icony + icon_h + interior_padding; execp->frontend->textx = execp->frontend->iconx; } } else { execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->textx = left_border_width(&execp->area) + horiz_padding; } } schedule_redraw(&execp->area); return result; }
int execp_compute_desired_size(void *obj) { Execp *execp = (Execp *)obj; Panel *panel = (Panel *)execp->area.panel; int horiz_padding = (panel_horizontal ? execp->area.paddingxlr : execp->area.paddingy); int vert_padding = (panel_horizontal ? execp->area.paddingy : execp->area.paddingxlr); int interior_padding = execp->area.paddingx; int icon_w, icon_h; if (reload_icon(execp)) { if (execp->backend->icon) { imlib_context_set_image(execp->backend->icon); icon_w = imlib_image_get_width(); icon_h = imlib_image_get_height(); } else { icon_w = icon_h = 0; } } else { icon_w = icon_h = 0; } int text_next_line = !panel_horizontal && icon_w > execp->area.width / 2; int txt_height_ink, txt_height, txt_width; if (panel_horizontal) { get_text_size2(execp->backend->font_desc, &txt_height_ink, &txt_height, &txt_width, panel->area.height, panel->area.width, execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, execp->backend->has_markup); } else { get_text_size2(execp->backend->font_desc, &txt_height_ink, &txt_height, &txt_width, panel->area.height, !text_next_line ? execp->area.width - icon_w - (icon_w ? interior_padding : 0) - 2 * horiz_padding - left_right_border_width(&execp->area) : execp->area.width - 2 * horiz_padding - left_right_border_width(&execp->area), execp->backend->text, strlen(execp->backend->text), PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_NONE, execp->backend->has_markup); } if (panel_horizontal) { int new_size = txt_width; if (icon_w) new_size += interior_padding + icon_w; new_size += 2 * horiz_padding + left_right_border_width(&execp->area); return new_size; } else { int new_size; if (!text_next_line) { new_size = txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area); new_size = MAX(new_size, icon_h + 2 * vert_padding + top_bottom_border_width(&execp->area)); } else { new_size = icon_h + interior_padding + txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area); } return new_size; } }