diff --git a/config.h b/config.h index 06670f2..c98cbad 100644 --- a/config.h +++ b/config.h @@ -121,7 +121,7 @@ struct settings defaults = { .progress_bar_frame_width = 1, -.no_progress_bar = false, +.progress_bar = true, }; struct rule default_rules[] = { diff --git a/docs/dunst.pod b/docs/dunst.pod index 90973ac..45864f9 100644 --- a/docs/dunst.pod +++ b/docs/dunst.pod @@ -142,6 +142,32 @@ the notification on the left border of the screen while a horizontal offset of =back +=item B (values: [true/false], default: true) + +When an integer value is passed to dunst as a hint (see B), a +progress bar will be drawn at the bottom of the notification. This +behavior can be turned off by setting this setting to false. + +=item B (default: 10) + +The height of the progress bar in pixel. This includes the frame. Make sure +this value is bigger than twice the frame width. + +=item B (default: 150) + +The minimum width of the progress bar in pixels. The notification is rescaled +to fit the bar. + +=item B (default: 300) + +The maximum width of the progress bar in pixels. The notification is resized +to fit the progress bar. + +=item B (default: 1) + +The frame width of the progress bar in pixels. This value should be smaller +than half of the progress bar height. + =item B (values: [true/false], default: true) If this is set to true, a notification indicating how many notifications are @@ -561,8 +587,8 @@ Specifies the keyboard shortcut that opens the context menu. The urgency sections work in a similar way to rules and can be used to specify attributes for the different urgency levels of notifications (low, normal, -critical). Currently only the background, foreground, timeout, frame_color and -icon attributes can be modified. +critical). Currently only the background, foreground, hightlight, timeout, +frame_color and icon attributes can be modified. The urgency sections are urgency_low, urgency_normal, urgency_critical for low, normal and critical urgency respectively. @@ -595,6 +621,12 @@ Defines the background color for low, normal and critical notifications respecti See COLORS for the value format. +=item B<-lh/nh/ch color> + +Defines the highlight color for low, normal and critical notifications respectively. + +See COLORS for the value format. + =item B<-lfr/nfr/cfr color> Defines the frame color for low, normal and critical notifications respectively. @@ -725,7 +757,12 @@ The background color of the notification. See COLORS for possible values. =item C -The background color of the notification. See COLORS for possible values. +The foreground color of the notification. See COLORS for possible values. + +=item C + +The highlight color of the notification. This color is used for coloring the +progress bar. See COLORS for possible values. =item C diff --git a/dunstrc b/dunstrc index 331347e..511eb4e 100644 --- a/dunstrc +++ b/dunstrc @@ -30,7 +30,24 @@ # The width can be negative. In this case the actual width is the # screen width minus the width defined in within the geometry option. geometry = "300x5-30+20" + + # Turn on the progess bar + progress_bar = true + # Set the progress bar height. This includes the frame, so make sure + # it's at least twice as big as the frame width. + progress_bar_height = 10 + + # Set the frame width of the progress bar + progress_bar_frame_width = 1 + + # Set the minimum width for the progress bar + progress_bar_min_width = 150 + + # Set the maximum width for the progress bar + progress_bar_max_width = 300 + + # Show how many messages are currently hidden (because of geometry). indicate_hidden = yes diff --git a/src/draw.c b/src/draw.c index 6019ec3..8a839c4 100644 --- a/src/draw.c +++ b/src/draw.c @@ -169,7 +169,7 @@ static bool have_dynamic_width(void) static bool have_progress_bar(const struct notification *n) { - return (n->progress >= 0 && settings.no_progress_bar == false); + return (n->progress >= 0 && settings.progress_bar == true); } static struct dimensions calculate_dimensions(GSList *layouts) @@ -366,6 +366,7 @@ static struct colored_layout *layout_from_notification(cairo_t *c, struct notifi 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 = n->displayed_height + settings.padding * 2; // progress bar @@ -646,7 +647,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width) // progress bar positioning if (have_progress_bar(cl->n)){ - int progress = cl->n->progress; + int progress = MIN(cl->n->progress, 100); 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, diff --git a/src/settings.c b/src/settings.c index e07f17a..419bf73 100644 --- a/src/settings.c +++ b/src/settings.c @@ -379,10 +379,10 @@ void load_settings(char *cmdline_config_path) "Frame width of the progress bar" ); - settings.no_progress_bar = option_get_bool( + settings.progress_bar = option_get_bool( "global", - "no_progress_bar", "-no_progress_bar", false, - "Hide the progress bar" + "progress_bar", "-progress_bar", true, + "Show the progress bar" ); // check sanity of the progress bar options diff --git a/src/settings.h b/src/settings.h index ba0aaea..d1787b6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -96,7 +96,7 @@ struct settings { int progress_bar_min_width; int progress_bar_max_width; int progress_bar_frame_width; - bool no_progress_bar; + bool progress_bar; }; extern struct settings settings; diff --git a/test/functional-tests/dunstrc.progress_bar b/test/functional-tests/dunstrc.progress_bar new file mode 100644 index 0000000..4d80ae3 --- /dev/null +++ b/test/functional-tests/dunstrc.progress_bar @@ -0,0 +1,10 @@ +[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/test.sh b/test/functional-tests/test.sh index ae3ca17..a8766f1 100755 --- a/test/functional-tests/test.sh +++ b/test/functional-tests/test.sh @@ -177,12 +177,35 @@ function geometry { keypress } +function progress_bar { + killall dunst + ../../dunst -config dunstrc.default & + ../../dunstify -h int:value:0 -a "dunst tester" -u c "Progress bar 0%: " + ../../dunstify -h int:value:33 -a "dunst tester" -u c "Progress bar 33%: " + ../../dunstify -h int:value:66 -a "dunst tester" -u c "Progress bar 66%: " + ../../dunstify -h int:value:100 -a "dunst tester" -u c "Progress bar 100%: " + keypress + killall dunst + ../../dunst -config dunstrc.default & + ../../dunstify -h int:value:33 -a "dunst tester" -u l "Low priority: " + ../../dunstify -h int:value:33 -a "dunst tester" -u n "Normal priority: " + ../../dunstify -h int:value:33 -a "dunst tester" -u c "Critical priority: " + keypress + killall dunst + ../../dunst -config dunstrc.progress_bar & + ../../dunstify -h int:value:33 -a "dunst tester" -u n "The progress bar should not be the entire width" + ../../dunstify -h int:value:33 -a "dunst tester" -u n "You might also notice height and frame size are changed" + ../../dunstify -h int:value:33 -a "dunst tester" -u c "Short" + keypress +} + if [ -n "$1" ]; then while [ -n "$1" ]; do $1 shift done else + progress_bar geometry corners show_age