18#include <KWayland/Client/compositor.h>
19#include <KWayland/Client/plasmawindowmanagement.h>
20#include <KWayland/Client/surface.h>
22#if KWIN_BUILD_SCREENLOCKER
23#include <KScreenLocker/KsldApp>
27#include <QRasterWindow>
30#include <xcb/xcb_icccm.h>
35static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_plasma-window-0");
44 void testCreateDestroyX11PlasmaWindow();
45 void testInternalWindowNoPlasmaWindow();
46 void testPopupWindowNoPlasmaWindow();
47 void testLockScreenNoPlasmaWindow();
48 void testDestroyedButNotUnmapped();
51 KWayland::Client::PlasmaWindowManagement *m_windowManagement =
nullptr;
52 KWayland::Client::Compositor *m_compositor =
nullptr;
55void PlasmaWindowTest::initTestCase()
57 qRegisterMetaType<KWin::Window *>();
61 QRect(0, 0, 1280, 1024),
62 QRect(1280, 0, 1280, 1024),
66 QVERIFY(applicationStartedSpy.wait());
68 QCOMPARE(outputs.count(), 2);
69 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
70 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
71 setenv(
"QT_QPA_PLATFORM",
"wayland",
true);
72 setenv(
"QMLSCENE_DEVICE",
"softwarecontext",
true);
75void PlasmaWindowTest::init()
85void PlasmaWindowTest::cleanup()
90void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow()
93 QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
97 QVERIFY(!xcb_connection_has_error(c.get()));
98 const QRect windowGeometry(0, 0, 100, 200);
99 xcb_window_t windowId = xcb_generate_id(c.get());
100 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId,
rootWindow(),
103 windowGeometry.width(),
104 windowGeometry.height(),
105 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0,
nullptr);
106 xcb_size_hints_t hints;
107 memset(&hints, 0,
sizeof(hints));
108 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
109 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
110 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
111 xcb_map_window(c.get(), windowId);
116 QVERIFY(windowCreatedSpy.wait());
117 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
119 QCOMPARE(window->window(), windowId);
120 QVERIFY(window->isDecorated());
121 QVERIFY(window->isActive());
123 if (!window->surface()) {
131 QVERIFY(plasmaWindowCreatedSpy.wait());
132 QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
133 QCOMPARE(m_windowManagement->windows().count(), 1);
134 auto pw = m_windowManagement->windows().first();
135 QCOMPARE(pw->geometry(), window->frameGeometry());
136 QSignalSpy geometryChangedSpy(pw, &KWayland::Client::PlasmaWindow::geometryChanged);
138 QSignalSpy unmappedSpy(m_windowManagement->windows().first(), &KWayland::Client::PlasmaWindow::unmapped);
139 QSignalSpy destroyedSpy(m_windowManagement->windows().first(), &QObject::destroyed);
142 const QRectF geoBeforeShade = window->frameGeometry();
143 QVERIFY(geoBeforeShade.isValid());
144 QVERIFY(!geoBeforeShade.isEmpty());
146 QVERIFY(window->isShade());
147 QVERIFY(window->frameGeometry() != geoBeforeShade);
148 QVERIFY(geometryChangedSpy.wait());
149 QCOMPARE(pw->geometry(), window->frameGeometry());
152 QVERIFY(!window->isShade());
153 QCOMPARE(window->frameGeometry(), geoBeforeShade);
154 QVERIFY(geometryChangedSpy.wait());
155 QCOMPARE(pw->geometry(), geoBeforeShade);
158 xcb_unmap_window(c.get(), windowId);
162 QVERIFY(windowClosedSpy.wait());
163 xcb_destroy_window(c.get(), windowId);
166 QVERIFY(unmappedSpy.wait());
167 QCOMPARE(unmappedSpy.count(), 1);
169 QVERIFY(destroyedSpy.wait());
172class HelperWindow :
public QRasterWindow
184 : QRasterWindow(nullptr)
193 p.fillRect(0, 0, width(), height(), Qt::red);
196void PlasmaWindowTest::testInternalWindowNoPlasmaWindow()
199 QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
201 win.setGeometry(0, 0, 100, 100);
204 QVERIFY(!plasmaWindowCreatedSpy.wait(100));
207void PlasmaWindowTest::testPopupWindowNoPlasmaWindow()
210 QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
216 QVERIFY(parentClient);
217 QVERIFY(plasmaWindowCreatedSpy.wait());
218 QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
222 positioner->set_size(10, 10);
223 positioner->set_anchor_rect(0, 0, 10, 10);
224 positioner->set_anchor(Test::XdgPositioner::anchor_bottom_right);
225 positioner->set_gravity(Test::XdgPositioner::gravity_bottom_right);
227 std::unique_ptr<Test::XdgPopup> popupShellSurface(
Test::createXdgPopupSurface(popupSurface.get(), parentShellSurface->xdgSurface(), positioner.get()));
229 QVERIFY(popupWindow);
230 QVERIFY(!plasmaWindowCreatedSpy.wait(100));
231 QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
234 popupShellSurface.reset();
236 parentShellSurface.reset();
240void PlasmaWindowTest::testLockScreenNoPlasmaWindow()
242#if KWIN_BUILD_SCREENLOCKER
244 QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
249 ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
250 QVERIFY(windowAddedSpy.wait());
251 QVERIFY(windowAddedSpy.first().first().value<
Window *>()->isLockScreen());
253 QVERIFY(plasmaWindowCreatedSpy.isEmpty());
254 QVERIFY(!plasmaWindowCreatedSpy.wait(100));
257 QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged);
258 const auto children = ScreenLocker::KSldApp::self()->children();
259 for (
auto it = children.begin(); it != children.end(); ++it) {
260 if (qstrcmp((*it)->metaObject()->className(),
"LogindIntegration") != 0) {
263 QMetaObject::invokeMethod(*it,
"requestUnlock");
266 QVERIFY(lockStateChangedSpy.wait());
269 QSKIP(
"KWin was built without lockscreen support");
273void PlasmaWindowTest::testDestroyedButNotUnmapped()
277 QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated);
283 Test::render(parentSurface.get(), QSize(100, 50), Qt::blue);
285 QVERIFY(plasmaWindowCreatedSpy.wait());
286 QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
287 auto window = plasmaWindowCreatedSpy.first().first().value<KWayland::Client::PlasmaWindow *>();
289 QSignalSpy destroyedSpy(window, &QObject::destroyed);
292 parentShellSurface.reset();
293 parentSurface.reset();
294 QVERIFY(destroyedSpy.wait());
300#include "plasmawindow_test.moc"
void paintEvent(QPaintEvent *event) override
~HelperWindow() override=default
bool event(QEvent *event) override
void windowAdded(KWin::Window *)
QList< Output * > outputs() const
void setActiveOutput(Output *output)
#define WAYLANDTEST_MAIN(TestObject)
XdgPositioner * createXdgPositioner()
Window * renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32, int timeout=5000)
XdgPopup * createXdgPopupSurface(KWayland::Client::Surface *surface, XdgSurface *parentSurface, XdgPositioner *positioner, CreationSetup configureMode=CreationSetup::CreateAndConfigure, QObject *parent=nullptr)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
KWayland::Client::Seat * seat
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
KWayland::Client::PlasmaWindowManagement * waylandWindowManagement()
KWayland::Client::Compositor * waylandCompositor()
void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32_Premultiplied)
bool waitForWaylandSurface(Window *window)
XcbConnectionPtr createX11Connection()
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
std::unique_ptr< xcb_connection_t, XcbConnectionDeleter > XcbConnectionPtr
bool waitForWindowClosed(Window *window)
KWIN_EXPORT xcb_window_t rootWindow()
WaylandServer * waylandServer()
InputRedirection * input()