make rules linked list instead of array
This commit is contained in:
parent
d5e89267df
commit
9ac34f6010
15
config.def.h
15
config.def.h
@ -36,19 +36,4 @@ KeySym mask = 0;
|
|||||||
* 3 -> print everything above + debug info
|
* 3 -> print everything above + debug info
|
||||||
*/
|
*/
|
||||||
int verbosity = 0;
|
int verbosity = 0;
|
||||||
|
|
||||||
/* You can use shell-like wildcards to match <appname> <summary> <body> and <icon>. */
|
|
||||||
const rule_t rules[] = {
|
|
||||||
/* appname, summary, body, icon, timeout, urgency, fg, bg, format */
|
|
||||||
{ NULL, NULL, NULL, NULL, -1, -1, NULL, NULL, NULL },
|
|
||||||
/* { "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b" }, */
|
|
||||||
/* { "Pidgin", NULL, NULL, NULL, -1, -1, NULL, NULL, "%s %b" }, */
|
|
||||||
/* { "Pidgin", "*signed on*", NULL, NULL, -1, LOW, NULL, NULL, "%s %b" }, */
|
|
||||||
/* { "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL, "%s %b" }, */
|
|
||||||
/* { "Pidgin", "*says*", NULL, NULL, -1, CRIT, NULL, NULL, "%s %b" }, */
|
|
||||||
/* { "Pidgin", "twitter.com*", NULL, NULL, -1, NORM, NULL, NULL, "%s %b" }, */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
44
dunst.c
44
dunst.c
@ -37,6 +37,8 @@ typedef struct _screen_info {
|
|||||||
|
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
|
|
||||||
|
rule_t *rules = NULL;
|
||||||
/* index of colors fit to urgency level */
|
/* index of colors fit to urgency level */
|
||||||
static unsigned long colors[3][ColLast];
|
static unsigned long colors[3][ColLast];
|
||||||
static Atom utf8;
|
static Atom utf8;
|
||||||
@ -68,6 +70,7 @@ void free_msgqueue_t(msg_queue_t *elem);
|
|||||||
void handle_mouse_click(XEvent ev);
|
void handle_mouse_click(XEvent ev);
|
||||||
void handleXEvents(void);
|
void handleXEvents(void);
|
||||||
void initmsg(msg_queue_t *msg);
|
void initmsg(msg_queue_t *msg);
|
||||||
|
rule_t *initrule(void);
|
||||||
char *string_replace(const char *needle, const char *replacement, char *haystack);
|
char *string_replace(const char *needle, const char *replacement, char *haystack);
|
||||||
void run(void);
|
void run(void);
|
||||||
void setup(void);
|
void setup(void);
|
||||||
@ -116,18 +119,20 @@ add(msg_queue_t *queue, msg_queue_t *new) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
apply_rules(msg_queue_t *msg) {
|
apply_rules(msg_queue_t *msg) {
|
||||||
int i;
|
rule_t *cur = rules;
|
||||||
for(i = 0; i < LENGTH(rules); i++) {
|
while(cur != NULL) {
|
||||||
if((!rules[i].appname || !fnmatch(rules[i].appname, msg->appname, 0))
|
if((!cur->appname || !fnmatch(cur->appname, msg->appname, 0))
|
||||||
&& (!rules[i].summary || !fnmatch(rules[i].summary, msg->summary, 0))
|
&& (!cur->summary || !fnmatch(cur->summary, msg->summary, 0))
|
||||||
&& (!rules[i].body || !fnmatch(rules[i].body, msg->body, 0))
|
&& (!cur->body || !fnmatch(cur->body, msg->body, 0))
|
||||||
&& (!rules[i].icon || !fnmatch(rules[i].icon, msg->icon, 0))) {
|
&& (!cur->icon || !fnmatch(cur->icon, msg->icon, 0))) {
|
||||||
msg->timeout = rules[i].timeout != -1 ? rules[i].timeout : msg->timeout;
|
msg->timeout = cur->timeout != -1 ? cur->timeout : msg->timeout;
|
||||||
msg->urgency = rules[i].urgency != -1 ? rules[i].urgency : msg->urgency;
|
msg->urgency = cur->urgency != -1 ? cur->urgency : msg->urgency;
|
||||||
msg->color_strings[ColFG] = rules[i].fg ? rules[i].fg : msg->color_strings[ColFG];
|
msg->color_strings[ColFG] = cur->fg ? cur->fg : msg->color_strings[ColFG];
|
||||||
msg->color_strings[ColBG] = rules[i].bg ? rules[i].bg : msg->color_strings[ColBG];
|
msg->color_strings[ColBG] = cur->bg ? cur->bg : msg->color_strings[ColBG];
|
||||||
msg->format = rules[i].format ? rules[i].format : msg->format;
|
msg->format = cur->format ? cur->format : msg->format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,6 +488,23 @@ initmsg(msg_queue_t *msg) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rule_t *
|
||||||
|
initrule(void) {
|
||||||
|
rule_t *r = malloc(sizeof(rule_t));
|
||||||
|
r->appname = NULL;
|
||||||
|
r->summary = NULL;
|
||||||
|
r->body = NULL;
|
||||||
|
r->icon = NULL;
|
||||||
|
r->timeout = -1;
|
||||||
|
r->urgency = -1;
|
||||||
|
r->fg = NULL;
|
||||||
|
r->bg = NULL;
|
||||||
|
r->format = NULL;
|
||||||
|
r->next = NULL;
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
string_replace(const char *needle, const char *replacement, char *haystack) {
|
string_replace(const char *needle, const char *replacement, char *haystack) {
|
||||||
char *tmp, *start;
|
char *tmp, *start;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user