queues: correctly sort notifications even when sort is false.
The sort name is a bit misleading. It should actually be called sort_urgency or something. Notifications are still not sorted based on time, but ID.
This commit is contained in:
parent
3acffdb194
commit
b75d35adb4
@ -192,7 +192,7 @@ const char *notification_urgency_to_string(const enum urgency urgency)
|
|||||||
/* see notification.h */
|
/* see notification.h */
|
||||||
int notification_cmp(const struct notification *a, const struct notification *b)
|
int notification_cmp(const struct notification *a, const struct notification *b)
|
||||||
{
|
{
|
||||||
if (a->urgency != b->urgency) {
|
if (settings.sort && a->urgency != b->urgency) {
|
||||||
return b->urgency - a->urgency;
|
return b->urgency - a->urgency;
|
||||||
} else {
|
} else {
|
||||||
return a->id - b->id;
|
return a->id - b->id;
|
||||||
@ -205,8 +205,6 @@ int notification_cmp_data(const void *va, const void *vb, void *data)
|
|||||||
struct notification *a = (struct notification *) va;
|
struct notification *a = (struct notification *) va;
|
||||||
struct notification *b = (struct notification *) vb;
|
struct notification *b = (struct notification *) vb;
|
||||||
|
|
||||||
ASSERT_OR_RET(settings.sort, 1);
|
|
||||||
|
|
||||||
return notification_cmp(a, b);
|
return notification_cmp(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,6 +763,68 @@ TEST test_queue_find_by_id(void)
|
|||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void print_queues() {
|
||||||
|
printf("\nQueues:\n");
|
||||||
|
for (GList *iter = g_queue_peek_head_link(QUEUE_WAIT); iter;
|
||||||
|
iter = iter->next) {
|
||||||
|
struct notification *notif = iter->data;
|
||||||
|
printf("waiting %s\n", notif->summary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if notifications are correctly sorted, even if dunst is paused in
|
||||||
|
// between. See #838 for the issue.
|
||||||
|
TEST test_queue_no_sort_and_pause(void)
|
||||||
|
{
|
||||||
|
// Setting sort to false, this means that notifications will only be
|
||||||
|
// sorted based on time
|
||||||
|
settings.sort = false;
|
||||||
|
settings.geometry.h = 0;
|
||||||
|
struct notification *n;
|
||||||
|
queues_init();
|
||||||
|
|
||||||
|
n = test_notification("n0", 0);
|
||||||
|
queues_notification_insert(n);
|
||||||
|
queues_update(STATUS_NORMAL);
|
||||||
|
|
||||||
|
n = test_notification("n1", 0);
|
||||||
|
queues_notification_insert(n);
|
||||||
|
queues_update(STATUS_NORMAL);
|
||||||
|
|
||||||
|
n = test_notification("n2", 0);
|
||||||
|
queues_notification_insert(n);
|
||||||
|
queues_update(STATUS_PAUSE);
|
||||||
|
|
||||||
|
n = test_notification("n3", 0);
|
||||||
|
queues_notification_insert(n);
|
||||||
|
queues_update(STATUS_PAUSE);
|
||||||
|
/* queues_update(STATUS_NORMAL); */
|
||||||
|
|
||||||
|
n = test_notification("n4", 0);
|
||||||
|
queues_notification_insert(n);
|
||||||
|
queues_update(STATUS_NORMAL);
|
||||||
|
|
||||||
|
QUEUE_LEN_ALL(0, 5, 0);
|
||||||
|
|
||||||
|
const char* order[] = {
|
||||||
|
"n0",
|
||||||
|
"n1",
|
||||||
|
"n2",
|
||||||
|
"n3",
|
||||||
|
"n4",
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < g_queue_get_length(QUEUE_DISP); i++) {
|
||||||
|
struct notification *notif = g_queue_peek_nth(QUEUE_DISP, i);
|
||||||
|
ASSERTm("Notifications are not in the right order",
|
||||||
|
STR_EQ(notif->summary, order[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
queues_teardown();
|
||||||
|
PASS();
|
||||||
|
}
|
||||||
|
|
||||||
SUITE(suite_queues)
|
SUITE(suite_queues)
|
||||||
{
|
{
|
||||||
settings.icon_path = "";
|
settings.icon_path = "";
|
||||||
@ -794,6 +856,7 @@ SUITE(suite_queues)
|
|||||||
RUN_TEST(test_queues_update_xmore);
|
RUN_TEST(test_queues_update_xmore);
|
||||||
RUN_TEST(test_queues_timeout_before_paused);
|
RUN_TEST(test_queues_timeout_before_paused);
|
||||||
RUN_TEST(test_queue_find_by_id);
|
RUN_TEST(test_queue_find_by_id);
|
||||||
|
RUN_TEST(test_queue_no_sort_and_pause);
|
||||||
|
|
||||||
settings.icon_path = NULL;
|
settings.icon_path = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user