Add rule to show notification on fullscreen

This commit is contained in:
Benedikt Heine 2017-08-14 01:59:35 +02:00
parent 9e824a79ee
commit bda8c1dbb2
7 changed files with 52 additions and 0 deletions

View File

@ -284,6 +284,8 @@ notification *notification_create(void)
n->transient = false; n->transient = false;
n->progress = -1; n->progress = -1;
n->fullscreen = FS_SHOW;
return n; return n;
} }

View File

@ -9,6 +9,12 @@
#define DUNST_NOTIF_MAX_CHARS 5000 #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 /// Representing the urgencies according to the notification spec
enum urgency { enum urgency {
URG_NONE = -1, /**< Urgency not set (invalid) */ URG_NONE = -1, /**< Urgency not set (invalid) */
@ -69,6 +75,7 @@ typedef struct _notification {
bool first_render; /**< markup has been rendered before? */ bool first_render; /**< markup has been rendered before? */
int dup_count; /**< amount of duplicate notifications stacked onto this */ int dup_count; /**< amount of duplicate notifications stacked onto this */
int displayed_height; int displayed_height;
enum behavior_fullscreen fullscreen; //!< The instruction what to do with it, when desktop enters fullscreen
/* derived fields */ /* derived fields */
char *msg; /**< formatted message */ char *msg; /**< formatted message */

View File

@ -551,4 +551,20 @@ const char *cmdline_create_usage(void)
return usage_str; 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: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -6,6 +6,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include "dunst.h"
int load_ini_file(FILE *); int load_ini_file(FILE *);
char *ini_get_path(const char *section, const char *key, const char *def); 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); 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); 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 #endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -16,6 +16,8 @@ void rule_apply(rule_t *r, notification *n)
n->timeout = r->timeout; n->timeout = r->timeout;
if (r->urgency != URG_NONE) if (r->urgency != URG_NONE)
n->urgency = r->urgency; n->urgency = r->urgency;
if (r->fullscreen != FS_NULL)
n->fullscreen = r->fullscreen;
if (r->history_ignore != -1) if (r->history_ignore != -1)
n->history_ignore = r->history_ignore; n->history_ignore = r->history_ignore;
if (r->set_transient != -1) if (r->set_transient != -1)
@ -69,6 +71,7 @@ void rule_init(rule_t *r)
r->msg_urgency = URG_NONE; r->msg_urgency = URG_NONE;
r->timeout = -1; r->timeout = -1;
r->urgency = URG_NONE; r->urgency = URG_NONE;
r->fullscreen = FS_NULL;
r->markup = MARKUP_NULL; r->markup = MARKUP_NULL;
r->new_icon = NULL; r->new_icon = NULL;
r->history_ignore = false; r->history_ignore = false;

View File

@ -30,6 +30,7 @@ typedef struct _rule_t {
char *bg; char *bg;
const char *format; const char *format;
const char *script; const char *script;
enum behavior_fullscreen fullscreen;
} rule_t; } rule_t;
extern GSList *rules; extern GSList *rules;

View File

@ -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->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->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->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); r->script = ini_get_path(cur_section, "script", NULL);
} }