From ae2ce4fb7030ec388d3262f665d42c1c2a9d40fe Mon Sep 17 00:00:00 2001 From: tatou-tatou Date: Fri, 30 May 2014 00:41:32 +0200 Subject: [PATCH 1/4] Fix padding when there's an icon --- x.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/x.c b/x.c index 0b40aa4..714817e 100644 --- a/x.c +++ b/x.c @@ -219,6 +219,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; + dim.h += 2*settings.frame_width; int text_width = 0, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { @@ -430,7 +431,9 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d { int h; pango_layout_get_pixel_size(cl->l, NULL, &h); - if (cl->icon) h = MAX(cairo_image_surface_get_height(cl->icon), h); + if (cl->icon) { + h = MAX(cairo_image_surface_get_height(cl->icon), h); + } int bg_x = 0; int bg_y = dim.y; @@ -439,22 +442,22 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d /* adding frame */ bg_x += settings.frame_width; - if (first) { - bg_y += settings.frame_width; - bg_height -= settings.frame_width; - } + bg_y += settings.frame_width; + bg_height -= settings.frame_width; bg_width -= 2 * settings.frame_width; - if (last) - bg_height -= settings.frame_width; + bg_height += settings.frame_width; cairo_set_source_rgb(c, cl->bg.r, cl->bg.g, cl->bg.b); cairo_rectangle(c, bg_x, bg_y, bg_width, bg_height); cairo_fill(c); dim.y += settings.padding; - if (cl->icon && settings.icon_position == icons_left) - cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, dim.y); - else cairo_move_to(c, settings.h_padding, dim.y); + if (cl->icon && settings.icon_position == icons_left) { + cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding ); + } + else { + cairo_move_to(c, settings.h_padding, bg_y + settings.padding); + } cairo_set_source_rgb(c, cl->fg.r, cl->fg.g, cl->fg.b); pango_cairo_update_layout(c, cl->l); pango_cairo_show_layout(c, cl->l); @@ -463,7 +466,7 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d if (settings.separator_height > 0 && !last) { cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b); - cairo_rectangle(c, settings.frame_width, dim.y, + cairo_rectangle(c, settings.frame_width, dim.y + settings.frame_width, dim.w - 2 * settings.frame_width , settings.separator_height); From c8575e1f91ef8482b4f6b3ee4df148a2df0b73f4 Mon Sep 17 00:00:00 2001 From: tatou-tatou Date: Fri, 30 May 2014 00:44:50 +0200 Subject: [PATCH 2/4] Center text vertically when there's an icon --- x.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x.c b/x.c index 714817e..391d885 100644 --- a/x.c +++ b/x.c @@ -430,8 +430,10 @@ static void r_free_layouts(GSList *layouts) static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t dim, bool first, bool last) { int h; + int h_text; pango_layout_get_pixel_size(cl->l, NULL, &h); if (cl->icon) { + h_text = h; h = MAX(cairo_image_surface_get_height(cl->icon), h); } @@ -453,7 +455,7 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d dim.y += settings.padding; if (cl->icon && settings.icon_position == icons_left) { - cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding ); + cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding + h/2 - h_text/2); } else { cairo_move_to(c, settings.h_padding, bg_y + settings.padding); From bc31a638f630107c689b651182dfdd53d4a717b6 Mon Sep 17 00:00:00 2001 From: tatou-tatou Date: Sat, 31 May 2014 16:34:06 +0200 Subject: [PATCH 3/4] Horizontal padding is now inside the border too --- x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x.c b/x.c index 391d885..aa5dad4 100644 --- a/x.c +++ b/x.c @@ -455,10 +455,10 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d dim.y += settings.padding; if (cl->icon && settings.icon_position == icons_left) { - cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding + h/2 - h_text/2); + cairo_move_to(c, settings.frame_width + cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding + h/2 - h_text/2); } else { - cairo_move_to(c, settings.h_padding, bg_y + settings.padding); + cairo_move_to(c, settings.frame_width + settings.h_padding, bg_y + settings.padding); } cairo_set_source_rgb(c, cl->fg.r, cl->fg.g, cl->fg.b); pango_cairo_update_layout(c, cl->l); @@ -483,8 +483,8 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d image_x, image_y = bg_y + settings.padding; - if (settings.icon_position == icons_left) image_x = settings.h_padding; - else image_x = bg_width - settings.h_padding - image_width; + if (settings.icon_position == icons_left) image_x = settings.frame_width + settings.h_padding; + else image_x = bg_width - settings.h_padding - image_width + settings.frame_width; cairo_set_source_surface (c, cl->icon, image_x, image_y); cairo_rectangle (c, image_x, image_y, image_width, image_height); From cee294d911b758acfa214209c38f07185b4016ad Mon Sep 17 00:00:00 2001 From: tatou-tatou Date: Sat, 31 May 2014 16:42:18 +0200 Subject: [PATCH 4/4] Text is vertically centered if the icon is on the right --- x.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x.c b/x.c index aa5dad4..e033d52 100644 --- a/x.c +++ b/x.c @@ -457,6 +457,9 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d if (cl->icon && settings.icon_position == icons_left) { cairo_move_to(c, settings.frame_width + cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, bg_y + settings.padding + h/2 - h_text/2); } + else if (cl->icon && settings.icon_position == icons_right) { + cairo_move_to(c, settings.frame_width + settings.h_padding, bg_y + settings.padding + h/2 - h_text/2); + } else { cairo_move_to(c, settings.frame_width + settings.h_padding, bg_y + settings.padding); }