overhaul get_sleep_time
This commit is contained in:
parent
5d46cd700c
commit
1f0e8d2181
34
src/dunst.c
34
src/dunst.c
@ -174,28 +174,34 @@ void wake_up(void)
|
|||||||
|
|
||||||
static gint64 get_sleep_time(void)
|
static gint64 get_sleep_time(void)
|
||||||
{
|
{
|
||||||
|
gint64 time = g_get_monotonic_time();
|
||||||
gint64 sleep = G_MAXINT64;
|
gint64 sleep = G_MAXINT64;
|
||||||
|
|
||||||
gint64 max_age = 0;
|
|
||||||
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
||||||
iter = iter->next) {
|
iter = iter->next) {
|
||||||
notification *n = iter->data;
|
notification *n = iter->data;
|
||||||
|
gint64 ttl = n->timeout - (time - n->start);
|
||||||
|
|
||||||
max_age = MAX(max_age, notification_get_age(n));
|
if (n->timeout > 0) {
|
||||||
gint64 ttl = notification_get_ttl(n);
|
if (ttl > 0)
|
||||||
if (ttl >= 0)
|
sleep = MIN(sleep, ttl);
|
||||||
sleep = MIN(sleep, ttl);
|
else
|
||||||
|
// while we're processing, the notification already timed out
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.show_age_threshold >= 0) {
|
||||||
|
gint64 age = time - n->timestamp;
|
||||||
|
|
||||||
|
if (age > settings.show_age_threshold)
|
||||||
|
// sleep exactly until the next shift of the second happens
|
||||||
|
sleep = MIN(sleep, ((G_USEC_PER_SEC) - (age % (G_USEC_PER_SEC))));
|
||||||
|
else if (ttl > settings.show_age_threshold)
|
||||||
|
sleep = MIN(sleep, settings.show_age_threshold);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if age_threshold is hit, seconds have to get updated every second */
|
return sleep != G_MAXINT64 ? sleep : -1;
|
||||||
if (settings.show_age_threshold >= 0) {
|
|
||||||
if (settings.show_age_threshold > max_age)
|
|
||||||
sleep = MIN(sleep, settings.show_age_threshold - max_age);
|
|
||||||
else
|
|
||||||
sleep = MIN(sleep, 1000*1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sleep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean run(void *data)
|
gboolean run(void *data)
|
||||||
|
@ -699,18 +699,6 @@ void notification_update_text_to_render(notification *n)
|
|||||||
n->text_to_render = buf;
|
n->text_to_render = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint64 notification_get_ttl(notification *n) {
|
|
||||||
if (n->timeout < 0) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return n->timeout - (g_get_monotonic_time() - n->start);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gint64 notification_get_age(notification *n) {
|
|
||||||
return g_get_monotonic_time() - n->timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the notification has exactly one action, or one is marked as default,
|
* If the notification has exactly one action, or one is marked as default,
|
||||||
* invoke it. If there are multiple and no default, open the context menu. If
|
* invoke it. If there are multiple and no default, open the context menu. If
|
||||||
|
@ -74,8 +74,6 @@ int notification_close(notification *n, int reason);
|
|||||||
void notification_print(notification *n);
|
void notification_print(notification *n);
|
||||||
void notification_replace_single_field(char **haystack, char **needle, const char *replacement, enum markup_mode markup_mode);
|
void notification_replace_single_field(char **haystack, char **needle, const char *replacement, enum markup_mode markup_mode);
|
||||||
void notification_update_text_to_render(notification *n);
|
void notification_update_text_to_render(notification *n);
|
||||||
gint64 notification_get_ttl(notification *n);
|
|
||||||
gint64 notification_get_age(notification *n);
|
|
||||||
void notification_do_action(notification *n);
|
void notification_do_action(notification *n);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user