diff --git a/src/deleted.h b/src/deleted.h index 897c414a76..55de08a2b5 100644 --- a/src/deleted.h +++ b/src/deleted.h @@ -101,8 +101,9 @@ public: { /* nothing to do */ } void updateCaption() override { /* nothing to do */ } - void resizeWithChecks(const QSizeF &) override + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &) override { /* nothing to do */ + return geometry; } WindowItem *createItem() override; diff --git a/src/internalwindow.cpp b/src/internalwindow.cpp index 312633e0e1..41cc622a1d 100644 --- a/src/internalwindow.cpp +++ b/src/internalwindow.cpp @@ -274,13 +274,13 @@ void InternalWindow::showClient() { } -void InternalWindow::resizeWithChecks(const QSizeF &size) +QRectF InternalWindow::resizeWithChecks(const QRectF &geometry, const QSizeF &size) { if (!m_handle) { - return; + return geometry; } - const QRectF area = workspace()->clientArea(WorkArea, this); - resize(size.boundedTo(area.size())); + const QRectF area = workspace()->clientArea(WorkArea, this, geometry.center()); + return QRectF(moveResizeGeometry().topLeft(), size.boundedTo(area.size())); } void InternalWindow::moveResizeInternal(const QRectF &rect, MoveResizeMode mode) diff --git a/src/internalwindow.h b/src/internalwindow.h index 145d7a295f..a8c613ccab 100644 --- a/src/internalwindow.h +++ b/src/internalwindow.h @@ -49,7 +49,7 @@ public: bool isHiddenInternal() const override; void hideClient() override; void showClient() override; - void resizeWithChecks(const QSizeF &size) override; + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override; Window *findModal(bool allow_itself = false) override; bool takeFocus() override; void setNoBorder(bool set) override; diff --git a/src/placement.cpp b/src/placement.cpp index 4479ef28de..19a59f2d6b 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -613,7 +613,7 @@ void Placement::placeMaximizing(Window *c, const QRect &area, Policy nextPlaceme c->moveResize(area); } } else { - c->resizeWithChecks(c->maxSize().boundedTo(area.size())); + c->moveResize(c->resizeWithChecks(c->moveResizeGeometry(), c->maxSize().boundedTo(area.size()))); place(c, area, nextPlacement); } } diff --git a/src/unmanaged.h b/src/unmanaged.h index c257cb5535..6e156169cd 100644 --- a/src/unmanaged.h +++ b/src/unmanaged.h @@ -56,8 +56,9 @@ public: { /* nothing to do */ } void updateCaption() override { /* nothing to do */ } - void resizeWithChecks(const QSizeF &) override + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &) override { /* nothing to do */ + return geometry; } WindowItem *createItem() override; diff --git a/src/waylandwindow.cpp b/src/waylandwindow.cpp index ce5d36cbc5..4183f3092b 100644 --- a/src/waylandwindow.cpp +++ b/src/waylandwindow.cpp @@ -96,9 +96,9 @@ Window *WaylandWindow::findModal(bool allow_itself) return nullptr; } -void WaylandWindow::resizeWithChecks(const QSizeF &size) +QRectF WaylandWindow::resizeWithChecks(const QRectF &geometry, const QSizeF &size) { - const QRectF area = workspace()->clientArea(WorkArea, this); + const QRectF area = workspace()->clientArea(WorkArea, this, geometry.center()); qreal width = size.width(); qreal height = size.height(); @@ -110,7 +110,7 @@ void WaylandWindow::resizeWithChecks(const QSizeF &size) if (height > area.height()) { height = area.height(); } - resize(QSizeF(width, height)); + return QRectF(geometry.topLeft(), QSizeF(width, height)); } void WaylandWindow::killWindow() diff --git a/src/waylandwindow.h b/src/waylandwindow.h index ed2d033e54..83ebdecab1 100644 --- a/src/waylandwindow.h +++ b/src/waylandwindow.h @@ -25,7 +25,7 @@ public: bool isLockScreen() const override; bool isLocalhost() const override; Window *findModal(bool allow_itself = false) override; - void resizeWithChecks(const QSizeF &size) override; + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override; void killWindow() override; QByteArray windowRole() const override; bool isShown() const override; diff --git a/src/window.cpp b/src/window.cpp index 9be30bc568..b62bb138d5 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1519,7 +1519,7 @@ void Window::keepInArea(QRectF area, bool partial) // resize to fit into area const QRectF geometry = moveResizeGeometry(); if (area.width() < geometry.width() || area.height() < geometry.height()) { - resizeWithChecks(geometry.size().boundedTo(area.size())); + moveResize(resizeWithChecks(geometry, geometry.size().boundedTo(area.size()))); } } diff --git a/src/window.h b/src/window.h index afb49bb56e..5abb54258e 100644 --- a/src/window.h +++ b/src/window.h @@ -1140,7 +1140,7 @@ public: void resize(const QSizeF &size); void moveResize(const QRectF &rect); - virtual void resizeWithChecks(const QSizeF &s) = 0; + virtual QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &s) = 0; void keepInArea(QRectF area, bool partial = false); virtual QSizeF minSize() const; virtual QSizeF maxSize() const; diff --git a/src/x11window.cpp b/src/x11window.cpp index 08be85d696..bda7ffea0f 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -3723,7 +3723,7 @@ void X11Window::getWmNormalHints() QSizeF new_size = clientSizeToFrameSize(constrainClientSize(clientSize())); if (new_size != size() && !isFullScreen()) { QRectF origClientGeometry = m_clientGeometry; - resizeWithChecks(new_size); + moveResize(resizeWithChecks(moveResizeGeometry(), new_size)); if ((!isSpecialWindow() || isToolbar()) && !isFullScreen()) { // try to keep the window in its xinerama screen if possible, // if that fails at least keep it visible somewhere @@ -3982,7 +3982,7 @@ void X11Window::configureRequest(int value_mask, qreal rx, qreal ry, qreal rw, q if (requestedFrameSize != size()) { // don't restore if some app sets its own size again QRectF origClientGeometry = m_clientGeometry; GeometryUpdatesBlocker blocker(this); - resizeWithChecks(requestedFrameSize, xcb_gravity_t(gravity)); + moveResize(resizeWithChecks(moveResizeGeometry(), requestedFrameSize, xcb_gravity_t(gravity))); if (!from_tool && (!isSpecialWindow() || isToolbar()) && !isFullScreen()) { // try to keep the window in its xinerama screen if possible, // if that fails at least keep it visible somewhere @@ -4002,7 +4002,7 @@ void X11Window::configureRequest(int value_mask, qreal rx, qreal ry, qreal rw, q // Handling of the real ConfigureRequest event forces sending it, as there it's necessary. } -void X11Window::resizeWithChecks(qreal w, qreal h, xcb_gravity_t gravity) +QRectF X11Window::resizeWithChecks(const QRectF &geometry, qreal w, qreal h, xcb_gravity_t gravity) { Q_ASSERT(!shade_geometry_change); if (isShade()) { @@ -4010,9 +4010,9 @@ void X11Window::resizeWithChecks(qreal w, qreal h, xcb_gravity_t gravity) qCWarning(KWIN_CORE) << "Shaded geometry passed for size:"; } } - qreal newx = x(); - qreal newy = y(); - QRectF area = workspace()->clientArea(WorkArea, this); + qreal newx = geometry.x(); + qreal newy = geometry.y(); + QRectF area = workspace()->clientArea(WorkArea, this, geometry.center()); // don't allow growing larger than workarea if (w > area.width()) { w = area.width(); @@ -4031,38 +4031,38 @@ void X11Window::resizeWithChecks(qreal w, qreal h, xcb_gravity_t gravity) default: break; case XCB_GRAVITY_NORTH: // middle of top border doesn't move - newx = (newx + width() / 2) - (w / 2); + newx = (newx + geometry.width() / 2) - (w / 2); break; case XCB_GRAVITY_NORTH_EAST: // top right corner doesn't move - newx = newx + width() - w; + newx = newx + geometry.width() - w; break; case XCB_GRAVITY_WEST: // middle of left border doesn't move - newy = (newy + height() / 2) - (h / 2); + newy = (newy + geometry.height() / 2) - (h / 2); break; case XCB_GRAVITY_CENTER: // middle point doesn't move - newx = (newx + width() / 2) - (w / 2); - newy = (newy + height() / 2) - (h / 2); + newx = (newx + geometry.width() / 2) - (w / 2); + newy = (newy + geometry.height() / 2) - (h / 2); break; case XCB_GRAVITY_STATIC: // top left corner of _client_ window doesn't move // since decoration doesn't change, equal to NorthWestGravity break; case XCB_GRAVITY_EAST: // // middle of right border doesn't move - newx = newx + width() - w; - newy = (newy + height() / 2) - (h / 2); + newx = newx + geometry.width() - w; + newy = (newy + geometry.height() / 2) - (h / 2); break; case XCB_GRAVITY_SOUTH_WEST: // bottom left corner doesn't move - newy = newy + height() - h; + newy = newy + geometry.height() - h; break; case XCB_GRAVITY_SOUTH: // middle of bottom border doesn't move - newx = (newx + width() / 2) - (w / 2); - newy = newy + height() - h; + newx = (newx + geometry.width() / 2) - (w / 2); + newy = newy + geometry.height() - h; break; case XCB_GRAVITY_SOUTH_EAST: // bottom right corner doesn't move - newx = newx + width() - w; - newy = newy + height() - h; + newx = newx + geometry.width() - w; + newy = newy + geometry.height() - h; break; } - moveResize(QRectF{newx, newy, w, h}); + return QRectF{newx, newy, w, h}; } // _NET_MOVERESIZE_WINDOW diff --git a/src/x11window.h b/src/x11window.h index 8c3d6697de..2f86963dc9 100644 --- a/src/x11window.h +++ b/src/x11window.h @@ -194,9 +194,9 @@ public: void updateShape(); /// resizeWithChecks() resizes according to gravity, and checks workarea position - void resizeWithChecks(const QSizeF &size) override; - void resizeWithChecks(qreal w, qreal h, xcb_gravity_t gravity); - void resizeWithChecks(const QSizeF &s, xcb_gravity_t gravity); + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override; + QRectF resizeWithChecks(const QRectF &geometry, qreal w, qreal h, xcb_gravity_t gravity); + QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &s, xcb_gravity_t gravity); QSizeF constrainClientSize(const QSizeF &size, SizeMode mode = SizeModeAny) const override; bool providesContextHelp() const override; @@ -619,14 +619,14 @@ inline bool X11Window::isManaged() const return m_managed; } -inline void X11Window::resizeWithChecks(const QSizeF &s) +inline QRectF X11Window::resizeWithChecks(const QRectF &geometry, const QSizeF &s) { - resizeWithChecks(s.width(), s.height(), XCB_GRAVITY_BIT_FORGET); + return resizeWithChecks(geometry, s.width(), s.height(), XCB_GRAVITY_BIT_FORGET); } -inline void X11Window::resizeWithChecks(const QSizeF &s, xcb_gravity_t gravity) +inline QRectF X11Window::resizeWithChecks(const QRectF &geometry, const QSizeF &s, xcb_gravity_t gravity) { - resizeWithChecks(s.width(), s.height(), gravity); + return resizeWithChecks(geometry, s.width(), s.height(), gravity); } inline bool X11Window::hasUserTimeSupport() const