Add docs, tests and fixes for progress bar

This commit is contained in:
fwsmit 2020-11-06 14:25:58 +01:00
parent bfcf655b1e
commit 4f10496123
8 changed files with 98 additions and 10 deletions

View File

@ -121,7 +121,7 @@ struct settings defaults = {
.progress_bar_frame_width = 1, .progress_bar_frame_width = 1,
.no_progress_bar = false, .progress_bar = true,
}; };
struct rule default_rules[] = { struct rule default_rules[] = {

View File

@ -142,6 +142,32 @@ the notification on the left border of the screen while a horizontal offset of
=back =back
=item B<progress_bar> (values: [true/false], default: true)
When an integer value is passed to dunst as a hint (see B<NOTIFY-SEND>), 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<progress_bar_height> (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<progress_bar_min_width> (default: 150)
The minimum width of the progress bar in pixels. The notification is rescaled
to fit the bar.
=item B<progress_bar_max_width> (default: 300)
The maximum width of the progress bar in pixels. The notification is resized
to fit the progress bar.
=item B<progress_bar_frame_width> (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<indicate_hidden> (values: [true/false], default: true) =item B<indicate_hidden> (values: [true/false], default: true)
If this is set to true, a notification indicating how many notifications are 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 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, attributes for the different urgency levels of notifications (low, normal,
critical). Currently only the background, foreground, timeout, frame_color and critical). Currently only the background, foreground, hightlight, timeout,
icon attributes can be modified. frame_color and icon attributes can be modified.
The urgency sections are urgency_low, urgency_normal, urgency_critical for low, The urgency sections are urgency_low, urgency_normal, urgency_critical for low,
normal and critical urgency respectively. 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. 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> =item B<-lfr/nfr/cfr color>
Defines the frame color for low, normal and critical notifications respectively. 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<foreground> =item C<foreground>
The background color of the notification. See COLORS for possible values. The foreground color of the notification. See COLORS for possible values.
=item C<highlight>
The highlight color of the notification. This color is used for coloring the
progress bar. See COLORS for possible values.
=item C<format> =item C<format>

17
dunstrc
View File

@ -31,6 +31,23 @@
# screen width minus the width defined in within the geometry option. # screen width minus the width defined in within the geometry option.
geometry = "300x5-30+20" 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). # Show how many messages are currently hidden (because of geometry).
indicate_hidden = yes indicate_hidden = yes

View File

@ -169,7 +169,7 @@ static bool have_dynamic_width(void)
static bool have_progress_bar(const struct notification *n) 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) 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)); 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); 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; n->displayed_height = n->displayed_height + settings.padding * 2;
// progress bar // progress bar
@ -646,7 +647,7 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width)
// progress bar positioning // progress bar positioning
if (have_progress_bar(cl->n)){ 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, unsigned int frame_width = settings.progress_bar_frame_width,
progress_width = MIN(width - 2 * settings.h_padding, settings.progress_bar_max_width), progress_width = MIN(width - 2 * settings.h_padding, settings.progress_bar_max_width),
progress_height = settings.progress_bar_height - frame_width, progress_height = settings.progress_bar_height - frame_width,

View File

@ -379,10 +379,10 @@ void load_settings(char *cmdline_config_path)
"Frame width of the progress bar" "Frame width of the progress bar"
); );
settings.no_progress_bar = option_get_bool( settings.progress_bar = option_get_bool(
"global", "global",
"no_progress_bar", "-no_progress_bar", false, "progress_bar", "-progress_bar", true,
"Hide the progress bar" "Show the progress bar"
); );
// check sanity of the progress bar options // check sanity of the progress bar options

View File

@ -96,7 +96,7 @@ struct settings {
int progress_bar_min_width; int progress_bar_min_width;
int progress_bar_max_width; int progress_bar_max_width;
int progress_bar_frame_width; int progress_bar_frame_width;
bool no_progress_bar; bool progress_bar;
}; };
extern struct settings settings; extern struct settings settings;

View File

@ -0,0 +1,10 @@
[global]
font = Monospace 8
allow_markup = yes
format = "<b>%s</b>\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

View File

@ -177,12 +177,35 @@ function geometry {
keypress 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 if [ -n "$1" ]; then
while [ -n "$1" ]; do while [ -n "$1" ]; do
$1 $1
shift shift
done done
else else
progress_bar
geometry geometry
corners corners
show_age show_age