moved rules related stuff to rules.{c,h}
This commit is contained in:
parent
56716ec948
commit
a587fea56f
2
Makefile
2
Makefile
@ -3,7 +3,7 @@
|
||||
|
||||
include config.mk
|
||||
|
||||
SRC = draw.c dunst.c dbus.c utils.c option_parser.c settings.c
|
||||
SRC = draw.c dunst.c dbus.c utils.c option_parser.c settings.c rules.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: doc options dunst service
|
||||
|
73
dunst.c
73
dunst.c
@ -33,6 +33,7 @@
|
||||
#include "draw.h"
|
||||
#include "dbus.h"
|
||||
#include "utils.h"
|
||||
#include "rules.h"
|
||||
|
||||
#include "option_parser.h"
|
||||
#include "settings.h"
|
||||
@ -98,10 +99,6 @@ GSList *rules = NULL;
|
||||
// }}}
|
||||
|
||||
// {{{ FUNCTION DEFINITIONS
|
||||
/* rules */
|
||||
void rule_apply(rule_t *r, notification *n);
|
||||
void rule_apply_all(notification *n);
|
||||
bool rule_matches_notification(rule_t *r, notification *n);
|
||||
|
||||
/* notifications */
|
||||
int notification_cmp(const void *a, const void *b);
|
||||
@ -765,74 +762,6 @@ int notification_close(notification * n, int reason)
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ RULE
|
||||
|
||||
/*
|
||||
* Apply rule to notification.
|
||||
*/
|
||||
void rule_apply(rule_t *r, notification *n)
|
||||
{ // {{{
|
||||
if (r->timeout != -1)
|
||||
n->timeout = r->timeout;
|
||||
if (r->urgency != -1)
|
||||
n->urgency = r->urgency;
|
||||
if (r->fg)
|
||||
n->color_strings[ColFG] = r->fg;
|
||||
if (r->bg)
|
||||
n->color_strings[ColBG] = r->bg;
|
||||
if (r->format)
|
||||
n->format = r->format;
|
||||
if (r->script)
|
||||
n->script = r->script;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Check all rules if they match n and apply.
|
||||
*/
|
||||
void rule_apply_all(notification *n)
|
||||
{ // {{{
|
||||
for (GSList *iter = rules; iter; iter = iter->next) {
|
||||
rule_t *r = iter->data;
|
||||
if (rule_matches_notification(r, n)) {
|
||||
rule_apply(r, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Initialize rule with default values.
|
||||
*/
|
||||
void rule_init(rule_t *r)
|
||||
{ // {{{
|
||||
r->name = NULL;
|
||||
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;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Check whether rule should be applied to n.
|
||||
*/
|
||||
bool rule_matches_notification(rule_t *r, notification *n)
|
||||
{ // {{{
|
||||
|
||||
return ((!r->appname || !fnmatch(r->appname, n->appname, 0))
|
||||
&& (!r->summary || !fnmatch(r->summary, n->summary, 0))
|
||||
&& (!r->body || !fnmatch(r->body, n->body, 0))
|
||||
&& (!r->icon || !fnmatch(r->icon, n->icon, 0)));
|
||||
}
|
||||
// }}}
|
||||
|
||||
// }}}
|
||||
|
||||
|
||||
// {{{ X
|
||||
|
18
dunst.h
18
dunst.h
@ -68,22 +68,6 @@ typedef struct _notification {
|
||||
Actions *actions;
|
||||
} notification;
|
||||
|
||||
typedef struct _rule_t {
|
||||
char *name;
|
||||
/* filters */
|
||||
char *appname;
|
||||
char *summary;
|
||||
char *body;
|
||||
char *icon;
|
||||
|
||||
/* actions */
|
||||
int timeout;
|
||||
int urgency;
|
||||
char *fg;
|
||||
char *bg;
|
||||
const char *format;
|
||||
const char *script;
|
||||
} rule_t;
|
||||
|
||||
typedef struct _keyboard_shortcut {
|
||||
const char *str;
|
||||
@ -99,13 +83,11 @@ typedef struct _render_text {
|
||||
} render_text;
|
||||
|
||||
extern int verbosity;
|
||||
extern GSList *rules;
|
||||
|
||||
/* return id of notification */
|
||||
int notification_init(notification * n, int id);
|
||||
int notification_close_by_id(int id, int reason);
|
||||
gboolean run(void *data);
|
||||
void wake_up(void);
|
||||
void rule_init(rule_t *r);
|
||||
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
69
rules.c
Normal file
69
rules.c
Normal file
@ -0,0 +1,69 @@
|
||||
// {{{ INVLUDES
|
||||
#include <glib.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#include "dunst.h"
|
||||
#include "rules.h"
|
||||
// }}}
|
||||
|
||||
/*
|
||||
* Apply rule to notification.
|
||||
*/
|
||||
void rule_apply(rule_t *r, notification *n)
|
||||
{
|
||||
if (r->timeout != -1)
|
||||
n->timeout = r->timeout;
|
||||
if (r->urgency != -1)
|
||||
n->urgency = r->urgency;
|
||||
if (r->fg)
|
||||
n->color_strings[ColFG] = r->fg;
|
||||
if (r->bg)
|
||||
n->color_strings[ColBG] = r->bg;
|
||||
if (r->format)
|
||||
n->format = r->format;
|
||||
if (r->script)
|
||||
n->script = r->script;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check all rules if they match n and apply.
|
||||
*/
|
||||
void rule_apply_all(notification *n)
|
||||
{
|
||||
for (GSList *iter = rules; iter; iter = iter->next) {
|
||||
rule_t *r = iter->data;
|
||||
if (rule_matches_notification(r, n)) {
|
||||
rule_apply(r, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize rule with default values.
|
||||
*/
|
||||
void rule_init(rule_t *r)
|
||||
{
|
||||
r->name = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check whether rule should be applied to n.
|
||||
*/
|
||||
bool rule_matches_notification(rule_t *r, notification *n)
|
||||
{
|
||||
|
||||
return ((!r->appname || !fnmatch(r->appname, n->appname, 0))
|
||||
&& (!r->summary || !fnmatch(r->summary, n->summary, 0))
|
||||
&& (!r->body || !fnmatch(r->body, n->body, 0))
|
||||
&& (!r->icon || !fnmatch(r->icon, n->icon, 0)));
|
||||
}
|
37
rules.h
Normal file
37
rules.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
// {{{ INCLUDES
|
||||
#include <glib.h>
|
||||
|
||||
#include "dunst.h"
|
||||
// }}}
|
||||
|
||||
// {{{ STRUCTS
|
||||
typedef struct _rule_t {
|
||||
char *name;
|
||||
/* filters */
|
||||
char *appname;
|
||||
char *summary;
|
||||
char *body;
|
||||
char *icon;
|
||||
|
||||
/* actions */
|
||||
int timeout;
|
||||
int urgency;
|
||||
char *fg;
|
||||
char *bg;
|
||||
const char *format;
|
||||
const char *script;
|
||||
} rule_t;
|
||||
// }}}
|
||||
|
||||
// {{{ GLOBALS
|
||||
extern GSList *rules;
|
||||
// }}}
|
||||
|
||||
// {{{ FUNCTIONS
|
||||
void rule_init(rule_t *r);
|
||||
void rule_apply(rule_t *r, notification *n);
|
||||
void rule_apply_all(notification *n);
|
||||
bool rule_matches_notification(rule_t *r, notification *n);
|
||||
// }}}
|
@ -5,6 +5,7 @@
|
||||
#include <basedir_fs.h>
|
||||
|
||||
#include "dunst.h"
|
||||
#include "rules.h"
|
||||
#include "option_parser.h"
|
||||
#include "settings.h"
|
||||
#include "config.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user