Commit cf271288 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii Committed by Vlad Zahorodnii
Browse files

Update input transformation matrix when buffer geometry changes

Currently, we update the input transformation matrix for the focused
pointer surface only when the frameGeometryChanged() signal is emitted.
However, since the input transformation matrix is computed based on the
current position of the upper left corner of the main surface, it is
wrong to do so because the frame geometry is a logical geometry that
doesn't have any direct relationship with the buffer geometry, i.e. the
rect on the screen occupied by the main surface.

If the input transformation matrix gets out of sync, user may notice
that pointer events are "shifted."

This change introduces a new signal that's emitted when the input
transformation matrix has been changed. Input related components in kwin
can connect to it to keep a copy of the input transformation matrix in
SeatInterface in sync. Under the hood, the new signal is just an alias
for the bufferGeometryChanged() signal.
parent c4c06c4e
......@@ -37,6 +37,8 @@ along with this program. If not, see <>.
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/compositor.h>
#include <KWayland/Client/output.h>
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/server_decoration.h>
#include <KWayland/Client/subsurface.h>
#include <KWayland/Client/surface.h>
......@@ -118,6 +120,7 @@ private Q_SLOTS:
void testXdgWindowGeometryInteractiveResize();
void testXdgWindowGeometryFullScreen();
void testXdgWindowGeometryMaximize();
void testPointerInputTransform();
void TestXdgShellClient::initTestCase()
......@@ -143,8 +146,10 @@ void TestXdgShellClient::initTestCase()
void TestXdgShellClient::init()
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration |
Test::AdditionalWaylandInterface::Seat |
Test::AdditionalWaylandInterface::XdgDecoration |
KWin::Cursors::self()->mouse()->setPos(QPoint(1280, 512));
......@@ -1581,5 +1586,64 @@ void TestXdgShellClient::testXdgWindowGeometryMaximize()
void TestXdgShellClient::testPointerInputTransform()
// This test verifies that XdgToplevelClient provides correct input transform matrix.
// The input transform matrix is used by seat to map pointer events from the global
// screen coordinates to the surface-local coordinates.
// Get a wl_pointer object on the client side.
QScopedPointer<KWayland::Client::Pointer> pointer(Test::waylandSeat()->createPointer());
QSignalSpy pointerEnteredSpy(, &KWayland::Client::Pointer::entered);
QSignalSpy pointerMotionSpy(, &KWayland::Client::Pointer::motion);
// Create an xdg_toplevel surface and wait for the compositor to catch up.
QScopedPointer<Surface> surface(Test::createSurface());
QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(;
AbstractClient *client = Test::renderAndWaitForShown(, QSize(200, 100), Qt::red);
QCOMPARE(client->bufferGeometry().size(), QSize(200, 100));
QCOMPARE(client->frameGeometry().size(), QSize(200, 100));
// Enter the surface.
quint32 timestamp = 0;
kwinApp()->platform()->pointerMotion(client->pos(), timestamp++);
// Move the pointer to (10, 5) relative to the upper left frame corner, which is located
// at (0, 0) in the surface-local coordinates.
kwinApp()->platform()->pointerMotion(client->pos() + QPoint(10, 5), timestamp++);
QCOMPARE(pointerMotionSpy.last().first(), QPoint(10, 5));
// Let's pretend that the client has changed the extents of the client-side drop-shadow
// but the frame geometry didn't change.
QSignalSpy bufferGeometryChangedSpy(client, &AbstractClient::bufferGeometryChanged);
QSignalSpy frameGeometryChangedSpy(client, &AbstractClient::frameGeometryChanged);
shellSurface->setWindowGeometry(QRect(10, 20, 200, 100));
Test::render(, QSize(220, 140), Qt::blue);
QCOMPARE(frameGeometryChangedSpy.count(), 0);
QCOMPARE(client->frameGeometry().size(), QSize(200, 100));
QCOMPARE(client->bufferGeometry().size(), QSize(220, 140));
// Move the pointer to (20, 50) relative to the upper left frame corner, which is located
// at (10, 20) in the surface-local coordinates.
kwinApp()->platform()->pointerMotion(client->pos() + QPoint(20, 50), timestamp++);
QCOMPARE(pointerMotionSpy.last().first(), QPoint(10, 20) + QPoint(20, 50));
// Destroy the xdg-toplevel surface.
#include "xdgshellclient_test.moc"
......@@ -565,7 +565,7 @@ void PointerInputRedirection::focusUpdate(Toplevel *focusOld, Toplevel *focusNow
seat->setFocusedPointerSurface(focusNow->surface(), focusNow->inputTransformation());
m_focusGeometryConnection = connect(focusNow, &Toplevel::frameGeometryChanged, this,
m_focusGeometryConnection = connect(focusNow, &Toplevel::inputTransformationChanged, this,
[this] {
// TODO: why no assert possible?
if (!focus()) {
......@@ -59,6 +59,7 @@ Toplevel::Toplevel()
connect(screens(), SIGNAL(changed()), SLOT(checkScreen()));
connect(screens(), SIGNAL(countChanged(int,int)), SLOT(checkScreen()));
connect(this, &Toplevel::bufferGeometryChanged, this, &Toplevel::inputTransformationChanged);
// Only for compatibility reasons, drop in the next major release.
connect(this, &Toplevel::frameGeometryChanged, this, &Toplevel::geometryChanged);
......@@ -590,6 +590,7 @@ public:
void opacityChanged(KWin::Toplevel* toplevel, qreal oldOpacity);
void damaged(KWin::Toplevel* toplevel, const QRect& damage);
void inputTransformationChanged();
* This signal is emitted when the Toplevel's frame geometry changes.
* @deprecated since 5.19, use frameGeometryChanged instead
Markdown is supported
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