Skip to content

Commit

Permalink
Merge pull request dunst-project#209 from Nauxuron/master
Browse files Browse the repository at this point in the history
Notification height option
  • Loading branch information
knopwob committed Dec 17, 2014
2 parents 56b0a7c + dfb4c93 commit f8e1e33
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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;
Expand Down
8 changes: 6 additions & 2 deletions dunstrc
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,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.
Expand Down
8 changes: 6 additions & 2 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,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,
Expand Down
1 change: 1 addition & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct _settings {
int word_wrap;
int ignore_newline;
int line_height;
int notification_height;
int separator_height;
int padding;
int h_padding;
Expand Down
21 changes: 16 additions & 5 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -449,7 +450,9 @@ 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;
int pango_offset = (int) floor(h/2.0);

/* adding frame */
bg_x += settings.frame_width;
Expand All @@ -465,14 +468,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) - 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);
dim.y += h + settings.padding;
if (use_padding)
dim.y += h + settings.padding;
else
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);
Expand Down

0 comments on commit f8e1e33

Please sign in to comment.