use n_stack for history
This commit is contained in:
parent
b2a20c0524
commit
b641a9c881
25
container.c
25
container.c
@ -263,4 +263,29 @@ void l_sort(list * l, int (*f) (void *, void *))
|
||||
free(old_list);
|
||||
}
|
||||
|
||||
void n_stack_push(n_stack **s, notification *n)
|
||||
{
|
||||
if (!n)
|
||||
return;
|
||||
|
||||
n_stack *new = malloc(sizeof(n_stack));
|
||||
new->n = n;
|
||||
new->next = *s;
|
||||
*s = new;
|
||||
}
|
||||
|
||||
notification *n_stack_pop(n_stack **s)
|
||||
{
|
||||
if (!s || !*s)
|
||||
return NULL;
|
||||
|
||||
n_stack *head = *s;
|
||||
*s = (*s)->next;
|
||||
|
||||
notification *n = head->n;
|
||||
free(head);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
27
container.h
27
container.h
@ -1,6 +1,8 @@
|
||||
#ifndef _LIST_H
|
||||
#define _LIST_H
|
||||
|
||||
#include "dunst.h"
|
||||
|
||||
typedef struct _l_node {
|
||||
struct _l_node *next;
|
||||
void *data;
|
||||
@ -10,6 +12,11 @@ typedef struct _list {
|
||||
l_node *head;
|
||||
} list;
|
||||
|
||||
typedef struct _n_stack {
|
||||
notification *n;
|
||||
struct _n_stack *next;
|
||||
} n_stack;
|
||||
|
||||
/* append to end of list */
|
||||
int l_push(list * l, void *data);
|
||||
|
||||
@ -54,6 +61,24 @@ int l_move(list * from, list * to, l_node * node);
|
||||
void l_sort(list * l, int (*f) (void *, void *));
|
||||
|
||||
list *l_init(void);
|
||||
#endif
|
||||
|
||||
|
||||
/************
|
||||
* stack
|
||||
*/
|
||||
|
||||
/**
|
||||
* push notification onto stack
|
||||
* creates a new stack if *s == NULL
|
||||
*/
|
||||
void n_stack_push(n_stack **s, notification *n);
|
||||
|
||||
/**
|
||||
* remove and return notification from stack
|
||||
* sets *s to NULL if stack is empty
|
||||
*/
|
||||
notification *n_stack_pop(n_stack **s);
|
||||
|
||||
|
||||
#endif
|
||||
/* vim: set ts=8 sw=8 tw=0: */
|
||||
|
29
dunst.c
29
dunst.c
@ -84,7 +84,7 @@ bool deprecated_dunstrc_shortcuts = false;
|
||||
/* notification lists */
|
||||
list *notification_queue = NULL; /* all new notifications get into here */
|
||||
list *displayed_notifications = NULL; /* currently displayed notifications */
|
||||
list *notification_history = NULL; /* history of displayed notifications */
|
||||
n_stack *n_history = NULL; /* history of displayed notifications */
|
||||
|
||||
/* misc funtions */
|
||||
void apply_rules(notification * n);
|
||||
@ -884,22 +884,15 @@ void move_all_to_history()
|
||||
|
||||
void history_pop(void)
|
||||
{
|
||||
l_node *iter;
|
||||
notification *data;
|
||||
|
||||
/* nothing to do */
|
||||
if (l_is_empty(notification_history)) {
|
||||
if (!n_history)
|
||||
return;
|
||||
}
|
||||
|
||||
for (iter = notification_history->head; iter->next; iter = iter->next) ;
|
||||
data = (notification *) iter->data;
|
||||
data->redisplayed = true;
|
||||
data->start = 0;
|
||||
if (sticky_history) {
|
||||
data->timeout = 0;
|
||||
}
|
||||
l_move(notification_history, notification_queue, iter);
|
||||
notification *n = n_stack_pop(&n_history);
|
||||
n->redisplayed = true;
|
||||
n->start = 0;
|
||||
n->timeout = sticky_history ? 0 : n->timeout;
|
||||
l_push(notification_queue, n);
|
||||
|
||||
if (!visible) {
|
||||
map_win();
|
||||
@ -1040,8 +1033,8 @@ int close_notification_by_id(int id, int reason)
|
||||
for (iter = displayed_notifications->head; iter; iter = iter->next) {
|
||||
notification *n = (notification *) iter->data;
|
||||
if (n->id == id) {
|
||||
l_move(displayed_notifications, notification_history,
|
||||
iter);
|
||||
l_remove(displayed_notifications, iter);
|
||||
n_stack_push(&n_history, n);
|
||||
target = n;
|
||||
break;
|
||||
}
|
||||
@ -1050,7 +1043,8 @@ int close_notification_by_id(int id, int reason)
|
||||
for (iter = notification_queue->head; iter; iter = iter->next) {
|
||||
notification *n = (notification *) iter->data;
|
||||
if (n->id == id) {
|
||||
l_move(notification_queue, notification_history, iter);
|
||||
l_remove(notification_queue, iter);
|
||||
n_stack_push(&n_history, n);
|
||||
target = n;
|
||||
break;
|
||||
}
|
||||
@ -1677,7 +1671,6 @@ int main(int argc, char *argv[])
|
||||
now = time(&now);
|
||||
|
||||
notification_queue = l_init();
|
||||
notification_history = l_init();
|
||||
displayed_notifications = l_init();
|
||||
r_line_cache_init(&line_cache);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user