From f4cdb2acfaf58d7cb8d8ae60d08a019f71ec4169 Mon Sep 17 00:00:00 2001 From: Wim de With Date: Sat, 13 Dec 2014 17:02:31 +0100 Subject: [PATCH 1/2] Add notification_height option Fix the line_height description --- config.def.h | 1 + dunstrc | 8 ++++++-- settings.c | 8 ++++++-- settings.h | 1 + x.c | 20 +++++++++++++++----- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/config.def.h b/config.def.h index 65e36d8dd..dbcc4b93e 100644 --- a/config.def.h +++ b/config.def.h @@ -31,6 +31,7 @@ int verbosity = 0; int word_wrap = False; int ignore_newline = False; int line_height = 0; /* if line height < font height, it will be raised to font height */ +int notification_height = 0; /* if notification height < font height and padding, it will be raised */ int separator_height = 2; /* height of the separator line between two notifications */ int padding = 0; diff --git a/dunstrc b/dunstrc index e28b1c46b..b31c3a839 100644 --- a/dunstrc +++ b/dunstrc @@ -106,11 +106,15 @@ # Display indicators for URLs (U) and actions (A). show_indicators = yes - # The height of a single line. If the height is smaller than the + # The spacing between lines. If the height is smaller than the # font height, it will get raised to the font height. - # This adds empty space above and under the text. line_height = 0 + # The height of the entire notification. If the height is smaller + # than the font height and padding combined, it will be raised + # to the font height and padding. + notification_height = 0 + # Draw a line of "separator_height" pixel height between two # notifications. # Set to 0 to disable. diff --git a/settings.c b/settings.c index e982fcff3..aa9a0f190 100644 --- a/settings.c +++ b/settings.c @@ -134,8 +134,12 @@ void load_settings(char *cmdline_config_path) "Shrink window if it's smaller than the width"); settings.line_height = option_get_int("global", "line_height", "-lh/-line_height", - line_height, - "Add additional padding above and beneath text"); + line_height, + "Add spacing between lines of text"); + settings.notification_height = + option_get_int("global", "notification_height", "-nh/-notification_height", + notification_height, + "Define height of the window"); settings.bounce_freq = option_get_double("global", "bounce_freq", "-bounce_freq", bounce_freq, diff --git a/settings.h b/settings.h index 26a049f7d..7c89630db 100644 --- a/settings.h +++ b/settings.h @@ -33,6 +33,7 @@ typedef struct _settings { int word_wrap; int ignore_newline; int line_height; + int notification_height; int separator_height; int padding; int h_padding; diff --git a/x.c b/x.c index 62ecde9c0..c2f110886 100644 --- a/x.c +++ b/x.c @@ -218,7 +218,6 @@ 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, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { @@ -229,6 +228,7 @@ static dimension_t calculate_dimensions(GSList *layouts) h = MAX(cairo_image_surface_get_height(cl->icon), h); w += cairo_image_surface_get_width(cl->icon) + settings.h_padding; } + h = MAX(settings.notification_height, h + settings.padding * 2); dim.h += h; text_width = MAX(w, text_width); @@ -260,6 +260,7 @@ static dimension_t calculate_dimensions(GSList *layouts) h = MAX(cairo_image_surface_get_height(cl->icon), h); w += cairo_image_surface_get_width(cl->icon) + settings.h_padding; } + h = MAX(settings.notification_height, h + settings.padding * 2); dim.h += h; text_width = MAX(w, text_width); } @@ -395,7 +396,7 @@ static colored_layout *r_create_layout_from_notification(cairo_t *c, notificatio pango_layout_get_pixel_size(cl->l, NULL, &(n->displayed_height)); if (cl->icon) n->displayed_height = MAX(cairo_image_surface_get_height(cl->icon), n->displayed_height); - n->displayed_height += 2 * settings.padding; + n->displayed_height = MAX(settings.notification_height, n->displayed_height + settings.padding * 2); n->first_render = false; return cl; @@ -449,7 +450,8 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d int bg_x = 0; int bg_y = dim.y; int bg_width = dim.w; - int bg_height = (2 * settings.padding) + h; + int bg_height = MAX(settings.notification_height, (2 * settings.padding) + h); + double bg_half_height = settings.notification_height/2.0; /* adding frame */ bg_x += settings.frame_width; @@ -465,14 +467,22 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d cairo_rectangle(c, bg_x, bg_y, bg_width, bg_height); cairo_fill(c); - dim.y += settings.padding; + bool use_padding = settings.notification_height <= (2 * settings.padding) + h; + if (use_padding) + dim.y += settings.padding; + else + dim.y += (int) (ceil(bg_half_height) - floor(h/2.0)); 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); 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); - dim.y += h + settings.padding; + + if (use_padding) + dim.y += h + settings.padding; + else + dim.y += (int) (floor(bg_half_height) + ceil(h/2.0)); color_t sep_color = x_get_separator_color(cl->fg, cl->bg); if (settings.separator_height > 0 && !last) { cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b); From dfb4c933dc1b716445ddf457d85071b6bdc431ed Mon Sep 17 00:00:00 2001 From: Wim de With Date: Sat, 13 Dec 2014 19:21:56 +0100 Subject: [PATCH 2/2] Fix issue with ceil and floor --- x.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x.c b/x.c index c2f110886..ea119c2d6 100644 --- a/x.c +++ b/x.c @@ -452,6 +452,7 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d int bg_width = dim.w; int bg_height = MAX(settings.notification_height, (2 * settings.padding) + h); double bg_half_height = settings.notification_height/2.0; + int pango_offset = (int) floor(h/2.0); /* adding frame */ bg_x += settings.frame_width; @@ -471,18 +472,18 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d if (use_padding) dim.y += settings.padding; else - dim.y += (int) (ceil(bg_half_height) - floor(h/2.0)); + dim.y += (int) (ceil(bg_half_height) - pango_offset); 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); 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); - if (use_padding) dim.y += h + settings.padding; else - dim.y += (int) (floor(bg_half_height) + ceil(h/2.0)); + dim.y += (int) (floor(bg_half_height) + pango_offset); + color_t sep_color = x_get_separator_color(cl->fg, cl->bg); if (settings.separator_height > 0 && !last) { cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b);