From dd047ccd2000b9447be62998f2b1e6047020cf97 Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 30 Apr 2013 14:55:50 +0200 Subject: [PATCH] implemented shrink option --- x.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/x.c b/x.c index 30bb6da..4a80509 100644 --- a/x.c +++ b/x.c @@ -203,7 +203,7 @@ static dimension_t calculate_dimensions(GSList *layouts) dim.h += (g_slist_length(layouts) - 1) * settings.separator_height; dim.h += g_slist_length(layouts) * settings.padding * 2; - int text_width = 0; + int text_width = 0, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { colored_layout *cl = iter->data; int w,h; @@ -211,26 +211,31 @@ static dimension_t calculate_dimensions(GSList *layouts) dim.h += h; text_width = MAX(w, text_width); - if (dim.w <= 0) { + if (dim.w <= 0 || settings.shrink) { /* dynamic width */ - if ((text_width + 2 * settings.h_padding) > scr.dim.w) { - /* it's bigger than the screen */ - /* subtract height from the unwrapped text */ - dim.h -= h; + total_width = MAX(text_width + 2 * settings.h_padding, total_width); + + /* subtract height from the unwrapped text */ + dim.h -= h; + + if (total_width > scr.dim.w) { /* set width to screen width */ dim.w = scr.dim.w - xctx.geometry.y * 2; - - /* re-setup the layout */ - int width = dim.w; - width -= 2 * settings.h_padding; - width -= 2 * settings.frame_width; - r_setup_pango_layout(cl->l, width); - - /* re-read information */ - pango_layout_get_pixel_size(cl->l, &w, &h); - dim.h += h; - text_width = MAX(w, text_width); + } else if (total_width < xctx.geometry.w && settings.shrink) { + /* set width to text width */ + dim.w = total_width + 2 * settings.frame_width; } + + /* re-setup the layout */ + int width = dim.w; + width -= 2 * settings.h_padding; + width -= 2 * settings.frame_width; + r_setup_pango_layout(cl->l, width); + + /* re-read information */ + pango_layout_get_pixel_size(cl->l, &w, &h); + dim.h += h; + text_width = MAX(w, text_width); } }