diff --git a/geometry.cpp b/geometry.cpp index a47c5676d7..bde47ee73a 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -2374,6 +2374,35 @@ void Client::changeMaximize(bool vertical, bool horizontal, bool adjust) r.moveRight(qMin(clientArea.right(), r.right())); } else { r.moveCenter(clientArea.center()); + const bool closeHeight = r.height() > 97*clientArea.height()/100; + const bool closeWidth = r.width() > 97*clientArea.width() /100; + const bool overHeight = r.height() > clientArea.height(); + const bool overWidth = r.width() > clientArea.width(); + if (closeWidth || closeHeight) { + Position titlePos = titlebarPosition(); + const QRect screenArea = workspace()->clientArea(ScreenArea, clientArea.center(), desktop()); + if (closeHeight) { + bool tryBottom = titlePos == PositionBottom; + if ((overHeight && titlePos == PositionTop) || + screenArea.top() == clientArea.top()) + r.setTop(clientArea.top()); + else + tryBottom = true; + if (tryBottom && + (overHeight || screenArea.bottom() == clientArea.bottom())) + r.setBottom(clientArea.bottom()); + } + if (closeWidth) { + bool tryLeft = titlePos == PositionLeft; + if ((overWidth && titlePos == PositionRight) || + screenArea.right() == clientArea.right()) + r.setRight(clientArea.right()); + else + tryLeft = true; + if (tryLeft && (overWidth || screenArea.left() == clientArea.left())) + r.setLeft(clientArea.left()); + } + } } r.moveTopLeft(rules()->checkPosition(r.topLeft())); }