moved default values to config.h and added Rules

I know, this should be splitted into more than one commit. Shame on me.
This commit is contained in:
Sascha Kruse 2011-11-14 23:22:50 +01:00
parent ea702f0dad
commit 45ec236958
5 changed files with 93 additions and 26 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ dunst
*.o *.o
core core
vgcore.* vgcore.*
config.h

View File

@ -18,9 +18,13 @@ options:
@echo CC -c $< @echo CC -c $<
@${CC} -c $< ${CFLAGS} @${CC} -c $< ${CFLAGS}
${OBJ}: config.mk ${OBJ}: config.h config.mk
dunst: dunst.o draw.o config.h:
@echo creating $@ from config.def.h
@cp config.def.h $@
dunst: draw.o dunst.o
@echo CC -o $@ @echo CC -o $@
@${CC} ${CFLAGS} -o $@ dunst.o draw.o ${LDFLAGS} @${CC} ${CFLAGS} -o $@ dunst.o draw.o ${LDFLAGS}

35
config.def.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef CONFIG_H
#define CONFIG_H
#include "dunst.h"
/* appearance */
const char *font = NULL;
const char *normbgcolor = "#1793D1";
const char *normfgcolor = "#DDDDDD";
const char *critbgcolor = "#ffaaaa";
const char *critfgcolor = "#000000";
const char *lowbgcolor = "#aaaaff";
const char *lowfgcolor = "#000000";
const char *format = "%a-->%s %b"; /* default format */
int timeouts[] = { 10, 10, 0 }; /* low, normal, critical */
const char *geom = "0x4-10+10"; /* geometry */
int verbose = True; /* print info to stdout? */
const rule_t rules[] = {
/* appname, summary, body, icon, timeout, urgency, fg, bg */
{ "notify-send", NULL, NULL, NULL, -1, -1, NULL, NULL },
{ "Pidgin", NULL, NULL, NULL, -1, -1, NULL, NULL },
{ "Pidgin", "*signed on*", NULL, NULL, -1, LOW, NULL, NULL },
{ "Pidgin", "*signed off*", NULL, NULL, -1, LOW, NULL, NULL },
{ "Pidgin", "*says*", NULL, NULL, -1, CRIT, NULL, NULL },
{ "Pidgin", "twitter.com*", NULL, NULL, -1, NORM, NULL, NULL },
};
#endif

48
dunst.c
View File

