Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/x11_client_test.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | Q_OBJECT | 44 | Q_OBJECT | ||
45 | private Q_SLOTS: | 45 | private Q_SLOTS: | ||
46 | void initTestCase(); | 46 | void initTestCase(); | ||
47 | void init(); | 47 | void init(); | ||
48 | void cleanup(); | 48 | void cleanup(); | ||
49 | 49 | | |||
50 | void testCaptionSimplified(); | 50 | void testCaptionSimplified(); | ||
51 | void testFullscreenLayerWithActiveWaylandWindow(); | 51 | void testFullscreenLayerWithActiveWaylandWindow(); | ||
52 | void testFocusInWithWaylandLastActiveWindow(); | ||||
52 | }; | 53 | }; | ||
53 | 54 | | |||
54 | void X11ClientTest::initTestCase() | 55 | void X11ClientTest::initTestCase() | ||
55 | { | 56 | { | ||
56 | qRegisterMetaType<KWin::ShellClient*>(); | 57 | qRegisterMetaType<KWin::ShellClient*>(); | ||
57 | qRegisterMetaType<KWin::AbstractClient*>(); | 58 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
58 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 59 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
59 | QVERIFY(workspaceCreatedSpy.isValid()); | 60 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
60 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 61 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
61 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 62 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
63 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||||
62 | 64 | | |||
63 | kwinApp()->start(); | 65 | kwinApp()->start(); | ||
64 | QVERIFY(workspaceCreatedSpy.wait()); | 66 | QVERIFY(workspaceCreatedSpy.wait()); | ||
65 | QVERIFY(KWin::Compositor::self()); | 67 | QVERIFY(KWin::Compositor::self()); | ||
66 | waylandServer()->initWorkspace(); | 68 | waylandServer()->initWorkspace(); | ||
67 | } | 69 | } | ||
68 | 70 | | |||
69 | void X11ClientTest::init() | 71 | void X11ClientTest::init() | ||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Line(s) | 141 | { | |||
207 | QTRY_VERIFY(client->isActive()); | 209 | QTRY_VERIFY(client->isActive()); | ||
208 | QCOMPARE(client->layer(), ActiveLayer); | 210 | QCOMPARE(client->layer(), ActiveLayer); | ||
209 | 211 | | |||
210 | // and destroy the window again | 212 | // and destroy the window again | ||
211 | xcb_unmap_window(c.data(), w); | 213 | xcb_unmap_window(c.data(), w); | ||
212 | xcb_flush(c.data()); | 214 | xcb_flush(c.data()); | ||
213 | } | 215 | } | ||
214 | 216 | | |||
217 | void X11ClientTest::testFocusInWithWaylandLastActiveWindow() | ||||
218 | { | ||||
219 | // this test verifies that Workspace::allowClientActivation does not crash if last client was a Wayland client | ||||
220 | | ||||
221 | // create an X11 window | ||||
222 | QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr)); | ||||
223 | QVERIFY(!xcb_connection_has_error(c.data())); | ||||
224 | const QRect windowGeometry(0, 0, 100, 200); | ||||
225 | xcb_window_t w = xcb_generate_id(c.data()); | ||||
226 | xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, w, rootWindow(), | ||||
227 | windowGeometry.x(), | ||||
228 | windowGeometry.y(), | ||||
229 | windowGeometry.width(), | ||||
230 | windowGeometry.height(), | ||||
231 | 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr); | ||||
232 | xcb_size_hints_t hints; | ||||
233 | memset(&hints, 0, sizeof(hints)); | ||||
234 | xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y()); | ||||
235 | xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height()); | ||||
236 | xcb_icccm_set_wm_normal_hints(c.data(), w, &hints); | ||||
237 | xcb_map_window(c.data(), w); | ||||
238 | xcb_flush(c.data()); | ||||
239 | | ||||
240 | // we should get a client for it | ||||
241 | QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded); | ||||
242 | QVERIFY(windowCreatedSpy.isValid()); | ||||
243 | QVERIFY(windowCreatedSpy.wait()); | ||||
244 | Client *client = windowCreatedSpy.first().first().value<Client*>(); | ||||
245 | QVERIFY(client); | ||||
246 | QCOMPARE(client->window(), w); | ||||
247 | QVERIFY(client->isActive()); | ||||
248 | | ||||
249 | // create Wayland window | ||||
250 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
251 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||||
252 | auto waylandClient = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
253 | QVERIFY(waylandClient); | ||||
254 | QVERIFY(waylandClient->isActive()); | ||||
255 | // activate no window | ||||
256 | workspace()->setActiveClient(nullptr); | ||||
257 | QVERIFY(!waylandClient->isActive()); | ||||
258 | QVERIFY(!workspace()->activeClient()); | ||||
259 | // and close Wayland window again | ||||
260 | shellSurface.reset(); | ||||
261 | surface.reset(); | ||||
262 | QVERIFY(Test::waitForWindowDestroyed(waylandClient)); | ||||
263 | | ||||
264 | // and try to activate the x11 client through X11 api | ||||
265 | const auto cookie = xcb_set_input_focus_checked(c.data(), XCB_INPUT_FOCUS_NONE, w, XCB_CURRENT_TIME); | ||||
266 | auto error = xcb_request_check(c.data(), cookie); | ||||
267 | QVERIFY(!error); | ||||
268 | // this accesses last_active_client on trying to activate | ||||
269 | QTRY_VERIFY(client->isActive()); | ||||
270 | | ||||
271 | // and destroy the window again | ||||
272 | xcb_unmap_window(c.data(), w); | ||||
273 | xcb_flush(c.data()); | ||||
274 | } | ||||
275 | | ||||
215 | WAYLANDTEST_MAIN(X11ClientTest) | 276 | WAYLANDTEST_MAIN(X11ClientTest) | ||
216 | #include "x11_client_test.moc" | 277 | #include "x11_client_test.moc" |