Refactor history_* functions to match queues namespace

This commit is contained in:
Benedikt Heine 2017-10-11 12:07:06 +02:00
parent 38e4bbb7bb
commit e3881766c0
3 changed files with 36 additions and 23 deletions

View File

@ -122,7 +122,7 @@ bool queues_notification_replace_id(notification *new)
new->start = time(NULL);
new->dup_count = old->dup_count;
notification_run_script(new);
history_push(old);
queues_history_push(old);
return true;
}
}
@ -134,7 +134,7 @@ bool queues_notification_replace_id(notification *new)
if (old->id == new->id) {
iter->data = new;
new->dup_count = old->dup_count;
history_push(old);
queues_history_push(old);
return true;
}
}
@ -150,7 +150,7 @@ int queues_notification_close_id(int id, int reason)
notification *n = iter->data;
if (n->id == id) {
g_queue_remove(displayed, n);
history_push(n);
queues_history_push(n);
target = n;
break;
}
@ -161,7 +161,7 @@ int queues_notification_close_id(int id, int reason)
notification *n = iter->data;
if (n->id == id) {
g_queue_remove(queue, n);
history_push(n);
queues_history_push(n);
target = n;
break;
}
@ -180,18 +180,7 @@ int queues_notification_close(notification *n, int reason)
return queues_notification_close_id(n->id, reason);
}
void move_all_to_history()
{
while (displayed->length > 0) {
queues_notification_close(g_queue_peek_head_link(displayed)->data, 2);
}
while (queue->length > 0) {
queues_notification_close(g_queue_peek_head_link(queue)->data, 2);
}
}
void history_pop(void)
void queues_history_pop(void)
{
if (g_queue_is_empty(history))
return;
@ -203,7 +192,7 @@ void history_pop(void)
g_queue_push_head(queue, n);
}
void history_push(notification *n)
void queues_history_push(notification *n)
{
if (settings.history_length > 0 && history->length >= settings.history_length) {
notification *to_free = g_queue_pop_head(history);
@ -214,6 +203,17 @@ void history_push(notification *n)
g_queue_push_tail(history, n);
}
void queues_history_push_all(void)
{
while (displayed->length > 0) {
queues_notification_close(g_queue_peek_head_link(displayed)->data, 2);
}
while (queue->length > 0) {
queues_notification_close(g_queue_peek_head_link(queue)->data, 2);
}
}
void queues_check_timeouts(bool idle)
{
/* nothing to do */

View File

@ -58,9 +58,22 @@ int queues_notification_close_id(int id, int reason);
/* Close the given notification. SEE queues_notification_close_id. */
int queues_notification_close(notification *n, int reason);
void history_pop(void);
void history_push(notification *n);
void move_all_to_history(void);
/*
* Pushed the latest notification of history to the displayed queue
* and removes it from history
*/
void queues_history_pop(void);
/*
* Push a single notification to history
* The given notification has to be removed its queue
*/
void queues_history_push(notification *n);
/*
* Push all waiting and displayed notifications to history
*/
void queues_history_push_all(void);
/*
* Check timeout of each notification and close it, if neccessary

View File

@ -866,14 +866,14 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback,
&& XLookupKeysym(&ev.xkey,
0) == settings.history_ks.sym
&& settings.history_ks.mask == state) {
history_pop();
queues_history_pop();
wake_up();
}
if (settings.close_all_ks.str
&& XLookupKeysym(&ev.xkey,
0) == settings.close_all_ks.sym
&& settings.close_all_ks.mask == state) {
move_all_to_history();
queues_history_push_all();
wake_up();
}
if (settings.context_ks.str
@ -917,7 +917,7 @@ bool x_is_idle(void)
static void x_handle_click(XEvent ev)
{
if (ev.xbutton.button == Button3) {
move_all_to_history();
queues_history_push_all();
return;
}