Move get_sleep_time to queues.c
This commit is contained in:
parent
3fab4c470b
commit
59ac6d0f88
35
src/dunst.c
35
src/dunst.c
@ -120,39 +120,6 @@ void wake_up(void)
|
||||
run(NULL);
|
||||
}
|
||||
|
||||
/* TODO: move parts to queue.c */
|
||||
static gint64 get_sleep_time(void)
|
||||
{
|
||||
gint64 time = g_get_monotonic_time();
|
||||
gint64 sleep = G_MAXINT64;
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
||||
iter = iter->next) {
|
||||
notification *n = iter->data;
|
||||
gint64 ttl = n->timeout - (time - n->start);
|
||||
|
||||
if (n->timeout > 0) {
|
||||
if (ttl > 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return sleep != G_MAXINT64 ? sleep : -1;
|
||||
}
|
||||
|
||||
gboolean run(void *data)
|
||||
{
|
||||
update_lists();
|
||||
@ -177,7 +144,7 @@ gboolean run(void *data)
|
||||
|
||||
if (xctx.visible) {
|
||||
gint64 now = g_get_monotonic_time();
|
||||
gint64 sleep = get_sleep_time();
|
||||
gint64 sleep = queues_get_next_datachange(now);
|
||||
gint64 timeout_at = now + sleep;
|
||||
|
||||
if (sleep >= 0) {
|
||||
|
31
src/queues.c
31
src/queues.c
@ -213,6 +213,37 @@ void history_push(notification *n)
|
||||
g_queue_push_tail(history, n);
|
||||
}
|
||||
|
||||
gint64 queues_get_next_datachange(gint64 time)
|
||||
{
|
||||
gint64 sleep = G_MAXINT64;
|
||||
|
||||
for (GList *iter = g_queue_peek_head_link(displayed); iter;
|
||||
iter = iter->next) {
|
||||
notification *n = iter->data;
|
||||
gint64 ttl = n->timeout - (time - n->start);
|
||||
|
||||
if (n->timeout > 0) {
|
||||
if (ttl > 0)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return sleep != G_MAXINT64 ? sleep : -1;
|
||||
}
|
||||
|
||||
static void teardown_notification(gpointer data)
|
||||
{
|
||||
notification *n = data;
|
||||
|
12
src/queues.h
12
src/queues.h
@ -62,6 +62,18 @@ void history_pop(void);
|
||||
void history_push(notification *n);
|
||||
void move_all_to_history(void);
|
||||
|
||||
/*
|
||||
* Return the distance to the next event in the queue,
|
||||
* which forces an update visible to the user
|
||||
*
|
||||
* This may be:
|
||||
*
|
||||
* - notification hits timeout
|
||||
* - notification's age second changes
|
||||
* - notification's age threshold is hit
|
||||
*/
|
||||
gint64 queues_get_next_datachange(gint64 time);
|
||||
|
||||
/*
|
||||
* Remove all notifications from all lists
|
||||
* and free the notifications
|
||||
|
Loading…
x
Reference in New Issue
Block a user