2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-02 07:12:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-08-02 07:12:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-08-02 07:12:57 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2016-08-02 07:12:57 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "effectloader.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "scripting/scripting.h"
|
2016-08-02 07:12:57 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2016-10-07 12:29:29 +00:00
|
|
|
|
|
|
|
#define private public
|
|
|
|
#include "screenedge.h"
|
|
|
|
#undef private
|
2016-08-02 07:12:57 +00:00
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(KWin::ElectricBorder)
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_scripting_screenedge-0");
|
|
|
|
|
|
|
|
class ScreenEdgeTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testEdge_data();
|
|
|
|
void testEdge();
|
2017-04-02 13:42:18 +00:00
|
|
|
void testTouchEdge_data();
|
|
|
|
void testTouchEdge();
|
2016-10-07 12:29:29 +00:00
|
|
|
void testEdgeUnregister();
|
2017-04-01 20:38:58 +00:00
|
|
|
void testDeclarativeTouchEdge();
|
2016-10-07 12:29:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void triggerConfigReload();
|
2016-08-02 07:12:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ScreenEdgeTest::initTestCase()
|
|
|
|
{
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-08-02 07:12:57 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2016-08-02 07:12:57 +00:00
|
|
|
|
|
|
|
// empty config to have defaults
|
|
|
|
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
|
|
|
|
// disable all effects to prevent them grabbing edges
|
|
|
|
KConfigGroup plugins(config, QStringLiteral("Plugins"));
|
2021-10-09 15:38:14 +00:00
|
|
|
const auto builtinNames = EffectLoader().listOfKnownEffects();
|
2016-08-02 07:12:57 +00:00
|
|
|
for (QString name : builtinNames) {
|
|
|
|
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
|
|
|
|
}
|
|
|
|
|
2016-10-07 12:29:29 +00:00
|
|
|
// disable electric border pushback
|
2016-08-02 07:12:57 +00:00
|
|
|
config->group("Windows").writeEntry("ElectricBorderPushbackPixels", 0);
|
2017-05-02 19:17:41 +00:00
|
|
|
config->group("TabBox").writeEntry("TouchBorderActivate", int(ElectricNone));
|
2016-08-02 07:12:57 +00:00
|
|
|
|
|
|
|
config->sync();
|
|
|
|
kwinApp()->setConfig(config);
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-08-02 07:12:57 +00:00
|
|
|
QVERIFY(Scripting::self());
|
2016-10-07 12:29:29 +00:00
|
|
|
|
2022-07-30 22:55:56 +00:00
|
|
|
workspace()->screenEdges()->setTimeThreshold(0);
|
|
|
|
workspace()->screenEdges()->setReActivationThreshold(0);
|
2016-08-02 07:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::init()
|
|
|
|
{
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(640, 512);
|
2016-08-02 07:12:57 +00:00
|
|
|
if (workspace()->showingDesktop()) {
|
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
}
|
|
|
|
QVERIFY(!workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::cleanup()
|
|
|
|
{
|
|
|
|
// try to unload the script
|
2017-04-02 13:42:18 +00:00
|
|
|
const QStringList scripts = {QFINDTESTDATA("./scripts/screenedge.js"), QFINDTESTDATA("./scripts/screenedgeunregister.js"), QFINDTESTDATA("./scripts/touchScreenedge.js")};
|
2022-03-23 10:13:38 +00:00
|
|
|
for (const QString &script : scripts) {
|
2016-10-07 12:29:29 +00:00
|
|
|
if (!script.isEmpty()) {
|
|
|
|
if (Scripting::self()->isScriptLoaded(script)) {
|
|
|
|
QVERIFY(Scripting::self()->unloadScript(script));
|
|
|
|
QTRY_VERIFY(!Scripting::self()->isScriptLoaded(script));
|
|
|
|
}
|
2016-08-02 07:12:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::testEdge_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::ElectricBorder>("edge");
|
|
|
|
QTest::addColumn<QPoint>("triggerPos");
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Top") << KWin::ElectricTop << QPoint(512, 0);
|
2016-08-02 07:12:57 +00:00
|
|
|
QTest::newRow("TopRight") << KWin::ElectricTopRight << QPoint(1279, 0);
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Right") << KWin::ElectricRight << QPoint(1279, 512);
|
2016-08-02 07:12:57 +00:00
|
|
|
QTest::newRow("BottomRight") << KWin::ElectricBottomRight << QPoint(1279, 1023);
|
|
|
|
QTest::newRow("Bottom") << KWin::ElectricBottom << QPoint(512, 1023);
|
|
|
|
QTest::newRow("BottomLeft") << KWin::ElectricBottomLeft << QPoint(0, 1023);
|
|
|
|
QTest::newRow("Left") << KWin::ElectricLeft << QPoint(0, 512);
|
|
|
|
QTest::newRow("TopLeft") << KWin::ElectricTopLeft << QPoint(0, 0);
|
2016-10-07 12:29:29 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// repeat a row to show previously unloading and re-registering works
|
|
|
|
QTest::newRow("Top") << KWin::ElectricTop << QPoint(512, 0);
|
2016-08-02 07:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::testEdge()
|
|
|
|
{
|
|
|
|
const QString scriptToLoad = QFINDTESTDATA("./scripts/screenedge.js");
|
|
|
|
QVERIFY(!scriptToLoad.isEmpty());
|
|
|
|
|
|
|
|
// mock the config
|
|
|
|
auto config = kwinApp()->config();
|
|
|
|
QFETCH(KWin::ElectricBorder, edge);
|
|
|
|
config->group(QLatin1String("Script-") + scriptToLoad).writeEntry("Edge", int(edge));
|
|
|
|
config->sync();
|
|
|
|
|
|
|
|
QVERIFY(!Scripting::self()->isScriptLoaded(scriptToLoad));
|
|
|
|
const int id = Scripting::self()->loadScript(scriptToLoad);
|
|
|
|
QVERIFY(id != -1);
|
|
|
|
QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad));
|
2016-08-19 07:12:49 +00:00
|
|
|
auto s = Scripting::self()->findScript(scriptToLoad);
|
|
|
|
QVERIFY(s);
|
|
|
|
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
|
|
|
QVERIFY(runningChangedSpy.isValid());
|
|
|
|
s->run();
|
|
|
|
QVERIFY(runningChangedSpy.wait());
|
|
|
|
QCOMPARE(runningChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(runningChangedSpy.first().first().toBool(), true);
|
2016-08-02 07:12:57 +00:00
|
|
|
// triggering the edge will result in show desktop being triggered
|
|
|
|
QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged);
|
|
|
|
QVERIFY(showDesktopSpy.isValid());
|
|
|
|
|
|
|
|
// trigger the edge
|
|
|
|
QFETCH(QPoint, triggerPos);
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(triggerPos);
|
2016-08-02 07:12:57 +00:00
|
|
|
QCOMPARE(showDesktopSpy.count(), 1);
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
2017-04-02 13:42:18 +00:00
|
|
|
void ScreenEdgeTest::testTouchEdge_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::ElectricBorder>("edge");
|
|
|
|
QTest::addColumn<QPoint>("triggerPos");
|
|
|
|
QTest::addColumn<QPoint>("motionPos");
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("Top") << KWin::ElectricTop << QPoint(50, 0) << QPoint(50, 500);
|
|
|
|
QTest::newRow("Right") << KWin::ElectricRight << QPoint(1279, 50) << QPoint(500, 50);
|
2017-04-02 13:42:18 +00:00
|
|
|
QTest::newRow("Bottom") << KWin::ElectricBottom << QPoint(512, 1023) << QPoint(512, 500);
|
|
|
|
QTest::newRow("Left") << KWin::ElectricLeft << QPoint(0, 50) << QPoint(500, 50);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// repeat a row to show previously unloading and re-registering works
|
|
|
|
QTest::newRow("Top") << KWin::ElectricTop << QPoint(512, 0) << QPoint(512, 500);
|
2017-04-02 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::testTouchEdge()
|
|
|
|
{
|
|
|
|
const QString scriptToLoad = QFINDTESTDATA("./scripts/touchScreenedge.js");
|
|
|
|
QVERIFY(!scriptToLoad.isEmpty());
|
|
|
|
|
|
|
|
// mock the config
|
|
|
|
auto config = kwinApp()->config();
|
|
|
|
QFETCH(KWin::ElectricBorder, edge);
|
|
|
|
config->group(QLatin1String("Script-") + scriptToLoad).writeEntry("Edge", int(edge));
|
|
|
|
config->sync();
|
|
|
|
|
|
|
|
QVERIFY(!Scripting::self()->isScriptLoaded(scriptToLoad));
|
|
|
|
const int id = Scripting::self()->loadScript(scriptToLoad);
|
|
|
|
QVERIFY(id != -1);
|
|
|
|
QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad));
|
|
|
|
auto s = Scripting::self()->findScript(scriptToLoad);
|
|
|
|
QVERIFY(s);
|
|
|
|
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
|
|
|
QVERIFY(runningChangedSpy.isValid());
|
|
|
|
s->run();
|
|
|
|
QVERIFY(runningChangedSpy.wait());
|
|
|
|
QCOMPARE(runningChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(runningChangedSpy.first().first().toBool(), true);
|
|
|
|
// triggering the edge will result in show desktop being triggered
|
|
|
|
QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged);
|
|
|
|
QVERIFY(showDesktopSpy.isValid());
|
|
|
|
|
|
|
|
// trigger the edge
|
|
|
|
QFETCH(QPoint, triggerPos);
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::touchDown(0, triggerPos, timestamp++);
|
2017-04-02 13:42:18 +00:00
|
|
|
QFETCH(QPoint, motionPos);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::touchMotion(0, motionPos, timestamp++);
|
|
|
|
Test::touchUp(0, timestamp++);
|
2017-04-02 13:42:18 +00:00
|
|
|
QVERIFY(showDesktopSpy.wait());
|
|
|
|
QCOMPARE(showDesktopSpy.count(), 1);
|
|
|
|
QVERIFY(workspace()->showingDesktop());
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
void ScreenEdgeTest::triggerConfigReload()
|
|
|
|
{
|
2016-10-07 12:29:29 +00:00
|
|
|
workspace()->slotReconfigure();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeTest::testEdgeUnregister()
|
|
|
|
{
|
|
|
|
const QString scriptToLoad = QFINDTESTDATA("./scripts/screenedgeunregister.js");
|
|
|
|
QVERIFY(!scriptToLoad.isEmpty());
|
|
|
|
|
|
|
|
Scripting::self()->loadScript(scriptToLoad);
|
|
|
|
auto s = Scripting::self()->findScript(scriptToLoad);
|
|
|
|
auto configGroup = s->config();
|
|
|
|
configGroup.writeEntry("Edge", int(KWin::ElectricLeft));
|
|
|
|
configGroup.sync();
|
|
|
|
const QPoint triggerPos = QPoint(0, 512);
|
|
|
|
|
|
|
|
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
|
|
|
s->run();
|
|
|
|
QVERIFY(runningChangedSpy.wait());
|
|
|
|
|
|
|
|
QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged);
|
|
|
|
QVERIFY(showDesktopSpy.isValid());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// trigger the edge
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(triggerPos);
|
2016-10-07 12:29:29 +00:00
|
|
|
QCOMPARE(showDesktopSpy.count(), 1);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// reset
|
|
|
|
KWin::Cursors::self()->mouse()->setPos(500, 500);
|
2016-10-07 12:29:29 +00:00
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
showDesktopSpy.clear();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// trigger again, to show that retriggering works
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(triggerPos);
|
2016-10-07 12:29:29 +00:00
|
|
|
QCOMPARE(showDesktopSpy.count(), 1);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// reset
|
|
|
|
KWin::Cursors::self()->mouse()->setPos(500, 500);
|
2016-10-07 12:29:29 +00:00
|
|
|
workspace()->slotToggleShowDesktop();
|
|
|
|
showDesktopSpy.clear();
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// make the script unregister the edge
|
2016-10-07 12:29:29 +00:00
|
|
|
configGroup.writeEntry("mode", "unregister");
|
|
|
|
triggerConfigReload();
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(triggerPos);
|
2022-03-23 10:13:38 +00:00
|
|
|
QCOMPARE(showDesktopSpy.count(), 0); // not triggered
|
2016-10-07 12:29:29 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// force the script to unregister a non-registered edge to prove it doesn't explode
|
2016-10-07 12:29:29 +00:00
|
|
|
triggerConfigReload();
|
|
|
|
}
|
|
|
|
|
2017-04-01 20:38:58 +00:00
|
|
|
void ScreenEdgeTest::testDeclarativeTouchEdge()
|
|
|
|
{
|
|
|
|
const QString scriptToLoad = QFINDTESTDATA("./scripts/screenedgetouch.qml");
|
|
|
|
QVERIFY(!scriptToLoad.isEmpty());
|
|
|
|
QVERIFY(Scripting::self()->loadDeclarativeScript(scriptToLoad) != -1);
|
|
|
|
QVERIFY(Scripting::self()->isScriptLoaded(scriptToLoad));
|
|
|
|
|
|
|
|
auto s = Scripting::self()->findScript(scriptToLoad);
|
|
|
|
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
|
|
|
s->run();
|
|
|
|
QTRY_COMPARE(runningChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
QSignalSpy showDesktopSpy(workspace(), &Workspace::showingDesktopChanged);
|
|
|
|
QVERIFY(showDesktopSpy.isValid());
|
|
|
|
|
|
|
|
// Trigger the edge through touch
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::touchDown(0, QPointF(0, 50), timestamp++);
|
|
|
|
Test::touchMotion(0, QPointF(500, 50), timestamp++);
|
|
|
|
Test::touchUp(0, timestamp++);
|
2017-04-01 20:38:58 +00:00
|
|
|
|
|
|
|
QVERIFY(showDesktopSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-08-02 07:12:57 +00:00
|
|
|
WAYLANDTEST_MAIN(ScreenEdgeTest)
|
|
|
|
#include "screenedge_test.moc"
|