2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-07-20 18:49:42 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
|
2017-07-20 18:49:42 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-07-20 18:49:42 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2017-07-20 18:49:42 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "scripting/scripting.h"
|
|
|
|
#include "useractions.h"
|
2017-07-21 05:12:36 +00:00
|
|
|
#include "virtualdesktops.h"
|
2017-07-20 18:49:42 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2017-07-20 18:49:42 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingReply>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_kwinbindings-0");
|
|
|
|
|
|
|
|
class KWinBindingsTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testSwitchWindow();
|
|
|
|
void testSwitchWindowScript();
|
2017-07-21 05:12:36 +00:00
|
|
|
void testWindowToDesktop_data();
|
|
|
|
void testWindowToDesktop();
|
2017-07-20 18:49:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void KWinBindingsTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2017-07-20 18:49:42 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2017-07-20 18:49:42 +00:00
|
|
|
|
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
2017-07-20 18:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinBindingsTest::init()
|
|
|
|
{
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2017-07-20 18:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinBindingsTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinBindingsTest::testSwitchWindow()
|
|
|
|
{
|
|
|
|
// first create windows
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface3(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface4(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface4(Test::createXdgToplevelSurface(surface4.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c4 = Test::renderAndWaitForShown(surface4.data(), QSize(100, 50), Qt::blue);
|
|
|
|
|
|
|
|
QVERIFY(c4->isActive());
|
|
|
|
QVERIFY(c4 != c3);
|
|
|
|
QVERIFY(c3 != c2);
|
|
|
|
QVERIFY(c2 != c1);
|
|
|
|
|
|
|
|
// let's position all windows
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
c1->move(QPoint(0, 0));
|
|
|
|
c2->move(QPoint(200, 0));
|
|
|
|
c3->move(QPoint(200, 200));
|
|
|
|
c4->move(QPoint(0, 200));
|
2017-07-20 18:49:42 +00:00
|
|
|
|
|
|
|
// now let's trigger the shortcuts
|
|
|
|
|
|
|
|
// invoke global shortcut through dbus
|
2022-03-23 10:13:38 +00:00
|
|
|
auto invokeShortcut = [](const QString &shortcut) {
|
2017-07-20 18:49:42 +00:00
|
|
|
auto msg = QDBusMessage::createMethodCall(
|
|
|
|
QStringLiteral("org.kde.kglobalaccel"),
|
|
|
|
QStringLiteral("/component/kwin"),
|
|
|
|
QStringLiteral("org.kde.kglobalaccel.Component"),
|
|
|
|
QStringLiteral("invokeShortcut"));
|
|
|
|
msg.setArguments(QList<QVariant>{shortcut});
|
|
|
|
QDBusConnection::sessionBus().asyncCall(msg);
|
|
|
|
};
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Up"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c1);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Right"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c2);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Down"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c3);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Left"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c4);
|
2017-07-20 19:52:17 +00:00
|
|
|
// test opposite direction
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Left"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c3);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Down"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c2);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Right"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c1);
|
|
|
|
invokeShortcut(QStringLiteral("Switch Window Up"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c4);
|
2017-07-20 18:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KWinBindingsTest::testSwitchWindowScript()
|
|
|
|
{
|
|
|
|
QVERIFY(Scripting::self());
|
|
|
|
|
|
|
|
// first create windows
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface3(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::blue);
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface4(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface4(Test::createXdgToplevelSurface(surface4.data()));
|
2017-07-20 18:49:42 +00:00
|
|
|
auto c4 = Test::renderAndWaitForShown(surface4.data(), QSize(100, 50), Qt::blue);
|
|
|
|
|
|
|
|
QVERIFY(c4->isActive());
|
|
|
|
QVERIFY(c4 != c3);
|
|
|
|
QVERIFY(c3 != c2);
|
|
|
|
QVERIFY(c2 != c1);
|
|
|
|
|
|
|
|
// let's position all windows
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
c1->move(QPoint(0, 0));
|
|
|
|
c2->move(QPoint(200, 0));
|
|
|
|
c3->move(QPoint(200, 200));
|
|
|
|
c4->move(QPoint(0, 200));
|
2017-07-20 18:49:42 +00:00
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
auto runScript = [](const QString &slot) {
|
2017-07-20 18:49:42 +00:00
|
|
|
QTemporaryFile tmpFile;
|
|
|
|
QVERIFY(tmpFile.open());
|
|
|
|
QTextStream out(&tmpFile);
|
|
|
|
out << "workspace." << slot << "()";
|
|
|
|
out.flush();
|
|
|
|
|
|
|
|
const int id = Scripting::self()->loadScript(tmpFile.fileName());
|
|
|
|
QVERIFY(id != -1);
|
|
|
|
QVERIFY(Scripting::self()->isScriptLoaded(tmpFile.fileName()));
|
|
|
|
auto s = Scripting::self()->findScript(tmpFile.fileName());
|
|
|
|
QVERIFY(s);
|
|
|
|
QSignalSpy runningChangedSpy(s, &AbstractScript::runningChanged);
|
|
|
|
QVERIFY(runningChangedSpy.isValid());
|
|
|
|
s->run();
|
2017-08-13 15:08:49 +00:00
|
|
|
QTRY_COMPARE(runningChangedSpy.count(), 1);
|
2017-07-20 18:49:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
runScript(QStringLiteral("slotSwitchWindowUp"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c1);
|
|
|
|
runScript(QStringLiteral("slotSwitchWindowRight"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c2);
|
|
|
|
runScript(QStringLiteral("slotSwitchWindowDown"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c3);
|
|
|
|
runScript(QStringLiteral("slotSwitchWindowLeft"));
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), c4);
|
|
|
|
}
|
|
|
|
|
2017-07-21 05:12:36 +00:00
|
|
|
void KWinBindingsTest::testWindowToDesktop_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("desktop");
|
|
|
|
|
|
|
|
QTest::newRow("2") << 2;
|
|
|
|
QTest::newRow("3") << 3;
|
|
|
|
QTest::newRow("4") << 4;
|
|
|
|
QTest::newRow("5") << 5;
|
|
|
|
QTest::newRow("6") << 6;
|
|
|
|
QTest::newRow("7") << 7;
|
|
|
|
QTest::newRow("8") << 8;
|
|
|
|
QTest::newRow("9") << 9;
|
|
|
|
QTest::newRow("10") << 10;
|
|
|
|
QTest::newRow("11") << 11;
|
|
|
|
QTest::newRow("12") << 12;
|
|
|
|
QTest::newRow("13") << 13;
|
|
|
|
QTest::newRow("14") << 14;
|
|
|
|
QTest::newRow("15") << 15;
|
|
|
|
QTest::newRow("16") << 16;
|
|
|
|
QTest::newRow("17") << 17;
|
|
|
|
QTest::newRow("18") << 18;
|
|
|
|
QTest::newRow("19") << 19;
|
|
|
|
QTest::newRow("20") << 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KWinBindingsTest::testWindowToDesktop()
|
|
|
|
{
|
|
|
|
// first go to desktop one
|
|
|
|
VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().first());
|
|
|
|
|
|
|
|
// now create a window
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.data()));
|
2017-07-21 05:12:36 +00:00
|
|
|
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
|
2022-04-22 17:39:12 +00:00
|
|
|
QSignalSpy desktopChangedSpy(c, &Window::desktopChanged);
|
2017-07-21 05:12:36 +00:00
|
|
|
QVERIFY(desktopChangedSpy.isValid());
|
|
|
|
QCOMPARE(workspace()->activeClient(), c);
|
|
|
|
|
|
|
|
QFETCH(int, desktop);
|
|
|
|
VirtualDesktopManager::self()->setCount(desktop);
|
|
|
|
|
|
|
|
// now trigger the shortcut
|
2022-03-23 10:13:38 +00:00
|
|
|
auto invokeShortcut = [](int desktop) {
|
2017-07-21 05:12:36 +00:00
|
|
|
auto msg = QDBusMessage::createMethodCall(
|
|
|
|
QStringLiteral("org.kde.kglobalaccel"),
|
|
|
|
QStringLiteral("/component/kwin"),
|
|
|
|
QStringLiteral("org.kde.kglobalaccel.Component"),
|
|
|
|
QStringLiteral("invokeShortcut"));
|
|
|
|
msg.setArguments(QList<QVariant>{QStringLiteral("Window to Desktop %1").arg(desktop)});
|
|
|
|
QDBusConnection::sessionBus().asyncCall(msg);
|
|
|
|
};
|
|
|
|
invokeShortcut(desktop);
|
|
|
|
QVERIFY(desktopChangedSpy.wait());
|
|
|
|
QCOMPARE(c->desktop(), desktop);
|
|
|
|
// back to desktop 1
|
|
|
|
invokeShortcut(1);
|
|
|
|
QVERIFY(desktopChangedSpy.wait());
|
|
|
|
QCOMPARE(c->desktop(), 1);
|
|
|
|
// invoke with one desktop too many
|
|
|
|
invokeShortcut(desktop + 1);
|
|
|
|
// that should fail
|
|
|
|
QVERIFY(!desktopChangedSpy.wait(100));
|
|
|
|
}
|
|
|
|
|
2017-07-20 18:49:42 +00:00
|
|
|
WAYLANDTEST_MAIN(KWinBindingsTest)
|
|
|
|
#include "kwinbindings_test.moc"
|