Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/wobbly_shade_test.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2018 Martin Flöser <mgraesslin@kde.org> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #include "kwin_wayland_test.h" | ||||
21 | #include "composite.h" | ||||
22 | #include "cursor.h" | ||||
23 | #include "effects.h" | ||||
24 | #include "effectloader.h" | ||||
25 | #include "cursor.h" | ||||
26 | #include "platform.h" | ||||
27 | #include "shell_client.h" | ||||
28 | #include "wayland_server.h" | ||||
29 | #include "workspace.h" | ||||
30 | #include "effect_builtins.h" | ||||
31 | | ||||
32 | #include <KConfigGroup> | ||||
33 | | ||||
34 | #include <KWayland/Client/connection_thread.h> | ||||
35 | #include <KWayland/Client/registry.h> | ||||
36 | #include <KWayland/Client/surface.h> | ||||
37 | #include <KWayland/Client/shell.h> | ||||
38 | #include <KWayland/Client/slide.h> | ||||
39 | | ||||
40 | #include <netwm.h> | ||||
41 | #include <xcb/xcb_icccm.h> | ||||
42 | | ||||
43 | using namespace KWin; | ||||
44 | static const QString s_socketName = QStringLiteral("wayland_test_effects_wobbly_shade-0"); | ||||
45 | | ||||
46 | class WobblyWindowsShadeTest : public QObject | ||||
47 | { | ||||
48 | Q_OBJECT | ||||
49 | private Q_SLOTS: | ||||
50 | void initTestCase(); | ||||
51 | void init(); | ||||
52 | void cleanup(); | ||||
53 | | ||||
54 | void testShadeMove(); | ||||
55 | }; | ||||
56 | | ||||
57 | void WobblyWindowsShadeTest::initTestCase() | ||||
58 | { | ||||
59 | qRegisterMetaType<KWin::ShellClient*>(); | ||||
60 | qRegisterMetaType<KWin::AbstractClient*>(); | ||||
61 | qRegisterMetaType<KWin::Effect*>(); | ||||
62 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||||
63 | QVERIFY(workspaceCreatedSpy.isValid()); | ||||
64 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||||
65 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||||
66 | | ||||
67 | // disable all effects - we don't want to have it interact with the rendering | ||||
68 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||||
69 | KConfigGroup plugins(config, QStringLiteral("Plugins")); | ||||
70 | ScriptedEffectLoader loader; | ||||
71 | const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects(); | ||||
72 | for (QString name : builtinNames) { | ||||
73 | plugins.writeEntry(name + QStringLiteral("Enabled"), false); | ||||
74 | } | ||||
75 | | ||||
76 | config->sync(); | ||||
77 | kwinApp()->setConfig(config); | ||||
78 | | ||||
79 | qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2")); | ||||
80 | qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", "1"); | ||||
81 | kwinApp()->start(); | ||||
82 | QVERIFY(workspaceCreatedSpy.wait()); | ||||
83 | QVERIFY(Compositor::self()); | ||||
84 | } | ||||
85 | | ||||
86 | void WobblyWindowsShadeTest::init() | ||||
87 | { | ||||
88 | QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration)); | ||||
89 | } | ||||
90 | | ||||
91 | void WobblyWindowsShadeTest::cleanup() | ||||
92 | { | ||||
93 | Test::destroyWaylandConnection(); | ||||
94 | EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects); | ||||
95 | while (!e->loadedEffects().isEmpty()) { | ||||
96 | const QString effect = e->loadedEffects().first(); | ||||
97 | e->unloadEffect(effect); | ||||
98 | QVERIFY(!e->isEffectLoaded(effect)); | ||||
99 | } | ||||
100 | } | ||||
101 | | ||||
102 | struct XcbConnectionDeleter | ||||
103 | { | ||||
104 | static inline void cleanup(xcb_connection_t *pointer) | ||||
105 | { | ||||
106 | xcb_disconnect(pointer); | ||||
107 | } | ||||
108 | }; | ||||
109 | | ||||
110 | void WobblyWindowsShadeTest::testShadeMove() | ||||
111 | { | ||||
112 | // this test simulates the condition from BUG 390953 | ||||
113 | EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects); | ||||
114 | QVERIFY(e->loadEffect(BuiltInEffects::nameForEffect(BuiltInEffect::WobblyWindows))); | ||||
115 | QVERIFY(e->isEffectLoaded(BuiltInEffects::nameForEffect(BuiltInEffect::WobblyWindows))); | ||||
116 | | ||||
117 | | ||||
118 | QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr)); | ||||
119 | QVERIFY(!xcb_connection_has_error(c.data())); | ||||
120 | const QRect windowGeometry(0, 0, 100, 200); | ||||
121 | xcb_window_t w = xcb_generate_id(c.data()); | ||||
122 | xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, w, rootWindow(), | ||||
123 | windowGeometry.x(), | ||||
124 | windowGeometry.y(), | ||||
125 | windowGeometry.width(), | ||||
126 | windowGeometry.height(), | ||||
127 | 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr); | ||||
128 | xcb_size_hints_t hints; | ||||
129 | memset(&hints, 0, sizeof(hints)); | ||||
130 | xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y()); | ||||
131 | xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height()); | ||||
132 | xcb_icccm_set_wm_normal_hints(c.data(), w, &hints); | ||||
133 | xcb_map_window(c.data(), w); | ||||
134 | xcb_flush(c.data()); | ||||
135 | | ||||
136 | // we should get a client for it | ||||
137 | QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded); | ||||
138 | QVERIFY(windowCreatedSpy.isValid()); | ||||
139 | QVERIFY(windowCreatedSpy.wait()); | ||||
140 | Client *client = windowCreatedSpy.first().first().value<Client*>(); | ||||
141 | QVERIFY(client); | ||||
142 | QCOMPARE(client->window(), w); | ||||
143 | QVERIFY(client->isDecorated()); | ||||
144 | QVERIFY(client->isShadeable()); | ||||
145 | QVERIFY(!client->isShade()); | ||||
146 | QVERIFY(client->isActive()); | ||||
147 | | ||||
148 | QSignalSpy windowShownSpy(client, &AbstractClient::windowShown); | ||||
149 | QVERIFY(windowShownSpy.isValid()); | ||||
150 | QVERIFY(windowShownSpy.wait()); | ||||
151 | | ||||
152 | // now shade the window | ||||
153 | workspace()->slotWindowShade(); | ||||
154 | QVERIFY(client->isShade()); | ||||
155 | | ||||
156 | QSignalSpy windowStartUserMovedResizedSpy(e, &EffectsHandler::windowStartUserMovedResized); | ||||
157 | QVERIFY(windowStartUserMovedResizedSpy.isValid()); | ||||
158 | | ||||
159 | // begin move | ||||
160 | QVERIFY(workspace()->getMovingClient() == nullptr); | ||||
161 | QCOMPARE(client->isMove(), false); | ||||
162 | workspace()->slotWindowMove(); | ||||
163 | QCOMPARE(workspace()->getMovingClient(), client); | ||||
164 | QCOMPARE(client->isMove(), true); | ||||
165 | QCOMPARE(windowStartUserMovedResizedSpy.count(), 1); | ||||
166 | | ||||
167 | // wait for frame rendered | ||||
168 | QTest::qWait(100); | ||||
169 | | ||||
170 | // send some key events, not going through input redirection | ||||
171 | client->keyPressEvent(Qt::Key_Right); | ||||
172 | client->updateMoveResize(KWin::Cursor::pos()); | ||||
173 | | ||||
174 | // wait for frame rendered | ||||
175 | QTest::qWait(100); | ||||
176 | | ||||
177 | client->keyPressEvent(Qt::Key_Right); | ||||
178 | client->updateMoveResize(KWin::Cursor::pos()); | ||||
179 | | ||||
180 | // wait for frame rendered | ||||
181 | QTest::qWait(100); | ||||
182 | | ||||
183 | client->keyPressEvent(Qt::Key_Down | Qt::ALT); | ||||
184 | client->updateMoveResize(KWin::Cursor::pos()); | ||||
185 | | ||||
186 | // wait for frame rendered | ||||
187 | QTest::qWait(100); | ||||
188 | | ||||
189 | // let's end | ||||
190 | client->keyPressEvent(Qt::Key_Enter); | ||||
191 | | ||||
192 | // wait for frame rendered | ||||
193 | QTest::qWait(100); | ||||
194 | } | ||||
195 | | ||||
196 | WAYLANDTEST_MAIN(WobblyWindowsShadeTest) | ||||
197 | #include "wobbly_shade_test.moc" |