- /* removing from the newest to the oldest is required */
- /* for maintaining the *latest* attribute */
- history_t *b = history_tail;
- while (b != NULL) {
- if ((n != NULL && n == b->loc.node) || (n == NULL && d == b->loc.desktop)) {
- history_t *a = b->next;
- history_t *c = b->prev;
- if (a != NULL) {
- /* remove duplicate entries */
- while (c != NULL && ((a->loc.node != NULL && a->loc.node == c->loc.node)
- || (a->loc.node == NULL && a->loc.desktop == c->loc.desktop))) {
- history_t *d = c->prev;
- if (history_head == c)
- history_head = history_tail;
- if (history_needle == c)
- history_needle = history_tail;
- free(c);
- c = d;
- }
- a->prev = c;
- }
- if (c != NULL)
- c->next = a;
- if (history_tail == b)
- history_tail = c;
- if (history_head == b)
- history_head = a;
- if (history_needle == b)
- history_needle = c;
- free(b);
- b = c;
- } else {
- b = b->prev;
- }
- }
+ /* removing from the newest to the oldest is required */
+ /* for maintaining the *latest* attribute */
+ history_t *b = history_tail;
+ while (b != NULL) {
+ if ((n != NULL && ((deep && is_descendant(b->loc.node, n)) || (!deep && b->loc.node == n))) ||
+ (n == NULL && d == b->loc.desktop)) {
+ history_t *a = b->next;
+ history_t *c = b->prev;
+ if (a != NULL) {
+ /* remove duplicate entries */
+ while (c != NULL && ((a->loc.node != NULL && a->loc.node == c->loc.node) ||
+ (a->loc.node == NULL && a->loc.desktop == c->loc.desktop))) {
+ history_t *p = c->prev;
+ if (history_head == c) {
+ history_head = history_tail;
+ }
+ if (history_needle == c) {
+ history_needle = history_tail;
+ }
+ free(c);
+ c = p;
+ }
+ a->prev = c;
+ }
+ if (c != NULL) {
+ c->next = a;
+ }
+ if (history_tail == b) {
+ history_tail = c;
+ }
+ if (history_head == b) {
+ history_head = a;
+ }
+ if (history_needle == b) {
+ history_needle = c;
+ }
+ free(b);
+ b = c;
+ } else {
+ b = b->prev;
+ }
+ }