Skip to content

Commit

Permalink
Add: rule attribute to override the timeout set by dbus (dunst-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
rpbranco committed Feb 19, 2022
1 parent b56e7da commit b8a2786
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
g_variant_unref(dict_value);
}

// Set the dbus timeout
n->dbus_timeout = timeout < 0 ? timeout : ((gint64)timeout) * 1000;

// All attributes that have to be set before initializations are set,
// so we can initialize the notification. This applies all rules that
// are defined and applies the formatting to the message.
Expand Down Expand Up @@ -633,8 +636,8 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
g_variant_unref(dict_value);
}

if (timeout >= 0)
n->timeout = ((gint64)timeout) * 1000;
if (n->dbus_timeout >= 0)
n->timeout = n->dbus_timeout;

g_variant_unref(hints);
g_variant_type_free(required_type);
Expand Down
1 change: 1 addition & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ struct notification *notification_create(void)

n->urgency = URG_NORM;
n->timeout = -1;
n->dbus_timeout = -1;

n->transient = false;
n->progress = -1;
Expand Down
1 change: 1 addition & 0 deletions src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct notification {
gint64 start; /**< begin of current display (in milliseconds) */
gint64 timestamp; /**< arrival time (in milliseconds) */
gint64 timeout; /**< time to display (in milliseconds) */
gint64 dbus_timeout; /**< time to display (in milliseconds) (set by dbus) */
int locked; /**< If non-zero the notification is locked **/
PangoAlignment progress_bar_alignment; /**< Horizontal alignment of the progress bar **/

Expand Down
2 changes: 2 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void rule_apply(struct rule *r, struct notification *n)
{
if (r->timeout != -1)
n->timeout = r->timeout;
if (r->override_dbus_timeout != -1)
n->dbus_timeout = r->override_dbus_timeout;
if (r->urgency != URG_NONE)
n->urgency = r->urgency;
if (r->fullscreen != FS_NULL)
Expand Down
1 change: 1 addition & 0 deletions src/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct rule {

/* modifying */
gint64 timeout; // this has to be the first modifying rule
gint64 override_dbus_timeout;
enum urgency urgency;
char *action_name;
enum markup_mode markup;
Expand Down
12 changes: 12 additions & 0 deletions src/settings_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static const struct rule empty_rule = {
.category = NULL,
.msg_urgency = URG_NONE,
.timeout = -1,
.override_dbus_timeout = -1,
.urgency = URG_NONE,
.markup = MARKUP_NULL,
.history_ignore = -1,
Expand Down Expand Up @@ -570,6 +571,17 @@ static const struct setting allowed_settings[] = {
.parser_data = NULL,
.rule_offset = offsetof(struct rule, timeout),
},
{
.name = "override_dbus_timeout",
.section = "*",
.description = "Replace the dbus timeout with this value.",
.type = TYPE_TIME,
.default_value = "*",
.value = NULL,
.parser = NULL,
.parser_data = NULL,
.rule_offset = offsetof(struct rule, override_dbus_timeout),
},
{
.name = "urgency",
.section = "*",
Expand Down

0 comments on commit b8a2786

Please sign in to comment.