Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/pointer_constraints_test.cpp
Show All 26 Lines | |||||
27 | #include "wayland_server.h" | 27 | #include "wayland_server.h" | ||
28 | #include "workspace.h" | 28 | #include "workspace.h" | ||
29 | 29 | | |||
30 | #include <KWayland/Client/compositor.h> | 30 | #include <KWayland/Client/compositor.h> | ||
31 | #include <KWayland/Client/keyboard.h> | 31 | #include <KWayland/Client/keyboard.h> | ||
32 | #include <KWayland/Client/pointer.h> | 32 | #include <KWayland/Client/pointer.h> | ||
33 | #include <KWayland/Client/pointerconstraints.h> | 33 | #include <KWayland/Client/pointerconstraints.h> | ||
34 | #include <KWayland/Client/region.h> | 34 | #include <KWayland/Client/region.h> | ||
35 | #include <KWayland/Client/shell.h> | | |||
36 | #include <KWayland/Client/seat.h> | 35 | #include <KWayland/Client/seat.h> | ||
37 | #include <KWayland/Client/shm_pool.h> | 36 | #include <KWayland/Client/shm_pool.h> | ||
38 | #include <KWayland/Client/surface.h> | 37 | #include <KWayland/Client/surface.h> | ||
39 | #include <KWayland/Server/seat_interface.h> | 38 | #include <KWayland/Server/seat_interface.h> | ||
40 | #include <KWayland/Server/surface_interface.h> | 39 | #include <KWayland/Server/surface_interface.h> | ||
41 | 40 | | |||
42 | #include <linux/input.h> | 41 | #include <linux/input.h> | ||
43 | 42 | | |||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
106 | 105 | | |||
107 | void TestPointerConstraints::cleanup() | 106 | void TestPointerConstraints::cleanup() | ||
108 | { | 107 | { | ||
109 | Test::destroyWaylandConnection(); | 108 | Test::destroyWaylandConnection(); | ||
110 | } | 109 | } | ||
111 | 110 | | |||
112 | void TestPointerConstraints::testConfinedPointer_data() | 111 | void TestPointerConstraints::testConfinedPointer_data() | ||
113 | { | 112 | { | ||
114 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 113 | QTest::addColumn<Test::XdgShellSurfaceType>("type"); | ||
115 | QTest::addColumn<PointerFunc>("positionFunction"); | 114 | QTest::addColumn<PointerFunc>("positionFunction"); | ||
116 | QTest::addColumn<int>("xOffset"); | 115 | QTest::addColumn<int>("xOffset"); | ||
117 | QTest::addColumn<int>("yOffset"); | 116 | QTest::addColumn<int>("yOffset"); | ||
118 | PointerFunc bottomLeft = &QRect::bottomLeft; | 117 | PointerFunc bottomLeft = &QRect::bottomLeft; | ||
119 | PointerFunc bottomRight = &QRect::bottomRight; | 118 | PointerFunc bottomRight = &QRect::bottomRight; | ||
120 | PointerFunc topRight = &QRect::topRight; | 119 | PointerFunc topRight = &QRect::topRight; | ||
121 | PointerFunc topLeft = &QRect::topLeft; | 120 | PointerFunc topLeft = &QRect::topLeft; | ||
122 | 121 | | |||
123 | QTest::newRow("wlShell - bottomLeft") << Test::ShellSurfaceType::WlShell << bottomLeft << -1 << 1; | 122 | QTest::newRow("XdgShellV5 - bottomLeft") << Test::XdgShellSurfaceType::XdgShellV5 << bottomLeft << -1 << 1; | ||
124 | QTest::newRow("wlShell - bottomRight") << Test::ShellSurfaceType::WlShell << bottomRight << 1 << 1; | 123 | QTest::newRow("XdgShellV5 - bottomRight") << Test::XdgShellSurfaceType::XdgShellV5 << bottomRight << 1 << 1; | ||
125 | QTest::newRow("wlShell - topLeft") << Test::ShellSurfaceType::WlShell << topLeft << -1 << -1; | 124 | QTest::newRow("XdgShellV5 - topLeft") << Test::XdgShellSurfaceType::XdgShellV5 << topLeft << -1 << -1; | ||
126 | QTest::newRow("wlShell - topRight") << Test::ShellSurfaceType::WlShell << topRight << 1 << -1; | 125 | QTest::newRow("XdgShellV5 - topRight") << Test::XdgShellSurfaceType::XdgShellV5 << topRight << 1 << -1; | ||
127 | QTest::newRow("XdgShellV5 - bottomLeft") << Test::ShellSurfaceType::XdgShellV5 << bottomLeft << -1 << 1; | 126 | QTest::newRow("XdgShellV6 - bottomLeft") << Test::XdgShellSurfaceType::XdgShellV6 << bottomLeft << -1 << 1; | ||
128 | QTest::newRow("XdgShellV5 - bottomRight") << Test::ShellSurfaceType::XdgShellV5 << bottomRight << 1 << 1; | 127 | QTest::newRow("XdgShellV6 - bottomRight") << Test::XdgShellSurfaceType::XdgShellV6 << bottomRight << 1 << 1; | ||
129 | QTest::newRow("XdgShellV5 - topLeft") << Test::ShellSurfaceType::XdgShellV5 << topLeft << -1 << -1; | 128 | QTest::newRow("XdgShellV6 - topLeft") << Test::XdgShellSurfaceType::XdgShellV6 << topLeft << -1 << -1; | ||
130 | QTest::newRow("XdgShellV5 - topRight") << Test::ShellSurfaceType::XdgShellV5 << topRight << 1 << -1; | 129 | QTest::newRow("XdgShellV6 - topRight") << Test::XdgShellSurfaceType::XdgShellV6 << topRight << 1 << -1; | ||
131 | QTest::newRow("XdgShellV6 - bottomLeft") << Test::ShellSurfaceType::XdgShellV6 << bottomLeft << -1 << 1; | 130 | QTest::newRow("XdgWmBase - bottomLeft") << Test::XdgShellSurfaceType::XdgShellStable << bottomLeft << -1 << 1; | ||
132 | QTest::newRow("XdgShellV6 - bottomRight") << Test::ShellSurfaceType::XdgShellV6 << bottomRight << 1 << 1; | 131 | QTest::newRow("XdgWmBase - bottomRight") << Test::XdgShellSurfaceType::XdgShellStable << bottomRight << 1 << 1; | ||
133 | QTest::newRow("XdgShellV6 - topLeft") << Test::ShellSurfaceType::XdgShellV6 << topLeft << -1 << -1; | 132 | QTest::newRow("XdgWmBase - topLeft") << Test::XdgShellSurfaceType::XdgShellStable << topLeft << -1 << -1; | ||
134 | QTest::newRow("XdgShellV6 - topRight") << Test::ShellSurfaceType::XdgShellV6 << topRight << 1 << -1; | 133 | QTest::newRow("XdgWmBase - topRight") << Test::XdgShellSurfaceType::XdgShellStable << topRight << 1 << -1; | ||
135 | QTest::newRow("XdgWmBase - bottomLeft") << Test::ShellSurfaceType::XdgShellStable << bottomLeft << -1 << 1; | | |||
136 | QTest::newRow("XdgWmBase - bottomRight") << Test::ShellSurfaceType::XdgShellStable << bottomRight << 1 << 1; | | |||
137 | QTest::newRow("XdgWmBase - topLeft") << Test::ShellSurfaceType::XdgShellStable << topLeft << -1 << -1; | | |||
138 | QTest::newRow("XdgWmBase - topRight") << Test::ShellSurfaceType::XdgShellStable << topRight << 1 << -1; | | |||
139 | } | 134 | } | ||
140 | 135 | | |||
141 | void TestPointerConstraints::testConfinedPointer() | 136 | void TestPointerConstraints::testConfinedPointer() | ||
142 | { | 137 | { | ||
143 | // this test sets up a Surface with a confined pointer | 138 | // this test sets up a Surface with a confined pointer | ||
144 | // simple interaction test to verify that the pointer gets confined | 139 | // simple interaction test to verify that the pointer gets confined | ||
145 | QScopedPointer<Surface> surface(Test::createSurface()); | 140 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
146 | QFETCH(Test::ShellSurfaceType, type); | 141 | QFETCH(Test::XdgShellSurfaceType, type); | ||
147 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | 142 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data())); | ||
148 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | 143 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | ||
149 | QScopedPointer<ConfinedPointer> confinedPointer(Test::waylandPointerConstraints()->confinePointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | 144 | QScopedPointer<ConfinedPointer> confinedPointer(Test::waylandPointerConstraints()->confinePointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | ||
150 | QSignalSpy confinedSpy(confinedPointer.data(), &ConfinedPointer::confined); | 145 | QSignalSpy confinedSpy(confinedPointer.data(), &ConfinedPointer::confined); | ||
151 | QVERIFY(confinedSpy.isValid()); | 146 | QVERIFY(confinedSpy.isValid()); | ||
152 | QSignalSpy unconfinedSpy(confinedPointer.data(), &ConfinedPointer::unconfined); | 147 | QSignalSpy unconfinedSpy(confinedPointer.data(), &ConfinedPointer::unconfined); | ||
153 | QVERIFY(unconfinedSpy.isValid()); | 148 | QVERIFY(unconfinedSpy.isValid()); | ||
154 | 149 | | |||
155 | // now map the window | 150 | // now map the window | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
246 | QCOMPARE(input()->pointer()->isConstrained(), false); | 241 | QCOMPARE(input()->pointer()->isConstrained(), false); | ||
247 | // activate it again, this confines again | 242 | // activate it again, this confines again | ||
248 | workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data())); | 243 | workspace()->activateClient(static_cast<AbstractClient*>(input()->pointer()->focus().data())); | ||
249 | QVERIFY(confinedSpy2.wait()); | 244 | QVERIFY(confinedSpy2.wait()); | ||
250 | QCOMPARE(input()->pointer()->isConstrained(), true); | 245 | QCOMPARE(input()->pointer()->isConstrained(), true); | ||
251 | 246 | | |||
252 | // create a second window and move it above our constrained window | 247 | // create a second window and move it above our constrained window | ||
253 | QScopedPointer<Surface> surface2(Test::createSurface()); | 248 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
254 | QScopedPointer<QObject> shellSurface2(Test::createShellSurface(type, surface2.data())); | 249 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellSurface(type, surface2.data())); | ||
255 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(1280, 1024), Qt::blue); | 250 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(1280, 1024), Qt::blue); | ||
256 | QVERIFY(c2); | 251 | QVERIFY(c2); | ||
257 | QVERIFY(unconfinedSpy2.wait()); | 252 | QVERIFY(unconfinedSpy2.wait()); | ||
258 | // and unmapping the second window should confine again | 253 | // and unmapping the second window should confine again | ||
259 | shellSurface2.reset(); | 254 | shellSurface2.reset(); | ||
260 | surface2.reset(); | 255 | surface2.reset(); | ||
261 | QVERIFY(confinedSpy2.wait()); | 256 | QVERIFY(confinedSpy2.wait()); | ||
262 | 257 | | |||
Show All 31 Lines | |||||
294 | shellSurface.reset(); | 289 | shellSurface.reset(); | ||
295 | surface.reset(); | 290 | surface.reset(); | ||
296 | QVERIFY(Test::waitForWindowDestroyed(c)); | 291 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||
297 | QCOMPARE(input()->pointer()->isConstrained(), false); | 292 | QCOMPARE(input()->pointer()->isConstrained(), false); | ||
298 | } | 293 | } | ||
299 | 294 | | |||
300 | void TestPointerConstraints::testLockedPointer_data() | 295 | void TestPointerConstraints::testLockedPointer_data() | ||
301 | { | 296 | { | ||
302 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 297 | QTest::addColumn<Test::XdgShellSurfaceType>("type"); | ||
303 | 298 | | |||
304 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | 299 | QTest::newRow("xdgShellV5") << Test::XdgShellSurfaceType::XdgShellV5; | ||
305 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | 300 | QTest::newRow("xdgShellV6") << Test::XdgShellSurfaceType::XdgShellV6; | ||
306 | QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; | 301 | QTest::newRow("xdgWmBase") << Test::XdgShellSurfaceType::XdgShellStable; | ||
307 | QTest::newRow("xdgWmBase") << Test::ShellSurfaceType::XdgShellStable; | | |||
308 | } | 302 | } | ||
309 | 303 | | |||
310 | void TestPointerConstraints::testLockedPointer() | 304 | void TestPointerConstraints::testLockedPointer() | ||
311 | { | 305 | { | ||
312 | // this test sets up a Surface with a locked pointer | 306 | // this test sets up a Surface with a locked pointer | ||
313 | // simple interaction test to verify that the pointer gets locked | 307 | // simple interaction test to verify that the pointer gets locked | ||
314 | // the various ways to unlock are not tested as that's already verified by testConfinedPointer | 308 | // the various ways to unlock are not tested as that's already verified by testConfinedPointer | ||
315 | QScopedPointer<Surface> surface(Test::createSurface()); | 309 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
316 | QFETCH(Test::ShellSurfaceType, type); | 310 | QFETCH(Test::XdgShellSurfaceType, type); | ||
317 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | 311 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data())); | ||
318 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | 312 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | ||
319 | QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | 313 | QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | ||
320 | QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked); | 314 | QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked); | ||
321 | QVERIFY(lockedSpy.isValid()); | 315 | QVERIFY(lockedSpy.isValid()); | ||
322 | QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked); | 316 | QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked); | ||
323 | QVERIFY(unlockedSpy.isValid()); | 317 | QVERIFY(unlockedSpy.isValid()); | ||
324 | 318 | | |||
325 | // now map the window | 319 | // now map the window | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
373 | // moving cursor should be allowed again | 367 | // moving cursor should be allowed again | ||
374 | QCOMPARE(input()->pointer()->isConstrained(), false); | 368 | QCOMPARE(input()->pointer()->isConstrained(), false); | ||
375 | KWin::Cursor::setPos(c->geometry().center()); | 369 | KWin::Cursor::setPos(c->geometry().center()); | ||
376 | QCOMPARE(KWin::Cursor::pos(), c->geometry().center()); | 370 | QCOMPARE(KWin::Cursor::pos(), c->geometry().center()); | ||
377 | } | 371 | } | ||
378 | 372 | | |||
379 | void TestPointerConstraints::testCloseWindowWithLockedPointer_data() | 373 | void TestPointerConstraints::testCloseWindowWithLockedPointer_data() | ||
380 | { | 374 | { | ||
381 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 375 | QTest::addColumn<Test::XdgShellSurfaceType>("type"); | ||
382 | 376 | | |||
383 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | 377 | QTest::newRow("XdgShellV5") << Test::XdgShellSurfaceType::XdgShellV5; | ||
384 | QTest::newRow("XdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | 378 | QTest::newRow("XdgShellV6") << Test::XdgShellSurfaceType::XdgShellV6; | ||
385 | QTest::newRow("XdgShellV6") << Test::ShellSurfaceType::XdgShellV6; | 379 | QTest::newRow("XdgWmBase") << Test::XdgShellSurfaceType::XdgShellStable; | ||
386 | QTest::newRow("XdgWmBase") << Test::ShellSurfaceType::XdgShellStable; | | |||
387 | } | 380 | } | ||
388 | 381 | | |||
389 | void TestPointerConstraints::testCloseWindowWithLockedPointer() | 382 | void TestPointerConstraints::testCloseWindowWithLockedPointer() | ||
390 | { | 383 | { | ||
391 | // test case which verifies that the pointer gets unlocked when the window for it gets closed | 384 | // test case which verifies that the pointer gets unlocked when the window for it gets closed | ||
392 | QScopedPointer<Surface> surface(Test::createSurface()); | 385 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
393 | QFETCH(Test::ShellSurfaceType, type); | 386 | QFETCH(Test::XdgShellSurfaceType, type); | ||
394 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | 387 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellSurface(type, surface.data())); | ||
395 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | 388 | QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer()); | ||
396 | QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | 389 | QScopedPointer<LockedPointer> lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); | ||
397 | QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked); | 390 | QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked); | ||
398 | QVERIFY(lockedSpy.isValid()); | 391 | QVERIFY(lockedSpy.isValid()); | ||
399 | QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked); | 392 | QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked); | ||
400 | QVERIFY(unlockedSpy.isValid()); | 393 | QVERIFY(unlockedSpy.isValid()); | ||
401 | 394 | | |||
402 | // now map the window | 395 | // now map the window | ||
Show All 21 Lines |