Commit 3fff256b authored by Xaver Hugl's avatar Xaver Hugl
Browse files

window: make resizeWithChecks not modify any window state

parent 5a3321be
......@@ -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;
......
......@@ -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)
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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;
......
......@@ -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()
......
......@@ -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;
......
......@@ -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())));
}
}
......
......@@ -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;
......
......@@ -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
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment