KWin
Loading...
Searching...
No Matches
wobbly_shade_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2018 Martin Flöser <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "cursor.h"
13#include "effect/effectloader.h"
14#include "wayland_server.h"
15#include "workspace.h"
16#include "x11window.h"
17
18#include <KConfigGroup>
19
20#include <KWayland/Client/connection_thread.h>
21#include <KWayland/Client/registry.h>
22#include <KWayland/Client/slide.h>
23#include <KWayland/Client/surface.h>
24
25#include <netwm.h>
26#include <xcb/xcb_icccm.h>
27
28using namespace KWin;
29static const QString s_socketName = QStringLiteral("wayland_test_effects_wobbly_shade-0");
30
31class WobblyWindowsShadeTest : public QObject
32{
33 Q_OBJECT
34private Q_SLOTS:
35 void initTestCase();
36 void init();
37 void cleanup();
38
39 void testShadeMove();
40};
41
42void WobblyWindowsShadeTest::initTestCase()
43{
45 QSKIP("no render node available");
46 return;
47 }
48 qRegisterMetaType<KWin::Window *>();
49 qRegisterMetaType<KWin::Effect *>();
50 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
51 QVERIFY(waylandServer()->init(s_socketName));
53 QRect(0, 0, 1280, 1024),
54 QRect(1280, 0, 1280, 1024),
55 });
56
57 // disable all effects - we don't want to have it interact with the rendering
58 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
59 KConfigGroup plugins(config, QStringLiteral("Plugins"));
60 const auto builtinNames = EffectLoader().listOfKnownEffects();
61 for (QString name : builtinNames) {
62 plugins.writeEntry(name + QStringLiteral("Enabled"), false);
63 }
64
65 config->sync();
66 kwinApp()->setConfig(config);
67
68 qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
69 qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", "1");
70 kwinApp()->start();
71 QVERIFY(applicationStartedSpy.wait());
72}
73
74void WobblyWindowsShadeTest::init()
75{
77}
78
79void WobblyWindowsShadeTest::cleanup()
80{
82
84 QVERIFY(effects->loadedEffects().isEmpty());
85}
86
87void WobblyWindowsShadeTest::testShadeMove()
88{
89 // this test simulates the condition from BUG 390953
90 QVERIFY(effects->loadEffect(QStringLiteral("wobblywindows")));
91 QVERIFY(effects->isEffectLoaded(QStringLiteral("wobblywindows")));
92
94 QVERIFY(!xcb_connection_has_error(c.get()));
95 const QRect windowGeometry(0, 0, 100, 200);
96 xcb_window_t windowId = xcb_generate_id(c.get());
97 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
98 windowGeometry.x(),
99 windowGeometry.y(),
100 windowGeometry.width(),
101 windowGeometry.height(),
102 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
103 xcb_size_hints_t hints;
104 memset(&hints, 0, sizeof(hints));
105 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
106 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
107 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
108 xcb_map_window(c.get(), windowId);
109 xcb_flush(c.get());
110
111 // we should get a window for it
112 QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
113 QVERIFY(windowCreatedSpy.wait());
114 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
115 QVERIFY(window);
116 QCOMPARE(window->window(), windowId);
117 QVERIFY(window->isDecorated());
118 QVERIFY(window->isShadeable());
119 QVERIFY(!window->isShade());
120 QVERIFY(window->isActive());
121
122 QSignalSpy readyForPaintingChangedSpy(window, &Window::readyForPaintingChanged);
123 QVERIFY(readyForPaintingChangedSpy.wait());
124
125 // now shade the window
127 QVERIFY(window->isShade());
128
129 QSignalSpy interactiveMoveResizeStartedSpy(window, &Window::interactiveMoveResizeStarted);
130
131 // begin move
132 QVERIFY(workspace()->moveResizeWindow() == nullptr);
133 QCOMPARE(window->isInteractiveMove(), false);
135 QCOMPARE(workspace()->moveResizeWindow(), window);
136 QCOMPARE(window->isInteractiveMove(), true);
137 QCOMPARE(interactiveMoveResizeStartedSpy.count(), 1);
138
139 // wait for frame rendered
140 QTest::qWait(100);
141
142 // send some key events, not going through input redirection
143 window->keyPressEvent(Qt::Key_Right);
144 window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
145
146 // wait for frame rendered
147 QTest::qWait(100);
148
149 window->keyPressEvent(Qt::Key_Right);
150 window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
151
152 // wait for frame rendered
153 QTest::qWait(100);
154
155 window->keyPressEvent(Qt::Key_Down | Qt::ALT);
156 window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
157
158 // wait for frame rendered
159 QTest::qWait(100);
160
161 // let's end
162 window->keyPressEvent(Qt::Key_Enter);
163
164 // wait for frame rendered
165 QTest::qWait(100);
166}
167
169#include "wobbly_shade_test.moc"
static Cursors * self()
Definition cursor.cpp:35
QStringList listOfKnownEffects() const override
All the Effects this loader knows of.
QStringList loadedEffects
Q_SCRIPTABLE bool loadEffect(const QString &name)
Q_SCRIPTABLE bool isEffectLoaded(const QString &name) const
bool isInteractiveMove() const
Definition window.h:1107
void updateInteractiveMoveResize(const QPointF &currentGlobalCursor)
Definition window.cpp:1378
bool isShade() const
Definition window.h:1034
bool isActive() const
Definition window.h:882
bool isDecorated() const
Definition window.h:1162
void windowAdded(KWin::Window *)
bool isShadeable() const override
void keyPressEvent(uint key_code, xcb_timestamp_t time)
Definition events.cpp:1321
xcb_window_t window() const
#define WAYLANDTEST_MAIN(TestObject)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
XcbConnectionPtr createX11Connection()
bool renderNodeAvailable()
std::unique_ptr< xcb_connection_t, XcbConnectionDeleter > XcbConnectionPtr
KWIN_EXPORT xcb_window_t rootWindow()
Definition xcb.h:24
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
EffectsHandler * effects