@ -5,6 +5,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fnmatch.h>
#include <getopt.h> #include <getopt.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
@ -13,28 +14,18 @@
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
#endif #endif
#include "config.h"
#include "dunst.h" #include "dunst.h"
#include "draw.h" #include "draw.h"
#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b))
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define FONT_HEIGHT_BORDER 2 #define FONT_HEIGHT_BORDER 2
#define LOW 0
#define NORM 1
#define CRIT 2
/* structs */ /* structs */
typedef struct _dimension_t {
int x;
int y;
unsigned int h;
unsigned int w;
int mask;
} dimension_t;
typedef struct _screen_info { typedef struct _screen_info {
int scr; int scr;
dimension_t dim; dimension_t dim;
@ -42,19 +33,11 @@ typedef struct _screen_info {
/* global variables */ /* global variables */
static const char *font = NULL;
static const char *normbgcolor = "#cccccc";
static const char *normfgcolor = "#000000";
static const char *critbgcolor = "#ffaaaa";
static const char *critfgcolor = "#000000";
static const char *lowbgcolor = "#aaaaff";
static const char *lowfgcolor = "#000000";
/* 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;
static DC *dc; static DC *dc;
static Window win; static Window win;
static double timeouts[] = { 10, 10, 0 };
static msg_queue_t *msgqueue = NULL; static msg_queue_t *msgqueue = NULL;
static time_t now; static time_t now;
static int visible = False; static int visible = False;
@ -63,8 +46,6 @@ static KeySym mask = 0;
static screen_info scr; static screen_info scr;
static dimension_t geometry; static dimension_t geometry;
static int font_h; static int font_h;
static const char *format = "%s %b";
static int verbose = False;
/* list functions */ /* list functions */
msg_queue_t *append(msg_queue_t *queue, msg_queue_t *msg); msg_queue_t *append(msg_queue_t *queue, msg_queue_t *msg);
@ -74,6 +55,7 @@ int list_len(msg_queue_t *list);
/* misc funtions */ /* misc funtions */
void apply_rules(msg_queue_t *msg);
void check_timeouts(void); void check_timeouts(void);
void delete_all_msg(void); void delete_all_msg(void);
void delete_msg(msg_queue_t *elem); void delete_msg(msg_queue_t *elem);
@ -107,6 +89,9 @@ msg_queue_t*
append(msg_queue_t *queue, msg_queue_t *new) { append(msg_queue_t *queue, msg_queue_t *new) {
msg_queue_t *last; msg_queue_t *last;
apply_rules(new);
new->msg = string_replace("%a", new->appname, strdup(format)); new->msg = string_replace("%a", new->appname, strdup(format));
new->msg = string_replace("%s", new->summary, new->msg); new->msg = string_replace("%s", new->summary, new->msg);
new->msg = string_replace("%i", new->icon, new->msg); new->msg = string_replace("%i", new->icon, new->msg);
@ -114,7 +99,6 @@ append(msg_queue_t *queue, msg_queue_t *new) {
new->msg = string_replace("%b", new->body, new->msg); new->msg = string_replace("%b", new->body, new->msg);
new->msg = fix_markup(new->msg); new->msg = fix_markup(new->msg);
/* urgency > CRIT -> array out of range */ /* urgency > CRIT -> array out of range */
new->urgency = new->urgency > CRIT ? CRIT : new->urgency; new->urgency = new->urgency > CRIT ? CRIT : new->urgency;
@ -135,6 +119,21 @@ append(msg_queue_t *queue, msg_queue_t *new) {
} }
void
apply_rules(msg_queue_t *msg) {
int i;
for(i = 0; i < LENGTH(rules); i++) {
if((!rules[i].appname || !fnmatch(rules[i].appname, msg->appname, 0))
&& (!rules[i].summary || !fnmatch(rules[i].summary, msg->summary, 0))
&& (!rules[i].body || !fnmatch(rules[i].body, msg->body, 0))
&& (!rules[i].icon || !fnmatch(rules[i].icon, msg->icon, 0))) {
msg->timeout = rules[i].timeout != -1 ? rules[i].timeout : msg->timeout;
msg->urgency = rules[i].urgency != -1 ? rules[i].urgency : msg->urgency;
msg->color_strings[ColFG] = rules[i].fg ? rules[i].fg : msg->color_strings[ColFG];
msg->color_strings[ColBG] = rules[i].bg ? rules[i].bg : msg->color_strings[ColBG];
}
}
}
msg_queue_t* msg_queue_t*
delete(msg_queue_t *elem) { delete(msg_queue_t *elem) {
@ -538,6 +537,9 @@ main(int argc, char *argv[]) {
now = time(&now); now = time(&now);
dc = initdc(); dc = initdc();
geometry.mask = XParseGeometry(geom,
&geometry.x, &geometry.y,
&geometry.w, &geometry.h);
while(1) { while(1) {
static struct option long_options[] = { static struct option long_options[] = {

27
dunst.h
View File

@ -3,6 +3,24 @@
#include "draw.h" #include "draw.h"
#define LOW 0
#define NORM 1
#define CRIT 2
typedef struct _rule_t {
/* filters */
char *appname;
char *summary;
char *body;
char *icon;
/* actions */
int timeout;
int urgency;
char *fg;
char *bg;
} rule_t;
typedef struct _msg_queue_t { typedef struct _msg_queue_t {
char *appname; char *appname;
char *summary; char *summary;
@ -16,5 +34,12 @@ typedef struct _msg_queue_t {
unsigned long colors[ColLast]; unsigned long colors[ColLast];
char *color_strings[ColLast]; char *color_strings[ColLast];
} msg_queue_t; } msg_queue_t;
#endif
typedef struct _dimension_t {
int x;
int y;
unsigned int h;
unsigned int w;
int mask;
} dimension_t;
#endif