Warning, file /plasma/kwin/autotests/integration/shade_test.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "kwin_wayland_test.h" 0010 0011 #include "core/output.h" 0012 #include "core/outputbackend.h" 0013 #include "cursor.h" 0014 #include "wayland_server.h" 0015 #include "workspace.h" 0016 #include "x11window.h" 0017 #include <kwineffects.h> 0018 0019 #include <KDecoration2/Decoration> 0020 0021 #include <netwm.h> 0022 #include <xcb/xcb_icccm.h> 0023 0024 namespace KWin 0025 { 0026 0027 static const QString s_socketName = QStringLiteral("wayland_test_kwin_shade-0"); 0028 0029 class ShadeTest : public QObject 0030 { 0031 Q_OBJECT 0032 private Q_SLOTS: 0033 void initTestCase(); 0034 void init(); 0035 void testShadeGeometry(); 0036 }; 0037 0038 void ShadeTest::initTestCase() 0039 { 0040 qRegisterMetaType<KWin::Window *>(); 0041 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started); 0042 QVERIFY(waylandServer()->init(s_socketName)); 0043 QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024))); 0044 0045 kwinApp()->start(); 0046 QVERIFY(applicationStartedSpy.wait()); 0047 const auto outputs = workspace()->outputs(); 0048 QCOMPARE(outputs.count(), 2); 0049 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024)); 0050 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024)); 0051 setenv("QT_QPA_PLATFORM", "wayland", true); 0052 } 0053 0054 void ShadeTest::init() 0055 { 0056 workspace()->setActiveOutput(QPoint(640, 512)); 0057 Cursors::self()->mouse()->setPos(QPoint(640, 512)); 0058 } 0059 0060 void ShadeTest::testShadeGeometry() 0061 { 0062 // this test verifies that the geometry is properly restored after shading 0063 // see BUG: 362501 0064 // create an xcb window 0065 struct XcbConnectionDeleter 0066 { 0067 void operator()(xcb_connection_t *pointer) 0068 { 0069 xcb_disconnect(pointer); 0070 } 0071 }; 0072 std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr)); 0073 QVERIFY(!xcb_connection_has_error(c.get())); 0074 const QRect windowGeometry(0, 0, 100, 200); 0075 xcb_window_t windowId = xcb_generate_id(c.get()); 0076 xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(), 0077 windowGeometry.x(), 0078 windowGeometry.y(), 0079 windowGeometry.width(), 0080 windowGeometry.height(), 0081 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr); 0082 xcb_size_hints_t hints; 0083 memset(&hints, 0, sizeof(hints)); 0084 xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y()); 0085 xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height()); 0086 xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints); 0087 xcb_map_window(c.get(), windowId); 0088 xcb_flush(c.get()); 0089 0090 // we should get a window for it 0091 QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded); 0092 QVERIFY(windowCreatedSpy.wait()); 0093 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>(); 0094 QVERIFY(window); 0095 QCOMPARE(window->window(), windowId); 0096 QVERIFY(window->isDecorated()); 0097 QVERIFY(window->isShadeable()); 0098 QVERIFY(!window->isShade()); 0099 QVERIFY(window->isActive()); 0100 0101 // now shade the window 0102 const QRectF geoBeforeShade = window->frameGeometry(); 0103 QVERIFY(geoBeforeShade.isValid()); 0104 QVERIFY(!geoBeforeShade.isEmpty()); 0105 workspace()->slotWindowShade(); 0106 QVERIFY(window->isShade()); 0107 QVERIFY(window->frameGeometry() != geoBeforeShade); 0108 // and unshade again 0109 workspace()->slotWindowShade(); 0110 QVERIFY(!window->isShade()); 0111 QCOMPARE(window->frameGeometry(), geoBeforeShade); 0112 0113 // and destroy the window again 0114 xcb_unmap_window(c.get(), windowId); 0115 xcb_destroy_window(c.get(), windowId); 0116 xcb_flush(c.get()); 0117 c.reset(); 0118 0119 QSignalSpy windowClosedSpy(window, &X11Window::windowClosed); 0120 QVERIFY(windowClosedSpy.wait()); 0121 } 0122 0123 } 0124 0125 WAYLANDTEST_MAIN(KWin::ShadeTest) 0126 #include "shade_test.moc"