Skip to content
15 changes: 13 additions & 2 deletions docs/dunst.5.pod
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,21 @@ Any other value is interpreted as a color, see COLORS

=back

=item B<sort> (values: [true/false], default: true)
=item B<sort> (values: [true/false/id/urgency_ascending/urgency_descending/update], default: true)

If set to true, display notifications with higher urgency above the others.
If set to true or urgency_descending, display notifications with higher urgency above the others.
critical first, then normal, then low.

If set to false or id, sort notifications by id.

If set to urgency_ascending, notifications are sorted by urgency,
low first, then normal, then critical.

If set to update, notifications are sorted by their update_time.
So the most recent is always at the top. This means that if you set sort to update,
and stack_duplicates to true, the duplicate will always be at the top.

When the notification window is at the bottom of the screen, this order is automatically reversed.
=item B<idle_threshold> (default: 0)

Don't timeout notifications if user is idle longer than this time.
Expand Down
7 changes: 6 additions & 1 deletion dunstrc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@
# * anything else will be interpreted as a X color.
separator_color = frame

# Sort messages by urgency.
# Sort type.
# possible values are:
# * id: sort by id
# * urgency_ascending: sort by urgency (low then normal then critical)
# * urgency_descending: sort by urgency (critical then normal then low)
# * update: sort by update (most recent always at the top)
sort = yes

# Don't remove messages, if the user is idle (no mouse or keyboard input)
Expand Down
26 changes: 23 additions & 3 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void notification_print(const struct notification *n)
printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : "");
printf("\tcategory: %s\n", n->category);
printf("\ttimeout: %ld\n", n->timeout/1000);
printf("\tstart: %ld\n", n->start);
printf("\ttimestamp: %ld\n", n->timestamp);
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency));
printf("\ttransient: %d\n", n->transient);
printf("\tformatted: '%s'\n", n->msg);
Expand Down Expand Up @@ -195,11 +197,29 @@ const char *notification_urgency_to_string(const enum urgency urgency)
/* see notification.h */
int notification_cmp(const struct notification *a, const struct notification *b)
{
if (settings.sort && a->urgency != b->urgency) {
return b->urgency - a->urgency;
const struct notification *a_order;
const struct notification *b_order;
if(settings.sort == SORT_TYPE_UPDATE && settings.origin & ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM){
a_order = b;
b_order = a;
} else {
return a->id - b->id;
a_order = a;
b_order = b;
}

if(settings.sort == SORT_TYPE_URGENCY_ASCENDING){
if(a_order->urgency != b_order->urgency){
return a_order->urgency - b_order->urgency;
}
} else if (settings.sort == SORT_TYPE_URGENCY_DESCENDING) {
if(a_order->urgency != b_order->urgency){
return b_order->urgency - a_order->urgency;
}
} else if(settings.sort == SORT_TYPE_UPDATE){
return b_order->timestamp - a_order->timestamp;
}

return a_order->id - b_order->id;
}

/* see notification.h */
Expand Down
6 changes: 5 additions & 1 deletion src/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ int queues_notification_insert(struct notification *n)
if (!inserted && STR_FULL(n->stack_tag) && queues_stack_by_tag(n))
inserted = true;

if (!inserted && settings.stack_duplicates && queues_stack_duplicate(n))
if (!inserted && settings.stack_duplicates && queues_stack_duplicate(n)){
if(settings.sort == SORT_TYPE_UPDATE){
g_queue_sort(displayed, notification_cmp_data, NULL);
}
inserted = true;
}

if (!inserted)
g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL);
Expand Down
3 changes: 2 additions & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define LIST_END (-1)

enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
enum sort_type { SORT_TYPE_ID, SORT_TYPE_URGENCY_ASCENDING, SORT_TYPE_URGENCY_DESCENDING, SORT_TYPE_UPDATE };
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 };
Expand Down Expand Up @@ -101,7 +102,7 @@ struct settings {
char *title;
char *class;
int shrink;
int sort;
enum sort_type sort;
int indicate_hidden;
gint64 idle_threshold;
gint64 show_age_threshold;
Expand Down
30 changes: 28 additions & 2 deletions src/settings_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ static const struct string_to_enum_def boolean_enum_data[] = {
ENUM_END,
};

static const struct string_to_enum_def sort_type_enum_data[] = {
{"True", SORT_TYPE_URGENCY_DESCENDING },
{"true", SORT_TYPE_URGENCY_DESCENDING },
{"On", SORT_TYPE_URGENCY_DESCENDING },
{"on", SORT_TYPE_URGENCY_DESCENDING },
{"Yes", SORT_TYPE_URGENCY_DESCENDING },
{"yes", SORT_TYPE_URGENCY_DESCENDING },
{"1", SORT_TYPE_URGENCY_DESCENDING },
{"False", SORT_TYPE_ID },
{"false", SORT_TYPE_ID },
{"Off", SORT_TYPE_ID },
{"off", SORT_TYPE_ID },
{"No", SORT_TYPE_ID },
{"no", SORT_TYPE_ID },
{"0", SORT_TYPE_ID },
{"n", SORT_TYPE_ID },
{"y", SORT_TYPE_ID },
{"N", SORT_TYPE_ID },
{"Y", SORT_TYPE_URGENCY_DESCENDING },
{"id", SORT_TYPE_ID},
{"urgency_ascending", SORT_TYPE_URGENCY_ASCENDING },
{"urgency_descending", SORT_TYPE_URGENCY_DESCENDING },
{"update", SORT_TYPE_UPDATE },
ENUM_END,
};

static const struct string_to_enum_def horizontal_alignment_enum_data[] = {
{"left", PANGO_ALIGN_LEFT },
{"center", PANGO_ALIGN_CENTER },
Expand Down Expand Up @@ -817,12 +843,12 @@ static const struct setting allowed_settings[] = {
{
.name = "sort",
.section = "global",
.description = "Sort notifications by urgency and date?",
.description = "Sort type by id/urgency/update",
.type = TYPE_CUSTOM,
.default_value = "true",
.value = &settings.sort,
.parser = string_parse_enum,
.parser_data = boolean_enum_data,
.parser_data = sort_type_enum_data,
},
{
.name = "indicate_hidden",
Expand Down
2 changes: 1 addition & 1 deletion test/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ TEST test_queues_update_paused(void)
TEST test_queues_update_seeping(void)
{
settings.notification_limit = 5;
settings.sort = true;
settings.sort = SORT_TYPE_URGENCY_DESCENDING;
settings.indicate_hidden = false;
struct notification *nl1, *nl2, *nl3, *nl4, *nl5;
struct notification *nc1, *nc2, *nc3, *nc4, *nc5;
Expand Down