5 history_t *make_history(monitor_t *m, desktop_t *d, node_t *n)
7 history_t *h = malloc(sizeof(history_t));
8 h->loc = (coordinates_t) {m, d, n};
9 h->prev = h->next = NULL;
14 void history_add(monitor_t *m, desktop_t *d, node_t *n)
16 history_t *h = make_history(m, d, n);
17 if (history_head == NULL) {
18 history_head = history_tail = h;
19 } else if ((n != NULL && history_tail->loc.node != n) || (n == NULL && d != history_tail->loc.desktop)) {
20 for (history_t *hh = history_tail; hh != NULL; hh = hh->prev)
21 if ((n != NULL && hh->loc.node == n) || (n == NULL && d == hh->loc.desktop))
23 history_tail->next = h;
24 h->prev = history_tail;
31 void history_transfer_node(monitor_t *m, desktop_t *d, node_t *n)
33 for (history_t *h = history_head; h != NULL; h = h->next)
34 if (h->loc.node == n) {
40 void history_transfer_desktop(monitor_t *m, desktop_t *d)
42 for (history_t *h = history_head; h != NULL; h = h->next)
43 if (h->loc.desktop == d)
47 void history_swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
49 for (history_t *h = history_head; h != NULL; h = h->next)
50 if (h->loc.node == n1) {
53 } else if (h->loc.node == n2) {
59 void history_swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2)
61 for (history_t *h = history_head; h != NULL; h = h->next)
62 if (h->loc.desktop == d1)
64 else if (h->loc.desktop == d2)
68 void history_remove(desktop_t *d, node_t *n)
70 /* removing from the newest to the oldest is required */
71 /* for maintaining the *latest* attribute */
72 history_t *b = history_tail;
74 if ((n != NULL && n == b->loc.node) || (n == NULL && d == b->loc.desktop)) {
75 history_t *a = b->next;
76 history_t *c = b->prev;
78 /* remove duplicate entries */
79 while (c != NULL && ((a->loc.node != NULL && a->loc.node == c->loc.node)
80 || (a->loc.node == NULL && a->loc.desktop == c->loc.desktop))) {
81 history_t *d = c->prev;
82 if (history_head == c)
83 history_head = history_tail;
91 if (history_tail == b)
93 if (history_head == b)
103 void empty_history(void)
105 history_t *h = history_head;
107 history_t *next = h->next;
111 history_head = history_tail = NULL;
114 node_t *history_get_node(desktop_t *d, node_t *n)
116 for (history_t *h = history_tail; h != NULL; h = h->prev)
117 if (h->latest && h->loc.node != NULL && h->loc.node != n && h->loc.desktop == d)
122 desktop_t *history_get_desktop(monitor_t *m, desktop_t *d)
124 for (history_t *h = history_tail; h != NULL; h = h->prev)
125 if (h->latest && h->loc.desktop != d && h->loc.monitor == m)
126 return h->loc.desktop;
130 monitor_t *history_get_monitor(monitor_t *m)
132 for (history_t *h = history_tail; h != NULL; h = h->prev)
133 if (h->latest && h->loc.monitor != m)
134 return h->loc.monitor;
138 bool history_last_node(node_t *n, client_select_t sel, coordinates_t *loc)
140 for (history_t *h = history_tail; h != NULL; h = h->prev) {
141 if (!h->latest || h->loc.node == NULL || h->loc.node == n || !node_matches(n, h->loc.node, sel))
149 bool history_last_desktop(desktop_t *d, desktop_select_t sel, coordinates_t *loc)
151 for (history_t *h = history_tail; h != NULL; h = h->prev) {
152 if (!h->latest || h->loc.desktop == d || !desktop_matches(h->loc.desktop, sel))
160 bool history_last_monitor(monitor_t *m, desktop_select_t sel, coordinates_t *loc)
162 for (history_t *h = history_tail; h != NULL; h = h->prev) {
163 if (!h->latest || h->loc.monitor == m || !desktop_matches(h->loc.monitor->desk, sel))
171 int history_rank(desktop_t *d, node_t *n)
174 history_t *h = history_tail;
175 while (h != NULL && (!h->latest || h->loc.node != n || h->loc.desktop != d)) {