refactor/cleanup
* run code through `indent --no-tabs -linux` * use generic list implemenation for queues This sould have been multiple commits but some git foobar on my part made me loose the history :-/
This commit is contained in:
parent
305a791e21
commit
b0bf0b0b07
6
Makefile
6
Makefile
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
SRC = draw.c dunst.c ini.c
|
SRC = draw.c dunst.c list.c dunst_dbus.c ini.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
all: doc options dunst
|
all: doc options dunst
|
||||||
@ -20,9 +20,9 @@ options:
|
|||||||
|
|
||||||
${OBJ}: config.mk
|
${OBJ}: config.mk
|
||||||
|
|
||||||
dunst: draw.o dunst.o ini.o
|
dunst: draw.o dunst.o list.o dunst_dbus.o ini.o
|
||||||
@echo CC -o $@
|
@echo CC -o $@
|
||||||
@${CC} ${CFLAGS} -o $@ dunst.o draw.o ini.o ${LDFLAGS}
|
@${CC} ${CFLAGS} -o $@ dunst.o draw.o list.o dunst_dbus.o ini.o ${LDFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
|
183
draw.c
183
draw.c
@ -42,129 +42,143 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
void
|
void
|
||||||
drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
|
drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, Bool fill,
|
||||||
|
unsigned long color)
|
||||||
|
{
|
||||||
XSetForeground(dc->dpy, dc->gc, color);
|
XSetForeground(dc->dpy, dc->gc, color);
|
||||||
if(fill)
|
if (fill)
|
||||||
XFillRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w, h);
|
XFillRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x,
|
||||||
|
dc->y + y, w, h);
|
||||||
else
|
else
|
||||||
XDrawRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x, dc->y + y, w-1, h-1);
|
XDrawRectangle(dc->dpy, dc->canvas, dc->gc, dc->x + x,
|
||||||
|
dc->y + y, w - 1, h - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void drawtext(DC * dc, const char *text, ColorSet * col)
|
||||||
drawtext(DC *dc, const char *text, ColorSet *col) {
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
size_t mn, n = strlen(text);
|
size_t mn, n = strlen(text);
|
||||||
|
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) + dc->font.height/2 > dc->w; mn--)
|
for (mn = MIN(n, sizeof buf);
|
||||||
if(mn == 0)
|
textnw(dc, text, mn) + dc->font.height / 2 > dc->w; mn--)
|
||||||
|
if (mn == 0)
|
||||||
return;
|
return;
|
||||||
memcpy(buf, text, mn);
|
memcpy(buf, text, mn);
|
||||||
if(mn < n)
|
if (mn < n)
|
||||||
for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
|
for (n = MAX(mn - 3, 0); n < mn; buf[n++] = '.') ;
|
||||||
|
|
||||||
drawrect(dc, 0, 0, dc->w, dc->h, True, col->BG);
|
drawrect(dc, 0, 0, dc->w, dc->h, True, col->BG);
|
||||||
drawtextn(dc, buf, mn, col);
|
drawtextn(dc, buf, mn, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void drawtextn(DC * dc, const char *text, size_t n, ColorSet * col)
|
||||||
drawtextn(DC *dc, const char *text, size_t n, ColorSet *col) {
|
{
|
||||||
int x = dc->x + dc->font.height/2;
|
int x = dc->x + dc->font.height / 2;
|
||||||
int y = dc->y + dc->font.ascent+1;
|
int y = dc->y + dc->font.ascent + 1;
|
||||||
|
|
||||||
XSetForeground(dc->dpy, dc->gc, col->FG);
|
XSetForeground(dc->dpy, dc->gc, col->FG);
|
||||||
if(dc->font.xft_font) {
|
if (dc->font.xft_font) {
|
||||||
if (!dc->xftdraw)
|
if (!dc->xftdraw)
|
||||||
eprintf("error, xft drawable does not exist");
|
eprintf("error, xft drawable does not exist");
|
||||||
XftDrawStringUtf8(dc->xftdraw, &col->FG_xft,
|
XftDrawStringUtf8(dc->xftdraw, &col->FG_xft,
|
||||||
dc->font.xft_font, x, y, (unsigned char*)text, n);
|
dc->font.xft_font, x, y,
|
||||||
} else if(dc->font.set) {
|
(unsigned char *)text, n);
|
||||||
|
} else if (dc->font.set) {
|
||||||
printf("XmbDrawString\n");
|
printf("XmbDrawString\n");
|
||||||
XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y, text, n);
|
XmbDrawString(dc->dpy, dc->canvas, dc->font.set, dc->gc, x, y,
|
||||||
|
text, n);
|
||||||
} else {
|
} else {
|
||||||
XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
|
XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
|
||||||
XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
|
XDrawString(dc->dpy, dc->canvas, dc->gc, x, y, text, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void eprintf(const char *fmt, ...)
|
||||||
eprintf(const char *fmt, ...) {
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(stderr, fmt, ap);
|
vfprintf(stderr, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if(fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':') {
|
if (fmt[0] != '\0' && fmt[strlen(fmt) - 1] == ':') {
|
||||||
fputc(' ', stderr);
|
fputc(' ', stderr);
|
||||||
perror(NULL);
|
perror(NULL);
|
||||||
}
|
}
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void freecol(DC * dc, ColorSet * col)
|
||||||
freecol(DC *dc, ColorSet *col) {
|
{
|
||||||
if(col) {
|
if (col) {
|
||||||
if(&col->FG_xft)
|
if (&col->FG_xft)
|
||||||
XftColorFree(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
|
XftColorFree(dc->dpy,
|
||||||
DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), &col->FG_xft);
|
DefaultVisual(dc->dpy,
|
||||||
|
DefaultScreen(dc->dpy)),
|
||||||
|
DefaultColormap(dc->dpy,
|
||||||
|
DefaultScreen(dc->dpy)),
|
||||||
|
&col->FG_xft);
|
||||||
free(col);
|
free(col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void freedc(DC * dc)
|
||||||
freedc(DC *dc) {
|
{
|
||||||
if(dc->font.xft_font) {
|
if (dc->font.xft_font) {
|
||||||
XftFontClose(dc->dpy, dc->font.xft_font);
|
XftFontClose(dc->dpy, dc->font.xft_font);
|
||||||
XftDrawDestroy(dc->xftdraw);
|
XftDrawDestroy(dc->xftdraw);
|
||||||
}
|
}
|
||||||
if(dc->font.set)
|
if (dc->font.set)
|
||||||
XFreeFontSet(dc->dpy, dc->font.set);
|
XFreeFontSet(dc->dpy, dc->font.set);
|
||||||
if(dc->font.xfont)
|
if (dc->font.xfont)
|
||||||
XFreeFont(dc->dpy, dc->font.xfont);
|
XFreeFont(dc->dpy, dc->font.xfont);
|
||||||
if(dc->canvas)
|
if (dc->canvas)
|
||||||
XFreePixmap(dc->dpy, dc->canvas);
|
XFreePixmap(dc->dpy, dc->canvas);
|
||||||
if(dc->gc)
|
if (dc->gc)
|
||||||
XFreeGC(dc->dpy, dc->gc);
|
XFreeGC(dc->dpy, dc->gc);
|
||||||
if(dc->dpy)
|
if (dc->dpy)
|
||||||
XCloseDisplay(dc->dpy);
|
XCloseDisplay(dc->dpy);
|
||||||
if(dc)
|
if (dc)
|
||||||
free(dc);
|
free(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long getcolor(DC * dc, const char *colstr)
|
||||||
getcolor(DC *dc, const char *colstr) {
|
{
|
||||||
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
|
Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
|
||||||
XColor color;
|
XColor color;
|
||||||
|
|
||||||
if(!XAllocNamedColor(dc->dpy, cmap, colstr, &color, &color))
|
if (!XAllocNamedColor(dc->dpy, cmap, colstr, &color, &color))
|
||||||
eprintf("cannot allocate color '%s'\n", colstr);
|
eprintf("cannot allocate color '%s'\n", colstr);
|
||||||
return color.pixel;
|
return color.pixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorSet *
|
ColorSet *initcolor(DC * dc, const char *foreground, const char *background)
|
||||||
initcolor(DC *dc, const char * foreground, const char * background) {
|
{
|
||||||
ColorSet * col = (ColorSet *)malloc(sizeof(ColorSet));
|
ColorSet *col = (ColorSet *) malloc(sizeof(ColorSet));
|
||||||
if(!col)
|
if (!col)
|
||||||
eprintf("error, cannot allocate memory for color set");
|
eprintf("error, cannot allocate memory for color set");
|
||||||
col->BG = getcolor(dc, background);
|
col->BG = getcolor(dc, background);
|
||||||
col->FG = getcolor(dc, foreground);
|
col->FG = getcolor(dc, foreground);
|
||||||
if(dc->font.xft_font)
|
if (dc->font.xft_font)
|
||||||
if(!XftColorAllocName(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
|
if (!XftColorAllocName
|
||||||
DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)), foreground, &col->FG_xft))
|
(dc->dpy, DefaultVisual(dc->dpy, DefaultScreen(dc->dpy)),
|
||||||
eprintf("error, cannot allocate xft font color '%s'\n", foreground);
|
DefaultColormap(dc->dpy, DefaultScreen(dc->dpy)),
|
||||||
|
foreground, &col->FG_xft))
|
||||||
|
eprintf("error, cannot allocate xft font color '%s'\n",
|
||||||
|
foreground);
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
DC *
|
DC *initdc(void)
|
||||||
initdc(void) {
|
{
|
||||||
DC *dc;
|
DC *dc;
|
||||||
|
|
||||||
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||||
fputs("no locale support\n", stderr);
|
fputs("no locale support\n", stderr);
|
||||||
if(!(dc = calloc(1, sizeof *dc)))
|
if (!(dc = calloc(1, sizeof *dc)))
|
||||||
eprintf("cannot malloc %u bytes:", sizeof *dc);
|
eprintf("cannot malloc %u bytes:", sizeof *dc);
|
||||||
if(!(dc->dpy = XOpenDisplay(NULL)))
|
if (!(dc->dpy = XOpenDisplay(NULL)))
|
||||||
eprintf("cannot open display\n");
|
eprintf("cannot open display\n");
|
||||||
|
|
||||||
dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
|
dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
|
||||||
@ -172,69 +186,80 @@ initdc(void) {
|
|||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void initfont(DC * dc, const char *fontstr)
|
||||||
initfont(DC *dc, const char *fontstr) {
|
{
|
||||||
char *def, **missing, **names;
|
char *def, **missing, **names;
|
||||||
int i, n;
|
int i, n;
|
||||||
XFontStruct **xfonts;
|
XFontStruct **xfonts;
|
||||||
|
|
||||||
missing = NULL;
|
missing = NULL;
|
||||||
if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
|
if ((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
|
||||||
dc->font.ascent = dc->font.xfont->ascent;
|
dc->font.ascent = dc->font.xfont->ascent;
|
||||||
dc->font.descent = dc->font.xfont->descent;
|
dc->font.descent = dc->font.xfont->descent;
|
||||||
dc->font.width = dc->font.xfont->max_bounds.width;
|
dc->font.width = dc->font.xfont->max_bounds.width;
|
||||||
} else if((dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
|
} else
|
||||||
|
if ((dc->font.set =
|
||||||
|
XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def))) {
|
||||||
n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
|
n = XFontsOfFontSet(dc->font.set, &xfonts, &names);
|
||||||
for(i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
dc->font.ascent = MAX(dc->font.ascent, xfonts[i]->ascent);
|
dc->font.ascent =
|
||||||
dc->font.descent = MAX(dc->font.descent, xfonts[i]->descent);
|
MAX(dc->font.ascent, xfonts[i]->ascent);
|
||||||
dc->font.width = MAX(dc->font.width, xfonts[i]->max_bounds.width);
|
dc->font.descent =
|
||||||
|
MAX(dc->font.descent, xfonts[i]->descent);
|
||||||
|
dc->font.width =
|
||||||
|
MAX(dc->font.width, xfonts[i]->max_bounds.width);
|
||||||
}
|
}
|
||||||
} else if((dc->font.xft_font = XftFontOpenName(dc->dpy, DefaultScreen(dc->dpy), fontstr))) {
|
} else
|
||||||
|
if ((dc->font.xft_font =
|
||||||
|
XftFontOpenName(dc->dpy, DefaultScreen(dc->dpy), fontstr))) {
|
||||||
dc->font.ascent = dc->font.xft_font->ascent;
|
dc->font.ascent = dc->font.xft_font->ascent;
|
||||||
dc->font.descent = dc->font.xft_font->descent;
|
dc->font.descent = dc->font.xft_font->descent;
|
||||||
dc->font.width = dc->font.xft_font->max_advance_width;
|
dc->font.width = dc->font.xft_font->max_advance_width;
|
||||||
} else {
|
} else {
|
||||||
eprintf("cannot load font '%s'\n", fontstr);
|
eprintf("cannot load font '%s'\n", fontstr);
|
||||||
}
|
}
|
||||||
if(missing)
|
if (missing)
|
||||||
XFreeStringList(missing);
|
XFreeStringList(missing);
|
||||||
dc->font.height = dc->font.ascent + dc->font.descent;
|
dc->font.height = dc->font.ascent + dc->font.descent;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mapdc(DC * dc, Window win, unsigned int w, unsigned int h)
|
||||||
mapdc(DC *dc, Window win, unsigned int w, unsigned int h) {
|
{
|
||||||
XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, w, h, 0, 0);
|
XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, w, h, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void resizedc(DC * dc, unsigned int w, unsigned int h)
|
||||||
resizedc(DC *dc, unsigned int w, unsigned int h) {
|
{
|
||||||
int screen = DefaultScreen(dc->dpy);
|
int screen = DefaultScreen(dc->dpy);
|
||||||
if(dc->canvas)
|
if (dc->canvas)
|
||||||
XFreePixmap(dc->dpy, dc->canvas);
|
XFreePixmap(dc->dpy, dc->canvas);
|
||||||
|
|
||||||
dc->w = w;
|
dc->w = w;
|
||||||
dc->h = h;
|
dc->h = h;
|
||||||
dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
|
dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
|
||||||
DefaultDepth(dc->dpy, screen));
|
DefaultDepth(dc->dpy, screen));
|
||||||
if(dc->xftdraw) {
|
if (dc->xftdraw) {
|
||||||
XftDrawDestroy(dc->xftdraw);
|
XftDrawDestroy(dc->xftdraw);
|
||||||
}
|
}
|
||||||
if(dc->font.xft_font) {
|
if (dc->font.xft_font) {
|
||||||
dc->xftdraw = XftDrawCreate(dc->dpy, dc->canvas, DefaultVisual(dc->dpy,screen), DefaultColormap(dc->dpy,screen));
|
dc->xftdraw =
|
||||||
if(!(dc->xftdraw))
|
XftDrawCreate(dc->dpy, dc->canvas,
|
||||||
|
DefaultVisual(dc->dpy, screen),
|
||||||
|
DefaultColormap(dc->dpy, screen));
|
||||||
|
if (!(dc->xftdraw))
|
||||||
eprintf("error, cannot create xft drawable\n");
|
eprintf("error, cannot create xft drawable\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int textnw(DC * dc, const char *text, size_t len)
|
||||||
textnw(DC *dc, const char *text, size_t len) {
|
{
|
||||||
if(dc->font.xft_font) {
|
if (dc->font.xft_font) {
|
||||||
XGlyphInfo gi;
|
XGlyphInfo gi;
|
||||||
XftTextExtentsUtf8(dc->dpy, dc->font.xft_font, (const FcChar8*)text, len, &gi);
|
XftTextExtentsUtf8(dc->dpy, dc->font.xft_font,
|
||||||
|
(const FcChar8 *)text, len, &gi);
|
||||||
return gi.width;
|
return gi.width;
|
||||||
} else if(dc->font.set) {
|
} else if (dc->font.set) {
|
||||||
XRectangle r;
|
XRectangle r;
|
||||||
XmbTextExtents(dc->font.set, text, len, NULL, &r);
|
XmbTextExtents(dc->font.set, text, len, NULL, &r);
|
||||||
return r.width;
|
return r.width;
|
||||||
@ -242,7 +267,9 @@ textnw(DC *dc, const char *text, size_t len) {
|
|||||||
return XTextWidth(dc->font.xfont, text, len);
|
return XTextWidth(dc->font.xfont, text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int textw(DC * dc, const char *text)
|
||||||
textw(DC *dc, const char *text) {
|
{
|
||||||
return textnw(dc, text, strlen(text)) + dc->font.height;
|
return textnw(dc, text, strlen(text)) + dc->font.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
26
draw.h
26
draw.h
@ -59,19 +59,21 @@ typedef struct {
|
|||||||
unsigned long BG;
|
unsigned long BG;
|
||||||
} ColorSet;
|
} ColorSet;
|
||||||
|
|
||||||
void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
|
void drawrect(DC * dc, int x, int y, unsigned int w, unsigned int h, Bool fill,
|
||||||
void drawtext(DC *dc, const char *text, ColorSet *col);
|
unsigned long color);
|
||||||
void drawtextn(DC *dc, const char *text, size_t n, ColorSet *col);
|
void drawtext(DC * dc, const char *text, ColorSet * col);
|
||||||
void freecol(DC *dc, ColorSet *col);
|
void drawtextn(DC * dc, const char *text, size_t n, ColorSet * col);
|
||||||
|
void freecol(DC * dc, ColorSet * col);
|
||||||
void eprintf(const char *fmt, ...);
|
void eprintf(const char *fmt, ...);
|
||||||
void freedc(DC *dc);
|
void freedc(DC * dc);
|
||||||
unsigned long getcolor(DC *dc, const char *colstr);
|
unsigned long getcolor(DC * dc, const char *colstr);
|
||||||
ColorSet *initcolor(DC *dc, const char *foreground, const char *background);
|
ColorSet *initcolor(DC * dc, const char *foreground, const char *background);
|
||||||
DC *initdc(void);
|
DC *initdc(void);
|
||||||
void initfont(DC *dc, const char *fontstr);
|
void initfont(DC * dc, const char *fontstr);
|
||||||
void mapdc(DC *dc, Window win, unsigned int w, unsigned int h);
|
void mapdc(DC * dc, Window win, unsigned int w, unsigned int h);
|
||||||
void resizedc(DC *dc, unsigned int w, unsigned int h);
|
void resizedc(DC * dc, unsigned int w, unsigned int h);
|
||||||
int textnw(DC *dc, const char *text, size_t len);
|
int textnw(DC * dc, const char *text, size_t len);
|
||||||
int textw(DC *dc, const char *text);
|
int textw(DC * dc, const char *text);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
11
dunst.h
11
dunst.h
@ -31,20 +31,21 @@ typedef struct _rule_t {
|
|||||||
struct _rule_t *next;
|
struct _rule_t *next;
|
||||||
} rule_t;
|
} rule_t;
|
||||||
|
|
||||||
typedef struct _msg_queue_t {
|
typedef struct _notification {
|
||||||
char *appname;
|
char *appname;
|
||||||
char *summary;
|
char *summary;
|
||||||
char *body;
|
char *body;
|
||||||
char *icon;
|
char *icon;
|
||||||
char *msg;
|
char *msg;
|
||||||
const char *format;
|
const char *format;
|
||||||
struct _msg_queue_t *next;
|
|
||||||
time_t start;
|
time_t start;
|
||||||
|
time_t timestamp;
|
||||||
int timeout;
|
int timeout;
|
||||||
int urgency;
|
int urgency;
|
||||||
|
int redisplayed; /* has been displayed before? */
|
||||||
ColorSet *colors;
|
ColorSet *colors;
|
||||||
char *color_strings[2];
|
char *color_strings[2];
|
||||||
} msg_queue_t;
|
} notification;
|
||||||
|
|
||||||
typedef struct _dimension_t {
|
typedef struct _dimension_t {
|
||||||
int x;
|
int x;
|
||||||
@ -54,3 +55,7 @@ typedef struct _dimension_t {
|
|||||||
int mask;
|
int mask;
|
||||||
} dimension_t;
|
} dimension_t;
|
||||||
#endif
|
#endif
|
||||||
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
|
||||||
|
void init_notification(notification * n);
|
||||||
|
void map_win(void);
|
||||||
|
280
dunst_dbus.c
280
dunst_dbus.c
@ -3,59 +3,57 @@
|
|||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
|
||||||
#include "dunst.h"
|
#include "dunst.h"
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
#define DBUS_POLL_TIMEOUT 200
|
#include "dunst_dbus.h"
|
||||||
|
|
||||||
DBusError dbus_err;
|
DBusError dbus_err;
|
||||||
DBusConnection *dbus_conn;
|
DBusConnection *dbus_conn;
|
||||||
dbus_uint32_t dbus_serial = 0;
|
dbus_uint32_t dbus_serial = 0;
|
||||||
|
|
||||||
|
|
||||||
static const char *introspect = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
static const char *introspect = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||||
|
"<node name=\"/org/freedesktop/Notifications\">"
|
||||||
|
" <interface name=\"org.freedesktop.Notifications\">"
|
||||||
|
" "
|
||||||
|
" <method name=\"GetCapabilities\">"
|
||||||
|
" <arg direction=\"out\" name=\"capabilities\" type=\"as\"/>"
|
||||||
|
" </method>"
|
||||||
|
" <method name=\"Notify\">"
|
||||||
|
" <arg direction=\"in\" name=\"app_name\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"replaces_id\" type=\"u\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"app_icon\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"summary\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"body\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"actions\" type=\"as\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"hints\" type=\"a{sv}\"/>"
|
||||||
|
" <arg direction=\"in\" name=\"expire_timeout\" type=\"i\"/>"
|
||||||
|
" <arg direction=\"out\" name=\"id\" type=\"u\"/>"
|
||||||
|
" </method>"
|
||||||
|
" "
|
||||||
|
" <method name=\"CloseNotification\">"
|
||||||
|
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
|
||||||
|
" </method>"
|
||||||
|
" <method name=\"GetServerInformation\">"
|
||||||
|
" <arg direction=\"out\" name=\"name\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"out\" name=\"vendor\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"out\" name=\"version\" type=\"s\"/>"
|
||||||
|
" <arg direction=\"out\" name=\"spec_version\" type=\"s\"/>"
|
||||||
|
" </method>"
|
||||||
|
" <signal name=\"NotificationClosed\">"
|
||||||
|
" <arg name=\"id\" type=\"u\"/>"
|
||||||
|
" <arg name=\"reason\" type=\"u\"/>"
|
||||||
|
" </signal>"
|
||||||
|
" <signal name=\"ActionInvoked\">"
|
||||||
|
" <arg name=\"id\" type=\"u\"/>"
|
||||||
|
" <arg name=\"action_key\" type=\"s\"/>"
|
||||||
|
" </signal>"
|
||||||
|
" </interface>"
|
||||||
|
" "
|
||||||
|
" <interface name=\"org.xfce.Notifyd\">"
|
||||||
|
" <method name=\"Quit\"/>" " </interface>" "</node>";
|
||||||
|
|
||||||
"<node name=\"/org/freedesktop/Notifications\">"
|
void dbus_introspect(DBusMessage * dmsg)
|
||||||
" <interface name=\"org.freedesktop.Notifications\">"
|
{
|
||||||
" "
|
|
||||||
" <method name=\"GetCapabilities\">"
|
|
||||||
" <arg direction=\"out\" name=\"capabilities\" type=\"as\"/>"
|
|
||||||
" </method>"
|
|
||||||
" <method name=\"Notify\">"
|
|
||||||
" <arg direction=\"in\" name=\"app_name\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"replaces_id\" type=\"u\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"app_icon\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"summary\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"body\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"actions\" type=\"as\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"hints\" type=\"a{sv}\"/>"
|
|
||||||
" <arg direction=\"in\" name=\"expire_timeout\" type=\"i\"/>"
|
|
||||||
" <arg direction=\"out\" name=\"id\" type=\"u\"/>"
|
|
||||||
" </method>"
|
|
||||||
" "
|
|
||||||
" <method name=\"CloseNotification\">"
|
|
||||||
" <arg direction=\"in\" name=\"id\" type=\"u\"/>"
|
|
||||||
" </method>"
|
|
||||||
" <method name=\"GetServerInformation\">"
|
|
||||||
" <arg direction=\"out\" name=\"name\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"out\" name=\"vendor\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"out\" name=\"version\" type=\"s\"/>"
|
|
||||||
" <arg direction=\"out\" name=\"spec_version\" type=\"s\"/>"
|
|
||||||
" </method>"
|
|
||||||
" <signal name=\"NotificationClosed\">"
|
|
||||||
" <arg name=\"id\" type=\"u\"/>"
|
|
||||||
" <arg name=\"reason\" type=\"u\"/>"
|
|
||||||
" </signal>"
|
|
||||||
" <signal name=\"ActionInvoked\">"
|
|
||||||
" <arg name=\"id\" type=\"u\"/>"
|
|
||||||
" <arg name=\"action_key\" type=\"s\"/>"
|
|
||||||
" </signal>"
|
|
||||||
" </interface>"
|
|
||||||
" "
|
|
||||||
" <interface name=\"org.xfce.Notifyd\">"
|
|
||||||
" <method name=\"Quit\"/>"
|
|
||||||
" </interface>"
|
|
||||||
"</node>";
|
|
||||||
|
|
||||||
void dbus_introspect(DBusMessage * dmsg) {
|
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
|
|
||||||
@ -69,98 +67,98 @@ void dbus_introspect(DBusMessage * dmsg) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void initdbus(void)
|
||||||
initdbus(void) {
|
{
|
||||||
int ret;
|
int ret;
|
||||||
dbus_error_init(&dbus_err);
|
dbus_error_init(&dbus_err);
|
||||||
dbus_conn = dbus_bus_get(DBUS_BUS_SESSION, &dbus_err);
|
dbus_conn = dbus_bus_get(DBUS_BUS_SESSION, &dbus_err);
|
||||||
if(dbus_error_is_set(&dbus_err)) {
|
if (dbus_error_is_set(&dbus_err)) {
|
||||||
fprintf(stderr, "Connection Error (%s)\n", dbus_err.message);
|
fprintf(stderr, "Connection Error (%s)\n", dbus_err.message);
|
||||||
dbus_error_free(&dbus_err);
|
dbus_error_free(&dbus_err);
|
||||||
}
|
}
|
||||||
if(dbus_conn == NULL) {
|
if (dbus_conn == NULL) {
|
||||||
fprintf(stderr, "dbus_con == NULL\n");
|
fprintf(stderr, "dbus_con == NULL\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = dbus_bus_request_name(dbus_conn, "org.freedesktop.Notifications",
|
ret = dbus_bus_request_name(dbus_conn, "org.freedesktop.Notifications",
|
||||||
DBUS_NAME_FLAG_REPLACE_EXISTING, &dbus_err);
|
DBUS_NAME_FLAG_REPLACE_EXISTING, &dbus_err);
|
||||||
if(dbus_error_is_set(&dbus_err)) {
|
if (dbus_error_is_set(&dbus_err)) {
|
||||||
fprintf(stderr, "Name Error (%s)\n", dbus_err.message);
|
fprintf(stderr, "Name Error (%s)\n", dbus_err.message);
|
||||||
}
|
}
|
||||||
if(DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
|
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
|
||||||
fprintf(stderr, "There's already another notification-daemon running\n");
|
fprintf(stderr,
|
||||||
|
"There's already another notification-daemon running\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_bus_add_match(dbus_conn,
|
dbus_bus_add_match(dbus_conn,
|
||||||
"type='signal',interface='org.freedesktop.Notifications'",
|
"type='signal',interface='org.freedesktop.Notifications'",
|
||||||
&dbus_err);
|
&dbus_err);
|
||||||
if(dbus_error_is_set(&dbus_err)) {
|
if (dbus_error_is_set(&dbus_err)) {
|
||||||
fprintf(stderr, "Match error (%s)\n", dbus_err.message);
|
fprintf(stderr, "Match error (%s)\n", dbus_err.message);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void dbus_poll(int timeout)
|
||||||
dbus_poll(void) {
|
{
|
||||||
DBusMessage *dbus_msg;
|
DBusMessage *dbus_msg;
|
||||||
|
|
||||||
/* make timeout smaller if we are displaying a message
|
dbus_connection_read_write(dbus_conn, timeout);
|
||||||
* to improve responsivness for mouse clicks
|
|
||||||
*/
|
|
||||||
if(msgqueue == NULL) {
|
|
||||||
dbus_connection_read_write(dbus_conn, DBUS_POLL_TIMEOUT);
|
|
||||||
} else {
|
|
||||||
dbus_connection_read_write(dbus_conn, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
dbus_msg = dbus_connection_pop_message(dbus_conn);
|
dbus_msg = dbus_connection_pop_message(dbus_conn);
|
||||||
/* we don't have a new message */
|
/* we don't have a new message */
|
||||||
if(dbus_msg == NULL) {
|
if (dbus_msg == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbus_message_is_method_call(dbus_msg,"org.freedesktop.DBus.Introspectable", "Introspect")) {
|
if (dbus_message_is_method_call
|
||||||
|
(dbus_msg, "org.freedesktop.DBus.Introspectable", "Introspect")) {
|
||||||
dbus_introspect(dbus_msg);
|
dbus_introspect(dbus_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dbus_message_is_method_call(dbus_msg,
|
if (dbus_message_is_method_call(dbus_msg,
|
||||||
"org.freedesktop.Notifications","Notify")) {
|
"org.freedesktop.Notifications",
|
||||||
|
"Notify")) {
|
||||||
notify(dbus_msg);
|
notify(dbus_msg);
|
||||||
}
|
}
|
||||||
if(dbus_message_is_method_call(dbus_msg,
|
if (dbus_message_is_method_call(dbus_msg,
|
||||||
"org.freedesktop.Notifications", "GetCapabilities")) {
|
"org.freedesktop.Notifications",
|
||||||
|
"GetCapabilities")) {
|
||||||
getCapabilities(dbus_msg);
|
getCapabilities(dbus_msg);
|
||||||
}
|
}
|
||||||
if(dbus_message_is_method_call(dbus_msg,
|
if (dbus_message_is_method_call(dbus_msg,
|
||||||
"org.freedesktop.Notifications", "GetServerInformation")) {
|
"org.freedesktop.Notifications",
|
||||||
|
"GetServerInformation")) {
|
||||||
getServerInformation(dbus_msg);
|
getServerInformation(dbus_msg);
|
||||||
}
|
}
|
||||||
if(dbus_message_is_method_call(dbus_msg,
|
if (dbus_message_is_method_call(dbus_msg,
|
||||||
"org.freedesktop.Notifications", "CloseNotification")) {
|
"org.freedesktop.Notifications",
|
||||||
|
"CloseNotification")) {
|
||||||
closeNotification(dbus_msg);
|
closeNotification(dbus_msg);
|
||||||
}
|
}
|
||||||
dbus_message_unref(dbus_msg);
|
dbus_message_unref(dbus_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void getCapabilities(DBusMessage * dmsg)
|
||||||
getCapabilities(DBusMessage *dmsg) {
|
{
|
||||||
DBusMessage* reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
DBusMessageIter subargs;
|
DBusMessageIter subargs;
|
||||||
|
|
||||||
const char *caps[1] = {"body"};
|
const char *caps[1] = { "body" };
|
||||||
dbus_serial++;
|
dbus_serial++;
|
||||||
|
|
||||||
reply = dbus_message_new_method_return(dmsg);
|
reply = dbus_message_new_method_return(dmsg);
|
||||||
if(!reply) {
|
if (!reply) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_message_iter_init_append(reply, &args);
|
dbus_message_iter_init_append(reply, &args);
|
||||||
|
|
||||||
if(!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subargs )
|
if (!dbus_message_iter_open_container
|
||||||
|
(&args, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subargs)
|
||||||
|| !dbus_message_iter_append_basic(&subargs, DBUS_TYPE_STRING, caps)
|
|| !dbus_message_iter_append_basic(&subargs, DBUS_TYPE_STRING, caps)
|
||||||
|| !dbus_message_iter_close_container(&args, &subargs)
|
|| !dbus_message_iter_close_container(&args, &subargs)
|
||||||
|| !dbus_connection_send(dbus_conn, reply, &dbus_serial)) {
|
|| !dbus_connection_send(dbus_conn, reply, &dbus_serial)) {
|
||||||
@ -172,42 +170,40 @@ getCapabilities(DBusMessage *dmsg) {
|
|||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void closeNotification(DBusMessage * dmsg)
|
||||||
closeNotification(DBusMessage *dmsg) {
|
{
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
reply = dbus_message_new_method_return(dmsg);
|
reply = dbus_message_new_method_return(dmsg);
|
||||||
if(!reply) {
|
if (!reply) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dbus_connection_send(dbus_conn, reply, &dbus_serial);
|
dbus_connection_send(dbus_conn, reply, &dbus_serial);
|
||||||
dbus_connection_flush(dbus_conn);
|
dbus_connection_flush(dbus_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void getServerInformation(DBusMessage * dmsg)
|
||||||
getServerInformation(DBusMessage *dmsg) {
|
{
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
char *param = "";
|
char *param = "";
|
||||||
const char *info[4] = {"dunst", "dunst", "2011", "2011"};
|
const char *info[4] = { "dunst", "dunst", "2011", "2011" };
|
||||||
|
|
||||||
|
|
||||||
if (!dbus_message_iter_init(dmsg, &args)) {
|
if (!dbus_message_iter_init(dmsg, &args)) {
|
||||||
}
|
} else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
|
||||||
else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
dbus_message_iter_get_basic(&args, ¶m);
|
dbus_message_iter_get_basic(&args, ¶m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
reply = dbus_message_new_method_return(dmsg);
|
reply = dbus_message_new_method_return(dmsg);
|
||||||
|
|
||||||
dbus_message_iter_init_append(reply, &args);
|
dbus_message_iter_init_append(reply, &args);
|
||||||
if(!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[0])
|
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[0])
|
||||||
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[1])
|
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
|
||||||
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[2])
|
&info[1])
|
||||||
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &info[3])) {
|
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
|
||||||
|
&info[2])
|
||||||
|
|| !dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
|
||||||
|
&info[3])) {
|
||||||
fprintf(stderr, "Unable to fill arguments");
|
fprintf(stderr, "Unable to fill arguments");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -222,36 +218,32 @@ getServerInformation(DBusMessage *dmsg) {
|
|||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _extract_basic(int type, DBusMessageIter * iter, void *target)
|
||||||
static void
|
{
|
||||||
_extract_basic(int type, DBusMessageIter *iter, void *target) {
|
|
||||||
int iter_type = dbus_message_iter_get_arg_type(iter);
|
int iter_type = dbus_message_iter_get_arg_type(iter);
|
||||||
if (iter_type != type) {
|
if (iter_type == type) {
|
||||||
dunst_printf(DEBUG, "Invalid dbus notification: expected type %d but got %d.\n",
|
|
||||||
type, iter_type);
|
|
||||||
} else {
|
|
||||||
dbus_message_iter_get_basic(iter, target);
|
dbus_message_iter_get_basic(iter, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_extract_hint(const char *name, const char *hint_name,
|
_extract_hint(const char *name, const char *hint_name,
|
||||||
DBusMessageIter *hint, void *target) {
|
DBusMessageIter * hint, void *target)
|
||||||
|
{
|
||||||
|
|
||||||
DBusMessageIter hint_value;
|
DBusMessageIter hint_value;
|
||||||
|
|
||||||
if(!strcmp(hint_name, name)) {
|
if (!strcmp(hint_name, name)) {
|
||||||
dunst_printf(DEBUG, "%s found\n", name);
|
|
||||||
dbus_message_iter_next(hint);
|
dbus_message_iter_next(hint);
|
||||||
dbus_message_iter_recurse(hint, &hint_value);
|
dbus_message_iter_recurse(hint, &hint_value);
|
||||||
do {
|
do {
|
||||||
dbus_message_iter_get_basic(&hint_value, target);
|
dbus_message_iter_get_basic(&hint_value, target);
|
||||||
} while(dbus_message_iter_next(hint));
|
} while (dbus_message_iter_next(hint));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void notify(DBusMessage * dmsg)
|
||||||
notify(DBusMessage *dmsg) {
|
{
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
DBusMessageIter args;
|
DBusMessageIter args;
|
||||||
DBusMessageIter hints;
|
DBusMessageIter hints;
|
||||||
@ -267,49 +259,41 @@ notify(DBusMessage *dmsg) {
|
|||||||
const char *fgcolor = NULL;
|
const char *fgcolor = NULL;
|
||||||
const char *bgcolor = NULL;
|
const char *bgcolor = NULL;
|
||||||
int urgency = 1;
|
int urgency = 1;
|
||||||
msg_queue_t *msg = malloc(sizeof(msg_queue_t));
|
notification *n = malloc(sizeof(notification));
|
||||||
dbus_uint32_t nid=0;
|
dbus_uint32_t nid = 0;
|
||||||
dbus_int32_t expires=-1;
|
dbus_int32_t expires = -1;
|
||||||
|
|
||||||
dbus_serial++;
|
dbus_serial++;
|
||||||
dunst_printf(DEBUG, "new dbus message\n");
|
|
||||||
dbus_message_iter_init(dmsg, &args);
|
dbus_message_iter_init(dmsg, &args);
|
||||||
|
|
||||||
dunst_printf(DEBUG, "extracting appname\n");
|
|
||||||
_extract_basic(DBUS_TYPE_STRING, &args, &appname);
|
_extract_basic(DBUS_TYPE_STRING, &args, &appname);
|
||||||
|
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
dunst_printf(DEBUG, "extracting nid\n");
|
|
||||||
_extract_basic(DBUS_TYPE_UINT32, &args, &nid);
|
_extract_basic(DBUS_TYPE_UINT32, &args, &nid);
|
||||||
|
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
dunst_printf(DEBUG, "extracting icon\n");
|
|
||||||
_extract_basic(DBUS_TYPE_STRING, &args, &icon);
|
_extract_basic(DBUS_TYPE_STRING, &args, &icon);
|
||||||
|
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
dunst_printf(DEBUG, "extracting summary\n");
|
|
||||||
_extract_basic(DBUS_TYPE_STRING, &args, &summary);
|
_extract_basic(DBUS_TYPE_STRING, &args, &summary);
|
||||||
|
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
dunst_printf(DEBUG, "extracting body\n");
|
|
||||||
_extract_basic(DBUS_TYPE_STRING, &args, &body);
|
_extract_basic(DBUS_TYPE_STRING, &args, &body);
|
||||||
|
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
|
|
||||||
dunst_printf(DEBUG, "extracting hints\n");
|
|
||||||
dbus_message_iter_recurse(&args, &hints);
|
dbus_message_iter_recurse(&args, &hints);
|
||||||
dbus_message_iter_next( &args );
|
dbus_message_iter_next(&args);
|
||||||
|
|
||||||
dunst_printf(DEBUG, "extracting expires\n");
|
|
||||||
_extract_basic(DBUS_TYPE_INT32, &args, &expires);
|
_extract_basic(DBUS_TYPE_INT32, &args, &expires);
|
||||||
|
|
||||||
|
|
||||||
dunst_printf(DEBUG, "extracting hints\n");
|
|
||||||
while (dbus_message_iter_get_arg_type(&hints) != DBUS_TYPE_INVALID) {
|
while (dbus_message_iter_get_arg_type(&hints) != DBUS_TYPE_INVALID) {
|
||||||
dbus_message_iter_recurse(&hints, &hint);
|
dbus_message_iter_recurse(&hints, &hint);
|
||||||
while (dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_INVALID) {
|
while (dbus_message_iter_get_arg_type(&hint) !=
|
||||||
if(dbus_message_iter_get_arg_type(&hint) != DBUS_TYPE_STRING) {
|
DBUS_TYPE_INVALID) {
|
||||||
|
if (dbus_message_iter_get_arg_type(&hint) !=
|
||||||
|
DBUS_TYPE_STRING) {
|
||||||
dbus_message_iter_next(&hint);
|
dbus_message_iter_next(&hint);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -322,28 +306,26 @@ notify(DBusMessage *dmsg) {
|
|||||||
dbus_message_iter_next(&hints);
|
dbus_message_iter_next(&hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expires > 0) {
|
||||||
if(expires > 0) {
|
|
||||||
/* do some rounding */
|
/* do some rounding */
|
||||||
expires = (expires+500)/1000;
|
expires = (expires + 500) / 1000;
|
||||||
if(expires < 1) {
|
if (expires < 1) {
|
||||||
expires = 1;
|
expires = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg->appname = strdup(appname);
|
n->appname = strdup(appname);
|
||||||
msg->summary = strdup(summary);
|
n->summary = strdup(summary);
|
||||||
msg->body = strdup(body);
|
n->body = strdup(body);
|
||||||
msg->icon = strdup(icon);
|
n->icon = strdup(icon);
|
||||||
msg->timeout = expires;
|
n->timeout = expires;
|
||||||
msg->urgency = urgency;
|
n->urgency = urgency;
|
||||||
for(i = 0; i < ColLast; i++) {
|
for (i = 0; i < ColLast; i++) {
|
||||||
msg->color_strings[i] = NULL;
|
n->color_strings[i] = NULL;
|
||||||
}
|
}
|
||||||
msg->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor);
|
n->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor);
|
||||||
msg->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor);
|
n->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor);
|
||||||
initmsg(msg);
|
init_notification(n);
|
||||||
msgqueue = add(msgqueue, msg);
|
map_win();
|
||||||
drawmsg();
|
|
||||||
|
|
||||||
reply = dbus_message_new_method_return(dmsg);
|
reply = dbus_message_new_method_return(dmsg);
|
||||||
|
|
||||||
@ -353,3 +335,5 @@ notify(DBusMessage *dmsg) {
|
|||||||
|
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
17
dunst_dbus.h
17
dunst_dbus.h
@ -1,12 +1,17 @@
|
|||||||
/* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
/* copyright 2012 Sascha Kruse and contributors (see LICENSE for licensing information) */
|
||||||
|
|
||||||
|
#ifndef _DUNST_DBUS_H
|
||||||
|
#define _DUNST_DBUS_H
|
||||||
|
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
|
||||||
void initdbus(void);
|
void initdbus(void);
|
||||||
void dbus_poll(void);
|
void dbus_poll(int timeout);
|
||||||
void notify(DBusMessage *msg);
|
void notify(DBusMessage * msg);
|
||||||
void getCapabilities(DBusMessage *dmsg);
|
void getCapabilities(DBusMessage * dmsg);
|
||||||
void closeNotification(DBusMessage *dmsg);
|
void closeNotification(DBusMessage * dmsg);
|
||||||
void getServerInformation(DBusMessage *dmsg);
|
void getServerInformation(DBusMessage * dmsg);
|
||||||
|
|
||||||
#include "dunst_dbus.c"
|
#endif
|
||||||
|
|
||||||
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user