all repos — tint2 @ 985c557dcda88f21063659321ca668ad1c0822e4

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Refactored text size computation
o9000 mrovi9000@gmail.com
commit

985c557dcda88f21063659321ca668ad1c0822e4

parent

6937aa8b9dd818c85d842237cb6e721d9c022a5a

M src/battery/battery.csrc/battery/battery.c

@@ -267,6 +267,8 @@ draw_text(layout, c, 0, battery->bat1_posy, &battery->font, ((Panel*)battery->area.panel)->font_shadow);

pango_layout_set_font_description(layout, bat2_font_desc); pango_layout_set_indent(layout, 0); + pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); pango_layout_set_text(layout, buf_bat_time, strlen(buf_bat_time)); pango_layout_set_width(layout, battery->area.width * PANGO_SCALE);

@@ -295,9 +297,13 @@ } else {

snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); } get_text_size2(bat1_font_desc, &bat_percentage_height_ink, &bat_percentage_height, &bat_percentage_width, - panel->area.height, panel->area.width, buf_bat_percentage, strlen(buf_bat_percentage)); + panel->area.height, panel->area.width, buf_bat_percentage, strlen(buf_bat_percentage), + PANGO_WRAP_WORD_CHAR, + PANGO_ELLIPSIZE_NONE); get_text_size2(bat2_font_desc, &bat_time_height_ink, &bat_time_height, &bat_time_width, - panel->area.height, panel->area.width, buf_bat_time, strlen(buf_bat_time)); + panel->area.height, panel->area.width, buf_bat_time, strlen(buf_bat_time), + PANGO_WRAP_WORD_CHAR, + PANGO_ELLIPSIZE_NONE); if (panel_horizontal) { int new_size = (bat_percentage_width > bat_time_width) ? bat_percentage_width : bat_time_width;
M src/clock/clock.csrc/clock/clock.c

@@ -213,6 +213,8 @@ // draw layout

pango_layout_set_font_description (layout, time1_font_desc); pango_layout_set_width (layout, clock->area.width * PANGO_SCALE); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); pango_layout_set_text (layout, buf_time, strlen(buf_time)); cairo_set_source_rgba (c, clock->font.color[0], clock->font.color[1], clock->font.color[2], clock->font.alpha);

@@ -244,10 +246,14 @@ 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)); + 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); 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)); + 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); } if (panel_horizontal) {
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -232,8 +232,8 @@ }

} // compute vertical position : text and icon - int height_ink, height; - get_text_size(panel->g_task.font_desc, &height_ink, &height, panel->area.height, "TAjpg", 5); + int height_ink, height, width; + get_text_size2(panel->g_task.font_desc, &height_ink, &height, &width, panel->area.height, panel->area.width, "TAjpg", 5, PANGO_WRAP_WORD_CHAR, PANGO_ELLIPSIZE_END); if (!panel->g_task.maximum_width && panel_horizontal) panel->g_task.maximum_width = server.monitor[panel->monitor].width;
M src/taskbar/taskbarname.csrc/taskbar/taskbarname.c

@@ -124,6 +124,8 @@ layout = pango_cairo_create_layout (c);

pango_layout_set_font_description (layout, panel_config.taskbarname_font_desc); pango_layout_set_width (layout, taskbar_name->area.width * PANGO_SCALE); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE); pango_layout_set_text (layout, taskbar_name->name, strlen(taskbar_name->name)); cairo_set_source_rgba (c, config_text->color[0], config_text->color[1], config_text->color[2], config_text->alpha);

@@ -144,7 +146,9 @@ int name_height, name_width, name_height_ink;

int ret = 0; taskbar_name->area.redraw = 1; - get_text_size2(panel_config.taskbarname_font_desc, &name_height_ink, &name_height, &name_width, panel->area.height, panel->area.width, taskbar_name->name, strlen(taskbar_name->name)); + get_text_size2(panel_config.taskbarname_font_desc, &name_height_ink, &name_height, &name_width, panel->area.height, panel->area.width, taskbar_name->name, strlen(taskbar_name->name), + PANGO_WRAP_WORD_CHAR, + PANGO_ELLIPSIZE_NONE); if (panel_horizontal) { int new_size = name_width + (2* (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width));
M src/util/window.csrc/util/window.c

@@ -321,41 +321,29 @@ return icon_data[icon_num];

} -void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len) -{ - PangoRectangle rect_ink, rect; - - Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); - - cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height); - cairo_t *c = cairo_create (cs); - - PangoLayout *layout = pango_cairo_create_layout (c); - pango_layout_set_font_description (layout, font); - pango_layout_set_text (layout, text, len); - - pango_layout_get_pixel_extents(layout, &rect_ink, &rect); - *height_ink = rect_ink.height; - *height = rect.height; - //printf("dimension : %d - %d\n", rect_ink.height, rect.height); - - g_object_unref (layout); - cairo_destroy (c); - cairo_surface_destroy (cs); - XFreePixmap (server.dsp, pmap); -} - - -void get_text_size2(PangoFontDescription *font, int *height_ink, int *height, int *width, int panel_height, int panel_with, char *text, int len) +void get_text_size2(PangoFontDescription *font, + int *height_ink, + int *height, + int *width, + int panel_height, + int panel_width, + char *text, + int len, + PangoWrapMode wrap, + PangoEllipsizeMode ellipsis) { PangoRectangle rect_ink, rect; - Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); + Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_width, server.depth); - cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_with); + cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_width); cairo_t *c = cairo_create (cs); PangoLayout *layout = pango_cairo_create_layout (c); + pango_layout_set_width(layout, panel_width * PANGO_SCALE); + pango_layout_set_height(layout, panel_height * PANGO_SCALE); + pango_layout_set_wrap(layout, wrap); + pango_layout_set_ellipsize(layout, ellipsis); pango_layout_set_font_description (layout, font); pango_layout_set_text (layout, text, len);
M src/util/window.hsrc/util/window.h

@@ -33,8 +33,16 @@ void windows_set_desktop (Window win, int desktop);

int window_get_monitor (Window win); Window window_get_active (); -void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len); -void get_text_size2(PangoFontDescription *font, int *height_ink, int *height, int *width, int panel_height, int panel_with, char *text, int len); +void get_text_size2(PangoFontDescription *font, + int *height_ink, + int *height, + int *width, + int panel_height, + int panel_with, + char *text, + int len, + PangoWrapMode wrap, + PangoEllipsizeMode ellipsis); #endif