From 536adf00c5153f9f67a6b0688f530e5c8a1234b4 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sat, 8 Jan 2022 01:31:39 -0700 Subject: [PATCH 01/21] add icon_position rule, add top as possible value --- docs/dunst.5.pod | 2 +- dunstrc | 2 +- src/notification.c | 1 + src/notification.h | 1 + src/rules.c | 2 ++ src/rules.h | 2 ++ src/settings.h | 2 +- src/settings_data.h | 15 ++++++++++++++- 8 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index 48e79c346..a34395a2b 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -364,7 +364,7 @@ Hide the count of stacked duplicate notifications. Show an indicator if a notification contains actions and/or open-able URLs. See ACTIONS below for further details. -=item B (values: [left/right/off], default: off) +=item B (values: [left/right/top/off], default: off) Defines the position of the icon in the notification window. Setting it to off disables icons. diff --git a/dunstrc b/dunstrc index c70de40bc..2fb4632c8 100644 --- a/dunstrc +++ b/dunstrc @@ -184,7 +184,7 @@ ### Icons ### - # Align icons left/right/off + # Align icons left/right/top/off icon_position = left # Scale small icons up to this size, set to 0 to disable. Helpful diff --git a/src/notification.c b/src/notification.c index 8584299fa..d0cc85cdf 100644 --- a/src/notification.c +++ b/src/notification.c @@ -417,6 +417,7 @@ struct notification *notification_create(void) n->word_wrap = true; n->ellipsize = PANGO_ELLIPSIZE_MIDDLE; n->alignment = PANGO_ALIGN_LEFT; + n->icon_position = (int)settings.icon_position; n->icon_size = 32; n->script_run = false; diff --git a/src/notification.h b/src/notification.h index a7dea05e5..19ae29ca9 100644 --- a/src/notification.h +++ b/src/notification.h @@ -58,6 +58,7 @@ struct notification { char *icon_path; /**< Full path to the notification's icon. */ char *default_icon_name; /**< The icon that is used when no other icon is available. */ int icon_size; /**< Size of the icon used for searching the right icon. */ + int icon_position; /**< Icon position (enum left,right,top,off). */ gint64 start; /**< begin of current display (in milliseconds) */ gint64 timestamp; /**< arrival time (in milliseconds) */ diff --git a/src/rules.c b/src/rules.c index 3c8cf9bbd..d4176397b 100644 --- a/src/rules.c +++ b/src/rules.c @@ -46,6 +46,8 @@ void rule_apply(struct rule *r, struct notification *n) } if (r->markup != MARKUP_NULL) n->markup = r->markup; + if (r->icon_position != -1) + n->icon_position = r->icon_position; if (r->set_icon_size > 0) n->icon_size = r->set_icon_size; if (r->fg) { diff --git a/src/rules.h b/src/rules.h index 44f305fdc..148331356 100644 --- a/src/rules.h +++ b/src/rules.h @@ -39,6 +39,7 @@ struct rule { int word_wrap; int ellipsize; int alignment; + int icon_position; int set_icon_size; char *new_icon; char *fg; @@ -52,6 +53,7 @@ struct rule { enum behavior_fullscreen fullscreen; char *set_stack_tag; // this has to be the last action bool enabled; + }; extern GSList *rules; diff --git a/src/settings.h b/src/settings.h index 80d84927c..d819834fd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,7 +14,7 @@ #define LIST_END (-1) enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; -enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_OFF }; +enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_TOP, ICON_OFF }; enum vertical_alignment { VERTICAL_TOP, VERTICAL_CENTER, VERTICAL_BOTTOM }; enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; diff --git a/src/settings_data.h b/src/settings_data.h index 43becefd1..a9e3c30b9 100644 --- a/src/settings_data.h +++ b/src/settings_data.h @@ -112,6 +112,7 @@ static const struct rule empty_rule = { .history_ignore = -1, .match_transient = -1, .set_transient = -1, + .icon_position = -1, .set_icon_size = -1, .skip_display = -1, .word_wrap = -1, @@ -212,6 +213,7 @@ static const struct string_to_enum_def fullscreen_enum_data[] = { static const struct string_to_enum_def icon_position_enum_data[] = { {"left", ICON_LEFT }, {"right", ICON_RIGHT }, + {"top", ICON_TOP }, {"off", ICON_OFF }, ENUM_END, }; @@ -619,6 +621,17 @@ static const struct setting allowed_settings[] = { .parser_data = markup_mode_enum_data, .rule_offset = offsetof(struct rule, markup), }, + { + .name = "icon_position", + .section = "*", + .description = "Align icons left/right/top/off", + .type = TYPE_CUSTOM, + .default_value = "*", + .value = NULL, + .parser = string_parse_enum, + .parser_data = icon_position_enum_data, + .rule_offset = offsetof(struct rule, icon_position), + }, { .name = "icon_size", .section = "*", @@ -1049,7 +1062,7 @@ static const struct setting allowed_settings[] = { { .name = "icon_position", .section = "global", - .description = "Align icons left/right/off", + .description = "Default icon alignment (left/right/top/off)", .type = TYPE_CUSTOM, .default_value = "left", .value = &settings.icon_position, From 7f9db5ad1e447567d0cd757a14542f49da28b551 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 9 Jan 2022 00:53:42 -0700 Subject: [PATCH 02/21] support ICON_TOP initial implementation --- src/draw.c | 58 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/draw.c b/src/draw.c index a4a1b5612..77028ecf8 100644 --- a/src/draw.c +++ b/src/draw.c @@ -167,7 +167,7 @@ static struct color layout_get_sepcolor(struct colored_layout *cl, } } -static int get_text_icon_padding() +static int get_horizontal_text_icon_padding() { if (settings.text_icon_padding) { return settings.text_icon_padding; @@ -176,6 +176,15 @@ static int get_text_icon_padding() } } +static int get_vertical_text_icon_padding() +{ + if (settings.text_icon_padding) { + return settings.text_icon_padding; + } else { + return settings.padding; + } +} + static bool have_progress_bar(const struct colored_layout *cl) { return (cl->n->progress >= 0 && settings.progress_bar == true && @@ -220,8 +229,8 @@ static void layout_setup_pango(PangoLayout *layout, int width, int height, // @param height Height of the layout static void layout_setup(struct colored_layout *cl, int width, int height, double scale) { - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_text_icon_padding() : 0; - int text_width = width - icon_width - 2 * settings.h_padding; + int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; + int text_width = width - 2 * settings.h_padding - (cl->n->icon_position != ICON_TOP ? icon_width : 0); int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; int max_text_height = MAX(0, settings.height - progress_bar_height - 2 * settings.padding); layout_setup_pango(cl->l, text_width, max_text_height, cl->n->word_wrap, cl->n->ellipsize, cl->n->alignment); @@ -242,12 +251,18 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout struct dimensions dim = { 0 }; layout_setup(cl, settings.width.max, settings.height, scale); - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_text_icon_padding() : 0; + int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; int icon_height = cl->icon? get_icon_height(cl->icon, scale) : 0; int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); - dim.h = MAX(icon_height, dim.text_height); + if (cl->n->icon_position == ICON_TOP && cl->n->icon) { + // dim.h = icon_height + dim.text_height + settings.padding*2 + get_vertical_text_icon_padding(); + dim.h = icon_height + dim.text_height + get_vertical_text_icon_padding(); + } else { + dim.h = MAX(icon_height, dim.text_height); + } + dim.h += progress_bar_height; dim.w = dim.text_width + icon_width + 2 * settings.h_padding; @@ -335,7 +350,7 @@ static struct colored_layout *layout_from_notification(cairo_t *c, struct notifi struct colored_layout *cl = layout_init_shared(c, n); - if (settings.icon_position != ICON_OFF && n->icon) { + if (n->icon_position != ICON_OFF && n->icon) { cl->icon = n->icon; } else { cl->icon = NULL; @@ -399,17 +414,22 @@ static GSList *create_layouts(cairo_t *c) static int layout_get_height(struct colored_layout *cl, double scale) { - int h; + int h_text; int h_icon = 0; int h_progress_bar = 0; - get_text_size(cl->l, NULL, &h, scale); + get_text_size(cl->l, NULL, &h_text, scale); if (cl->icon) h_icon = get_icon_height(cl->icon, scale); if (have_progress_bar(cl)){ h_progress_bar = settings.progress_bar_height + settings.padding; } - int res = MAX(h, h_icon) + h_progress_bar; + int res = MAX(h_text, h_icon) + h_progress_bar; + + if (cl->n->icon_position == ICON_TOP && cl->n->icon) { + res = h_icon + h_text + h_progress_bar + get_vertical_text_icon_padding(); + } + return res; } @@ -594,9 +614,10 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou const int h = layout_get_height(cl, scale); LOG_D("Layout height %i", h); int h_without_progress_bar = h; - if (have_progress_bar(cl)){ + if (have_progress_bar(cl)) { h_without_progress_bar -= settings.progress_bar_height + settings.padding; } + int h_text; get_text_size(cl->l, NULL, &h_text, scale); @@ -615,8 +636,10 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou } // else VERTICAL_CENTER // icon position - if (settings.icon_position == ICON_LEFT) { - text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_text_icon_padding(); + if (cl->n->icon_position == ICON_LEFT) { + text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding(); + } else if (cl->n->icon_position == ICON_TOP) { + text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding(); } // else ICON_RIGHT } cairo_move_to(c, round(text_x * scale), round(text_y * scale)); @@ -643,8 +666,13 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou } // else VERTICAL_CENTER // icon position - if (settings.icon_position == ICON_LEFT) { + if (cl->n->icon_position == ICON_LEFT) { image_x = settings.h_padding; + } else if (cl->n->icon_position == ICON_TOP) { + image_y = settings.padding; + image_x = width/2 - image_width/2; + // image_x = settings.h_padding + image_width/2; + // image_x = image_width/2; } // else ICON_RIGHT cairo_set_source_surface(c, cl->icon, round(image_x * scale), round(image_y * scale)); @@ -701,11 +729,13 @@ static struct dimensions layout_render(cairo_surface_t *srf, bool last) { double scale = output->get_scale(); - const int cl_h = layout_get_height(cl, scale); int h_text = 0; get_text_size(cl->l, NULL, &h_text, scale); + const int cl_h = layout_get_height(cl, scale); + + int bg_width = 0; int bg_height = MIN(settings.height, (2 * settings.padding) + cl_h); From 39a7d1c20294ab6eac3c214fe970babb013fe65d Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 9 Jan 2022 23:48:30 -0700 Subject: [PATCH 03/21] center progress bar --- src/draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/draw.c b/src/draw.c index 77028ecf8..fd041bfc1 100644 --- a/src/draw.c +++ b/src/draw.c @@ -686,7 +686,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou unsigned int frame_width = settings.progress_bar_frame_width, progress_width = MIN(width - 2 * settings.h_padding, settings.progress_bar_max_width), progress_height = settings.progress_bar_height - frame_width, - frame_x = settings.h_padding, + frame_x = width/2 - progress_width/2, frame_y = settings.padding + h - settings.progress_bar_height, progress_width_without_frame = progress_width - 2 * frame_width, progress_width_1 = progress_width_without_frame * progress / 100, From 4357000d29abeab29d444d23eb14fc95f016e946 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Fri, 14 Jan 2022 21:10:21 -0700 Subject: [PATCH 04/21] remove commented lines --- src/draw.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/draw.c b/src/draw.c index fd041bfc1..746a340e6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -671,8 +671,6 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou } else if (cl->n->icon_position == ICON_TOP) { image_y = settings.padding; image_x = width/2 - image_width/2; - // image_x = settings.h_padding + image_width/2; - // image_x = image_width/2; } // else ICON_RIGHT cairo_set_source_surface(c, cl->icon, round(image_x * scale), round(image_y * scale)); From 46c691ea8021c5a5ea839f5dbee55bb1ed4c4fe9 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sat, 15 Jan 2022 13:23:18 -0700 Subject: [PATCH 05/21] add hide_text notification rule and documentation --- docs/dunst.5.pod | 7 +++++++ dunstrc | 2 ++ src/notification.c | 1 + src/notification.h | 1 + src/rules.c | 2 ++ src/rules.h | 1 + src/settings_data.h | 12 ++++++++++++ 7 files changed, 26 insertions(+) diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index a34395a2b..db81bd200 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -884,6 +884,13 @@ Specifies where truncated lines should be ellipsized. Defines how the text should be aligned within the notification. +=item B (values: [true/false], default: false) + +Setting this to true will skip displaying any text related to the notification. +The notification icon and progress bar will still be displayed. This option may +be useful for notifications where an icon or progress bar may be sufficient +information for the notification, such as audio volume or brightness level. + =item B (values: [full/strip/no], default: no) Defines how markup in notifications is handled. diff --git a/dunstrc b/dunstrc index 2fb4632c8..a05eee95b 100644 --- a/dunstrc +++ b/dunstrc @@ -339,12 +339,14 @@ # set_category # timeout # urgency +# icon_position # skip_display # history_ignore # action_name # word_wrap # ellipsize # alignment +# hide_text # # Shell-like globbing will get expanded. # diff --git a/src/notification.c b/src/notification.c index d0cc85cdf..96e51fd17 100644 --- a/src/notification.c +++ b/src/notification.c @@ -417,6 +417,7 @@ struct notification *notification_create(void) n->word_wrap = true; n->ellipsize = PANGO_ELLIPSIZE_MIDDLE; n->alignment = PANGO_ALIGN_LEFT; + n->hide_text = false; n->icon_position = (int)settings.icon_position; n->icon_size = 32; diff --git a/src/notification.h b/src/notification.h index 19ae29ca9..47336f999 100644 --- a/src/notification.h +++ b/src/notification.h @@ -93,6 +93,7 @@ struct notification { bool word_wrap; PangoEllipsizeMode ellipsize; PangoAlignment alignment; + bool hide_text; /* derived fields */ char *msg; /**< formatted message */ diff --git a/src/rules.c b/src/rules.c index d4176397b..c8306bd40 100644 --- a/src/rules.c +++ b/src/rules.c @@ -36,6 +36,8 @@ void rule_apply(struct rule *r, struct notification *n) n->ellipsize = r->ellipsize; if (r->alignment != -1) n->alignment = r->alignment; + if (r->hide_text != -1) + n->hide_text = r->hide_text; if (r->action_name) { g_free(n->default_action_name); n->default_action_name = g_strdup(r->action_name); diff --git a/src/rules.h b/src/rules.h index 148331356..9a5f87f61 100644 --- a/src/rules.h +++ b/src/rules.h @@ -39,6 +39,7 @@ struct rule { int word_wrap; int ellipsize; int alignment; + int hide_text; int icon_position; int set_icon_size; char *new_icon; diff --git a/src/settings_data.h b/src/settings_data.h index a9e3c30b9..2d0bd9b77 100644 --- a/src/settings_data.h +++ b/src/settings_data.h @@ -118,6 +118,7 @@ static const struct rule empty_rule = { .word_wrap = -1, .ellipsize = -1, .alignment = -1, + .hide_text = -1, .new_icon = NULL, .fg = NULL, .bg = NULL, @@ -610,6 +611,17 @@ static const struct setting allowed_settings[] = { .parser_data = horizontal_alignment_enum_data, .rule_offset = offsetof(struct rule, alignment), }, + { + .name = "hide_text", + .section = "*", + .description = "Skip rendering summary and body text in notification window (keeps icon and progress bar)", + .type = TYPE_CUSTOM, + .default_value = "*", + .value = NULL, + .parser = string_parse_enum, + .parser_data = boolean_enum_data, + .rule_offset = offsetof(struct rule, hide_text), + }, { .name = "markup", .section = "*", From 7d5f46503a4c641abe6e1cfabfd1e4a736e8ba68 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sat, 15 Jan 2022 13:24:33 -0700 Subject: [PATCH 06/21] change icon_position to enum in notification struct --- src/notification.h | 9 ++++++++- src/settings.h | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/notification.h b/src/notification.h index 47336f999..e5f2af81f 100644 --- a/src/notification.h +++ b/src/notification.h @@ -11,6 +11,13 @@ #define DUNST_NOTIF_MAX_CHARS 50000 +enum icon_position { + ICON_LEFT, + ICON_RIGHT, + ICON_TOP, + ICON_OFF +}; + enum behavior_fullscreen { FS_NULL, //!< Invalid value FS_DELAY, //!< Delay the notification until leaving fullscreen mode @@ -58,7 +65,7 @@ struct notification { char *icon_path; /**< Full path to the notification's icon. */ char *default_icon_name; /**< The icon that is used when no other icon is available. */ int icon_size; /**< Size of the icon used for searching the right icon. */ - int icon_position; /**< Icon position (enum left,right,top,off). */ + enum icon_position icon_position; /**< Icon position (enum left,right,top,off). */ gint64 start; /**< begin of current display (in milliseconds) */ gint64 timestamp; /**< arrival time (in milliseconds) */ diff --git a/src/settings.h b/src/settings.h index d819834fd..b91e9da1b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -14,7 +14,6 @@ #define LIST_END (-1) enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; -enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_TOP, ICON_OFF }; enum vertical_alignment { VERTICAL_TOP, VERTICAL_CENTER, VERTICAL_BOTTOM }; enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; From bc91854950be3e2355bfc937ae611c55d294e5ee Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sat, 15 Jan 2022 13:25:50 -0700 Subject: [PATCH 07/21] implement hide_text compatibily with icon_position --- src/draw.c | 79 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/src/draw.c b/src/draw.c index 746a340e6..2024d97eb 100644 --- a/src/draw.c +++ b/src/draw.c @@ -254,11 +254,19 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; int icon_height = cl->icon? get_icon_height(cl->icon, scale) : 0; int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; - get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); + + int vertical_padding; + if (!cl->n->hide_text) { + get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); + vertical_padding = get_vertical_text_icon_padding(); + } else { + vertical_padding = 0; + dim.text_width = 0; + dim.text_height = 0; + } if (cl->n->icon_position == ICON_TOP && cl->n->icon) { - // dim.h = icon_height + dim.text_height + settings.padding*2 + get_vertical_text_icon_padding(); - dim.h = icon_height + dim.text_height + get_vertical_text_icon_padding(); + dim.h = icon_height + dim.text_height + vertical_padding; } else { dim.h = MAX(icon_height, dim.text_height); } @@ -414,10 +422,18 @@ static GSList *create_layouts(cairo_t *c) static int layout_get_height(struct colored_layout *cl, double scale) { - int h_text; + int h_text = 0; int h_icon = 0; int h_progress_bar = 0; - get_text_size(cl->l, NULL, &h_text, scale); + + int vertical_padding; + if (!cl->n->hide_text) { + get_text_size(cl->l, NULL, &h_text, scale); + vertical_padding = get_vertical_text_icon_padding(); + } else { + vertical_padding = 0; + } + if (cl->icon) h_icon = get_icon_height(cl->icon, scale); if (have_progress_bar(cl)){ @@ -427,7 +443,7 @@ static int layout_get_height(struct colored_layout *cl, double scale) int res = MAX(h_text, h_icon) + h_progress_bar; if (cl->n->icon_position == ICON_TOP && cl->n->icon) { - res = h_icon + h_text + h_progress_bar + get_vertical_text_icon_padding(); + res = h_icon + h_text + h_progress_bar + vertical_padding; } return res; @@ -618,36 +634,37 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou h_without_progress_bar -= settings.progress_bar_height + settings.padding; } - int h_text; - get_text_size(cl->l, NULL, &h_text, scale); + if (!cl->n->hide_text) { + int h_text = 0; + get_text_size(cl->l, NULL, &h_text, scale); - int text_x = settings.h_padding, - text_y = settings.padding + h_without_progress_bar / 2 - h_text / 2; + int text_x = settings.h_padding, + text_y = settings.padding + h_without_progress_bar / 2 - h_text / 2; - // text positioning - if (cl->icon) { - // vertical alignment - if (settings.vertical_alignment == VERTICAL_TOP) { - text_y = settings.padding; - } else if (settings.vertical_alignment == VERTICAL_BOTTOM) { - text_y = h_without_progress_bar + settings.padding - h_text; - if (text_y < 0) + // text positioning + if (cl->icon) { + // vertical alignment + if (settings.vertical_alignment == VERTICAL_TOP) { text_y = settings.padding; - } // else VERTICAL_CENTER + } else if (settings.vertical_alignment == VERTICAL_BOTTOM) { + text_y = h_without_progress_bar + settings.padding - h_text; + if (text_y < 0) + text_y = settings.padding; + } // else VERTICAL_CENTER + + // icon position + if (cl->n->icon_position == ICON_LEFT) { + text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding(); + } else if (cl->n->icon_position == ICON_TOP) { + text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding(); + } // else ICON_RIGHT + } + cairo_move_to(c, round(text_x * scale), round(text_y * scale)); - // icon position - if (cl->n->icon_position == ICON_LEFT) { - text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding(); - } else if (cl->n->icon_position == ICON_TOP) { - text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding(); - } // else ICON_RIGHT + cairo_set_source_rgba(c, cl->fg.r, cl->fg.g, cl->fg.b, cl->fg.a); + pango_cairo_update_layout(c, cl->l); + pango_cairo_show_layout(c, cl->l); } - cairo_move_to(c, round(text_x * scale), round(text_y * scale)); - - cairo_set_source_rgba(c, cl->fg.r, cl->fg.g, cl->fg.b, cl->fg.a); - pango_cairo_update_layout(c, cl->l); - pango_cairo_show_layout(c, cl->l); - // icon positioning if (cl->icon) { From 0e388bb99b739b720799f371a190515747d50db7 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 02:36:40 -0700 Subject: [PATCH 08/21] add test for icon_position & hide_text --- test/functional-tests/dunstrc.hide_text | 26 ++++++++++++++++++++ test/functional-tests/dunstrc.icon_position | 27 +++++++++++++++++++++ test/functional-tests/test.sh | 23 ++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 test/functional-tests/dunstrc.hide_text create mode 100644 test/functional-tests/dunstrc.icon_position diff --git a/test/functional-tests/dunstrc.hide_text b/test/functional-tests/dunstrc.hide_text new file mode 100644 index 000000000..ceee8e28b --- /dev/null +++ b/test/functional-tests/dunstrc.hide_text @@ -0,0 +1,26 @@ +[urgency_low] + background = "#222222" + foreground = "#888888" + timeout = 10 + hide_text = yes + +[urgency_normal] + background = "#285577" + foreground = "#ffffff" + timeout = 10 + +[urgency_critical] + background = "#900000" + foreground = "#ffffff" + timeout = 0 + +[global] + font = Monospace 8 + allow_markup = yes + format = "%s\n%b" + geometry = "0x5-30+20" + icon_position = left + progress_bar_min_width = 100 + progress_bar_max_width = 200 + progress_bar_frame_width = 5 + progress_bar_height = 30 diff --git a/test/functional-tests/dunstrc.icon_position b/test/functional-tests/dunstrc.icon_position new file mode 100644 index 000000000..322229717 --- /dev/null +++ b/test/functional-tests/dunstrc.icon_position @@ -0,0 +1,27 @@ +[urgency_low] + background = "#222222" + foreground = "#888888" + timeout = 10 + alignment = left + +[urgency_normal] + background = "#285577" + foreground = "#ffffff" + timeout = 10 + alignment = center + +[urgency_critical] + background = "#900000" + foreground = "#ffffff" + timeout = 0 + alignment = right + +[global] + font = Monospace 8 + allow_markup = yes + format = "%s\n%b" + geometry = "0x5-30+20" + progress_bar_min_width = 100 + progress_bar_max_width = 200 + progress_bar_frame_width = 5 + progress_bar_height = 30 diff --git a/test/functional-tests/test.sh b/test/functional-tests/test.sh index 4f75c553b..3d3fb87df 100755 --- a/test/functional-tests/test.sh +++ b/test/functional-tests/test.sh @@ -188,6 +188,27 @@ function progress_bar { keypress } +function icon_position { + for position in left top right off; do + tmp_dunstrc dunstrc.icon_position "icon_position = $position" + start_dunst dunstrc.tmp + for urgency in l n c; do + ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u $urgency "icon_position = $position" + done + rm dunstrc.tmp + keypress + done +} + +function hide_text { + start_dunst dunstrc.hide_text + ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u n "text not hidden" "You should be able to read me!\nThe next notifications should not have any text." + ../../dunstify -a "dunst tester" -u l "text hidden" "If you can read me then hide_text is not working." + ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u l "text hidden + icon" "If you can read me then hide_text is not working." + ../../dunstify -a "dunst tester" -h int:value:$((RANDOM%100)) -I '../data/icons/valid.png' -u l "text hidden + icon + progress bar" "If you can read me then hide_text is not working." + keypress +} + if [ -n "$1" ]; then while [ -n "$1" ]; do $1 @@ -204,6 +225,8 @@ else replace markup progress_bar + icon_position + hide_text fi killall dunst From 5ef58f68237039de13333e696e8ca3597612aa06 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 02:52:08 -0700 Subject: [PATCH 09/21] minor formatting --- src/draw.c | 4 +--- src/notification.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/draw.c b/src/draw.c index 2024d97eb..c1019239c 100644 --- a/src/draw.c +++ b/src/draw.c @@ -744,13 +744,11 @@ static struct dimensions layout_render(cairo_surface_t *srf, bool last) { double scale = output->get_scale(); + const int cl_h = layout_get_height(cl, scale); int h_text = 0; get_text_size(cl->l, NULL, &h_text, scale); - const int cl_h = layout_get_height(cl, scale); - - int bg_width = 0; int bg_height = MIN(settings.height, (2 * settings.padding) + cl_h); diff --git a/src/notification.c b/src/notification.c index 96e51fd17..690b342d3 100644 --- a/src/notification.c +++ b/src/notification.c @@ -418,7 +418,7 @@ struct notification *notification_create(void) n->ellipsize = PANGO_ELLIPSIZE_MIDDLE; n->alignment = PANGO_ALIGN_LEFT; n->hide_text = false; - n->icon_position = (int)settings.icon_position; + n->icon_position = settings.icon_position; n->icon_size = 32; n->script_run = false; From cfada4261f8883e849411c1a87959ac1d416df5b Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 12:13:35 -0700 Subject: [PATCH 10/21] simplify hide_text boolean checks --- src/draw.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/draw.c b/src/draw.c index c1019239c..f2d4ba4fa 100644 --- a/src/draw.c +++ b/src/draw.c @@ -256,13 +256,13 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; int vertical_padding; - if (!cl->n->hide_text) { - get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); - vertical_padding = get_vertical_text_icon_padding(); - } else { + if (cl->n->hide_text) { vertical_padding = 0; dim.text_width = 0; dim.text_height = 0; + } else { + get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); + vertical_padding = get_vertical_text_icon_padding(); } if (cl->n->icon_position == ICON_TOP && cl->n->icon) { @@ -427,11 +427,11 @@ static int layout_get_height(struct colored_layout *cl, double scale) int h_progress_bar = 0; int vertical_padding; - if (!cl->n->hide_text) { + if (cl->n->hide_text) { + vertical_padding = 0; + } else { get_text_size(cl->l, NULL, &h_text, scale); vertical_padding = get_vertical_text_icon_padding(); - } else { - vertical_padding = 0; } if (cl->icon) From 87a8b605b1d51f65afbb292c8ee18eedd51696df Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 12:53:29 -0700 Subject: [PATCH 11/21] simplify ternary width check --- src/draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/draw.c b/src/draw.c index f2d4ba4fa..dc5abc422 100644 --- a/src/draw.c +++ b/src/draw.c @@ -230,7 +230,7 @@ static void layout_setup_pango(PangoLayout *layout, int width, int height, static void layout_setup(struct colored_layout *cl, int width, int height, double scale) { int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; - int text_width = width - 2 * settings.h_padding - (cl->n->icon_position != ICON_TOP ? icon_width : 0); + int text_width = width - 2 * settings.h_padding - (cl->n->icon_position == ICON_TOP ? 0 : icon_width); int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; int max_text_height = MAX(0, settings.height - progress_bar_height - 2 * settings.padding); layout_setup_pango(cl->l, text_width, max_text_height, cl->n->word_wrap, cl->n->ellipsize, cl->n->alignment); From db460c7e103697efce13832ab85892f1208d2ab5 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 12:59:46 -0700 Subject: [PATCH 12/21] remove unintentional newline --- src/rules.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rules.h b/src/rules.h index 9a5f87f61..15cd2e9f9 100644 --- a/src/rules.h +++ b/src/rules.h @@ -54,7 +54,6 @@ struct rule { enum behavior_fullscreen fullscreen; char *set_stack_tag; // this has to be the last action bool enabled; - }; extern GSList *rules; From 1c1e89b3682a171a1236d192014096bb943d02d1 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:37:42 -0700 Subject: [PATCH 13/21] remove icon_position global setting change icon_position rule defaults to enum off change tests to not read icon_position from settings --- src/notification.c | 4 ++-- src/rules.c | 2 +- src/settings.h | 1 - src/settings_data.h | 12 +----------- test/draw.c | 6 +++--- test/notification.c | 12 +++++++----- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/notification.c b/src/notification.c index 690b342d3..000cfe557 100644 --- a/src/notification.c +++ b/src/notification.c @@ -216,7 +216,7 @@ bool notification_is_duplicate(const struct notification *a, const struct notifi return STR_EQ(a->appname, b->appname) && STR_EQ(a->summary, b->summary) && STR_EQ(a->body, b->body) - && (settings.icon_position != ICON_OFF ? STR_EQ(a->icon_id, b->icon_id) : 1) + && (a->icon_position != ICON_OFF ? STR_EQ(a->icon_id, b->icon_id) : 1) && a->urgency == b->urgency; } @@ -418,7 +418,7 @@ struct notification *notification_create(void) n->ellipsize = PANGO_ELLIPSIZE_MIDDLE; n->alignment = PANGO_ALIGN_LEFT; n->hide_text = false; - n->icon_position = settings.icon_position; + n->icon_position = ICON_OFF; n->icon_size = 32; n->script_run = false; diff --git a/src/rules.c b/src/rules.c index c8306bd40..ab0bb73ea 100644 --- a/src/rules.c +++ b/src/rules.c @@ -48,7 +48,7 @@ void rule_apply(struct rule *r, struct notification *n) } if (r->markup != MARKUP_NULL) n->markup = r->markup; - if (r->icon_position != -1) + if (r->icon_position != ICON_OFF) n->icon_position = r->icon_position; if (r->set_icon_size > 0) n->icon_size = r->set_icon_size; diff --git a/src/settings.h b/src/settings.h index b91e9da1b..c668f395a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -126,7 +126,6 @@ struct settings { char **dmenu_cmd; char *browser; char **browser_cmd; - enum icon_position icon_position; enum vertical_alignment vertical_alignment; int min_icon_size; int max_icon_size; diff --git a/src/settings_data.h b/src/settings_data.h index 2d0bd9b77..1446786cb 100644 --- a/src/settings_data.h +++ b/src/settings_data.h @@ -112,7 +112,7 @@ static const struct rule empty_rule = { .history_ignore = -1, .match_transient = -1, .set_transient = -1, - .icon_position = -1, + .icon_position = ICON_OFF, .set_icon_size = -1, .skip_display = -1, .word_wrap = -1, @@ -1071,16 +1071,6 @@ static const struct setting allowed_settings[] = { .parser = string_parse_sepcolor, .parser_data = sep_color_enum_data, }, - { - .name = "icon_position", - .section = "global", - .description = "Default icon alignment (left/right/top/off)", - .type = TYPE_CUSTOM, - .default_value = "left", - .value = &settings.icon_position, - .parser = string_parse_enum, - .parser_data = icon_position_enum_data, - }, { .name = "vertical_alignment", .section = "global", diff --git a/test/draw.c b/test/draw.c index 81034fcc8..103159588 100644 --- a/test/draw.c +++ b/test/draw.c @@ -33,8 +33,8 @@ const struct output dummy_output = { TEST test_layout_from_notification(void) { - settings.icon_position = ICON_LEFT; struct notification *n = test_notification_with_icon("test", 10); + n->icon_position = ICON_LEFT; ASSERT(n->icon); n->text_to_render = g_strdup(""); struct colored_layout *cl = layout_from_notification(c, n); @@ -46,8 +46,8 @@ TEST test_layout_from_notification(void) TEST test_layout_from_notification_icon_off(void) { - settings.icon_position = ICON_OFF; struct notification *n = test_notification_with_icon("test", 10); + n->icon_position = ICON_OFF; ASSERT(n->icon); n->text_to_render = g_strdup(""); struct colored_layout *cl = layout_from_notification(c, n); @@ -59,8 +59,8 @@ TEST test_layout_from_notification_icon_off(void) TEST test_layout_from_notification_no_icon(void) { - settings.icon_position = ICON_LEFT; struct notification *n = test_notification("test", 10); + n->icon_position = ICON_LEFT; ASSERT_FALSE(n->icon); n->text_to_render = g_strdup(""); struct colored_layout *cl = layout_from_notification(c, n); diff --git a/test/notification.c b/test/notification.c index 5d4f4c254..b4c955752 100644 --- a/test/notification.c +++ b/test/notification.c @@ -48,9 +48,9 @@ TEST test_notification_is_duplicate(void) ASSERTm("One of the notifications got corrupted during test", notification_is_duplicate(a, b)); - enum icon_position icon_setting_tmp = settings.icon_position; + enum icon_position icon_setting_tmp = a->icon_position; - settings.icon_position = ICON_OFF; + a->icon_position = ICON_OFF; ASSERT(notification_is_duplicate(a, b)); //Setting pointer to a random value since we are checking for null char *icon_id = b->icon_id; @@ -59,13 +59,15 @@ TEST test_notification_is_duplicate(void) notification_is_duplicate(a, b)); b->icon_id = icon_id; - settings.icon_position = ICON_LEFT; + a->icon_position = ICON_LEFT; + b->icon_position = ICON_LEFT; CHECK_CALL(test_notification_is_duplicate_field(&(b->icon_id), a, b)); - settings.icon_position = ICON_RIGHT; + a->icon_position = ICON_RIGHT; + b->icon_position = ICON_RIGHT; CHECK_CALL(test_notification_is_duplicate_field(&(b->icon_id), a, b)); - settings.icon_position = icon_setting_tmp; + a->icon_position = icon_setting_tmp; ASSERT(notification_is_duplicate(a, b)); From 20d2ffee207b8572349570c76869067920935a9f Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 21:55:59 -0700 Subject: [PATCH 14/21] use default icons for icon_position & hide_text tests --- test/functional-tests/dunstrc.hide_text | 8 +++++--- test/functional-tests/dunstrc.icon_position | 4 ++-- test/functional-tests/test.sh | 14 ++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/test/functional-tests/dunstrc.hide_text b/test/functional-tests/dunstrc.hide_text index ceee8e28b..87cc5e5ca 100644 --- a/test/functional-tests/dunstrc.hide_text +++ b/test/functional-tests/dunstrc.hide_text @@ -8,6 +8,8 @@ background = "#285577" foreground = "#ffffff" timeout = 10 + icon_position = top + hide_text = yes [urgency_critical] background = "#900000" @@ -16,11 +18,11 @@ [global] font = Monospace 8 - allow_markup = yes + markup = full format = "%s\n%b" - geometry = "0x5-30+20" - icon_position = left + icon_position = off progress_bar_min_width = 100 progress_bar_max_width = 200 progress_bar_frame_width = 5 progress_bar_height = 30 + icon_path = /usr/share/icons/Papirus/24x24/status/:/usr/share/icons/Papirus/24x24/devices/:/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/ \ No newline at end of file diff --git a/test/functional-tests/dunstrc.icon_position b/test/functional-tests/dunstrc.icon_position index 322229717..77c32d088 100644 --- a/test/functional-tests/dunstrc.icon_position +++ b/test/functional-tests/dunstrc.icon_position @@ -18,10 +18,10 @@ [global] font = Monospace 8 - allow_markup = yes + markup = full format = "%s\n%b" - geometry = "0x5-30+20" progress_bar_min_width = 100 progress_bar_max_width = 200 progress_bar_frame_width = 5 progress_bar_height = 30 + icon_path = /usr/share/icons/Papirus/24x24/status/:/usr/share/icons/Papirus/24x24/devices/:/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/ \ No newline at end of file diff --git a/test/functional-tests/test.sh b/test/functional-tests/test.sh index 3d3fb87df..18807de1e 100755 --- a/test/functional-tests/test.sh +++ b/test/functional-tests/test.sh @@ -190,10 +190,10 @@ function progress_bar { function icon_position { for position in left top right off; do - tmp_dunstrc dunstrc.icon_position "icon_position = $position" + tmp_dunstrc dunstrc.icon_position "icon_position = $position" # use default icon theme start_dunst dunstrc.tmp for urgency in l n c; do - ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u $urgency "icon_position = $position" + ../../dunstify -a "dunst tester" -u $urgency "icon_position = $position" done rm dunstrc.tmp keypress @@ -202,10 +202,12 @@ function icon_position { function hide_text { start_dunst dunstrc.hide_text - ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u n "text not hidden" "You should be able to read me!\nThe next notifications should not have any text." - ../../dunstify -a "dunst tester" -u l "text hidden" "If you can read me then hide_text is not working." - ../../dunstify -a "dunst tester" -I '../data/icons/valid.png' -u l "text hidden + icon" "If you can read me then hide_text is not working." - ../../dunstify -a "dunst tester" -h int:value:$((RANDOM%100)) -I '../data/icons/valid.png' -u l "text hidden + icon + progress bar" "If you can read me then hide_text is not working." + ../../dunstify -a "dunst tester" -u c "text not hidden" "You should be able to read me!\nThe next notifications should not have any text." + local hidden_body="If you can read me then hide_text is not working." + ../../dunstify -a "dunst tester" -u l "text hidden" "$hidden_body" + ../../dunstify -a "dunst tester" -h int:value:$((RANDOM%100)) -u l "text hidden + progress bar" "$hidden_body" + ../../dunstify -a "dunst tester" -u n "text hidden + icon" "$hidden_body" + ../../dunstify -a "dunst tester" -h int:value:$((RANDOM%100)) -u n "text hidden + icon + progress bar" "$hidden_body" keypress } From 4bdf2aba4179e74c7470c5ee5eb639bb5e0c1854 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 23:44:28 -0700 Subject: [PATCH 15/21] use text_icon_padding when icon_position == ICON_TOP --- src/draw.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/draw.c b/src/draw.c index dc5abc422..e513daf5f 100644 --- a/src/draw.c +++ b/src/draw.c @@ -167,24 +167,6 @@ static struct color layout_get_sepcolor(struct colored_layout *cl, } } -static int get_horizontal_text_icon_padding() -{ - if (settings.text_icon_padding) { - return settings.text_icon_padding; - } else { - return settings.h_padding; - } -} - -static int get_vertical_text_icon_padding() -{ - if (settings.text_icon_padding) { - return settings.text_icon_padding; - } else { - return settings.padding; - } -} - static bool have_progress_bar(const struct colored_layout *cl) { return (cl->n->progress >= 0 && settings.progress_bar == true && @@ -229,7 +211,7 @@ static void layout_setup_pango(PangoLayout *layout, int width, int height, // @param height Height of the layout static void layout_setup(struct colored_layout *cl, int width, int height, double scale) { - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; + int icon_width = cl->icon? get_icon_width(cl->icon, scale) + settings.h_padding : 0; int text_width = width - 2 * settings.h_padding - (cl->n->icon_position == ICON_TOP ? 0 : icon_width); int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; int max_text_height = MAX(0, settings.height - progress_bar_height - 2 * settings.padding); @@ -251,7 +233,7 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout struct dimensions dim = { 0 }; layout_setup(cl, settings.width.max, settings.height, scale); - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0; + int icon_width = cl->icon? get_icon_width(cl->icon, scale) + settings.h_padding : 0; int icon_height = cl->icon? get_icon_height(cl->icon, scale) : 0; int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; @@ -262,7 +244,7 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout dim.text_height = 0; } else { get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); - vertical_padding = get_vertical_text_icon_padding(); + vertical_padding = settings.text_icon_padding; } if (cl->n->icon_position == ICON_TOP && cl->n->icon) { @@ -431,12 +413,13 @@ static int layout_get_height(struct colored_layout *cl, double scale) vertical_padding = 0; } else { get_text_size(cl->l, NULL, &h_text, scale); - vertical_padding = get_vertical_text_icon_padding(); + vertical_padding = settings.text_icon_padding; } if (cl->icon) h_icon = get_icon_height(cl->icon, scale); - if (have_progress_bar(cl)){ + + if (have_progress_bar(cl)) { h_progress_bar = settings.progress_bar_height + settings.padding; } @@ -654,9 +637,9 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou // icon position if (cl->n->icon_position == ICON_LEFT) { - text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding(); + text_x = get_icon_width(cl->icon, scale) + settings.h_padding * 2; } else if (cl->n->icon_position == ICON_TOP) { - text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding(); + text_y = get_icon_height(cl->icon, scale) + settings.padding + settings.text_icon_padding; } // else ICON_RIGHT } cairo_move_to(c, round(text_x * scale), round(text_y * scale)); From cf3393e1b38e0a6fdf3d5e95d93e450ed027e653 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 23:45:20 -0700 Subject: [PATCH 16/21] undo enum init leading to incorrect default overriding --- src/rules.c | 2 +- src/settings_data.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rules.c b/src/rules.c index ab0bb73ea..c8306bd40 100644 --- a/src/rules.c +++ b/src/rules.c @@ -48,7 +48,7 @@ void rule_apply(struct rule *r, struct notification *n) } if (r->markup != MARKUP_NULL) n->markup = r->markup; - if (r->icon_position != ICON_OFF) + if (r->icon_position != -1) n->icon_position = r->icon_position; if (r->set_icon_size > 0) n->icon_size = r->set_icon_size; diff --git a/src/settings_data.h b/src/settings_data.h index 1446786cb..7dedb85da 100644 --- a/src/settings_data.h +++ b/src/settings_data.h @@ -112,7 +112,7 @@ static const struct rule empty_rule = { .history_ignore = -1, .match_transient = -1, .set_transient = -1, - .icon_position = ICON_OFF, + .icon_position = -1, .set_icon_size = -1, .skip_display = -1, .word_wrap = -1, From 80a7e280d62228ff68bcb668240628818c08b09d Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Sun, 16 Jan 2022 23:46:03 -0700 Subject: [PATCH 17/21] fix config with incorrect enum init default values --- test/functional-tests/dunstrc.hide_text | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional-tests/dunstrc.hide_text b/test/functional-tests/dunstrc.hide_text index 87cc5e5ca..1340983cf 100644 --- a/test/functional-tests/dunstrc.hide_text +++ b/test/functional-tests/dunstrc.hide_text @@ -2,6 +2,7 @@ background = "#222222" foreground = "#888888" timeout = 10 + icon_position = top hide_text = yes [urgency_normal] @@ -20,7 +21,6 @@ font = Monospace 8 markup = full format = "%s\n%b" - icon_position = off progress_bar_min_width = 100 progress_bar_max_width = 200 progress_bar_frame_width = 5 From 903719c1b5883d3a005c85b56bd3da948e581bb0 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Fri, 21 Jan 2022 18:48:09 -0700 Subject: [PATCH 18/21] simplify layout_get_height --- src/draw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/draw.c b/src/draw.c index e513daf5f..7399c4643 100644 --- a/src/draw.c +++ b/src/draw.c @@ -423,13 +423,12 @@ static int layout_get_height(struct colored_layout *cl, double scale) h_progress_bar = settings.progress_bar_height + settings.padding; } - int res = MAX(h_text, h_icon) + h_progress_bar; if (cl->n->icon_position == ICON_TOP && cl->n->icon) { - res = h_icon + h_text + h_progress_bar + vertical_padding; + return h_icon + h_text + h_progress_bar + vertical_padding; + } else { + return MAX(h_text, h_icon) + h_progress_bar; } - - return res; } /* Attempt to make internal radius more organic. From e0189e627cecfba17d3ab41bdbba62e958bdc797 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Fri, 21 Jan 2022 22:20:02 -0700 Subject: [PATCH 19/21] restore text_icon_padding functions with icon-conditionals --- src/draw.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/draw.c b/src/draw.c index 7399c4643..44de3940d 100644 --- a/src/draw.c +++ b/src/draw.c @@ -167,6 +167,28 @@ static struct color layout_get_sepcolor(struct colored_layout *cl, } } +static int get_horizontal_text_icon_padding(struct notification *n) +{ + bool horizontal_icon = ( + n->icon && (n->icon_position == ICON_LEFT || n->icon_position == ICON_RIGHT) + ); + if (settings.text_icon_padding && horizontal_icon) { + return settings.text_icon_padding; + } else { + return settings.h_padding; + } +} + +static int get_vertical_text_icon_padding(struct notification *n) +{ + bool vertical_icon = n->icon && (n->icon_position == ICON_TOP); + if (settings.text_icon_padding && vertical_icon) { + return settings.text_icon_padding; + } else { + return settings.padding; + } +} + static bool have_progress_bar(const struct colored_layout *cl) { return (cl->n->progress >= 0 && settings.progress_bar == true && @@ -211,7 +233,8 @@ static void layout_setup_pango(PangoLayout *layout, int width, int height, // @param height Height of the layout static void layout_setup(struct colored_layout *cl, int width, int height, double scale) { - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + settings.h_padding : 0; + int horizontal_padding = get_horizontal_text_icon_padding(cl->n); + int icon_width = cl->icon ? get_icon_width(cl->icon, scale) + horizontal_padding : 0; int text_width = width - 2 * settings.h_padding - (cl->n->icon_position == ICON_TOP ? 0 : icon_width); int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; int max_text_height = MAX(0, settings.height - progress_bar_height - 2 * settings.padding); @@ -233,7 +256,8 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout struct dimensions dim = { 0 }; layout_setup(cl, settings.width.max, settings.height, scale); - int icon_width = cl->icon? get_icon_width(cl->icon, scale) + settings.h_padding : 0; + int horizontal_padding = get_horizontal_text_icon_padding(cl->n); + int icon_width = cl->icon? get_icon_width(cl->icon, scale) + horizontal_padding : 0; int icon_height = cl->icon? get_icon_height(cl->icon, scale) : 0; int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0; @@ -244,7 +268,7 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout dim.text_height = 0; } else { get_text_size(cl->l, &dim.text_width, &dim.text_height, scale); - vertical_padding = settings.text_icon_padding; + vertical_padding = get_vertical_text_icon_padding(cl->n); } if (cl->n->icon_position == ICON_TOP && cl->n->icon) { @@ -413,7 +437,7 @@ static int layout_get_height(struct colored_layout *cl, double scale) vertical_padding = 0; } else { get_text_size(cl->l, NULL, &h_text, scale); - vertical_padding = settings.text_icon_padding; + vertical_padding = get_vertical_text_icon_padding(cl->n); } if (cl->icon) @@ -636,9 +660,9 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou // icon position if (cl->n->icon_position == ICON_LEFT) { - text_x = get_icon_width(cl->icon, scale) + settings.h_padding * 2; + text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding(cl->n); } else if (cl->n->icon_position == ICON_TOP) { - text_y = get_icon_height(cl->icon, scale) + settings.padding + settings.text_icon_padding; + text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding(cl->n); } // else ICON_RIGHT } cairo_move_to(c, round(text_x * scale), round(text_y * scale)); From 7d56731604db69ee167820766b61b043f2479121 Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Fri, 21 Jan 2022 22:24:40 -0700 Subject: [PATCH 20/21] default icon_position = left --- docs/dunst.5.pod | 2 +- src/notification.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index db81bd200..f6e90280e 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -364,7 +364,7 @@ Hide the count of stacked duplicate notifications. Show an indicator if a notification contains actions and/or open-able URLs. See ACTIONS below for further details. -=item B (values: [left/right/top/off], default: off) +=item B (values: [left/right/top/off], default: left) Defines the position of the icon in the notification window. Setting it to off disables icons. diff --git a/src/notification.c b/src/notification.c index 000cfe557..3efbccb1b 100644 --- a/src/notification.c +++ b/src/notification.c @@ -418,7 +418,7 @@ struct notification *notification_create(void) n->ellipsize = PANGO_ELLIPSIZE_MIDDLE; n->alignment = PANGO_ALIGN_LEFT; n->hide_text = false; - n->icon_position = ICON_OFF; + n->icon_position = ICON_LEFT; n->icon_size = 32; n->script_run = false; From b20544a3eeb3cbc2610988201a37e60d71a248dd Mon Sep 17 00:00:00 2001 From: M B <85039141+m-bartlett@users.noreply.github.com> Date: Fri, 21 Jan 2022 22:34:00 -0700 Subject: [PATCH 21/21] add padding demonstration to icon_position tests --- test/functional-tests/dunstrc.icon_position | 64 ++++++++++++++++++++- test/functional-tests/test.sh | 27 +++++++-- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/test/functional-tests/dunstrc.icon_position b/test/functional-tests/dunstrc.icon_position index 77c32d088..a54287847 100644 --- a/test/functional-tests/dunstrc.icon_position +++ b/test/functional-tests/dunstrc.icon_position @@ -2,20 +2,77 @@ background = "#222222" foreground = "#888888" timeout = 10 - alignment = left [urgency_normal] background = "#285577" foreground = "#ffffff" - timeout = 10 - alignment = center + timeout = 0 [urgency_critical] background = "#900000" foreground = "#ffffff" timeout = 0 + +[icon-left-alignment-left] + category = "icon-left-alignment-left" + icon_position = left + alignment = left + +[icon-left-alignment-right] + category = "icon-left-alignment-right" + icon_position = left alignment = right +[icon-left-alignment-center] + category = "icon-left-alignment-center" + icon_position = left + alignment = center + +[icon-right-alignment-left] + category = "icon-right-alignment-left" + icon_position = right + alignment = left + +[icon-right-alignment-right] + category = "icon-right-alignment-right" + icon_position = right + alignment = right + +[icon-right-alignment-center] + category = "icon-right-alignment-center" + icon_position = right + alignment = center + +[icon-top-alignment-left] + category = "icon-top-alignment-left" + icon_position = top + alignment = left + +[icon-top-alignment-right] + category = "icon-top-alignment-right" + icon_position = top + alignment = right + +[icon-top-alignment-center] + category = "icon-top-alignment-center" + icon_position = top + alignment = center + +[icon-off-alignment-left] + category = "icon-off-alignment-left" + icon_position = off + alignment = left + +[icon-off-alignment-right] + category = "icon-off-alignment-right" + icon_position = off + alignment = right + +[icon-off-alignment-center] + category = "icon-off-alignment-center" + icon_position = off + alignment = center + [global] font = Monospace 8 markup = full @@ -24,4 +81,5 @@ progress_bar_max_width = 200 progress_bar_frame_width = 5 progress_bar_height = 30 + width = (500,750) icon_path = /usr/share/icons/Papirus/24x24/status/:/usr/share/icons/Papirus/24x24/devices/:/usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/ \ No newline at end of file diff --git a/test/functional-tests/test.sh b/test/functional-tests/test.sh index 18807de1e..6a7177946 100755 --- a/test/functional-tests/test.sh +++ b/test/functional-tests/test.sh @@ -189,11 +189,30 @@ function progress_bar { } function icon_position { - for position in left top right off; do - tmp_dunstrc dunstrc.icon_position "icon_position = $position" # use default icon theme + padding_cases=( + '0 0 0 no padding' + '15 1 1 vertical' + '1 50 1 horizontal' + '1 1 25 icon ' + ) + + for padding_case in "${padding_cases[@]}"; do + read vertical horizontal icon label <<<"$padding_case" + + padding_settings=" + padding = $vertical + horizontal_padding = $horizontal + text_icon_padding = $icon + " + + tmp_dunstrc dunstrc.icon_position "$padding_settings" start_dunst dunstrc.tmp - for urgency in l n c; do - ../../dunstify -a "dunst tester" -u $urgency "icon_position = $position" + + for position in left top right off; do + for alignment in left center right; do + category="icon-$position-alignment-$alignment" + ../../dunstify -a "dunst tester" --hints string:category:$category -u n "$category"$'\n'"padding emphasis: $label" + done done rm dunstrc.tmp keypress