- if (d1 == NULL || d2 == NULL || d1 == d2)
- return;
-
- PRINTF("swap desktops %s %s\n", d1->name, d2->name);
-
- bool d1_focused = (m1->desk == d1);
- bool d2_focused = (m2->desk == d2);
-
- if (m1 != m2) {
- if (m1->desk == d1)
- m1->desk = d2;
- if (m1->desk_head == d1)
- m1->desk_head = d2;
- if (m1->desk_tail == d1)
- m1->desk_tail = d2;
- if (m2->desk == d2)
- m2->desk = d1;
- if (m2->desk_head == d2)
- m2->desk_head = d1;
- if (m2->desk_tail == d2)
- m2->desk_tail = d1;
- } else {
- if (m1->desk_head == d1)
- m1->desk_head = d2;
- else if (m1->desk_head == d2)
- m1->desk_head = d1;
- if (m1->desk_tail == d1)
- m1->desk_tail = d2;
- else if (m1->desk_tail == d2)
- m1->desk_tail = d1;
- }
-
- desktop_t *p1 = d1->prev;
- desktop_t *n1 = d1->next;
- desktop_t *p2 = d2->prev;
- desktop_t *n2 = d2->next;
-
- if (p1 != NULL && p1 != d2)
- p1->next = d2;
- if (n1 != NULL && n1 != d2)
- n1->prev = d2;
- if (p2 != NULL && p2 != d1)
- p2->next = d1;
- if (n2 != NULL && n2 != d1)
- n2->prev = d1;
-
- d1->prev = p2 == d1 ? d2 : p2;
- d1->next = n2 == d1 ? d2 : n2;
- d2->prev = p1 == d2 ? d1 : p1;
- d2->next = n1 == d2 ? d1 : n1;
-
- if (m1 != m2) {
- for (node_t *n = first_extrema(d1->root); n != NULL; n = next_leaf(n, d1->root))
- fit_monitor(m2, n->client);
- for (node_t *n = first_extrema(d2->root); n != NULL; n = next_leaf(n, d2->root))
- fit_monitor(m1, n->client);
- history_swap_desktops(m1, d1, m2, d2);
- arrange(m1, d2);
- arrange(m2, d1);
- if (d1_focused && !d2_focused) {
- hide_desktop(d1);
- show_desktop(d2);
- } else if (!d1_focused && d2_focused) {
- show_desktop(d1);
- hide_desktop(d2);
- }
- }
-
- update_input_focus();
- ewmh_update_wm_desktops();
- ewmh_update_desktop_names();
- ewmh_update_current_desktop();
- put_status();
+ if (d1 == NULL || d2 == NULL || d1 == d2)
+ return;
+
+ PRINTF("swap desktops %s %s\n", d1->name, d2->name);
+
+ bool d1_focused = (m1->desk == d1);
+ bool d2_focused = (m2->desk == d2);
+
+ if (m1 != m2) {
+ if (m1->desk == d1)
+ m1->desk = d2;
+ if (m1->desk_head == d1)
+ m1->desk_head = d2;
+ if (m1->desk_tail == d1)
+ m1->desk_tail = d2;
+ if (m2->desk == d2)
+ m2->desk = d1;
+ if (m2->desk_head == d2)
+ m2->desk_head = d1;
+ if (m2->desk_tail == d2)
+ m2->desk_tail = d1;
+ } else {
+ if (m1->desk_head == d1)
+ m1->desk_head = d2;
+ else if (m1->desk_head == d2)
+ m1->desk_head = d1;
+ if (m1->desk_tail == d1)
+ m1->desk_tail = d2;
+ else if (m1->desk_tail == d2)
+ m1->desk_tail = d1;
+ }
+
+ desktop_t *p1 = d1->prev;
+ desktop_t *n1 = d1->next;
+ desktop_t *p2 = d2->prev;
+ desktop_t *n2 = d2->next;
+
+ if (p1 != NULL && p1 != d2)
+ p1->next = d2;
+ if (n1 != NULL && n1 != d2)
+ n1->prev = d2;
+ if (p2 != NULL && p2 != d1)
+ p2->next = d1;
+ if (n2 != NULL && n2 != d1)
+ n2->prev = d1;
+
+ d1->prev = p2 == d1 ? d2 : p2;
+ d1->next = n2 == d1 ? d2 : n2;
+ d2->prev = p1 == d2 ? d1 : p1;
+ d2->next = n1 == d2 ? d1 : n1;
+
+ if (m1 != m2) {
+ for (node_t *n = first_extrema(d1->root); n != NULL; n = next_leaf(n, d1->root))
+ translate_client(m1, m2, n->client);
+ for (node_t *n = first_extrema(d2->root); n != NULL; n = next_leaf(n, d2->root))
+ translate_client(m2, m1, n->client);
+ history_swap_desktops(m1, d1, m2, d2);
+ arrange(m1, d2);
+ arrange(m2, d1);
+ if (d1_focused && !d2_focused) {
+ hide_desktop(d1);
+ show_desktop(d2);
+ } else if (!d1_focused && d2_focused) {
+ show_desktop(d1);
+ hide_desktop(d2);
+ }
+ }
+
+ update_input_focus();
+ ewmh_update_wm_desktops();
+ ewmh_update_desktop_names();
+ ewmh_update_current_desktop();
+ put_status();