alignment

This commit is contained in:
Sascha Kruse 2012-06-30 23:29:14 +02:00
parent 7a1d758242
commit 7e696cc02d
3 changed files with 33 additions and 1 deletions

27
dunst.c
View File

@ -47,6 +47,7 @@ typedef struct _screen_info {
typedef struct _notification_buffer { typedef struct _notification_buffer {
char txt[BUFSIZ]; char txt[BUFSIZ];
notification *n; notification *n;
int x_offset;
} notification_buffer; } notification_buffer;
/* global variables */ /* global variables */
@ -68,6 +69,7 @@ char *key_string = NULL;
char *history_key_string = NULL; char *history_key_string = NULL;
KeySym mask = 0; KeySym mask = 0;
int idle_threshold = 0; int idle_threshold = 0;
enum alignment align = left;
int verbosity = 0; int verbosity = 0;
@ -320,6 +322,7 @@ void draw_win(void)
for (i = 0, iter = displayed_notifications->head; i < height; i++) { for (i = 0, iter = displayed_notifications->head; i < height; i++) {
memset(n_buf[i].txt, '\0', BUFSIZ); memset(n_buf[i].txt, '\0', BUFSIZ);
n_buf[i].x_offset = 0;
if (iter) { if (iter) {
n_buf[i].n = (notification *) iter->data; n_buf[i].n = (notification *) iter->data;
strncpy(n_buf[i].txt, n_buf[i].n->msg, BUFSIZ); strncpy(n_buf[i].txt, n_buf[i].n->msg, BUFSIZ);
@ -359,6 +362,18 @@ void draw_win(void)
width = scr.dim.w; width = scr.dim.w;
} }
/* calculate offsets for alignment */
for (i = 0; i < height; i++) {
if (strlen(n_buf[i].txt) < 1)
continue;
if (align == right) {
n_buf[i].x_offset = width - textw(dc, n_buf[i].txt);
} else if (align == center) {
n_buf[i].x_offset = (width - textw(dc,
n_buf[i].txt)) / 2;
}
}
/* calculate window position */ /* calculate window position */
if (geometry.mask & XNegative) { if (geometry.mask & XNegative) {
@ -388,8 +403,9 @@ void draw_win(void)
* its attributes * its attributes
*/ */
n = n_buf[i].n ? n_buf[i].n : n_buf[i - 1].n; n = n_buf[i].n ? n_buf[i].n : n_buf[i - 1].n;
dc->x = 0;
drawrect(dc, 0, 0, width, font_h, True, n->colors->BG); drawrect(dc, 0, 0, width, font_h, True, n->colors->BG);
dc->x = n_buf[i].x_offset;
drawtext(dc, n_buf[i].txt, n->colors); drawtext(dc, n_buf[i].txt, n->colors);
dc->y += font_h; dc->y += font_h;
} }
@ -1065,9 +1081,18 @@ dunst_ini_handle(void *user_data, const char *section,
} else if (!strcmp(mod, "mod1")) { } else if (!strcmp(mod, "mod1")) {
mask = Mod1Mask; mask = Mod1Mask;
} else { } else {
/* FIXME warning on unknown modifier */
mask = 0; mask = 0;
} }
free(mod); free(mod);
} else if (strcmp(name, "alignment") == 0) {
if (strcmp(value, "left") == 0)
align = left;
else if (strcmp(value, "center") == 0)
align = center;
else if (strcmp(value, "right") == 0)
align = right;
/* FIXME warning on unknown alignment */
} }
} else if (strcmp(section, "urgency_low") == 0) { } else if (strcmp(section, "urgency_low") == 0) {
if (strcmp(name, "background") == 0) if (strcmp(name, "background") == 0)

View File

@ -13,6 +13,8 @@
#define ColFG 1 #define ColFG 1
#define ColBG 0 #define ColBG 0
enum alignment {left, center, right};
typedef struct _rule_t { typedef struct _rule_t {
char *name; char *name;
/* filters */ /* filters */

View File

@ -25,6 +25,10 @@
# key to redisplay last message(s) # key to redisplay last message(s)
history_key = grave history_key = grave
# alignment of message text.
# Possible values are "left", "center" and "right"
alignment = left
# the geometry of the window # the geometry of the window
# geometry [{width}]x{height}][+/-{x}+/-{y}] # geometry [{width}]x{height}][+/-{x}+/-{y}]
@ -45,6 +49,7 @@
# Which monitor should the notifications be displayed one # Which monitor should the notifications be displayed one
monitor = 0 monitor = 0
[urgency_low] [urgency_low]
# IMPORTANT: colors have to be defined in quotation marks. # IMPORTANT: colors have to be defined in quotation marks.
# Otherwise the '#' and following would be interpreted as a comment. # Otherwise the '#' and following would be interpreted as a comment.