2016-06-03 07:28:46 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
#include "platform.h"
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.h"
|
2016-06-03 07:28:46 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "screenedge.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
#include <kwineffects.h>
|
|
|
|
|
|
|
|
#include <KWayland/Client/compositor.h>
|
|
|
|
#include <KWayland/Client/plasmawindowmanagement.h>
|
|
|
|
#include <KWayland/Client/surface.h>
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/seat_interface.h>
|
2016-06-03 13:27:36 +00:00
|
|
|
//screenlocker
|
|
|
|
#include <KScreenLocker/KsldApp>
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRasterWindow>
|
|
|
|
|
|
|
|
#include <netwm.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_plasma-window-0");
|
|
|
|
|
|
|
|
class PlasmaWindowTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
void testCreateDestroyX11PlasmaWindow();
|
|
|
|
void testInternalWindowNoPlasmaWindow();
|
|
|
|
void testPopupWindowNoPlasmaWindow();
|
2016-06-03 13:27:36 +00:00
|
|
|
void testLockScreenNoPlasmaWindow();
|
2016-06-03 14:53:23 +00:00
|
|
|
void testDestroyedButNotUnmapped();
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PlasmaWindowManagement *m_windowManagement = nullptr;
|
|
|
|
KWayland::Client::Compositor *m_compositor = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PlasmaWindowTest::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
|
|
|
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
|
|
|
|
QVERIFY(workspaceCreatedSpy.isValid());
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2016-07-04 07:09:03 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
|
2019-08-26 21:16:53 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(workspaceCreatedSpy.wait());
|
|
|
|
QCOMPARE(screens()->count(), 2);
|
|
|
|
QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024));
|
|
|
|
setenv("QT_QPA_PLATFORM", "wayland", true);
|
2016-06-03 13:27:36 +00:00
|
|
|
setenv("QMLSCENE_DEVICE", "softwarecontext", true);
|
2016-06-03 07:28:46 +00:00
|
|
|
waylandServer()->initWorkspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::init()
|
|
|
|
{
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::WindowManagement));
|
2016-06-30 11:32:54 +00:00
|
|
|
m_windowManagement = Test::waylandWindowManagement();
|
|
|
|
m_compositor = Test::waylandCompositor();
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
screens()->setCurrent(0);
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2016-06-03 07:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::cleanup()
|
|
|
|
{
|
2016-06-30 11:32:54 +00:00
|
|
|
Test::destroyWaylandConnection();
|
2016-06-03 07:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow()
|
|
|
|
{
|
|
|
|
// this test verifies that a PlasmaWindow gets unmapped on Client side when an X11 client is destroyed
|
|
|
|
QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated);
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isValid());
|
|
|
|
|
|
|
|
// create an xcb window
|
|
|
|
struct XcbConnectionDeleter
|
|
|
|
{
|
|
|
|
static inline void cleanup(xcb_connection_t *pointer)
|
|
|
|
{
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.data()));
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
|
|
|
xcb_window_t w = xcb_generate_id(c.data());
|
|
|
|
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, w, rootWindow(),
|
|
|
|
windowGeometry.x(),
|
|
|
|
windowGeometry.y(),
|
|
|
|
windowGeometry.width(),
|
|
|
|
windowGeometry.height(),
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.data(), w, &hints);
|
|
|
|
xcb_map_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
|
|
|
// we should get a client for it
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2019-09-24 08:48:08 +00:00
|
|
|
X11Client *client = windowCreatedSpy.first().first().value<X11Client *>();
|
2016-06-03 07:28:46 +00:00
|
|
|
QVERIFY(client);
|
|
|
|
QCOMPARE(client->window(), w);
|
|
|
|
QVERIFY(client->isDecorated());
|
|
|
|
QVERIFY(client->isActive());
|
2016-06-26 13:57:38 +00:00
|
|
|
// verify that it gets the keyboard focus
|
2017-07-25 19:16:23 +00:00
|
|
|
if (!client->surface()) {
|
|
|
|
// we don't have a surface yet, so focused keyboard surface if set is not ours
|
|
|
|
QVERIFY(!waylandServer()->seat()->focusedKeyboardSurface());
|
|
|
|
QSignalSpy surfaceChangedSpy(client, &Toplevel::surfaceChanged);
|
|
|
|
QVERIFY(surfaceChangedSpy.isValid());
|
|
|
|
QVERIFY(surfaceChangedSpy.wait());
|
|
|
|
}
|
2016-06-26 13:57:38 +00:00
|
|
|
QVERIFY(client->surface());
|
|
|
|
QCOMPARE(waylandServer()->seat()->focusedKeyboardSurface(), client->surface());
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
// now that should also give it to us on client side
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
|
|
|
|
QCOMPARE(m_windowManagement->windows().count(), 1);
|
2016-07-18 06:22:33 +00:00
|
|
|
auto pw = m_windowManagement->windows().first();
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(pw->geometry(), client->frameGeometry());
|
2016-07-18 06:22:33 +00:00
|
|
|
QSignalSpy geometryChangedSpy(pw, &PlasmaWindow::geometryChanged);
|
|
|
|
QVERIFY(geometryChangedSpy.isValid());
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
QSignalSpy unmappedSpy(m_windowManagement->windows().first(), &PlasmaWindow::unmapped);
|
|
|
|
QVERIFY(unmappedSpy.isValid());
|
|
|
|
QSignalSpy destroyedSpy(m_windowManagement->windows().first(), &QObject::destroyed);
|
|
|
|
QVERIFY(destroyedSpy.isValid());
|
|
|
|
|
|
|
|
// now shade the window
|
2019-09-27 10:01:10 +00:00
|
|
|
const QRect geoBeforeShade = client->frameGeometry();
|
2016-06-03 07:28:46 +00:00
|
|
|
QVERIFY(geoBeforeShade.isValid());
|
|
|
|
QVERIFY(!geoBeforeShade.isEmpty());
|
|
|
|
workspace()->slotWindowShade();
|
|
|
|
QVERIFY(client->isShade());
|
2019-09-27 10:01:10 +00:00
|
|
|
QVERIFY(client->frameGeometry() != geoBeforeShade);
|
2016-07-18 06:22:33 +00:00
|
|
|
QVERIFY(geometryChangedSpy.wait());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(pw->geometry(), client->frameGeometry());
|
2016-06-03 07:28:46 +00:00
|
|
|
// and unshade again
|
|
|
|
workspace()->slotWindowShade();
|
|
|
|
QVERIFY(!client->isShade());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(client->frameGeometry(), geoBeforeShade);
|
2016-07-18 06:22:33 +00:00
|
|
|
QVERIFY(geometryChangedSpy.wait());
|
|
|
|
QCOMPARE(pw->geometry(), geoBeforeShade);
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
// and destroy the window again
|
|
|
|
xcb_unmap_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
|
2019-09-24 08:48:08 +00:00
|
|
|
QSignalSpy windowClosedSpy(client, &X11Client::windowClosed);
|
2016-06-03 07:28:46 +00:00
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
xcb_destroy_window(c.data(), w);
|
|
|
|
c.reset();
|
|
|
|
|
|
|
|
QVERIFY(unmappedSpy.wait());
|
|
|
|
QCOMPARE(unmappedSpy.count(), 1);
|
|
|
|
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
class HelperWindow : public QRasterWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
HelperWindow();
|
Run clang-tidy with modernize-use-override check
Summary:
Currently code base of kwin can be viewed as two pieces. One is very
ancient, and the other one is more modern, which uses new C++ features.
The main problem with the ancient code is that it was written before
C++11 era. So, no override or final keywords, lambdas, etc.
Quite recently, KDE compiler settings were changed to show a warning if
a virtual method has missing override keyword. As you might have already
guessed, this fired back at us because of that ancient code. We had
about 500 new compiler warnings.
A "solution" was proposed to that problem - disable -Wno-suggest-override
and the other similar warning for clang. It's hard to call a solution
because those warnings are disabled not only for the old code, but also
for new. This is not what we want!
The main argument for not actually fixing the problem was that git
history will be screwed as well because of human factor. While good git
history is a very important thing, we should not go crazy about it and
block every change that somehow alters git history. git blame allows to
specify starting revision for a reason.
The other argument (human factor) can be easily solved by using tools
such as clang-tidy. clang-tidy is a clang-based linter for C++. It can
be used for various things, e.g. fixing coding style(e.g. add missing
braces to if statements, readability-braces-around-statements check),
or in our case add missing override keywords.
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, apol, romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D22371
2019-07-22 16:52:26 +00:00
|
|
|
~HelperWindow() override;
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
HelperWindow::HelperWindow()
|
|
|
|
: QRasterWindow(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HelperWindow::~HelperWindow() = default;
|
|
|
|
|
|
|
|
void HelperWindow::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
QPainter p(this);
|
|
|
|
p.fillRect(0, 0, width(), height(), Qt::red);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::testInternalWindowNoPlasmaWindow()
|
|
|
|
{
|
|
|
|
// this test verifies that an internal window is not added as a PlasmaWindow to the client
|
|
|
|
QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated);
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isValid());
|
|
|
|
HelperWindow win;
|
|
|
|
win.setGeometry(0, 0, 100, 100);
|
|
|
|
win.show();
|
|
|
|
|
|
|
|
QVERIFY(!plasmaWindowCreatedSpy.wait());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::testPopupWindowNoPlasmaWindow()
|
|
|
|
{
|
|
|
|
// this test verifies that for a popup window no PlasmaWindow is sent to the client
|
|
|
|
QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated);
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isValid());
|
|
|
|
|
|
|
|
// first create the parent window
|
2016-06-30 11:32:54 +00:00
|
|
|
QScopedPointer<Surface> parentSurface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QScopedPointer<XdgShellSurface> parentShellSurface(Test::createXdgShellStableSurface(parentSurface.data()));
|
2020-03-04 07:55:26 +00:00
|
|
|
AbstractClient *parentClient = Test::renderAndWaitForShown(parentSurface.data(), QSize(100, 50), Qt::blue);
|
2019-08-27 15:01:14 +00:00
|
|
|
QVERIFY(parentClient);
|
2016-06-03 07:28:46 +00:00
|
|
|
QVERIFY(plasmaWindowCreatedSpy.wait());
|
2019-08-27 15:01:14 +00:00
|
|
|
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
|
2016-06-03 07:28:46 +00:00
|
|
|
|
|
|
|
// now let's create a popup window for it
|
2019-08-27 15:01:14 +00:00
|
|
|
XdgPositioner positioner(QSize(10, 10), QRect(0, 0, 10, 10));
|
|
|
|
positioner.setAnchorEdge(Qt::BottomEdge | Qt::RightEdge);
|
|
|
|
positioner.setGravity(Qt::BottomEdge | Qt::RightEdge);
|
2016-06-30 11:32:54 +00:00
|
|
|
QScopedPointer<Surface> popupSurface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QScopedPointer<XdgShellPopup> popupShellSurface(Test::createXdgShellStablePopup(popupSurface.data(), parentShellSurface.data(), positioner));
|
2020-03-04 07:55:26 +00:00
|
|
|
AbstractClient *popupClient = Test::renderAndWaitForShown(popupSurface.data(), positioner.initialSize(), Qt::blue);
|
2019-08-27 15:01:14 +00:00
|
|
|
QVERIFY(popupClient);
|
|
|
|
QVERIFY(!plasmaWindowCreatedSpy.wait(100));
|
|
|
|
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
|
2016-06-03 13:27:36 +00:00
|
|
|
|
|
|
|
// let's destroy the windows
|
|
|
|
popupShellSurface.reset();
|
2019-08-27 15:01:14 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(popupClient));
|
2016-06-03 13:27:36 +00:00
|
|
|
parentShellSurface.reset();
|
2019-08-27 15:01:14 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(parentClient));
|
2016-06-03 13:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlasmaWindowTest::testLockScreenNoPlasmaWindow()
|
|
|
|
{
|
|
|
|
// this test verifies that lock screen windows are not exposed to PlasmaWindow
|
|
|
|
QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated);
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isValid());
|
|
|
|
|
2019-08-30 21:36:58 +00:00
|
|
|
// this time we use a QSignalSpy on XdgShellClient as it'a a little bit more complex setup
|
2016-06-03 13:27:36 +00:00
|
|
|
QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded);
|
|
|
|
QVERIFY(clientAddedSpy.isValid());
|
|
|
|
// lock
|
|
|
|
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
|
|
|
|
QVERIFY(clientAddedSpy.wait());
|
2020-03-04 07:55:26 +00:00
|
|
|
QVERIFY(clientAddedSpy.first().first().value<AbstractClient *>()->isLockScreen());
|
2016-06-03 13:27:36 +00:00
|
|
|
// should not be sent to the client
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isEmpty());
|
|
|
|
QVERIFY(!plasmaWindowCreatedSpy.wait());
|
|
|
|
|
|
|
|
// fake unlock
|
|
|
|
QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged);
|
|
|
|
QVERIFY(lockStateChangedSpy.isValid());
|
|
|
|
const auto children = ScreenLocker::KSldApp::self()->children();
|
|
|
|
for (auto it = children.begin(); it != children.end(); ++it) {
|
|
|
|
if (qstrcmp((*it)->metaObject()->className(), "LogindIntegration") != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
QMetaObject::invokeMethod(*it, "requestUnlock");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QVERIFY(lockStateChangedSpy.wait());
|
|
|
|
QVERIFY(!waylandServer()->isScreenLocked());
|
2016-06-03 07:28:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 14:53:23 +00:00
|
|
|
void PlasmaWindowTest::testDestroyedButNotUnmapped()
|
|
|
|
{
|
|
|
|
// this test verifies that also when a ShellSurface gets destroyed without a prior unmap
|
|
|
|
// the PlasmaWindow gets destroyed on Client side
|
|
|
|
QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated);
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.isValid());
|
|
|
|
|
|
|
|
// first create the parent window
|
2016-06-30 11:32:54 +00:00
|
|
|
QScopedPointer<Surface> parentSurface(Test::createSurface());
|
2019-08-27 15:01:14 +00:00
|
|
|
QScopedPointer<XdgShellSurface> parentShellSurface(Test::createXdgShellStableSurface(parentSurface.data()));
|
2016-06-03 14:53:23 +00:00
|
|
|
// map that window
|
2016-06-30 11:32:54 +00:00
|
|
|
Test::render(parentSurface.data(), QSize(100, 50), Qt::blue);
|
2016-06-03 14:53:23 +00:00
|
|
|
// this should create a plasma window
|
|
|
|
QVERIFY(plasmaWindowCreatedSpy.wait());
|
|
|
|
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
|
|
|
|
auto window = plasmaWindowCreatedSpy.first().first().value<PlasmaWindow*>();
|
|
|
|
QVERIFY(window);
|
|
|
|
QSignalSpy destroyedSpy(window, &QObject::destroyed);
|
|
|
|
QVERIFY(destroyedSpy.isValid());
|
|
|
|
|
|
|
|
// now destroy without an unmap
|
|
|
|
parentShellSurface.reset();
|
|
|
|
parentSurface.reset();
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-06-03 07:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::PlasmaWindowTest)
|
|
|
|
#include "plasmawindow_test.moc"
|