2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-10-25 11:21:27 +00:00
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/output.h"
|
2022-11-05 10:43:41 +00:00
|
|
|
#include "core/outputbackend.h"
|
2019-10-25 11:21:27 +00:00
|
|
|
#include "scripting/scripting.h"
|
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2019-10-25 11:21:27 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KPackage/PackageLoader>
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_minimizeall-0");
|
|
|
|
static const QString s_scriptName = QStringLiteral("minimizeall");
|
|
|
|
|
|
|
|
class MinimizeAllScriptTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testMinimizeUnminimize();
|
|
|
|
};
|
|
|
|
|
|
|
|
void MinimizeAllScriptTest::initTestCase()
|
|
|
|
{
|
|
|
|
qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8());
|
|
|
|
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<Window *>();
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2022-11-05 10:43:41 +00:00
|
|
|
kwinApp()->outputBackend()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-11-05 10:43:41 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2019-10-25 11:21:27 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2022-07-11 10:41:15 +00:00
|
|
|
const auto outputs = workspace()->outputs();
|
2021-08-31 07:03:05 +00:00
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2019-10-25 11:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static QString locateMainScript(const QString &pluginName)
|
|
|
|
{
|
|
|
|
const QList<KPluginMetaData> offers = KPackage::PackageLoader::self()->findPackages(
|
|
|
|
QStringLiteral("KWin/Script"),
|
|
|
|
QStringLiteral("kwin/scripts"),
|
|
|
|
[&](const KPluginMetaData &metaData) {
|
|
|
|
return metaData.pluginId() == pluginName;
|
2022-03-23 10:13:38 +00:00
|
|
|
});
|
2019-10-25 11:21:27 +00:00
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
const KPluginMetaData &metaData = offers.first();
|
|
|
|
const QString mainScriptFileName = metaData.value(QStringLiteral("X-Plasma-MainScript"));
|
|
|
|
const QFileInfo metaDataFileInfo(metaData.fileName());
|
|
|
|
return metaDataFileInfo.path() + QLatin1String("/contents/") + mainScriptFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAllScriptTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
|
|
|
|
|
|
|
Scripting::self()->loadScript(locateMainScript(s_scriptName), s_scriptName);
|
|
|
|
QTRY_VERIFY(Scripting::self()->isScriptLoaded(s_scriptName));
|
|
|
|
|
|
|
|
AbstractScript *script = Scripting::self()->findScript(s_scriptName);
|
|
|
|
QVERIFY(script);
|
|
|
|
QSignalSpy runningChangedSpy(script, &AbstractScript::runningChanged);
|
|
|
|
script->run();
|
|
|
|
QTRY_COMPARE(runningChangedSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAllScriptTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
|
|
|
|
Scripting::self()->unloadScript(s_scriptName);
|
|
|
|
QTRY_VERIFY(!Scripting::self()->isScriptLoaded(s_scriptName));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAllScriptTest::testMinimizeUnminimize()
|
|
|
|
{
|
|
|
|
// This test verifies that all windows are minimized when Meta+Shift+D
|
|
|
|
// is pressed, and unminimized when the shortcut is pressed once again.
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Create a couple of test windows.
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
Window *window1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window1);
|
|
|
|
QVERIFY(window1->isActive());
|
|
|
|
QVERIFY(window1->isMinimizable());
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
Window *window2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::red);
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(window2);
|
|
|
|
QVERIFY(window2->isActive());
|
|
|
|
QVERIFY(window2->isMinimizable());
|
2019-10-25 11:21:27 +00:00
|
|
|
|
|
|
|
// Minimize the windows.
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_D, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_D, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QTRY_VERIFY(window1->isMinimized());
|
|
|
|
QTRY_VERIFY(window2->isMinimized());
|
2019-10-25 11:21:27 +00:00
|
|
|
|
|
|
|
// Unminimize the windows.
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_D, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_D, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
QTRY_VERIFY(!window1->isMinimized());
|
|
|
|
QTRY_VERIFY(!window2->isMinimized());
|
2019-10-25 11:21:27 +00:00
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
// Destroy test windows.
|
2019-10-25 11:21:27 +00:00
|
|
|
shellSurface2.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window2));
|
2019-10-25 11:21:27 +00:00
|
|
|
shellSurface1.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window1));
|
2019-10-25 11:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::MinimizeAllScriptTest)
|
|
|
|
#include "minimizeall_test.moc"
|