From 145497598192f7db5f2082573e58c972649e957c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Fri, 29 May 2015 23:49:22 +0200 Subject: [PATCH 1/3] Added a testcases for #1056 to test whether hovering over a window decoration causes the corresponding window to be focused. --- testcases/t/246-window-decoration-focus.t | 148 ++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 testcases/t/246-window-decoration-focus.t diff --git a/testcases/t/246-window-decoration-focus.t b/testcases/t/246-window-decoration-focus.t new file mode 100644 index 00000000..06dfad89 --- /dev/null +++ b/testcases/t/246-window-decoration-focus.t @@ -0,0 +1,148 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Ensure that hovering over the window decoration of a window causes it to focus +# correctly. +# Ticket: #1056 +# Bug still in: 4.10.2-174-g8029ff0 +use i3test; + +my ($ws, $A, $B, $C, $target, $y); +my @cons; + +# ================================================================================== +# Given the following layout (= denotes the window decoration), +# when moving the mouse from 1 to 2, +# then the C should be focused. +# +# This should especially be the case if B is the focus head of its vertically split parent container. +# +# +===A===+===B===+ +# | | | +# | 1 +=2=C===+ +# | | | +# +-------+-------+ +# +# ================================================================================== + +$ws = fresh_workspace; + +open_window; +$B = open_window; +cmd 'split v'; +open_window; +$target = get_focused($ws); + +@cons = @{get_ws($ws)->{nodes}}; +$A = $cons[0]; +$C = $cons[1]->{nodes}[1]; + +$y = $C->{rect}->{y} - 0.5 * $C->{deco_rect}->{height}; + +# make sure that B is the focus head of its parent +cmd '[id="' . $B->{id} . '"] focus'; + +# move pointer to position 1 +$x->root->warp_pointer($C->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y); +sync_with_i3; + +# move pointer to position 2 +$x->root->warp_pointer($C->{rect}->{x} + 0.5 * $C->{rect}->{width}, $y); +sync_with_i3; + +is(get_focused($ws), $target, 'focus switched to container C'); + +# ================================================================================== +# Given a tabbed container when the mouse is moved onto the window decoration +# then the focus head of the tabbed container is focused regardless of which particular +# tab's decoration the mouse is on. +# +# +=========+=========+ +# | | | +# | 1 +=2==|****| <- tab to the right is focus head of tabbed container +# | | | +# +---------+---------+ +# +# ================================================================================== + +$ws = fresh_workspace; + +open_window; +open_window; +cmd 'split v'; +open_window; +cmd 'split h'; +open_window; +$target = get_focused($ws); +cmd 'layout tabbed'; + +@cons = @{get_ws($ws)->{nodes}}; +$A = $cons[0]; +$B = $cons[1]->{nodes}[1]->{nodes}[1]; + +$y = $B->{rect}->{y} - 0.5 * $B->{deco_rect}->{height}; + +$x->root->warp_pointer($B->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y); +sync_with_i3; + +$x->root->warp_pointer($B->{rect}->{x} + 0.2 * $B->{rect}->{width}, $y); +sync_with_i3; + +is(get_focused($ws), $target, 'focus switched to the focus head of the tabbed container'); + +# ================================================================================== +# Given a stacked container when the mouse is moved onto the window decoration +# then the focus head of the stacked container is focused regardless of which particular +# tab's decoration the mouse is on. +# +# +=========+=========+ +# | | | +# | 1 +=2=======+ +# | +*********+ <- the lower tab is the focus head of the stacked container +# | | | +# +---------+---------+ +# +# ================================================================================== + +$ws = fresh_workspace; + +open_window; +open_window; +cmd 'split v'; +open_window; +cmd 'split h'; +open_window; +$target = get_focused($ws); +cmd 'layout stacked'; + +@cons = @{get_ws($ws)->{nodes}}; +$A = $cons[0]; +$B = $cons[1]->{nodes}[1]->{nodes}[0]; +$C = $cons[1]->{nodes}[1]->{nodes}[1]; + +$y = $B->{rect}->{y} - 1.5 * $B->{deco_rect}->{height}; + +$x->root->warp_pointer($B->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y); +sync_with_i3; + +$x->root->warp_pointer($B->{rect}->{x} + 0.5 * $B->{rect}->{width}, $y); +sync_with_i3; + +is(get_focused($ws), $target, 'focus switched to the focus head of the stacked container'); + +# ================================================================================== + +done_testing; From 3c11f27201b1b4e79ee590f0b89bedc694a60b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Fri, 29 May 2015 20:28:24 +0200 Subject: [PATCH 2/3] Allow hovering over the window decoration to change the focus if the parent container is split horizontally or vertically. fixes #1056 --- src/handlers.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/handlers.c b/src/handlers.c index e7dde581..c6d3e81d 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -228,7 +228,7 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { if (config.disable_focus_follows_mouse) return; - if (con->layout != L_DEFAULT) + if (con->layout != L_DEFAULT && con->layout != L_SPLITV && con->layout != L_SPLITH) return; /* see over which rect the user is */ @@ -245,8 +245,6 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { x_push_changes(croot); return; } - - return; } /* From 27e50b827c1994f48721150810ba8df1a695becb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20B=C3=BCrk?= Date: Fri, 29 May 2015 20:28:35 +0200 Subject: [PATCH 3/3] Use XCB_NONE instead of hard-coded 0. --- src/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers.c b/src/handlers.c index c6d3e81d..0eda54b0 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -215,7 +215,7 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) { /* Skip events where the pointer was over a child window, we are only * interested in events on the root window. */ - if (event->child != 0) + if (event->child != XCB_NONE) return; Con *con;