From bda8c1dbb2589e462303df12cc31db7238118c9a Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Mon, 14 Aug 2017 01:59:35 +0200 Subject: [PATCH] Add rule to show notification on fullscreen --- src/notification.c | 2 ++ src/notification.h | 7 +++++++ src/option_parser.c | 16 ++++++++++++++++ src/option_parser.h | 14 ++++++++++++++ src/rules.c | 3 +++ src/rules.h | 1 + src/settings.c | 9 +++++++++ 7 files changed, 52 insertions(+) diff --git a/src/notification.c b/src/notification.c index f689193..6418b09 100644 --- a/src/notification.c +++ b/src/notification.c @@ -284,6 +284,8 @@ notification *notification_create(void) n->transient = false; n->progress = -1; + n->fullscreen = FS_SHOW; + return n; } diff --git a/src/notification.h b/src/notification.h index 11632a9..0d619c1 100644 --- a/src/notification.h +++ b/src/notification.h @@ -9,6 +9,12 @@ #define DUNST_NOTIF_MAX_CHARS 5000 +enum behavior_fullscreen { + FS_NULL, //!< Invalid value + FS_DELAY, //!< Delay the notification until leaving fullscreen mode + FS_SHOW, //!< Show the message when in fullscreen mode +}; + /// Representing the urgencies according to the notification spec enum urgency { URG_NONE = -1, /**< Urgency not set (invalid) */ @@ -69,6 +75,7 @@ typedef struct _notification { bool first_render; /**< markup has been rendered before? */ int dup_count; /**< amount of duplicate notifications stacked onto this */ int displayed_height; + enum behavior_fullscreen fullscreen; //!< The instruction what to do with it, when desktop enters fullscreen /* derived fields */ char *msg; /**< formatted message */ diff --git a/src/option_parser.c b/src/option_parser.c index 6573d73..ca82813 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -551,4 +551,20 @@ const char *cmdline_create_usage(void) return usage_str; } +/* see option_parser.h */ +enum behavior_fullscreen parse_enum_fullscreen(const char *string, enum behavior_fullscreen def) +{ + if (!string) + return def; + + if (strcmp(string, "show") == 0) + return FS_SHOW; + else if (strcmp(string, "delay") == 0) + return FS_DELAY; + else { + LOG_W("Unknown fullscreen value: '%s'\n", string); + return def; + } +} + /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/option_parser.h b/src/option_parser.h index e816b7e..d712fa8 100644 --- a/src/option_parser.h +++ b/src/option_parser.h @@ -6,6 +6,8 @@ #include #include +#include "dunst.h" + int load_ini_file(FILE *); char *ini_get_path(const char *section, const char *key, const char *def); char *ini_get_string(const char *section, const char *key, const char *def); @@ -63,5 +65,17 @@ int option_get_bool(const char *ini_section, */ const char *next_section(const char *section); +/** + * Parse the fullscreen behavior value of the given string + * + * @param string the string representation of #behavior_fullscreen. + * The string must not contain any waste characters. + * @param def value to return in case of errors + * + * @return the #behavior_fullscreen representation of `string` + * @return `def` if `string` is invalid or `NULL` + */ +enum behavior_fullscreen parse_enum_fullscreen(const char *string, enum behavior_fullscreen def); + #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/rules.c b/src/rules.c index 7be1abb..22e5bf3 100644 --- a/src/rules.c +++ b/src/rules.c @@ -16,6 +16,8 @@ void rule_apply(rule_t *r, notification *n) n->timeout = r->timeout; if (r->urgency != URG_NONE) n->urgency = r->urgency; + if (r->fullscreen != FS_NULL) + n->fullscreen = r->fullscreen; if (r->history_ignore != -1) n->history_ignore = r->history_ignore; if (r->set_transient != -1) @@ -69,6 +71,7 @@ void rule_init(rule_t *r) r->msg_urgency = URG_NONE; r->timeout = -1; r->urgency = URG_NONE; + r->fullscreen = FS_NULL; r->markup = MARKUP_NULL; r->new_icon = NULL; r->history_ignore = false; diff --git a/src/rules.h b/src/rules.h index b8d1d87..9bee0a9 100644 --- a/src/rules.h +++ b/src/rules.h @@ -30,6 +30,7 @@ typedef struct _rule_t { char *bg; const char *format; const char *script; + enum behavior_fullscreen fullscreen; } rule_t; extern GSList *rules; diff --git a/src/settings.c b/src/settings.c index c9264f5..75aead6 100644 --- a/src/settings.c +++ b/src/settings.c @@ -684,6 +684,15 @@ void load_settings(char *cmdline_config_path) r->history_ignore = ini_get_bool(cur_section, "history_ignore", r->history_ignore); 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); + { + char *c = ini_get_string( + cur_section, + "fullscreen", NULL + ); + + r->fullscreen = parse_enum_fullscreen(c, r->fullscreen); + g_free(c); + } r->script = ini_get_path(cur_section, "script", NULL); }