13#include "virtualdesktops.h"
18#include <KWayland/Client/compositor.h>
19#include <KWayland/Client/connection_thread.h>
20#include <KWayland/Client/event_queue.h>
21#include <KWayland/Client/plasmashell.h>
22#include <KWayland/Client/registry.h>
23#include <KWayland/Client/shm_pool.h>
24#include <KWayland/Client/surface.h>
30static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_plasma_surface-0");
40 void testRoleOnAllDesktops_data();
41 void testRoleOnAllDesktops();
42 void testAcceptsFocus_data();
43 void testAcceptsFocus();
44 void testOSDPlacement();
45 void testOSDPlacementManualPosition();
46 void testPanelActivate_data();
47 void testPanelActivate();
48 void testMovable_data();
52 KWayland::Client::Compositor *m_compositor =
nullptr;
53 KWayland::Client::PlasmaShell *m_plasmaShell =
nullptr;
56void PlasmaSurfaceTest::initTestCase()
58 qRegisterMetaType<KWin::Window *>();
64 QVERIFY(applicationStartedSpy.wait());
67void PlasmaSurfaceTest::init()
76void PlasmaSurfaceTest::cleanup()
81void PlasmaSurfaceTest::testRoleOnAllDesktops_data()
83 QTest::addColumn<KWayland::Client::PlasmaShellSurface::Role>(
"role");
84 QTest::addColumn<bool>(
"expectedOnAllDesktops");
86 QTest::newRow(
"Desktop") << KWayland::Client::PlasmaShellSurface::Role::Desktop <<
true;
87 QTest::newRow(
"Panel") << KWayland::Client::PlasmaShellSurface::Role::Panel <<
true;
88 QTest::newRow(
"OSD") << KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay <<
true;
89 QTest::newRow(
"Normal") << KWayland::Client::PlasmaShellSurface::Role::Normal <<
false;
90 QTest::newRow(
"Notification") << KWayland::Client::PlasmaShellSurface::Role::Notification <<
true;
91 QTest::newRow(
"ToolTip") << KWayland::Client::PlasmaShellSurface::Role::ToolTip <<
true;
92 QTest::newRow(
"CriticalNotification") << KWayland::Client::PlasmaShellSurface::Role::CriticalNotification <<
true;
93 QTest::newRow(
"AppletPopup") << KWayland::Client::PlasmaShellSurface::Role::AppletPopup <<
true;
96void PlasmaSurfaceTest::testRoleOnAllDesktops()
100 QVERIFY(surface !=
nullptr);
102 QVERIFY(shellSurface !=
nullptr);
103 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.get()));
104 QVERIFY(plasmaSurface !=
nullptr);
109 QCOMPARE(
workspace()->activeWindow(), window);
112 QCOMPARE(window->isOnAllDesktops(),
false);
115 QSignalSpy onAllDesktopsSpy(window, &Window::desktopsChanged);
116 QFETCH(KWayland::Client::PlasmaShellSurface::Role, role);
117 plasmaSurface->setRole(role);
118 QFETCH(
bool, expectedOnAllDesktops);
119 QCOMPARE(onAllDesktopsSpy.wait(), expectedOnAllDesktops);
120 QCOMPARE(window->isOnAllDesktops(), expectedOnAllDesktops);
125 QVERIFY(surface2 !=
nullptr);
126 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface2(m_plasmaShell->createSurface(surface2.get()));
127 QVERIFY(plasmaSurface2 !=
nullptr);
128 plasmaSurface2->setRole(role);
130 QVERIFY(shellSurface2 !=
nullptr);
133 QVERIFY(window != c2);
135 QCOMPARE(c2->isOnAllDesktops(), expectedOnAllDesktops);
138void PlasmaSurfaceTest::testAcceptsFocus_data()
140 QTest::addColumn<KWayland::Client::PlasmaShellSurface::Role>(
"role");
141 QTest::addColumn<bool>(
"wantsInput");
142 QTest::addColumn<bool>(
"active");
144 QTest::newRow(
"Desktop") << KWayland::Client::PlasmaShellSurface::Role::Desktop <<
true <<
true;
145 QTest::newRow(
"Panel") << KWayland::Client::PlasmaShellSurface::Role::Panel <<
true <<
false;
146 QTest::newRow(
"OSD") << KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay <<
false <<
false;
147 QTest::newRow(
"Normal") << KWayland::Client::PlasmaShellSurface::Role::Normal <<
true <<
true;
148 QTest::newRow(
"Notification") << KWayland::Client::PlasmaShellSurface::Role::Notification <<
false <<
false;
149 QTest::newRow(
"ToolTip") << KWayland::Client::PlasmaShellSurface::Role::ToolTip <<
false <<
false;
150 QTest::newRow(
"CriticalNotification") << KWayland::Client::PlasmaShellSurface::Role::CriticalNotification <<
false <<
false;
151 QTest::newRow(
"AppletPopup") << KWayland::Client::PlasmaShellSurface::Role::AppletPopup <<
true <<
true;
154void PlasmaSurfaceTest::testAcceptsFocus()
158 QVERIFY(surface !=
nullptr);
160 QVERIFY(shellSurface !=
nullptr);
161 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.get()));
162 QVERIFY(plasmaSurface !=
nullptr);
163 QFETCH(KWayland::Client::PlasmaShellSurface::Role, role);
164 plasmaSurface->setRole(role);
170 QTEST(window->wantsInput(),
"wantsInput");
171 QTEST(window->isActive(),
"active");
174void PlasmaSurfaceTest::testOSDPlacement()
177 QVERIFY(surface !=
nullptr);
179 QVERIFY(shellSurface !=
nullptr);
180 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.get()));
181 QVERIFY(plasmaSurface !=
nullptr);
182 plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay);
188 QCOMPARE(window->windowType(), NET::OnScreenDisplay);
189 QVERIFY(window->isOnScreenDisplay());
190 QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 100 / 2, 2 * 1024 / 3 - 50 / 2, 100, 50));
193 const QList<QRect> geometries{QRect(0, 0, 1280, 1024), QRect(1280, 0, 1280, 1024)};
197 QCOMPARE(outputs[0]->geometry(), geometries[0]);
198 QCOMPARE(outputs[1]->geometry(), geometries[1]);
200 QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 100 / 2, 2 * 1024 / 3 - 50 / 2, 100, 50));
203 QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
205 QVERIFY(frameGeometryChangedSpy.wait());
206 QCOMPARE(window->frameGeometry(), QRect(1280 / 2 - 200 / 2, 2 * 1024 / 3 - 100 / 2, 200, 100));
209void PlasmaSurfaceTest::testOSDPlacementManualPosition()
212 QVERIFY(surface !=
nullptr);
213 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.get()));
214 QVERIFY(plasmaSurface !=
nullptr);
215 plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay);
217 plasmaSurface->setPosition(QPoint(50, 70));
220 QVERIFY(shellSurface !=
nullptr);
226 QVERIFY(!window->isPlaceable());
227 QCOMPARE(window->windowType(), NET::OnScreenDisplay);
228 QVERIFY(window->isOnScreenDisplay());
229 QCOMPARE(window->frameGeometry(), QRect(50, 70, 100, 50));
232void PlasmaSurfaceTest::testPanelActivate_data()
234 QTest::addColumn<bool>(
"wantsFocus");
235 QTest::addColumn<bool>(
"active");
237 QTest::newRow(
"no focus") <<
false <<
false;
238 QTest::newRow(
"focus") <<
true <<
true;
241void PlasmaSurfaceTest::testPanelActivate()
244 QVERIFY(surface !=
nullptr);
246 QVERIFY(shellSurface !=
nullptr);
247 std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.get()));
248 QVERIFY(plasmaSurface !=
nullptr);
249 plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
250 QFETCH(
bool, wantsFocus);
251 plasmaSurface->setPanelTakesFocus(wantsFocus);
256 QCOMPARE(panel->windowType(), NET::Dock);
257 QVERIFY(panel->isDock());
258 QFETCH(
bool, active);
259 QCOMPARE(panel->dockWantsInput(), active);
260 QCOMPARE(panel->isActive(), active);
263void PlasmaSurfaceTest::testMovable_data()
265 QTest::addColumn<KWayland::Client::PlasmaShellSurface::Role>(
"role");
266 QTest::addColumn<bool>(
"movable");
267 QTest::addColumn<bool>(
"movableAcrossScreens");
268 QTest::addColumn<bool>(
"resizable");
270 QTest::newRow(
"normal") << KWayland::Client::PlasmaShellSurface::Role::Normal <<
true <<
true <<
true;
271 QTest::newRow(
"desktop") << KWayland::Client::PlasmaShellSurface::Role::Desktop <<
false <<
false <<
false;
272 QTest::newRow(
"panel") << KWayland::Client::PlasmaShellSurface::Role::Panel <<
false <<
false <<
false;
273 QTest::newRow(
"osd") << KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay <<
false <<
false <<
false;
276void PlasmaSurfaceTest::testMovable()
280 QVERIFY(surface !=
nullptr);
283 QVERIFY(shellSurface !=
nullptr);
286 QVERIFY(plasmaSurface !=
nullptr);
287 QFETCH(KWayland::Client::PlasmaShellSurface::Role, role);
288 plasmaSurface->setRole(role);
293 QTEST(window->isMovable(),
"movable");
294 QTEST(window->isMovableAcrossScreens(),
"movableAcrossScreens");
295 QTEST(window->isResizable(),
"resizable");
301#include "plasma_surface_test.moc"
QList< Output * > outputs() const
#define WAYLANDTEST_MAIN(TestObject)
Window * renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32, int timeout=5000)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
KWayland::Client::Compositor * waylandCompositor()
void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32_Premultiplied)
QList< KWayland::Client::Output * > outputs
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
KWayland::Client::PlasmaShell * waylandPlasmaShell()
bool waitForWindowClosed(Window *window)
WaylandServer * waylandServer()
InputRedirection * input()