]> git.lizzy.rs Git - bspwm.git/commitdiff
Handle sticky nodes in `swap_desktops`
authorBastien Dejean <nihilhill@gmail.com>
Mon, 31 May 2021 08:57:17 +0000 (10:57 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Mon, 31 May 2021 08:57:17 +0000 (10:57 +0200)
Fixes #1298.

src/desktop.c

index 6738ea042a7900dbba24d890c90022b2743ea9b5..b622e8d40439de06e1d10834ed7a83aad0acb38c 100644 (file)
@@ -372,9 +372,7 @@ void merge_desktops(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd)
 
 bool swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2, bool follow)
 {
-       if (d1 == NULL || d2 == NULL || d1 == d2 ||
-           (m1->desk == d1 && m1->sticky_count > 0) ||
-           (m2->desk == d2 && m2->sticky_count > 0)) {
+       if (d1 == NULL || d2 == NULL || d1 == d2) {
                return false;
        }
 
@@ -384,6 +382,20 @@ bool swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2, b
        bool d2_was_active = (m2->desk == d2);
        bool d1_was_focused = (mon->desk == d1);
        bool d2_was_focused = (mon->desk == d2);
+       desktop_t *d1_stickies = NULL;
+       desktop_t *d2_stickies = NULL;
+
+       if (m1->sticky_count > 0 && d1 == m1->desk && sticky_count(d1->root) > 0) {
+               d1_stickies = make_desktop(NULL, XCB_NONE);
+               insert_desktop(m1, d1_stickies);
+               transfer_sticky_nodes(m1, d1, m1, d1_stickies, d1->root);
+       }
+
+       if (m2->sticky_count > 0 && d2 == m2->desk && sticky_count(d2->root) > 0) {
+               d2_stickies = make_desktop(NULL, XCB_NONE);
+               insert_desktop(m2, d2_stickies);
+               transfer_sticky_nodes(m2, d2, m2, d2_stickies, d2->root);
+       }
 
        if (m1 != m2) {
                if (m1->desk == d1) {
@@ -454,6 +466,18 @@ bool swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2, b
                arrange(m2, d1);
        }
 
+       if (d1_stickies != NULL) {
+               transfer_sticky_nodes(m1, d1_stickies, m1, d2, d1_stickies->root);
+               unlink_desktop(m1, d1_stickies);
+               free(d1_stickies);
+       }
+
+       if (d2_stickies != NULL) {
+               transfer_sticky_nodes(m2, d2_stickies, m2, d1, d2_stickies->root);
+               unlink_desktop(m2, d2_stickies);
+               free(d2_stickies);
+       }
+
        if (d1_was_active && !d2_was_active) {
                if ((!follow && m1 != m2) || !d1_was_focused) {
                        hide_desktop(d1);