x11window: Calculate the native floor from the begining of the output

If this function is useful to make sure we are properly aligned with the
output's pixels, we should start with the output's 0, otherwise we'll be
carrying over the rounding errors increasingly as our workspace grows.

BUG: 459373
This commit is contained in:
Aleix Pol 2022-11-18 22:49:37 +01:00 committed by Aleix Pol Gonzalez
parent cdeacdbdad
commit df77fcd9e0
4 changed files with 29 additions and 5 deletions

View file

@ -154,6 +154,16 @@ QRect Output::mapFromGlobal(const QRect &rect) const
return rect.translated(-geometry().topLeft()); 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 Output::Capabilities Output::capabilities() const
{ {
return m_information.capabilities; return m_information.capabilities;

View file

@ -109,6 +109,16 @@ public:
*/ */
QRect mapFromGlobal(const QRect &rect) const; 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. * Returns a short identifiable name of this output.
*/ */

View file

@ -9,6 +9,9 @@
*/ */
#include "utils/xcbutils.h" #include "utils/xcbutils.h"
#include "utils/common.h" #include "utils/common.h"
#include <core/output.h>
#include <workspace.h>
// Qt // Qt
#include <QDebug> #include <QDebug>
// xcb // xcb
@ -641,15 +644,17 @@ QSizeF fromXNative(const QSize &s)
return QSizeF(fromXNative(s.width()), fromXNative(s.height())); 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(); 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()), const auto output = workspace()->outputAt(rect.center());
nativeFloor(value.width()), nativeFloor(value.height())); const QRectF outputRect = output->mapFromGlobal(rect);
return output->mapToGlobal(QRectF(nativeFloor(outputRect.left()), nativeFloor(outputRect.top()),
nativeFloor(outputRect.width()), nativeFloor(outputRect.height())));
} }
} // namespace Xcb } // namespace Xcb

View file

@ -43,7 +43,6 @@ QSizeF KWIN_EXPORT fromXNative(const QSize &value);
* Use when flooring to ints from Xwayland * Use when flooring to ints from Xwayland
* i.e floor(a/scale) * scale * i.e floor(a/scale) * scale
*/ */
qreal KWIN_EXPORT nativeFloor(qreal value);
QRectF KWIN_EXPORT nativeFloor(const QRectF &value); QRectF KWIN_EXPORT nativeFloor(const QRectF &value);
// forward declaration of methods // forward declaration of methods