From 2d59a77e0caf309d329f74663b2c35559087c5fc Mon Sep 17 00:00:00 2001 From: Giuliano Schneider Date: Tue, 23 Apr 2013 20:58:19 +0200 Subject: [PATCH] wrap the text if it's wider than the screen width (Fixes #53) --- x.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/x.c b/x.c index 2ad74d3..30bb6da 100644 --- a/x.c +++ b/x.c @@ -210,6 +210,28 @@ static dimension_t calculate_dimensions(GSList *layouts) pango_layout_get_pixel_size(cl->l, &w, &h); dim.h += h; text_width = MAX(w, text_width); + + if (dim.w <= 0) { + /* 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; + /* 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); + } + } } if (dim.w <= 0) {