Skip to content

Commit

Permalink
Merge pull request #590 from mgsloan/skip-display-rule-option
Browse files Browse the repository at this point in the history
Skip display rule option
  • Loading branch information
tsipinakis committed Feb 9, 2019
2 parents 9e8142a + 802b1ab commit 63ec283
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 6 deletions.
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
11 changes: 9 additions & 2 deletions 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;

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

Expand Down Expand Up @@ -427,8 +430,12 @@ void queues_update(struct dunst_status status)
n->start = time_monotonic_now();
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_notification_close(n, REASON_USER);
} else {
g_queue_delete_link(waiting, iter);
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);
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

0 comments on commit 63ec283

Please sign in to comment.