File indexing completed on 2024-05-05 17:35:54
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "kwin_wayland_test.h" 0010 0011 #include "core/outputbackend.h" 0012 #include "cursor.h" 0013 #include "wayland_server.h" 0014 0015 namespace KWin 0016 { 0017 0018 static const QString s_socketName = QStringLiteral("wayland_test_kwin_platform_cursor-0"); 0019 0020 class PlatformCursorTest : public QObject 0021 { 0022 Q_OBJECT 0023 private Q_SLOTS: 0024 void initTestCase(); 0025 void testPos(); 0026 }; 0027 0028 void PlatformCursorTest::initTestCase() 0029 { 0030 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); 0031 QVERIFY(waylandServer()->init(s_socketName)); 0032 QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024))); 0033 0034 kwinApp()->start(); 0035 QVERIFY(applicationStartedSpy.wait()); 0036 } 0037 0038 void PlatformCursorTest::testPos() 0039 { 0040 // this test verifies that the PlatformCursor of the QPA plugin forwards ::pos and ::setPos correctly 0041 // that is QCursor should work just like KWin::Cursor 0042 0043 // cursor should be centered on screen 0044 QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(639, 511)); 0045 QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(639, 511)); 0046 0047 // let's set the pos through QCursor API 0048 QCursor::setPos(QPoint(10, 10)); 0049 QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(10, 10)); 0050 QCOMPARE(QCursor::pos(), QPoint(10, 10)); 0051 0052 // and let's set the pos through Cursor API 0053 QCursor::setPos(QPoint(20, 20)); 0054 QCOMPARE(Cursors::self()->mouse()->pos(), QPoint(20, 20)); 0055 QCOMPARE(QCursor::pos(), QPoint(20, 20)); 0056 } 0057 0058 } 0059 0060 WAYLANDTEST_MAIN(KWin::PlatformCursorTest) 0061 #include "platformcursor.moc"