Merge pull request #62 from npcardoso/434a575bfb3fd0564001d03715d5582201f7dbd9

Implemented bouncing text
This commit is contained in:
Sascha Kruse 2012-09-13 14:49:02 -07:00
commit afe456c0ba
4 changed files with 20 additions and 3 deletions

View File

@ -18,6 +18,7 @@ int indicate_hidden = True; /* show count of hidden messages */
int idle_threshold = 0; /* don't timeout notifications when idle for x seconds */ int idle_threshold = 0; /* don't timeout notifications when idle for x seconds */
int show_age_threshold = -1; /* show age of notification, when notification is older than x seconds */ int show_age_threshold = -1; /* show age of notification, when notification is older than x seconds */
enum alignment align = left; /* text alignment [left/center/right] */ enum alignment align = left; /* text alignment [left/center/right] */
float bounce_freq = 1; /* determines the bounce frequency (if activated) */
int sticky_history = True; int sticky_history = True;
int verbosity = 0; int verbosity = 0;
int word_wrap = False; int word_wrap = False;

View File

@ -23,7 +23,7 @@ INIFLAGS = -DINI_ALLOW_MULTILINE=0
# includes and libs # includes and libs
INCS = -I${X11INC} $(shell pkg-config --cflags dbus-1 libxdg-basedir) ${XFTINC} INCS = -I${X11INC} $(shell pkg-config --cflags dbus-1 libxdg-basedir) ${XFTINC}
LIBS = -L${X11LIB} -lX11 -lXss ${XFTLIBS} ${XINERAMALIBS} $(shell pkg-config --libs dbus-1 libxdg-basedir) LIBS = -lm -L${X11LIB} -lX11 -lXss ${XFTLIBS} ${XINERAMALIBS} $(shell pkg-config --libs dbus-1 libxdg-basedir)
# flags # flags
CPPFLAGS += -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${INIFLAGS} CPPFLAGS += -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} ${INIFLAGS}

17
dunst.c
View File

@ -9,6 +9,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <sys/time.h>
#include <math.h>
#include <getopt.h> #include <getopt.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
@ -474,13 +476,22 @@ char *draw_txt_get_line(draw_txt * dt, int line)
int calculate_x_offset(int line_width, int text_width) int calculate_x_offset(int line_width, int text_width)
{ {
int leftover = line_width - text_width;
struct timeval t;
float pos;
/* If the text is wider than the frame, bouncing is enabled and word_wrap disabled */
if (line_width < text_width && bounce_freq > 0.0001 && !word_wrap) {
gettimeofday(&t, NULL);
pos = ((t.tv_sec % 100) * 1e6 + t.tv_usec) / (1e6 / bounce_freq);
return (1 + sinf(2 * 3.14159 * pos)) * leftover / 2;
}
switch (align) { switch (align) {
case left: case left:
return 0; return 0;
case center: case center:
return (line_width - text_width) / 2; return leftover / 2;
case right: case right:
return line_width - text_width; return leftover;
default: default:
/* this can't happen */ /* this can't happen */
return 0; return 0;
@ -1552,6 +1563,8 @@ dunst_ini_handle(void *user_data, const char *section,
close_all_ks.str = dunst_ini_get_string(value); close_all_ks.str = dunst_ini_get_string(value);
} else if (strcmp(name, "history_key") == 0) { } else if (strcmp(name, "history_key") == 0) {
history_ks.str = dunst_ini_get_string(value); history_ks.str = dunst_ini_get_string(value);
} else if (strcmp(name, "bounce_freq") == 0) {
bounce_freq = atof(value);
} else if (strcmp(name, "alignment") == 0) { } else if (strcmp(name, "alignment") == 0) {
if (strcmp(value, "left") == 0) if (strcmp(value, "left") == 0)
align = left; align = left;

View File

@ -19,6 +19,9 @@
# Possible values are "left", "center" and "right" # Possible values are "left", "center" and "right"
alignment = left alignment = left
# determines the bounce frequency (in hz, 0 to disable)
bounce_freq = 0
# show age of message if message is older than show_age_threshold seconds. # show age of message if message is older than show_age_threshold seconds.
# set to -1 to disable # set to -1 to disable
show_age_threshold = 60; show_age_threshold = 60;