From 24f0ea2f24661932e9e5055beeda7650621d5db0 Mon Sep 17 00:00:00 2001 From: Deiz Date: Wed, 25 Mar 2015 22:40:59 -0400 Subject: [PATCH 1/2] Make center coordinates relative to current workspace Fixes #1211 --- src/commands.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands.c b/src/commands.c index 9b51b3ec..2121fc66 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1761,8 +1761,8 @@ void cmd_move_window_to_center(I3_CMD, char *method) { Rect newrect = focused->parent->rect; DLOG("moving to center\n"); - newrect.x = wsrect->width / 2 - newrect.width / 2; - newrect.y = wsrect->height / 2 - newrect.height / 2; + newrect.x = wsrect->x + wsrect->width / 2 - newrect.width / 2; + newrect.y = wsrect->y + wsrect->height / 2 - newrect.height / 2; floating_reposition(focused->parent, newrect); } From bae66a9dae68870491be50b9fb1d5adf23d7f99c Mon Sep 17 00:00:00 2001 From: Deiz Date: Fri, 27 Mar 2015 14:29:53 -0400 Subject: [PATCH 2/2] Add a test case for #1211 --- testcases/t/523-move-position-center.t | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 testcases/t/523-move-position-center.t diff --git a/testcases/t/523-move-position-center.t b/testcases/t/523-move-position-center.t new file mode 100644 index 00000000..6b584245 --- /dev/null +++ b/testcases/t/523-move-position-center.t @@ -0,0 +1,63 @@ +#!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) +# +# Verifies that 'move position center' moves floating cons to the center of +# the appropriate output. +# Ticket: #1211 +# Bug still in: 4.9.1-108-g037cb31 +use i3test i3_autostart => 0; + +my $config = <{floating_nodes}}, 1, 'one floating node on left ws'); +is(scalar @{get_ws('right')->{floating_nodes}}, 0, 'no floating nodes on right ws'); + +# Center the window on the right workspace +cmd 'move workspace right; workspace right; move position center'; +sync_with_i3; + +is(scalar @{get_ws('left')->{floating_nodes}}, 0, 'no floating nodes on left ws'); +is(scalar @{get_ws('right')->{floating_nodes}}, 1, 'one floating node on right ws'); + +exit_gracefully($pid); + +done_testing;