5 focus_history_t *make_focus_history(void)
7 focus_history_t *f = malloc(sizeof(focus_history_t));
8 f->head = f->tail = NULL;
12 node_list_t *make_node_list(void)
14 node_list_t *n = malloc(sizeof(node_list_t));
16 n->prev = n->next = NULL;
21 void history_add(focus_history_t *f, node_t *n)
23 node_list_t *a = make_node_list();
25 if (f->head == NULL) {
26 f->head = f->tail = a;
27 } else if (f->head->node != n) {
28 for (node_list_t *b = f->head; b != NULL; b = b->next)
39 void history_remove(focus_history_t *f, node_t *n)
41 /* in order to maintain the `latest` node list state,
42 we remove node lists from head to tail */
43 node_list_t *b = f->head;
46 node_list_t *a = b->prev;
47 node_list_t *c = b->next;
49 /* remove duplicate entries */
50 while (c != NULL && c->node == a->node) {
51 node_list_t *d = c->next;
73 void empty_history(focus_history_t *f)
75 node_list_t *a = f->head;
77 node_list_t *b = a->next;
81 f->head = f->tail = NULL;
84 node_t *history_get(focus_history_t *f, int i)
86 node_list_t *a = f->head;
87 while (a != NULL && i > 0) {
97 node_t *history_last(focus_history_t *f, node_t *n, client_select_t sel)
99 for (node_list_t *a = f->head; a != NULL; a = a->next) {
100 if (!a->latest || a->node == n || !node_matches(n, a->node, sel))
107 int history_rank(focus_history_t *f, node_t *n)
110 node_list_t *a = f->head;
111 while (a != NULL && (!a->latest || a->node != n)) {