11#include "virtualdesktops.h"
16#include <KWayland/Client/surface.h>
20static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_idle_inhbition_test-0");
31 void testDontInhibitWhenNotOnCurrentDesktop();
32 void testDontInhibitWhenMinimized();
33 void testDontInhibitWhenUnmapped();
34 void testDontInhibitWhenLeftCurrentDesktop();
37void TestIdleInhibition::initTestCase()
39 qRegisterMetaType<KWin::Window *>();
44 QRect(0, 0, 1280, 1024),
45 QRect(1280, 0, 1280, 1024),
49 QVERIFY(applicationStartedSpy.wait());
52void TestIdleInhibition::init()
57void TestIdleInhibition::cleanup()
61 VirtualDesktopManager::self()->setCount(1);
62 QCOMPARE(VirtualDesktopManager::self()->count(), 1u);
65void TestIdleInhibition::testInhibit()
68 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
83 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
88 QGuiApplication::processEvents();
89 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
94 QGuiApplication::processEvents();
95 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
99 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
102void TestIdleInhibition::testDontInhibitWhenNotOnCurrentDesktop()
107 VirtualDesktopManager::self()->setCount(2);
108 QCOMPARE(VirtualDesktopManager::self()->count(), 2u);
112 QVERIFY(surface !=
nullptr);
114 QVERIFY(shellSurface !=
nullptr);
125 QCOMPARE(window->desktops().count(), 1);
126 QCOMPARE(window->desktops().first(), VirtualDesktopManager::self()->desktops().first());
129 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
132 VirtualDesktopManager::self()->setCurrent(2);
136 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
139 VirtualDesktopManager::self()->setCurrent(1);
143 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
146 shellSurface.reset();
148 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
151void TestIdleInhibition::testDontInhibitWhenMinimized()
158 QVERIFY(surface !=
nullptr);
160 QVERIFY(shellSurface !=
nullptr);
171 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
174 window->setMinimized(
true);
175 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
178 window->setMinimized(
false);
179 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
182 shellSurface.reset();
184 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
187void TestIdleInhibition::testDontInhibitWhenUnmapped()
194 QVERIFY(surface !=
nullptr);
196 QVERIFY(shellSurface !=
nullptr);
206 QVERIFY(windowAddedSpy.isEmpty());
207 QVERIFY(windowAddedSpy.wait());
208 QCOMPARE(windowAddedSpy.count(), 1);
209 Window *window = windowAddedSpy.last().first().value<
Window *>();
211 QCOMPARE(window->readyForPainting(),
true);
214 QVERIFY(surfaceConfigureRequestedSpy.wait());
215 QCOMPARE(surfaceConfigureRequestedSpy.count(), 1);
218 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
221 surface->attachBuffer(KWayland::Client::Buffer::Ptr());
222 surface->commit(KWayland::Client::Surface::CommitFlag::None);
227 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
230 surface->commit(KWayland::Client::Surface::CommitFlag::None);
233 QVERIFY(surfaceConfigureRequestedSpy.wait());
234 QCOMPARE(surfaceConfigureRequestedSpy.count(), 2);
238 QVERIFY(windowAddedSpy.wait());
239 QCOMPARE(windowAddedSpy.count(), 2);
240 window = windowAddedSpy.last().first().value<
Window *>();
242 QCOMPARE(window->readyForPainting(),
true);
246 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
249 shellSurface.reset();
251 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
254void TestIdleInhibition::testDontInhibitWhenLeftCurrentDesktop()
259 VirtualDesktopManager::self()->setCount(2);
260 QCOMPARE(VirtualDesktopManager::self()->count(), 2u);
264 QVERIFY(surface !=
nullptr);
266 QVERIFY(shellSurface !=
nullptr);
277 QCOMPARE(window->desktops().count(), 1);
278 QCOMPARE(window->desktops().first(), VirtualDesktopManager::self()->desktops().first());
281 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
284 window->enterDesktop(VirtualDesktopManager::self()->desktops().at(1));
285 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
289 window->leaveDesktop(VirtualDesktopManager::self()->desktops().at(0));
290 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
294 window->enterDesktop(VirtualDesktopManager::self()->desktops().at(0));
295 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{window});
298 shellSurface.reset();
300 QCOMPARE(
input()->idleInhibitors(), QList<Window *>{});
304#include "idle_inhibition_test.moc"
void configureRequested(quint32 serial)
void windowAdded(KWin::Window *)
#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())
void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32_Premultiplied)
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
IdleInhibitorV1 * createIdleInhibitorV1(KWayland::Client::Surface *surface)
void flushWaylandConnection()
bool waitForWindowClosed(Window *window)
WaylandServer * waylandServer()
InputRedirection * input()