Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/placement_test.cpp
Show All 16 Lines | |||||
17 | 17 | | |||
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | *********************************************************************/ | 20 | *********************************************************************/ | ||
21 | #include "cursor.h" | 21 | #include "cursor.h" | ||
22 | #include "kwin_wayland_test.h" | 22 | #include "kwin_wayland_test.h" | ||
23 | #include "platform.h" | 23 | #include "platform.h" | ||
24 | #include "screens.h" | 24 | #include "screens.h" | ||
25 | #include "shell_client.h" | 25 | #include "xdgshellclient.h" | ||
26 | #include "wayland_server.h" | 26 | #include "wayland_server.h" | ||
27 | #include "workspace.h" | 27 | #include "workspace.h" | ||
28 | 28 | | |||
29 | #include <KWayland/Client/compositor.h> | 29 | #include <KWayland/Client/compositor.h> | ||
30 | #include <KWayland/Client/plasmashell.h> | 30 | #include <KWayland/Client/plasmashell.h> | ||
31 | #include <KWayland/Client/server_decoration.h> | 31 | #include <KWayland/Client/server_decoration.h> | ||
32 | #include <KWayland/Client/shm_pool.h> | 32 | #include <KWayland/Client/shm_pool.h> | ||
33 | #include <KWayland/Client/surface.h> | 33 | #include <KWayland/Client/surface.h> | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
84 | 84 | | |||
85 | void TestPlacement::cleanup() | 85 | void TestPlacement::cleanup() | ||
86 | { | 86 | { | ||
87 | Test::destroyWaylandConnection(); | 87 | Test::destroyWaylandConnection(); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | void TestPlacement::initTestCase() | 90 | void TestPlacement::initTestCase() | ||
91 | { | 91 | { | ||
92 | qRegisterMetaType<KWin::ShellClient*>(); | 92 | qRegisterMetaType<KWin::XdgShellClient *>(); | ||
93 | qRegisterMetaType<KWin::AbstractClient*>(); | 93 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
94 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 94 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
95 | QVERIFY(workspaceCreatedSpy.isValid()); | 95 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
96 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 96 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
97 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 97 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
98 | QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); | 98 | QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); | ||
99 | 99 | | |||
100 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | 100 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 208 | { | |||
210 | 210 | | |||
211 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 211 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
212 | group.writeEntry("Placement", Placement::policyToString(Placement::Centered)); | 212 | group.writeEntry("Placement", Placement::policyToString(Placement::Centered)); | ||
213 | group.sync(); | 213 | group.sync(); | ||
214 | workspace()->slotReconfigure(); | 214 | workspace()->slotReconfigure(); | ||
215 | 215 | | |||
216 | QScopedPointer<Surface> surface(Test::createSurface()); | 216 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
217 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | 217 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
218 | ShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | 218 | XdgShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | ||
219 | QVERIFY(client); | 219 | QVERIFY(client); | ||
220 | QCOMPARE(client->geometry(), QRect(590, 487, 100, 50)); | 220 | QCOMPARE(client->geometry(), QRect(590, 487, 100, 50)); | ||
221 | 221 | | |||
222 | shellSurface.reset(); | 222 | shellSurface.reset(); | ||
223 | QVERIFY(Test::waitForWindowDestroyed(client)); | 223 | QVERIFY(Test::waitForWindowDestroyed(client)); | ||
224 | } | 224 | } | ||
225 | 225 | | |||
226 | void TestPlacement::testPlaceUnderMouse() | 226 | void TestPlacement::testPlaceUnderMouse() | ||
227 | { | 227 | { | ||
228 | // This test verifies that Under Mouse placement policy works. | 228 | // This test verifies that Under Mouse placement policy works. | ||
229 | 229 | | |||
230 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 230 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
231 | group.writeEntry("Placement", Placement::policyToString(Placement::UnderMouse)); | 231 | group.writeEntry("Placement", Placement::policyToString(Placement::UnderMouse)); | ||
232 | group.sync(); | 232 | group.sync(); | ||
233 | workspace()->slotReconfigure(); | 233 | workspace()->slotReconfigure(); | ||
234 | 234 | | |||
235 | KWin::Cursor::setPos(QPoint(200, 300)); | 235 | KWin::Cursor::setPos(QPoint(200, 300)); | ||
236 | QCOMPARE(KWin::Cursor::pos(), QPoint(200, 300)); | 236 | QCOMPARE(KWin::Cursor::pos(), QPoint(200, 300)); | ||
237 | 237 | | |||
238 | QScopedPointer<Surface> surface(Test::createSurface()); | 238 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
239 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | 239 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
240 | ShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | 240 | XdgShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | ||
241 | QVERIFY(client); | 241 | QVERIFY(client); | ||
242 | QCOMPARE(client->geometry(), QRect(151, 276, 100, 50)); | 242 | QCOMPARE(client->geometry(), QRect(151, 276, 100, 50)); | ||
243 | 243 | | |||
244 | shellSurface.reset(); | 244 | shellSurface.reset(); | ||
245 | QVERIFY(Test::waitForWindowDestroyed(client)); | 245 | QVERIFY(Test::waitForWindowDestroyed(client)); | ||
246 | } | 246 | } | ||
247 | 247 | | |||
248 | void TestPlacement::testPlaceCascaded() | 248 | void TestPlacement::testPlaceCascaded() | ||
249 | { | 249 | { | ||
250 | // This test verifies that Cascaded placement policy works. | 250 | // This test verifies that Cascaded placement policy works. | ||
251 | 251 | | |||
252 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 252 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
253 | group.writeEntry("Placement", Placement::policyToString(Placement::Cascade)); | 253 | group.writeEntry("Placement", Placement::policyToString(Placement::Cascade)); | ||
254 | group.sync(); | 254 | group.sync(); | ||
255 | workspace()->slotReconfigure(); | 255 | workspace()->slotReconfigure(); | ||
256 | 256 | | |||
257 | QScopedPointer<Surface> surface1(Test::createSurface()); | 257 | QScopedPointer<Surface> surface1(Test::createSurface()); | ||
258 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | 258 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | ||
259 | ShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | 259 | XdgShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | ||
260 | QVERIFY(client1); | 260 | QVERIFY(client1); | ||
261 | QCOMPARE(client1->pos(), QPoint(0, 0)); | 261 | QCOMPARE(client1->pos(), QPoint(0, 0)); | ||
262 | QCOMPARE(client1->size(), QSize(100, 50)); | 262 | QCOMPARE(client1->size(), QSize(100, 50)); | ||
263 | 263 | | |||
264 | QScopedPointer<Surface> surface2(Test::createSurface()); | 264 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
265 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | 265 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
266 | ShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | 266 | XdgShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | ||
267 | QVERIFY(client2); | 267 | QVERIFY(client2); | ||
268 | QCOMPARE(client2->pos(), client1->pos() + workspace()->cascadeOffset(client2)); | 268 | QCOMPARE(client2->pos(), client1->pos() + workspace()->cascadeOffset(client2)); | ||
269 | QCOMPARE(client2->size(), QSize(100, 50)); | 269 | QCOMPARE(client2->size(), QSize(100, 50)); | ||
270 | 270 | | |||
271 | QScopedPointer<Surface> surface3(Test::createSurface()); | 271 | QScopedPointer<Surface> surface3(Test::createSurface()); | ||
272 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | 272 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | ||
273 | ShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | 273 | XdgShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | ||
274 | QVERIFY(client3); | 274 | QVERIFY(client3); | ||
275 | QCOMPARE(client3->pos(), client2->pos() + workspace()->cascadeOffset(client3)); | 275 | QCOMPARE(client3->pos(), client2->pos() + workspace()->cascadeOffset(client3)); | ||
276 | QCOMPARE(client3->size(), QSize(100, 50)); | 276 | QCOMPARE(client3->size(), QSize(100, 50)); | ||
277 | 277 | | |||
278 | shellSurface3.reset(); | 278 | shellSurface3.reset(); | ||
279 | QVERIFY(Test::waitForWindowDestroyed(client3)); | 279 | QVERIFY(Test::waitForWindowDestroyed(client3)); | ||
280 | shellSurface2.reset(); | 280 | shellSurface2.reset(); | ||
281 | QVERIFY(Test::waitForWindowDestroyed(client2)); | 281 | QVERIFY(Test::waitForWindowDestroyed(client2)); | ||
282 | shellSurface1.reset(); | 282 | shellSurface1.reset(); | ||
283 | QVERIFY(Test::waitForWindowDestroyed(client1)); | 283 | QVERIFY(Test::waitForWindowDestroyed(client1)); | ||
284 | } | 284 | } | ||
285 | 285 | | |||
286 | void TestPlacement::testPlaceRandom() | 286 | void TestPlacement::testPlaceRandom() | ||
287 | { | 287 | { | ||
288 | // This test verifies that Random placement policy works. | 288 | // This test verifies that Random placement policy works. | ||
289 | 289 | | |||
290 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 290 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
291 | group.writeEntry("Placement", Placement::policyToString(Placement::Random)); | 291 | group.writeEntry("Placement", Placement::policyToString(Placement::Random)); | ||
292 | group.sync(); | 292 | group.sync(); | ||
293 | workspace()->slotReconfigure(); | 293 | workspace()->slotReconfigure(); | ||
294 | 294 | | |||
295 | QScopedPointer<Surface> surface1(Test::createSurface()); | 295 | QScopedPointer<Surface> surface1(Test::createSurface()); | ||
296 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | 296 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | ||
297 | ShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | 297 | XdgShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | ||
298 | QVERIFY(client1); | 298 | QVERIFY(client1); | ||
299 | QCOMPARE(client1->size(), QSize(100, 50)); | 299 | QCOMPARE(client1->size(), QSize(100, 50)); | ||
300 | 300 | | |||
301 | QScopedPointer<Surface> surface2(Test::createSurface()); | 301 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
302 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | 302 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
303 | ShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | 303 | XdgShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | ||
304 | QVERIFY(client2); | 304 | QVERIFY(client2); | ||
305 | QVERIFY(client2->pos() != client1->pos()); | 305 | QVERIFY(client2->pos() != client1->pos()); | ||
306 | QCOMPARE(client2->size(), QSize(100, 50)); | 306 | QCOMPARE(client2->size(), QSize(100, 50)); | ||
307 | 307 | | |||
308 | QScopedPointer<Surface> surface3(Test::createSurface()); | 308 | QScopedPointer<Surface> surface3(Test::createSurface()); | ||
309 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | 309 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | ||
310 | ShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | 310 | XdgShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | ||
311 | QVERIFY(client3); | 311 | QVERIFY(client3); | ||
312 | QVERIFY(client3->pos() != client1->pos()); | 312 | QVERIFY(client3->pos() != client1->pos()); | ||
313 | QVERIFY(client3->pos() != client2->pos()); | 313 | QVERIFY(client3->pos() != client2->pos()); | ||
314 | QCOMPARE(client3->size(), QSize(100, 50)); | 314 | QCOMPARE(client3->size(), QSize(100, 50)); | ||
315 | 315 | | |||
316 | shellSurface3.reset(); | 316 | shellSurface3.reset(); | ||
317 | QVERIFY(Test::waitForWindowDestroyed(client3)); | 317 | QVERIFY(Test::waitForWindowDestroyed(client3)); | ||
318 | shellSurface2.reset(); | 318 | shellSurface2.reset(); | ||
319 | QVERIFY(Test::waitForWindowDestroyed(client2)); | 319 | QVERIFY(Test::waitForWindowDestroyed(client2)); | ||
320 | shellSurface1.reset(); | 320 | shellSurface1.reset(); | ||
321 | QVERIFY(Test::waitForWindowDestroyed(client1)); | 321 | QVERIFY(Test::waitForWindowDestroyed(client1)); | ||
322 | } | 322 | } | ||
323 | 323 | | |||
324 | WAYLANDTEST_MAIN(TestPlacement) | 324 | WAYLANDTEST_MAIN(TestPlacement) | ||
325 | #include "placement_test.moc" | 325 | #include "placement_test.moc" |