Add notification_height option

Fix the line_height description
This commit is contained in:
Wim de With 2014-12-13 17:02:31 +01:00
parent be0c965027
commit f4cdb2acfa
5 changed files with 29 additions and 9 deletions

View File

@ -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;

View File

@ -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.

View File

@ -135,7 +135,11 @@ void load_settings(char *cmdline_config_path)
settings.line_height =
option_get_int("global", "line_height", "-lh/-line_height",
line_height,
"Add additional padding above and beneath text");
"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,

View File

@ -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;

16
x.c
View File

@ -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);
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);
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);