Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/transient_placement.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 54 | private Q_SLOTS: | |||
---|---|---|---|---|---|
58 | void testSimplePosition_data(); | 58 | void testSimplePosition_data(); | ||
59 | void testSimplePosition(); | 59 | void testSimplePosition(); | ||
60 | void testDecorationPosition_data(); | 60 | void testDecorationPosition_data(); | ||
61 | void testDecorationPosition(); | 61 | void testDecorationPosition(); | ||
62 | 62 | | |||
63 | private: | 63 | private: | ||
64 | AbstractClient *showWindow(const QSize &size, bool decorated = false, KWayland::Client::Surface *parent = nullptr, const QPoint &offset = QPoint()); | 64 | AbstractClient *showWindow(const QSize &size, bool decorated = false, KWayland::Client::Surface *parent = nullptr, const QPoint &offset = QPoint()); | ||
65 | KWayland::Client::Surface *surfaceForClient(AbstractClient *c) const; | 65 | KWayland::Client::Surface *surfaceForClient(AbstractClient *c) const; | ||
66 | KWayland::Client::ConnectionThread *m_connection = nullptr; | | |||
67 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
68 | KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; | | |||
69 | KWayland::Client::Seat *m_seat = nullptr; | | |||
70 | KWayland::Client::ShmPool *m_shm = nullptr; | | |||
71 | KWayland::Client::Shell *m_shell = nullptr; | | |||
72 | KWayland::Client::EventQueue *m_queue = nullptr; | | |||
73 | QThread *m_thread = nullptr; | | |||
74 | }; | 66 | }; | ||
75 | 67 | | |||
76 | void TransientPlacementTest::initTestCase() | 68 | void TransientPlacementTest::initTestCase() | ||
77 | { | 69 | { | ||
78 | qRegisterMetaType<KWin::ShellClient*>(); | 70 | qRegisterMetaType<KWin::ShellClient*>(); | ||
79 | qRegisterMetaType<KWin::AbstractClient*>(); | 71 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
80 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 72 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
81 | QVERIFY(workspaceCreatedSpy.isValid()); | 73 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
82 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 74 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
83 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | 75 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | ||
84 | waylandServer()->init(s_socketName.toLocal8Bit()); | 76 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
85 | 77 | | |||
86 | kwinApp()->start(); | 78 | kwinApp()->start(); | ||
87 | QVERIFY(workspaceCreatedSpy.wait()); | 79 | QVERIFY(workspaceCreatedSpy.wait()); | ||
88 | QCOMPARE(screens()->count(), 2); | 80 | QCOMPARE(screens()->count(), 2); | ||
89 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 81 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
90 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 82 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
91 | setenv("QT_QPA_PLATFORM", "wayland", true); | 83 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
92 | waylandServer()->initWorkspace(); | 84 | waylandServer()->initWorkspace(); | ||
93 | } | 85 | } | ||
94 | 86 | | |||
95 | void TransientPlacementTest::init() | 87 | void TransientPlacementTest::init() | ||
96 | { | 88 | { | ||
97 | using namespace KWayland::Client; | 89 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); | ||
98 | // setup connection | | |||
99 | m_connection = new ConnectionThread; | | |||
100 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | | |||
101 | QVERIFY(connectedSpy.isValid()); | | |||
102 | m_connection->setSocketName(s_socketName); | | |||
103 | | ||||
104 | m_thread = new QThread(this); | | |||
105 | m_connection->moveToThread(m_thread); | | |||
106 | m_thread->start(); | | |||
107 | | ||||
108 | m_connection->initConnection(); | | |||
109 | QVERIFY(connectedSpy.wait()); | | |||
110 | | ||||
111 | m_queue = new EventQueue(this); | | |||
112 | QVERIFY(!m_queue->isValid()); | | |||
113 | m_queue->setup(m_connection); | | |||
114 | QVERIFY(m_queue->isValid()); | | |||
115 | | ||||
116 | Registry registry; | | |||
117 | registry.setEventQueue(m_queue); | | |||
118 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | | |||
119 | QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); | | |||
120 | QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); | | |||
121 | QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); | | |||
122 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
123 | QVERIFY(allAnnounced.isValid()); | | |||
124 | QVERIFY(shmSpy.isValid()); | | |||
125 | QVERIFY(shellSpy.isValid()); | | |||
126 | QVERIFY(compositorSpy.isValid()); | | |||
127 | QVERIFY(seatSpy.isValid()); | | |||
128 | registry.create(m_connection->display()); | | |||
129 | QVERIFY(registry.isValid()); | | |||
130 | registry.setup(); | | |||
131 | QVERIFY(allAnnounced.wait()); | | |||
132 | QVERIFY(!compositorSpy.isEmpty()); | | |||
133 | QVERIFY(!shmSpy.isEmpty()); | | |||
134 | QVERIFY(!shellSpy.isEmpty()); | | |||
135 | QVERIFY(!seatSpy.isEmpty()); | | |||
136 | | ||||
137 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | | |||
138 | QVERIFY(m_compositor->isValid()); | | |||
139 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | | |||
140 | QVERIFY(m_shm->isValid()); | | |||
141 | m_shell = registry.createShell(shellSpy.first().first().value<quint32>(), shellSpy.first().last().value<quint32>(), this); | | |||
142 | QVERIFY(m_shell->isValid()); | | |||
143 | m_seat = registry.createSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>(), this); | | |||
144 | QVERIFY(m_seat->isValid()); | | |||
145 | QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); | | |||
146 | QVERIFY(hasPointerSpy.isValid()); | | |||
147 | QVERIFY(hasPointerSpy.wait()); | | |||
148 | | ||||
149 | m_deco = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, registry.interface(Registry::Interface::ServerSideDecorationManager).version, this); | | |||
150 | QVERIFY(m_deco->isValid()); | | |||
151 | 90 | | |||
152 | screens()->setCurrent(0); | 91 | screens()->setCurrent(0); | ||
153 | Cursor::setPos(QPoint(640, 512)); | 92 | Cursor::setPos(QPoint(640, 512)); | ||
154 | } | 93 | } | ||
155 | 94 | | |||
156 | void TransientPlacementTest::cleanup() | 95 | void TransientPlacementTest::cleanup() | ||
157 | { | 96 | { | ||
158 | delete m_deco; | 97 | Test::destroyWaylandConnection(); | ||
159 | m_deco = nullptr; | | |||
160 | delete m_compositor; | | |||
161 | m_compositor = nullptr; | | |||
162 | delete m_seat; | | |||
163 | m_seat = nullptr; | | |||
164 | delete m_shm; | | |||
165 | m_shm = nullptr; | | |||
166 | delete m_shell; | | |||
167 | m_shell = nullptr; | | |||
168 | delete m_queue; | | |||
169 | m_queue = nullptr; | | |||
170 | if (m_thread) { | | |||
171 | m_connection->deleteLater(); | | |||
172 | m_thread->quit(); | | |||
173 | m_thread->wait(); | | |||
174 | delete m_thread; | | |||
175 | m_thread = nullptr; | | |||
176 | m_connection = nullptr; | | |||
177 | } | | |||
178 | } | 98 | } | ||
179 | 99 | | |||
180 | AbstractClient *TransientPlacementTest::showWindow(const QSize &size, bool decorated, KWayland::Client::Surface *parent, const QPoint &offset) | 100 | AbstractClient *TransientPlacementTest::showWindow(const QSize &size, bool decorated, KWayland::Client::Surface *parent, const QPoint &offset) | ||
181 | { | 101 | { | ||
182 | using namespace KWayland::Client; | 102 | using namespace KWayland::Client; | ||
183 | #define VERIFY(statement) \ | 103 | #define VERIFY(statement) \ | ||
184 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | 104 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
185 | return nullptr; | 105 | return nullptr; | ||
186 | #define COMPARE(actual, expected) \ | 106 | #define COMPARE(actual, expected) \ | ||
187 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | 107 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
188 | return nullptr; | 108 | return nullptr; | ||
189 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 109 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
190 | VERIFY(clientAddedSpy.isValid()); | 110 | VERIFY(clientAddedSpy.isValid()); | ||
191 | 111 | | |||
192 | Surface *surface = m_compositor->createSurface(m_compositor); | 112 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
193 | VERIFY(surface); | 113 | VERIFY(surface); | ||
194 | ShellSurface *shellSurface = m_shell->createSurface(surface, surface); | 114 | ShellSurface *shellSurface = Test::createShellSurface(surface, surface); | ||
195 | VERIFY(shellSurface); | 115 | VERIFY(shellSurface); | ||
196 | if (parent) { | 116 | if (parent) { | ||
197 | shellSurface->setTransient(parent, offset); | 117 | shellSurface->setTransient(parent, offset); | ||
198 | } | 118 | } | ||
199 | if (decorated) { | 119 | if (decorated) { | ||
200 | auto deco = m_deco->create(surface, surface); | 120 | auto deco = Test::waylandServerSideDecoration()->create(surface, surface); | ||
201 | QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); | 121 | QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); | ||
202 | VERIFY(decoSpy.isValid()); | 122 | VERIFY(decoSpy.isValid()); | ||
203 | VERIFY(decoSpy.wait()); | 123 | VERIFY(decoSpy.wait()); | ||
204 | deco->requestMode(ServerSideDecoration::Mode::Server); | 124 | deco->requestMode(ServerSideDecoration::Mode::Server); | ||
205 | VERIFY(decoSpy.wait()); | 125 | VERIFY(decoSpy.wait()); | ||
206 | COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); | 126 | COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); | ||
207 | } | 127 | } | ||
208 | // let's render | 128 | // let's render | ||
209 | QImage img(size, QImage::Format_ARGB32); | 129 | Test::render(surface, size, Qt::blue); | ||
210 | img.fill(Qt::blue); | | |||
211 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
212 | surface->damage(QRect(QPoint(0, 0), size)); | | |||
213 | surface->commit(Surface::CommitFlag::None); | | |||
214 | 130 | | |||
215 | m_connection->flush(); | 131 | Test::flushWaylandConnection(); | ||
216 | VERIFY(clientAddedSpy.wait()); | 132 | VERIFY(clientAddedSpy.wait()); | ||
217 | AbstractClient *c = workspace()->activeClient(); | 133 | AbstractClient *c = workspace()->activeClient(); | ||
218 | VERIFY(c); | 134 | VERIFY(c); | ||
219 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | 135 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | ||
220 | 136 | | |||
221 | #undef VERIFY | 137 | #undef VERIFY | ||
222 | #undef COMPARE | 138 | #undef COMPARE | ||
223 | 139 | | |||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |