From 56b08ab4fc0489315bd06f2ea6d68ae7d6370b5f Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 11 Mar 2010 23:34:29 +0100 Subject: [PATCH] =?UTF-8?q?Bugfix:=20Don=E2=80=99t=20mess=20up=20x/y=20coo?= =?UTF-8?q?rdinates=20in=20configurerequests=20for=20floating=20windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was the cause for ticket #93, which actually has a false conclusion for the reason of this bug. This code needs to be refactored. --- src/handlers.c | 28 ++++++++-- testcases/t/12-floating-resize.t | 90 ++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 testcases/t/12-floating-resize.t diff --git a/src/handlers.c b/src/handlers.c index 0dc0295b..ad43cc4d 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -341,11 +341,31 @@ int handle_configure_request(void *prophs, xcb_connection_t *conn, xcb_configure if (client_is_floating(client)) { i3Font *font = load_font(conn, config.font); int mode = (client->container != NULL ? client->container->mode : MODE_DEFAULT); + /* TODO: refactor this code. we need a function to translate + * coordinates of child_rect/rect. */ - if (event->value_mask & XCB_CONFIG_WINDOW_X) - client->rect.x = event->x; - if (event->value_mask & XCB_CONFIG_WINDOW_Y) - client->rect.y = event->y; + if (event->value_mask & XCB_CONFIG_WINDOW_X) { + if (mode == MODE_STACK || mode == MODE_TABBED) { + client->rect.x = event->x - 2; + } else { + if (client->titlebar_position == TITLEBAR_OFF && client->borderless) + client->rect.x = event->x; + else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) + client->rect.x = event->x - 1; + else client->rect.x = event->x - 2; + } + } + if (event->value_mask & XCB_CONFIG_WINDOW_Y) { + if (mode == MODE_STACK || mode == MODE_TABBED) { + client->rect.y = event->y - 2; + } else { + if (client->titlebar_position == TITLEBAR_OFF && client->borderless) + client->rect.y = event->y; + else if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) + client->rect.y = event->y - 1; + else client->rect.y = event->y - font->height - 2 - 2; + } + } if (event->value_mask & XCB_CONFIG_WINDOW_WIDTH) { if (mode == MODE_STACK || mode == MODE_TABBED) { client->rect.width = event->width + 2 + 2; diff --git a/testcases/t/12-floating-resize.t b/testcases/t/12-floating-resize.t new file mode 100644 index 00000000..d908d345 --- /dev/null +++ b/testcases/t/12-floating-resize.t @@ -0,0 +1,90 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# Beware that this test uses workspace 9 to perform some tests (it expects +# the workspace to be empty). +# TODO: skip it by default? + +use Test::More tests => 17; +use Test::Deep; +use X11::XCB qw(:all); +use Data::Dumper; +use Time::HiRes qw(sleep); +use FindBin; +use Digest::SHA1 qw(sha1_base64); +use lib "$FindBin::Bin/lib"; +use i3test; + +BEGIN { + use_ok('IO::Socket::UNIX') or BAIL_OUT('Cannot load IO::Socket::UNIX'); + use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection'); +} + +my $x = X11::XCB::Connection->new; + +my $sock = IO::Socket::UNIX->new(Peer => '/tmp/i3-ipc.sock'); +isa_ok($sock, 'IO::Socket::UNIX'); + +# Switch to the nineth workspace +$sock->write(i3test::format_ipc_command("9")); + +sleep 0.25; + +##################################################################### +# Create a floating window and see if resizing works +##################################################################### + +# Create a floating window +my $window = $x->root->create_child( + class => WINDOW_CLASS_INPUT_OUTPUT, + rect => [ 0, 0, 30, 30], + background_color => '#C0C0C0', + # replace the type with 'utility' as soon as the coercion works again in X11::XCB + type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), +); + +isa_ok($window, 'X11::XCB::Window'); + +$window->map; +sleep 0.25; + +# See if configurerequests cause window movements (they should not) +my ($a, $t) = $window->rect; +$window->rect(X11::XCB::Rect->new(x => $a->x, y => $a->y, width => $a->width, height => $a->height)); + +sleep 0.25; +my ($na, $nt) = $window->rect; +is_deeply($na, $a, 'Rects are equal after configurerequest'); + +sub test_resize { + $window->rect(X11::XCB::Rect->new(x => 0, y => 0, width => 100, height => 100)); + + my ($absolute, $top) = $window->rect; + + # Make sure the width/height are different from what we’re gonna test, so + # that the test will work. + isnt($absolute->width, 300, 'width != 300'); + isnt($absolute->height, 500, 'height != 500'); + + $window->rect(X11::XCB::Rect->new(x => 0, y => 0, width => 300, height => 500)); + sleep 0.25; + + ($absolute, $top) = $window->rect; + + is($absolute->width, 300, 'width = 300'); + is($absolute->height, 500, 'height = 500'); +} + +# Test with default border +test_resize; + +# Test borderless +$sock->write(i3test::format_ipc_command("bb")); +sleep 0.25; + +test_resize; + +# Test with 1-px-border +$sock->write(i3test::format_ipc_command("bp")); +sleep 0.25; + +test_resize;