11#include "compositor.h"
15#include "virtualdesktops.h"
20#include <KConfigGroup>
23#include <xcb/xcb_icccm.h>
26static const QString s_socketName = QStringLiteral(
"wayland_test_effects_translucency-0");
36 void testMoveAfterDesktopChange();
37 void testDialogClose();
40 Effect *m_translucencyEffect =
nullptr;
43void TranslucencyTest::initTestCase()
45 qputenv(
"XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
46 qRegisterMetaType<KWin::Window *>();
47 qRegisterMetaType<KWin::Effect *>();
51 QRect(0, 0, 1280, 1024),
52 QRect(1280, 0, 1280, 1024),
56 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
57 KConfigGroup plugins(config, QStringLiteral(
"Plugins"));
59 for (QString name : builtinNames) {
60 plugins.writeEntry(name + QStringLiteral(
"Enabled"),
false);
62 config->group(QStringLiteral(
"Outline")).writeEntry(QStringLiteral(
"QmlPath"), QString(
"/does/not/exist.qml"));
63 config->group(QStringLiteral(
"Effect-translucency")).writeEntry(QStringLiteral(
"Dialogs"), 90);
66 kwinApp()->setConfig(config);
68 qputenv(
"KWIN_EFFECTS_FORCE_ANIMATIONS",
"1");
70 QVERIFY(applicationStartedSpy.wait());
74void TranslucencyTest::init()
78 QVERIFY(effectloader);
85 QCOMPARE(effectLoadedSpy.count(), 1);
86 m_translucencyEffect = effectLoadedSpy.first().first().value<
Effect *>();
87 QVERIFY(m_translucencyEffect);
90void TranslucencyTest::cleanup()
96 m_translucencyEffect =
nullptr;
99void TranslucencyTest::testMoveAfterDesktopChange()
102 QVERIFY(!m_translucencyEffect->
isActive());
108 QVERIFY(!xcb_connection_has_error(c.get()));
109 const QRect windowGeometry(0, 0, 100, 200);
110 xcb_window_t windowId = xcb_generate_id(c.get());
111 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId,
rootWindow(),
114 windowGeometry.width(),
115 windowGeometry.height(),
116 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0,
nullptr);
117 xcb_size_hints_t hints;
118 memset(&hints, 0,
sizeof(hints));
119 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
120 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
121 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
122 xcb_map_window(c.get(), windowId);
127 QVERIFY(windowCreatedSpy.wait());
130 QCOMPARE(window->
window(), windowId);
133 QCOMPARE(windowAddedSpy.count(), 1);
134 QVERIFY(!m_translucencyEffect->
isActive());
138 const QList<VirtualDesktop *> desktops = vds->
desktops();
141 QVERIFY(!m_translucencyEffect->
isActive());
144 QVERIFY(m_translucencyEffect->
isActive());
146 QVERIFY(m_translucencyEffect->
isActive());
149 QVERIFY(m_translucencyEffect->
isActive());
151 QTRY_VERIFY(!m_translucencyEffect->
isActive());
154 xcb_unmap_window(c.get(), windowId);
157 QSignalSpy windowClosedSpy(window, &X11Window::closed);
158 QVERIFY(windowClosedSpy.wait());
159 xcb_destroy_window(c.get(), windowId);
163void TranslucencyTest::testDialogClose()
167 QVERIFY(!m_translucencyEffect->
isActive());
172 QVERIFY(!xcb_connection_has_error(c.get()));
173 const QRect windowGeometry(0, 0, 100, 200);
174 xcb_window_t windowId = xcb_generate_id(c.get());
175 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId,
rootWindow(),
178 windowGeometry.width(),
179 windowGeometry.height(),
180 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0,
nullptr);
181 xcb_size_hints_t hints;
182 memset(&hints, 0,
sizeof(hints));
183 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
184 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
185 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
186 NETWinInfo winInfo(c.get(), windowId,
rootWindow(), NET::Properties(), NET::Properties2());
187 winInfo.setWindowType(NET::Dialog);
188 xcb_map_window(c.get(), windowId);
193 QVERIFY(windowCreatedSpy.wait());
196 QCOMPARE(window->
window(), windowId);
200 QCOMPARE(windowAddedSpy.count(), 1);
201 QTRY_VERIFY(m_translucencyEffect->
isActive());
203 xcb_unmap_window(c.get(), windowId);
206 QSignalSpy windowClosedSpy(window, &X11Window::closed);
209 QVERIFY(windowClosedSpy.wait());
210 if (windowDeletedSpy.isEmpty()) {
211 QVERIFY(windowDeletedSpy.wait());
213 QCOMPARE(windowDeletedSpy.count(), 1);
214 QTRY_VERIFY(!m_translucencyEffect->
isActive());
215 xcb_destroy_window(c.get(), windowId);
220#include "translucency_test.moc"
Interface to describe how an effect loader has to function.
void effectLoaded(KWin::Effect *effect, const QString &name)
The loader emits this signal when it successfully loaded an effect.
static Compositor * self()
Base class for all KWin effects.
QStringList listOfKnownEffects() const override
All the Effects this loader knows of.
Q_SCRIPTABLE void unloadEffect(const QString &name)
void windowDeleted(KWin::EffectWindow *w)
Q_SCRIPTABLE bool loadEffect(const QString &name)
Q_SCRIPTABLE bool isEffectLoaded(const QString &name) const
void windowAdded(KWin::EffectWindow *w)
Manages the number of available virtual desktops, the layout of those and which virtual desktop is th...
QList< VirtualDesktop * > desktops() const
void setCount(uint count)
bool setCurrent(uint current)
void endInteractiveMoveResize()
void performWindowOperation(KWin::Window *window, Options::WindowOperation op)
void windowAdded(KWin::Window *)
void sendWindowToDesktops(Window *window, const QList< VirtualDesktop * > &desktops, bool dont_activate)
xcb_window_t window() const
virtual bool isActive() const
#define WAYLANDTEST_MAIN(TestObject)
void setOutputConfig(const QList< QRect > &geometries)
XcbConnectionPtr createX11Connection()
std::unique_ptr< xcb_connection_t, XcbConnectionDeleter > XcbConnectionPtr
KWIN_EXPORT xcb_window_t rootWindow()
WaylandServer * waylandServer()
InputRedirection * input()