Merge pull request #109 from progandy/master

Fix unreliable timeouts
This commit is contained in:
Sascha Kruse 2013-06-10 12:50:00 -07:00
commit a7dfd7f973
2 changed files with 9 additions and 15 deletions

20
dunst.c
View File

@ -168,10 +168,8 @@ void history_pop(void)
n->timeout = settings.sticky_history ? 0 : n->timeout; n->timeout = settings.sticky_history ? 0 : n->timeout;
g_queue_push_head(queue, n); g_queue_push_head(queue, n);
if (!xctx.visible) {
wake_up(); wake_up();
} }
}
void wake_up(void) void wake_up(void)
{ {
@ -183,7 +181,7 @@ static int get_sleep_time(void)
if (settings.show_age_threshold == 0) { if (settings.show_age_threshold == 0) {
/* we need to update every second */ /* we need to update every second */
return 1000; return 1;
} }
bool have_ttl = false; bool have_ttl = false;
@ -195,7 +193,7 @@ static int get_sleep_time(void)
max_age = MAX(max_age, notification_get_age(n)); max_age = MAX(max_age, notification_get_age(n));
int ttl = notification_get_ttl(n); int ttl = notification_get_ttl(n);
if (ttl > 0) { if (ttl >= 0) {
if (have_ttl) { if (have_ttl) {
min_ttl = MIN(min_ttl, ttl); min_ttl = MIN(min_ttl, ttl);
} else { } else {
@ -209,7 +207,7 @@ static int get_sleep_time(void)
int show_age_timeout = settings.show_age_threshold - max_age; int show_age_timeout = settings.show_age_threshold - max_age;
if (show_age_timeout < 1) { if (show_age_timeout < 1) {
return 1000; return 1;
} }
if (!have_ttl) { if (!have_ttl) {
@ -220,13 +218,9 @@ static int get_sleep_time(void)
/* show_age_timeout might be negative */ /* show_age_timeout might be negative */
if (min_timeout < 1) { if (min_timeout < 1) {
return 1000; return 1;
} else { } else {
/* add 501 milliseconds to make sure we wake are in the second return min_timeout;
* after the next notification times out. Otherwise we'll wake
* up, but the notification won't get closed until we get woken
* up again (which might be multiple seconds later */
return min_timeout * 1000 + 501;
} }
} }
@ -253,13 +247,13 @@ gboolean run(void *data)
} }
if (xctx.visible) { if (xctx.visible) {
int now = time(NULL) * 1000; int now = time(NULL);
int sleep = get_sleep_time(); int sleep = get_sleep_time();
if (sleep > 0) { if (sleep > 0) {
int timeout_at = now + sleep; int timeout_at = now + sleep;
if (timeout_cnt == 0 || timeout_at < next_timeout) { if (timeout_cnt == 0 || timeout_at < next_timeout) {
g_timeout_add(sleep, run, mainloop); g_timeout_add_seconds(sleep, run, mainloop);
next_timeout = timeout_at; next_timeout = timeout_at;
timeout_cnt++; timeout_cnt++;
} }

View File

@ -520,7 +520,7 @@ void notification_update_text_to_render(notification *n)
int notification_get_ttl(notification *n) { int notification_get_ttl(notification *n) {
if (n->timeout == 0) { if (n->timeout == 0) {
return 0; return -1;
} else { } else {
return n->timeout - (time(NULL) - n->start); return n->timeout - (time(NULL) - n->start);
} }