Add the text_icon_padding feature as per #543

This commit is contained in:
GuessWhatBBQ 2021-01-23 15:15:26 +06:00
parent 77bfbc4f7f
commit be8e32098f
6 changed files with 49 additions and 8 deletions

View File

@ -54,6 +54,7 @@ struct settings defaults = {
.separator_height = 2, /* height of the separator line between two notifications */
.padding = 0,
.h_padding = 0, /* horizontal padding */
.text_icon_padding = 0, /* padding between icon and text*/
.sep_color = {SEP_AUTO}, /* SEP_AUTO, SEP_FOREGROUND, SEP_FRAME, SEP_CUSTOM */
.frame_width = 0,

View File

@ -218,6 +218,23 @@ in the vertical axis
The distance in pixels from the content to the border of the window
in the horizontal axis
=item B<text_icon_padding> (default: 0)
The distance in pixels from the text to the icon (or vice versa)
in the horizontal axis.
Setting this to a non-zero value overwrites any padding that horizontal_padding was adding between the notification text and icon.
So for example setting
text_icon_padding=10
horizontal_padding=10
is equivalent to
text_icon_padding=0
horizontal_padding=10
=item B<frame_width> (default: 0)
Defines width in pixels of frame around the notification window. Set to 0 to

View File

@ -76,6 +76,9 @@
# Horizontal padding.
horizontal_padding = 8
# Padding between text and icon.
text_icon_padding = 0
# Defines width in pixels of frame around the notification window.
# Set to 0 to disable.
frame_width = 3

View File

@ -179,6 +179,15 @@ static bool have_dynamic_width(void)
return (settings.geometry.width_set && settings.geometry.w == 0);
}
static int get_text_icon_padding()
{
if (settings.text_icon_padding) {
return settings.text_icon_padding;
} else {
return settings.h_padding;
}
}
static bool have_progress_bar(const struct notification *n)
{
return (n->progress >= 0 && settings.progress_bar == true);
@ -241,7 +250,9 @@ static struct dimensions calculate_dimensions(GSList *layouts)
w = dim.w;
w -= 2 * settings.h_padding;
w -= 2 * settings.frame_width;
if (cl->icon) w -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
if (cl->icon) {
w -= cairo_image_surface_get_width(cl->icon) + get_text_icon_padding();
}
layout_setup_pango(cl->l, w);
/* re-read information */
@ -335,7 +346,9 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const struct notifi
} else {
width -= 2 * settings.h_padding;
width -= 2 * settings.frame_width;
if (cl->icon) width -= cairo_image_surface_get_width(cl->icon) + settings.h_padding;
if (cl->icon) {
width -= cairo_image_surface_get_width(cl->icon) + get_text_icon_padding();
}
layout_setup_pango(cl->l, width);
}
@ -621,7 +634,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width)
// icon position
if (settings.icon_position == ICON_LEFT) {
text_x = cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding;
text_x = cairo_image_surface_get_width(cl->icon) + settings.h_padding + get_text_icon_padding();
} // else ICON_RIGHT
}
cairo_move_to(c, text_x, text_y);

View File

@ -366,6 +366,12 @@ void load_settings(char *cmdline_config_path)
"horizontal padding"
);
settings.text_icon_padding = option_get_int(
"global",
"text_icon_padding", "-text_icon_padding", defaults.text_icon_padding,
"Padding between text and icon"
);
settings.transparency = option_get_int(
"global",
"transparency", "-transparency", defaults.transparency,

View File

@ -81,6 +81,7 @@ struct settings {
int separator_height;
int padding;
int h_padding;
int text_icon_padding;
struct separator_color_data sep_color;
int frame_width;
char *frame_color;