2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2018 David Edmundson <davidedmundson@kde.org>
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2018-05-15 09:45:17 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2018-05-15 09:45:17 +00:00
|
|
|
// KWin
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/output.h"
|
|
|
|
#include "wayland/xdgoutput_v1.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/output.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/xdgoutput.h"
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2022-08-25 08:02:48 +00:00
|
|
|
#include "../../tests/fakeoutput.h"
|
|
|
|
|
2018-05-15 09:45:17 +00:00
|
|
|
class TestXdgOutput : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestXdgOutput(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
void testChanges();
|
2021-08-29 05:11:06 +00:00
|
|
|
|
2018-05-15 09:45:17 +00:00
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
2022-08-25 08:02:48 +00:00
|
|
|
std::unique_ptr<FakeOutput> m_outputHandle;
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::OutputInterface *m_serverOutput;
|
|
|
|
KWin::XdgOutputManagerV1Interface *m_serverXdgOutputManager;
|
2018-05-15 09:45:17 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-test-xdg-output-0");
|
|
|
|
|
|
|
|
TestXdgOutput::TestXdgOutput(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_serverOutput(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXdgOutput::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2018-05-15 09:45:17 +00:00
|
|
|
delete m_display;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2018-05-15 09:45:17 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
2022-08-25 08:02:48 +00:00
|
|
|
m_outputHandle = std::make_unique<FakeOutput>();
|
|
|
|
m_outputHandle->setMode(QSize(1920, 1080), 60000);
|
2022-10-20 09:15:47 +00:00
|
|
|
m_outputHandle->moveTo(QPoint(11, 12)); // not a sensible value for one monitor, but works for this test
|
|
|
|
m_outputHandle->setScale(1.5);
|
|
|
|
m_outputHandle->setName("testName");
|
|
|
|
m_outputHandle->setManufacturer("foo");
|
|
|
|
m_outputHandle->setModel("bar");
|
2022-08-25 08:02:48 +00:00
|
|
|
|
|
|
|
m_serverOutput = new OutputInterface(m_display, m_outputHandle.get(), this);
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_serverXdgOutputManager = new XdgOutputManagerV1Interface(m_display, this);
|
2022-10-27 10:37:46 +00:00
|
|
|
m_serverXdgOutputManager->offer(m_serverOutput);
|
2018-05-15 09:45:17 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2018-05-15 09:45:17 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXdgOutput::cleanup()
|
|
|
|
{
|
|
|
|
if (m_queue) {
|
|
|
|
delete m_queue;
|
|
|
|
m_queue = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
delete m_connection;
|
|
|
|
m_connection = nullptr;
|
|
|
|
|
|
|
|
delete m_serverOutput;
|
|
|
|
m_serverOutput = nullptr;
|
2022-08-25 08:02:48 +00:00
|
|
|
m_outputHandle.reset();
|
2018-05-15 09:45:17 +00:00
|
|
|
|
|
|
|
delete m_display;
|
|
|
|
m_display = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXdgOutput::testChanges()
|
|
|
|
{
|
|
|
|
// verify the server modes
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2018-05-15 09:45:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy announced(®istry, &KWayland::Client::Registry::outputAnnounced);
|
|
|
|
QSignalSpy xdgOutputAnnounced(®istry, &KWayland::Client::Registry::xdgOutputAnnounced);
|
2018-05-15 09:45:17 +00:00
|
|
|
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(announced.wait());
|
|
|
|
if (xdgOutputAnnounced.count() != 1) {
|
|
|
|
QVERIFY(xdgOutputAnnounced.wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
KWayland::Client::Output output;
|
2021-02-25 13:48:11 +00:00
|
|
|
QSignalSpy outputChanged(&output, &KWayland::Client::Output::changed);
|
2018-05-15 09:45:17 +00:00
|
|
|
|
|
|
|
output.setup(registry.bindOutput(announced.first().first().value<quint32>(), announced.first().last().value<quint32>()));
|
|
|
|
QVERIFY(outputChanged.wait());
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::XdgOutputManager> xdgOutputManager(
|
2021-08-29 05:11:06 +00:00
|
|
|
registry.createXdgOutputManager(xdgOutputAnnounced.first().first().value<quint32>(), xdgOutputAnnounced.first().last().value<quint32>(), this));
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::XdgOutput> xdgOutput(xdgOutputManager->getXdgOutput(&output, this));
|
|
|
|
QSignalSpy xdgOutputChanged(xdgOutput.get(), &KWayland::Client::XdgOutput::changed);
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
// check details are sent on client bind
|
2018-05-15 09:45:17 +00:00
|
|
|
QVERIFY(xdgOutputChanged.wait());
|
|
|
|
xdgOutputChanged.clear();
|
2021-08-29 05:11:06 +00:00
|
|
|
QCOMPARE(xdgOutput->logicalPosition(), QPoint(11, 12));
|
|
|
|
QCOMPARE(xdgOutput->logicalSize(), QSize(1280, 720));
|
2020-03-24 10:50:08 +00:00
|
|
|
QCOMPARE(xdgOutput->name(), "testName");
|
2022-10-20 09:15:47 +00:00
|
|
|
QCOMPARE(xdgOutput->description(), "foo bar");
|
2018-05-15 09:45:17 +00:00
|
|
|
|
2022-10-20 09:15:47 +00:00
|
|
|
// change the logical position
|
|
|
|
m_outputHandle->moveTo(QPoint(1000, 2000));
|
2018-05-15 09:45:17 +00:00
|
|
|
QVERIFY(xdgOutputChanged.wait());
|
|
|
|
QCOMPARE(xdgOutputChanged.count(), 1);
|
|
|
|
QCOMPARE(xdgOutput->logicalPosition(), QPoint(1000, 2000));
|
2022-10-20 09:15:47 +00:00
|
|
|
QEXPECT_FAIL("", "KWayland::Client::XdgOutput incorrectly handles partial updates", Continue);
|
|
|
|
QCOMPARE(xdgOutput->logicalSize(), QSize(1280, 720));
|
|
|
|
|
|
|
|
// change the logical size
|
|
|
|
m_outputHandle->setScale(2);
|
|
|
|
QVERIFY(xdgOutputChanged.wait());
|
|
|
|
QCOMPARE(xdgOutputChanged.count(), 2);
|
|
|
|
QEXPECT_FAIL("", "KWayland::Client::XdgOutput incorrectly handles partial updates", Continue);
|
|
|
|
QCOMPARE(xdgOutput->logicalPosition(), QPoint(1000, 2000));
|
|
|
|
QCOMPARE(xdgOutput->logicalSize(), QSize(960, 540));
|
2018-05-15 09:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestXdgOutput)
|
|
|
|
#include "test_xdg_output.moc"
|