From 2073415f911cd370177328cffaf76ce48a7d2bba Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 25 Jul 2022 17:06:03 +0100 Subject: [PATCH] Ensure size is valid after maximising In X11 when a window is maximised if the client is unable to fufill the space provided we centre align the window. With the new floating point geometry behaviour of centreing changes. Instead of a 1 pixel gap at the top, we get a 0.5 pixel gap either side. When we get into the codepath to "fix" the window in `closeHeight` we only move the top, giving us an invalid buffer size. We don't really want to change the logic here; on xwayland with the scaling opt-out path it's feasible for a floating sized logical size to still be representable. This code rounds to the native unit after all the logic has taken effect. --- autotests/xcb_scaling_mock.cpp | 4 ++++ src/utils/xcbutils.cpp | 6 ++++++ src/utils/xcbutils.h | 1 + src/x11window.cpp | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/autotests/xcb_scaling_mock.cpp b/autotests/xcb_scaling_mock.cpp index edc4d2c647..9493cf23cd 100644 --- a/autotests/xcb_scaling_mock.cpp +++ b/autotests/xcb_scaling_mock.cpp @@ -27,4 +27,8 @@ QSizeF Xcb::fromXNative(const QSize &value) return value; } +QRectF Xcb::nativeFloor(const QRectF &value) +{ + return value; +} } diff --git a/src/utils/xcbutils.cpp b/src/utils/xcbutils.cpp index d9b4db173e..44f5110faa 100644 --- a/src/utils/xcbutils.cpp +++ b/src/utils/xcbutils.cpp @@ -646,5 +646,11 @@ qreal nativeFloor(qreal value) return std::floor(value / kwinApp()->xwaylandScale()) * kwinApp()->xwaylandScale(); } +QRectF nativeFloor(const QRectF &value) +{ + return QRectF(nativeFloor(value.left()), nativeFloor(value.top()), + nativeFloor(value.width()), nativeFloor(value.height())); +} + } // namespace Xcb } // namespace KWin diff --git a/src/utils/xcbutils.h b/src/utils/xcbutils.h index 8f66e35ea8..ad1c223ed6 100644 --- a/src/utils/xcbutils.h +++ b/src/utils/xcbutils.h @@ -47,6 +47,7 @@ QSizeF KWIN_EXPORT fromXNative(const QSize &value); * i.e floor(a/scale) * scale */ qreal KWIN_EXPORT nativeFloor(qreal value); +QRectF KWIN_EXPORT nativeFloor(const QRectF &value); // forward declaration of methods static void defineCursor(xcb_window_t window, xcb_cursor_t cursor); diff --git a/src/x11window.cpp b/src/x11window.cpp index a5a6ab172c..e5cf1f2d21 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -4536,6 +4536,10 @@ void X11Window::changeMaximize(bool horizontal, bool vertical, bool adjust) } r.moveTopLeft(rules()->checkPosition(r.topLeft())); } + // The above code tries to center align the window followed by setting top and bottom + // it's possible that we no longer have a valid size + r = Xcb::nativeFloor(r); + moveResize(r); if (options->electricBorderMaximize() && r.top() == clientArea.top()) { updateQuickTileMode(QuickTileFlag::Maximize);