Keep the focused item focused

Fixes #691.
Fixes #701.
This commit is contained in:
Bastien Dejean 2017-09-07 21:23:11 +02:00
parent 417bd714ba
commit 412da35b73
5 changed files with 48 additions and 44 deletions

View file

@ -56,6 +56,17 @@ void focus_desktop(monitor_t *m, desktop_t *d)
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;
}
@ -159,9 +170,12 @@ bool transfer_desktop(monitor_t *ms, monitor_t *md, desktop_t *d)
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);
}
}
}
@ -174,12 +188,8 @@ bool transfer_desktop(monitor_t *ms, monitor_t *md, desktop_t *d)
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();
@ -308,7 +318,10 @@ void remove_desktop(monitor_t *m, desktop_t *d)
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);
}
}
}
@ -333,8 +346,10 @@ bool swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2)
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) {
@ -404,21 +419,21 @@ bool swap_desktops(monitor_t *m1, desktop_t *d1, monitor_t *m2, desktop_t *d2)
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);

View file

@ -438,17 +438,6 @@ void insert_receptacle(monitor_t *m, desktop_t *d, node_t *n)
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) {
@ -475,8 +464,6 @@ bool activate_node(monitor_t *m, desktop_t *d, node_t *n)
draw_border(n, true, (m == mon));
}
activate_desktop(m, d);
d->focus = n;
history_add(m, d, n);
@ -1344,9 +1331,12 @@ bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop
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);
}
@ -1355,8 +1345,8 @@ bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop
}
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);
}
@ -1431,16 +1421,15 @@ bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desk
} 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));

View file

@ -19,9 +19,9 @@ bspc desktop "TEST-SWAP-A:^1" -s "TEST-SWAP-B:^1"
[ "$(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

View file

@ -17,10 +17,10 @@ bspc node @/2 -s @test-swap-b:/1
[ "$(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

View file

@ -13,13 +13,13 @@ next_focus_b=$(bspc query -N -n @/2/2/1)
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