Skip to content

Commit

Permalink
Don't raise floating windows when focused because of focus_follows_mouse
Browse files Browse the repository at this point in the history
Fixes i3#2990
  • Loading branch information
orestisfl committed Sep 28, 2017
1 parent fa96db2 commit aca27ef
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/con.h
Expand Up @@ -37,6 +37,7 @@ void con_free(Con *con);
*
*/
void con_focus(Con *con);
void _con_focus(Con *con, bool raise_floating);

/**
* Closes the given container.
Expand Down
10 changes: 7 additions & 3 deletions src/con.c
Expand Up @@ -220,7 +220,7 @@ void con_detach(Con *con) {
* run of x_push_changes().
*
*/
void con_focus(Con *con) {
void _con_focus(Con *con, bool raise_floating) {
assert(con != NULL);
DLOG("con_focus = %p\n", con);

Expand All @@ -229,7 +229,7 @@ void con_focus(Con *con) {
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
TAILQ_INSERT_HEAD(&(con->parent->focus_head), con, focused);
if (con->parent->parent != NULL)
con_focus(con->parent);
_con_focus(con->parent, raise_floating);

focused = con;
/* We can't blindly reset non-leaf containers since they might have
Expand All @@ -247,11 +247,15 @@ void con_focus(Con *con) {
/* Focusing a container with a floating parent should raise it to the top. Since
* con_focus is called recursively for each parent we don't need to use
* con_inside_floating(). */
if (con->type == CT_FLOATING_CON) {
if (raise_floating && con->type == CT_FLOATING_CON) {
floating_raise_con(con);
}
}

void con_focus(Con *con) {
_con_focus(con, true);
}

/*
* Closes the given container.
*
Expand Down
6 changes: 3 additions & 3 deletions src/handlers.c
Expand Up @@ -109,7 +109,7 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) {
/* Since we are switching outputs, this *must* be a different workspace, so
* call workspace_show() */
workspace_show(con_get_workspace(next));
con_focus(next);
_con_focus(next, false);

/* If the focus changed, we re-render to get updated decorations */
if (old_focused != focused)
Expand Down Expand Up @@ -182,7 +182,7 @@ static void handle_enter_notify(xcb_enter_notify_event_t *event) {
workspace_show(ws);

focused_id = XCB_NONE;
con_focus(con_descend_focused(con));
_con_focus(con_descend_focused(con), false);
tree_render();

return;
Expand Down Expand Up @@ -225,7 +225,7 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) {
if (TAILQ_FIRST(&(con->focus_head)) == current)
return;

con_focus(current);
_con_focus(current, false);
x_push_changes(croot);
return;
}
Expand Down
28 changes: 28 additions & 0 deletions testcases/t/293-focus-follows-mouse.t
Expand Up @@ -57,4 +57,32 @@ is($x->input_focus, $second->id, 'second (tabbed) window focused');
synced_warp_pointer(0, 0);
is($x->input_focus, $second->id, 'second window still focused');

###################################################################
# Test that floating windows are focused but not raised to the top.
# See issue #2990.
###################################################################

my $ws;
my $tmp = fresh_workspace;
my ($first_floating, $second_floating);

synced_warp_pointer(0, 0);
$first_floating = open_floating_window;
$first_floating->rect(X11::XCB::Rect->new(x => 1, y => 1, width => 100, height => 100));
$second_floating = open_floating_window;
$second_floating->rect(X11::XCB::Rect->new(x => 50, y => 50, width => 100, height => 100));
sync_with_i3;
$first = open_window;

is($x->input_focus, $first->id, 'first (tiling) window focused');
$ws = get_ws($tmp);
is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $second_floating->id, 'second floating on top');
is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first_floating->id, 'first floating behind');

synced_warp_pointer(40, 40);
is($x->input_focus, $first_floating->id, 'first floating window focused');
$ws = get_ws($tmp);
is($ws->{floating_nodes}->[1]->{nodes}->[0]->{window}, $second_floating->id, 'second floating still on top');
is($ws->{floating_nodes}->[0]->{nodes}->[0]->{window}, $first_floating->id, 'first floating still behind');

done_testing;

0 comments on commit aca27ef

Please sign in to comment.