Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/placement_test.cpp
Show All 12 Lines | |||||
13 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | 16 | GNU General Public License for more details. | ||
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 "abstract_client.h" | ||||
21 | #include "cursor.h" | 22 | #include "cursor.h" | ||
22 | #include "kwin_wayland_test.h" | 23 | #include "kwin_wayland_test.h" | ||
23 | #include "platform.h" | 24 | #include "platform.h" | ||
24 | #include "screens.h" | 25 | #include "screens.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 51 Lines • ▼ Show 20 Line(s) | |||||
85 | 85 | | |||
86 | void TestPlacement::cleanup() | 86 | void TestPlacement::cleanup() | ||
87 | { | 87 | { | ||
88 | Test::destroyWaylandConnection(); | 88 | Test::destroyWaylandConnection(); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | void TestPlacement::initTestCase() | 91 | void TestPlacement::initTestCase() | ||
92 | { | 92 | { | ||
93 | qRegisterMetaType<KWin::XdgShellClient *>(); | | |||
94 | qRegisterMetaType<KWin::AbstractClient*>(); | 93 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
95 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 94 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
96 | QVERIFY(workspaceCreatedSpy.isValid()); | 95 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
97 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 96 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
98 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 97 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
99 | QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); | 98 | QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); | ||
100 | 99 | | |||
101 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | 100 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 243 | { | |||
246 | 245 | | |||
247 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 246 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
248 | group.writeEntry("Placement", Placement::policyToString(Placement::Centered)); | 247 | group.writeEntry("Placement", Placement::policyToString(Placement::Centered)); | ||
249 | group.sync(); | 248 | group.sync(); | ||
250 | workspace()->slotReconfigure(); | 249 | workspace()->slotReconfigure(); | ||
251 | 250 | | |||
252 | QScopedPointer<Surface> surface(Test::createSurface()); | 251 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
253 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | 252 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
254 | XdgShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | 253 | AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | ||
255 | QVERIFY(client); | 254 | QVERIFY(client); | ||
256 | QCOMPARE(client->frameGeometry(), QRect(590, 487, 100, 50)); | 255 | QCOMPARE(client->frameGeometry(), QRect(590, 487, 100, 50)); | ||
257 | 256 | | |||
258 | shellSurface.reset(); | 257 | shellSurface.reset(); | ||
259 | QVERIFY(Test::waitForWindowDestroyed(client)); | 258 | QVERIFY(Test::waitForWindowDestroyed(client)); | ||
260 | } | 259 | } | ||
261 | 260 | | |||
262 | void TestPlacement::testPlaceUnderMouse() | 261 | void TestPlacement::testPlaceUnderMouse() | ||
263 | { | 262 | { | ||
264 | // This test verifies that Under Mouse placement policy works. | 263 | // This test verifies that Under Mouse placement policy works. | ||
265 | 264 | | |||
266 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 265 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
267 | group.writeEntry("Placement", Placement::policyToString(Placement::UnderMouse)); | 266 | group.writeEntry("Placement", Placement::policyToString(Placement::UnderMouse)); | ||
268 | group.sync(); | 267 | group.sync(); | ||
269 | workspace()->slotReconfigure(); | 268 | workspace()->slotReconfigure(); | ||
270 | 269 | | |||
271 | KWin::Cursor::setPos(QPoint(200, 300)); | 270 | KWin::Cursor::setPos(QPoint(200, 300)); | ||
272 | QCOMPARE(KWin::Cursor::pos(), QPoint(200, 300)); | 271 | QCOMPARE(KWin::Cursor::pos(), QPoint(200, 300)); | ||
273 | 272 | | |||
274 | QScopedPointer<Surface> surface(Test::createSurface()); | 273 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
275 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | 274 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
276 | XdgShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | 275 | AbstractClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::red); | ||
277 | QVERIFY(client); | 276 | QVERIFY(client); | ||
278 | QCOMPARE(client->frameGeometry(), QRect(151, 276, 100, 50)); | 277 | QCOMPARE(client->frameGeometry(), QRect(151, 276, 100, 50)); | ||
279 | 278 | | |||
280 | shellSurface.reset(); | 279 | shellSurface.reset(); | ||
281 | QVERIFY(Test::waitForWindowDestroyed(client)); | 280 | QVERIFY(Test::waitForWindowDestroyed(client)); | ||
282 | } | 281 | } | ||
283 | 282 | | |||
284 | void TestPlacement::testPlaceCascaded() | 283 | void TestPlacement::testPlaceCascaded() | ||
285 | { | 284 | { | ||
286 | // This test verifies that Cascaded placement policy works. | 285 | // This test verifies that Cascaded placement policy works. | ||
287 | 286 | | |||
288 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 287 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
289 | group.writeEntry("Placement", Placement::policyToString(Placement::Cascade)); | 288 | group.writeEntry("Placement", Placement::policyToString(Placement::Cascade)); | ||
290 | group.sync(); | 289 | group.sync(); | ||
291 | workspace()->slotReconfigure(); | 290 | workspace()->slotReconfigure(); | ||
292 | 291 | | |||
293 | QScopedPointer<Surface> surface1(Test::createSurface()); | 292 | QScopedPointer<Surface> surface1(Test::createSurface()); | ||
294 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | 293 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | ||
295 | XdgShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | 294 | AbstractClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | ||
296 | QVERIFY(client1); | 295 | QVERIFY(client1); | ||
297 | QCOMPARE(client1->pos(), QPoint(0, 0)); | 296 | QCOMPARE(client1->pos(), QPoint(0, 0)); | ||
298 | QCOMPARE(client1->size(), QSize(100, 50)); | 297 | QCOMPARE(client1->size(), QSize(100, 50)); | ||
299 | 298 | | |||
300 | QScopedPointer<Surface> surface2(Test::createSurface()); | 299 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
301 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | 300 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
302 | XdgShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | 301 | AbstractClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | ||
303 | QVERIFY(client2); | 302 | QVERIFY(client2); | ||
304 | QCOMPARE(client2->pos(), client1->pos() + workspace()->cascadeOffset(client2)); | 303 | QCOMPARE(client2->pos(), client1->pos() + workspace()->cascadeOffset(client2)); | ||
305 | QCOMPARE(client2->size(), QSize(100, 50)); | 304 | QCOMPARE(client2->size(), QSize(100, 50)); | ||
306 | 305 | | |||
307 | QScopedPointer<Surface> surface3(Test::createSurface()); | 306 | QScopedPointer<Surface> surface3(Test::createSurface()); | ||
308 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | 307 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | ||
309 | XdgShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | 308 | AbstractClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | ||
310 | QVERIFY(client3); | 309 | QVERIFY(client3); | ||
311 | QCOMPARE(client3->pos(), client2->pos() + workspace()->cascadeOffset(client3)); | 310 | QCOMPARE(client3->pos(), client2->pos() + workspace()->cascadeOffset(client3)); | ||
312 | QCOMPARE(client3->size(), QSize(100, 50)); | 311 | QCOMPARE(client3->size(), QSize(100, 50)); | ||
313 | 312 | | |||
314 | shellSurface3.reset(); | 313 | shellSurface3.reset(); | ||
315 | QVERIFY(Test::waitForWindowDestroyed(client3)); | 314 | QVERIFY(Test::waitForWindowDestroyed(client3)); | ||
316 | shellSurface2.reset(); | 315 | shellSurface2.reset(); | ||
317 | QVERIFY(Test::waitForWindowDestroyed(client2)); | 316 | QVERIFY(Test::waitForWindowDestroyed(client2)); | ||
318 | shellSurface1.reset(); | 317 | shellSurface1.reset(); | ||
319 | QVERIFY(Test::waitForWindowDestroyed(client1)); | 318 | QVERIFY(Test::waitForWindowDestroyed(client1)); | ||
320 | } | 319 | } | ||
321 | 320 | | |||
322 | void TestPlacement::testPlaceRandom() | 321 | void TestPlacement::testPlaceRandom() | ||
323 | { | 322 | { | ||
324 | // This test verifies that Random placement policy works. | 323 | // This test verifies that Random placement policy works. | ||
325 | 324 | | |||
326 | KConfigGroup group = kwinApp()->config()->group("Windows"); | 325 | KConfigGroup group = kwinApp()->config()->group("Windows"); | ||
327 | group.writeEntry("Placement", Placement::policyToString(Placement::Random)); | 326 | group.writeEntry("Placement", Placement::policyToString(Placement::Random)); | ||
328 | group.sync(); | 327 | group.sync(); | ||
329 | workspace()->slotReconfigure(); | 328 | workspace()->slotReconfigure(); | ||
330 | 329 | | |||
331 | QScopedPointer<Surface> surface1(Test::createSurface()); | 330 | QScopedPointer<Surface> surface1(Test::createSurface()); | ||
332 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | 331 | QScopedPointer<XdgShellSurface> shellSurface1(Test::createXdgShellStableSurface(surface1.data())); | ||
333 | XdgShellClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | 332 | AbstractClient *client1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::red); | ||
334 | QVERIFY(client1); | 333 | QVERIFY(client1); | ||
335 | QCOMPARE(client1->size(), QSize(100, 50)); | 334 | QCOMPARE(client1->size(), QSize(100, 50)); | ||
336 | 335 | | |||
337 | QScopedPointer<Surface> surface2(Test::createSurface()); | 336 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
338 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | 337 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
339 | XdgShellClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | 338 | AbstractClient *client2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); | ||
340 | QVERIFY(client2); | 339 | QVERIFY(client2); | ||
341 | QVERIFY(client2->pos() != client1->pos()); | 340 | QVERIFY(client2->pos() != client1->pos()); | ||
342 | QCOMPARE(client2->size(), QSize(100, 50)); | 341 | QCOMPARE(client2->size(), QSize(100, 50)); | ||
343 | 342 | | |||
344 | QScopedPointer<Surface> surface3(Test::createSurface()); | 343 | QScopedPointer<Surface> surface3(Test::createSurface()); | ||
345 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | 344 | QScopedPointer<XdgShellSurface> shellSurface3(Test::createXdgShellStableSurface(surface3.data())); | ||
346 | XdgShellClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | 345 | AbstractClient *client3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::green); | ||
347 | QVERIFY(client3); | 346 | QVERIFY(client3); | ||
348 | QVERIFY(client3->pos() != client1->pos()); | 347 | QVERIFY(client3->pos() != client1->pos()); | ||
349 | QVERIFY(client3->pos() != client2->pos()); | 348 | QVERIFY(client3->pos() != client2->pos()); | ||
350 | QCOMPARE(client3->size(), QSize(100, 50)); | 349 | QCOMPARE(client3->size(), QSize(100, 50)); | ||
351 | 350 | | |||
352 | shellSurface3.reset(); | 351 | shellSurface3.reset(); | ||
353 | QVERIFY(Test::waitForWindowDestroyed(client3)); | 352 | QVERIFY(Test::waitForWindowDestroyed(client3)); | ||
354 | shellSurface2.reset(); | 353 | shellSurface2.reset(); | ||
355 | QVERIFY(Test::waitForWindowDestroyed(client2)); | 354 | QVERIFY(Test::waitForWindowDestroyed(client2)); | ||
356 | shellSurface1.reset(); | 355 | shellSurface1.reset(); | ||
357 | QVERIFY(Test::waitForWindowDestroyed(client1)); | 356 | QVERIFY(Test::waitForWindowDestroyed(client1)); | ||
358 | } | 357 | } | ||
359 | 358 | | |||
360 | WAYLANDTEST_MAIN(TestPlacement) | 359 | WAYLANDTEST_MAIN(TestPlacement) | ||
361 | #include "placement_test.moc" | 360 | #include "placement_test.moc" |