Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip display rule option #590

Merged
merged 3 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
have to wait for a timeout in a displayed notification (#541)
- `<I> more` notifications don't occupy space anymore, if there is only a single
notification waiting to get displayed. The notification gets displayed directly (#467)
- Added `skip_display` rule option to skip initial notification display, and
include the notification in the history.

## 1.3.2 - 2018-05-06

Expand Down
1 change: 1 addition & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct rule default_rules[] = {
.history_ignore = -1,
.match_transient = -1,
.set_transient = -1,
.skip_display = -1,
.new_icon = NULL,
.fg = NULL,
.bg = NULL,
Expand Down
6 changes: 3 additions & 3 deletions docs/dunst.pod
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,9 @@ together. The default stack_stag value is set from the string hints
"synchronous", "private-synchronous", "x-canonical-private-synchronous", and
"x-dunst-stack-tag".

If you want to skip display of a notification, but still have it in
history, setting 'timeout' to "1ms" will essentially skip initial
display.
If you want to skip initial display of a notification, but still have
it in history, you can set 'skip_display' to 'true' to get this
behavior.

=back

Expand Down
5 changes: 5 additions & 0 deletions dunstrc
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@
# summary = "foobar"
# history_ignore = yes

#[skip-display]
# # This notification will not be displayed, but will be included in the history
# summary = "foobar"
# skip_display = yes

#[signed_on]
# appname = Pidgin
# summary = "*signed on*"
Expand Down
2 changes: 1 addition & 1 deletion src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ static void dbus_cb_Notify(

// The message got discarded
if (id == 0) {
signal_notification_closed(n, 2);
signal_notification_closed(n, REASON_USER);
notification_unref(n);
}

Expand Down
1 change: 1 addition & 0 deletions src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct notification {
bool transient; /**< timeout albeit user is idle */
int progress; /**< percentage (-1: undefined) */
int history_ignore; /**< push to history or free directly */
int skip_display; /**< insert notification into history, skipping initial waiting and display */

/* internal */
bool redisplayed; /**< has been displayed before? */
Expand Down
10 changes: 9 additions & 1 deletion src/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ static bool queues_notification_is_finished(struct notification *n, struct dunst
{
assert(n);

if (n->skip_display && !n->redisplayed)
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hunk seems redundant, the notifications never see the displayed queue but skip directly from waiting to history. Was there a reason for adding this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, would need to ask @bebehei as he wrote this. It does seem redundant for the current use of queues_notification_is_finished, but if there are future usages of it, it might be good to have this check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may seem redundant, but actually it isn't. For the case, that an already displayed notification gets replaced, this would trigger the immediate removal.


if (n->timeout == 0) // sticky
return false;

Expand Down Expand Up @@ -428,7 +431,12 @@ void queues_update(struct dunst_status status)
notification_run_script(n);

g_queue_delete_link(waiting, iter);
g_queue_insert_sorted(displayed, n, notification_cmp_data, NULL);

if (n->skip_display && !n->redisplayed) {
queues_history_push(n);
} else {
g_queue_insert_sorted(displayed, n, notification_cmp_data, NULL);
}

iter = nextiter;
}
Expand Down
3 changes: 3 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ void rule_apply(struct rule *r, struct notification *n)
n->history_ignore = r->history_ignore;
if (r->set_transient != -1)
n->transient = r->set_transient;
if (r->skip_display != -1)
n->skip_display = r->skip_display;
if (r->markup != MARKUP_NULL)
n->markup = r->markup;
if (r->new_icon)
Expand Down Expand Up @@ -75,6 +77,7 @@ struct rule *rule_new(void)
r->history_ignore = false;
r->match_transient = -1;
r->set_transient = -1;
r->skip_display = -1;

return r;
}
Expand Down
1 change: 1 addition & 0 deletions src/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct rule {
int history_ignore;
int match_transient;
int set_transient;
int skip_display;
char *new_icon;
char *fg;
char *bg;
Expand Down
1 change: 1 addition & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ void load_settings(char *cmdline_config_path)
r->match_transient = ini_get_bool(cur_section, "match_transient", r->match_transient);
r->set_transient = ini_get_bool(cur_section, "set_transient", r->set_transient);
r->desktop_entry = ini_get_string(cur_section, "desktop_entry", r->desktop_entry);
r->skip_display = ini_get_bool(cur_section, "skip_display", r->skip_display);
{
char *c = ini_get_string(
cur_section,
Expand Down
46 changes: 46 additions & 0 deletions test/queues.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,50 @@ TEST test_queue_notification_close_histignore(void)
PASS();
}

TEST test_queue_notification_skip_display(void)
{
struct notification *n;

// Test skipping display
n = test_notification("n", -1);
n->skip_display = true;

queues_init();
queues_notification_insert(n);
QUEUE_LEN_ALL(1, 0, 0);
queues_update(STATUS_NORMAL);
QUEUE_LEN_ALL(0, 0, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm missing another check for the signal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we check for the signal? Note that this code is exercising the queues, not end-to-end dbus functionality (the signal is done in dbus.c not queues.c). I don't see any end-to-end tests that also involve rules.

queues_teardown();

PASS();
}

TEST test_queue_notification_skip_display_redisplayed(void)
{
struct notification *n;

// Test skipping display
n = test_notification("n", -1);
n->skip_display = true;

queues_init();
queues_notification_insert(n);
QUEUE_LEN_ALL(1, 0, 0);
queues_update(STATUS_NORMAL);
QUEUE_LEN_ALL(0, 0, 1);

queues_history_pop();
QUEUE_LEN_ALL(1, 0, 0);
queues_update(STATUS_NORMAL);
QUEUE_CONTAINSm("A skip display notification should stay in displayed "
"queue when it got pulled out of history queue",
DISP, n);

queues_teardown();

PASS();
}

TEST test_queue_history_overfull(void)
{
settings.history_length = 10;
Expand Down Expand Up @@ -714,6 +758,8 @@ SUITE(suite_queues)
RUN_TEST(test_queue_length);
RUN_TEST(test_queue_notification_close);
RUN_TEST(test_queue_notification_close_histignore);
RUN_TEST(test_queue_notification_skip_display);
RUN_TEST(test_queue_notification_skip_display_redisplayed);
RUN_TEST(test_queue_stacking);
RUN_TEST(test_queue_stacktag);
RUN_TEST(test_queue_teardown);
Expand Down