Fixes #691.
Fixes #701.
bool activate_desktop(monitor_t *m, desktop_t *d)
{
+ if (d == NULL) {
+ d = history_last_desktop(m, NULL);
+ if (d == NULL) {
+ d = m->desk_head;
+ }
+ }
+
+ if (d == NULL) {
+ return false;
+ }
+
if (m == mon || d == m->desk) {
return false;
}
if (was_active) {
if (mon == ms) {
- focus_node(ms, NULL, NULL);
+ focus_node(md, d, d->focus);
} else {
- activate_node(ms, NULL, NULL);
+ activate_desktop(ms, NULL);
+ if (ms->desk != NULL) {
+ activate_node(ms, ms->desk, NULL);
+ }
}
}
adapt_geometry(&ms->rectangle, &md->rectangle, d->root);
arrange(md, d);
- if (md->desk == d) {
- if (mon == md) {
- focus_node(md, d, d->focus);
- } else {
- activate_node(md, d, d->focus);
- }
+ if (md->desk == d && mon != md) {
+ activate_node(md, d, d->focus);
}
ewmh_update_wm_desktops();
if (m == mon) {
focus_node(m, NULL, NULL);
} else {
- activate_node(m, NULL, NULL);
+ activate_desktop(m, NULL);
+ if (m->desk != NULL) {
+ activate_node(m, m->desk, m->desk->focus);
+ }
}
}
put_status(SBSC_MASK_DESKTOP_SWAP, "desktop_swap 0x%08X 0x%08X 0x%08X 0x%08X\n", m1->id, d1->id, m2->id, d2->id);
- bool d1_focused = (m1->desk == d1);
- bool d2_focused = (m2->desk == d2);
+ bool d1_was_active = (m1->desk == d1);
+ bool d2_was_active = (m2->desk == d2);
+ bool d1_was_focused = (mon->desk == d1);
+ bool d2_was_focused = (mon->desk == d2);
if (m1 != m2) {
if (m1->desk == d1) {
arrange(m2, d1);
}
- if (d1_focused && !d2_focused) {
+ if (d1_was_active && !d2_was_active) {
hide_desktop(d1);
show_desktop(d2);
- } else if (!d1_focused && d2_focused) {
+ } else if (!d1_was_active && d2_was_active) {
show_desktop(d1);
hide_desktop(d2);
}
- if (d1 == mon->desk) {
+ if (d1_was_focused) {
focus_node(m2, d1, d1->focus);
} else if (d1 == m2->desk) {
activate_node(m2, d1, d1->focus);
}
- if (d2 == mon->desk) {
+ if (d2_was_focused) {
focus_node(m1, d2, d2->focus);
} else if (d2 == m1->desk) {
activate_node(m1, d2, d2->focus);
bool activate_node(monitor_t *m, desktop_t *d, node_t *n)
{
- if (d == NULL) {
- d = history_last_desktop(m, NULL);
- if (d == NULL) {
- d = m->desk_head;
- }
- }
-
- if (d == NULL) {
- return false;
- }
-
if (n == NULL && d->root != NULL) {
n = history_last_node(d, NULL);
if (n == NULL) {
draw_border(n, true, (m == mon));
}
- activate_desktop(m, d);
-
d->focus = n;
history_add(m, d, n);
show_node(d1, n2);
}
+ bool d1_was_focused = (d1 == mon->desk);
+ bool d2_was_focused = (d2 == mon->desk);
+
if (n1_held_focus) {
- if (d1 == mon->desk) {
- focus_node(m1, d1, d1->focus);
+ if (d1_was_focused) {
+ focus_node(m2, d2, last_d1_focus);
} else {
activate_node(m1, d1, d1->focus);
}
}
if (n2_held_focus) {
- if (d2 == mon->desk) {
- focus_node(m2, d2, d2->focus);
+ if (d2_was_focused) {
+ focus_node(m1, d1, last_d2_focus);
} else {
activate_node(m2, d2, d2->focus);
}
} else {
if (held_focus) {
if (ds == mon->desk) {
- focus_node(ms, ds, ds->focus);
- } else {
- activate_node(ms, ds, ds->focus);
+ focus_node(md, dd, last_ds_focus);
}
+ activate_node(ms, ds, ds->focus);
}
if (dd->focus == ns) {
if (dd == mon->desk) {
- focus_node(md, dd, held_focus ? last_ds_focus : dd->focus);
+ focus_node(md, dd, held_focus ? last_ds_focus : ns);
} else {
- activate_node(md, dd, held_focus ? last_ds_focus : dd->focus);
+ activate_node(md, dd, held_focus ? last_ds_focus : ns);
}
} else {
draw_border(ns, is_descendant(ns, dd->focus), (md == mon));
[ "$(bspc query -N -m 'TEST-SWAP-A')" = "$nodes_b" ] || fail "Wrong nodes in first monitor"
[ "$(bspc query -N -m 'TEST-SWAP-B')" = "$nodes_a" ] || fail "Wrong nodes in second monitor"
-window remove 3
-bspc monitor -f "TEST-SWAP-A"
window remove 2
+bspc monitor -f "TEST-SWAP-B"
+window remove 3
bspc monitor "TEST-SWAP-A" -r
bspc monitor "TEST-SWAP-B" -r
[ "$(bspc query -N -n @test-swap-b:)" = "$next_focus_b" ] || fail "Invalid focus after swap."
-window remove 2
-bspc desktop -f "test-swap-b"
window remove 1 2
window remove 4
+bspc desktop -f "test-swap-a"
+window remove 2
bspc desktop "test-swap-a" -r
bspc desktop "test-swap-b" -r
bspc node -f $next_focus_b
bspc node @/2 -d "test-transfer-b"
-[ "$next_focus_a" = "$(bspc query -N -n)" ] || fail "Invalid focus after transfer from source."
+[ "$next_focus_a" = "$(bspc query -N -n @test-transfer-a:)" ] || fail "Invalid focus after transfer from source."
[ "$next_focus_b" = "$(bspc query -N -n @test-transfer-b:)" ] || fail "Invalid focus after transfer in destination."
-window remove
-bspc desktop -f "test-transfer-b"
window remove 1 2
window remove 2
+bspc desktop -f "test-transfer-a"
+window remove
bspc desktop "test-transfer-a" -r
bspc desktop "test-transfer-b" -r