diff --git a/src/core/output.cpp b/src/core/output.cpp index abd25c91af..63029a3fe5 100644 --- a/src/core/output.cpp +++ b/src/core/output.cpp @@ -154,6 +154,16 @@ QRect Output::mapFromGlobal(const QRect &rect) const return rect.translated(-geometry().topLeft()); } +QRectF Output::mapFromGlobal(const QRectF &rect) const +{ + return rect.translated(-geometry().topLeft()); +} + +QRectF Output::mapToGlobal(const QRectF &rect) const +{ + return rect.translated(geometry().topLeft()); +} + Output::Capabilities Output::capabilities() const { return m_information.capabilities; diff --git a/src/core/output.h b/src/core/output.h index 3d2945625a..cc45723eb2 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -109,6 +109,16 @@ public: */ QRect mapFromGlobal(const QRect &rect) const; + /** + * Maps the specified @a rect from the global coordinate system to the output-local coords. + */ + QRectF mapFromGlobal(const QRectF &rect) const; + + /** + * Maps a @a rect in this output coordinates to the global coordinate system. + */ + QRectF mapToGlobal(const QRectF &rect) const; + /** * Returns a short identifiable name of this output. */ diff --git a/src/utils/xcbutils.cpp b/src/utils/xcbutils.cpp index 99089b304e..7f0ff780b4 100644 --- a/src/utils/xcbutils.cpp +++ b/src/utils/xcbutils.cpp @@ -9,6 +9,9 @@ */ #include "utils/xcbutils.h" #include "utils/common.h" +#include +#include + // Qt #include // xcb @@ -641,15 +644,17 @@ QSizeF fromXNative(const QSize &s) return QSizeF(fromXNative(s.width()), fromXNative(s.height())); } -qreal nativeFloor(qreal value) +static qreal nativeFloor(qreal value) { return std::floor(value / kwinApp()->xwaylandScale()) * kwinApp()->xwaylandScale(); } -QRectF nativeFloor(const QRectF &value) +QRectF nativeFloor(const QRectF &rect) { - return QRectF(nativeFloor(value.left()), nativeFloor(value.top()), - nativeFloor(value.width()), nativeFloor(value.height())); + const auto output = workspace()->outputAt(rect.center()); + const QRectF outputRect = output->mapFromGlobal(rect); + return output->mapToGlobal(QRectF(nativeFloor(outputRect.left()), nativeFloor(outputRect.top()), + nativeFloor(outputRect.width()), nativeFloor(outputRect.height()))); } } // namespace Xcb diff --git a/src/utils/xcbutils.h b/src/utils/xcbutils.h index 0667797ec7..76b1331d63 100644 --- a/src/utils/xcbutils.h +++ b/src/utils/xcbutils.h @@ -43,7 +43,6 @@ QSizeF KWIN_EXPORT fromXNative(const QSize &value); * Use when flooring to ints from Xwayland * i.e floor(a/scale) * scale */ -qreal KWIN_EXPORT nativeFloor(qreal value); QRectF KWIN_EXPORT nativeFloor(const QRectF &value); // forward declaration of methods