File indexing completed on 2024-11-10 04:56:12

0001 /*
0002     SPDX-FileCopyrightText: 2024 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kwin_wayland_test.h"
0008 
0009 #include "core/output.h"
0010 #include "wayland_server.h"
0011 #include "workspace.h"
0012 
0013 namespace KWin
0014 {
0015 
0016 static const QString s_socketName = QStringLiteral("wayland_test_kwin_xinerama-0");
0017 
0018 class XineramaTest : public QObject
0019 {
0020     Q_OBJECT
0021 
0022 private Q_SLOTS:
0023     void initTestCase();
0024     void indexToOutput();
0025 };
0026 
0027 void XineramaTest::initTestCase()
0028 {
0029     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0030     QVERIFY(waylandServer()->init(s_socketName));
0031     kwinApp()->start();
0032     QVERIFY(applicationStartedSpy.wait());
0033 }
0034 
0035 void XineramaTest::indexToOutput()
0036 {
0037     Test::setOutputConfig({
0038         Test::OutputInfo{
0039             .geometry = QRect(0, 0, 1280, 1024),
0040             .scale = 1.5,
0041         },
0042         Test::OutputInfo{
0043             .geometry = QRect(1280, 0, 1280, 1024),
0044             .scale = 1.5,
0045         },
0046     });
0047     kwinApp()->setXwaylandScale(1.5);
0048 
0049     // Start Xwayland
0050     Test::XcbConnectionPtr c = Test::createX11Connection();
0051     QVERIFY(!xcb_connection_has_error(c.get()));
0052 
0053     const auto outputs = workspace()->outputs();
0054     QCOMPARE(workspace()->xineramaIndexToOutput(0), outputs.at(0));
0055     QCOMPARE(workspace()->xineramaIndexToOutput(1), outputs.at(1));
0056 
0057     workspace()->setOutputOrder({outputs[1], outputs[0]});
0058     QCOMPARE(workspace()->xineramaIndexToOutput(0), outputs.at(1));
0059     QCOMPARE(workspace()->xineramaIndexToOutput(1), outputs.at(0));
0060 }
0061 
0062 } // namespace KWin
0063 
0064 WAYLANDTEST_MAIN(KWin::XineramaTest)
0065 #include "xinerama_test.moc"