2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2018-12-02 12:09:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2018 Martin Flöser <mgraesslin@kde.org>
|
2018-12-02 12:09:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2018-12-02 12:09:37 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2018-12-02 12:09:37 +00:00
|
|
|
#include "input.h"
|
|
|
|
#include "keyboard_input.h"
|
2023-02-09 13:07:56 +00:00
|
|
|
#include "pointer_input.h"
|
2018-12-02 12:09:37 +00:00
|
|
|
#include "screenedge.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KGlobalAccel>
|
|
|
|
|
2022-10-24 14:41:35 +00:00
|
|
|
#include <QAction>
|
2018-12-02 12:09:37 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_no_global_shortcuts-0");
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(KWin::ElectricBorder)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test verifies the NoGlobalShortcuts initialization flag
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2018-12-02 12:09:37 +00:00
|
|
|
class NoGlobalShortcutsTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testKGlobalAccel();
|
|
|
|
void testPointerShortcut();
|
|
|
|
void testAxisShortcut_data();
|
|
|
|
void testAxisShortcut();
|
|
|
|
void testScreenEdge();
|
|
|
|
};
|
|
|
|
|
|
|
|
class Target : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
Target();
|
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
|
|
|
~Target() override;
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
Q_SCRIPTABLE void shortcut();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void shortcutTriggered();
|
|
|
|
};
|
|
|
|
|
|
|
|
Target::Target()
|
|
|
|
: QObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Target::~Target()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Target::shortcut()
|
|
|
|
{
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT shortcutTriggered();
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::initTestCase()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KWin::ElectricBorder>("ElectricBorder");
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName, KWin::WaylandServer::InitializationFlag::NoGlobalShortcuts));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
|
|
|
qputenv("KWIN_XKB_DEFAULT_KEYMAP", "1");
|
|
|
|
qputenv("XKB_DEFAULT_RULES", "evdev");
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::init()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2023-02-09 13:07:56 +00:00
|
|
|
KWin::input()->pointer()->warp(QPoint(640, 512));
|
2018-12-02 12:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::testKGlobalAccel()
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QAction> action(new QAction(nullptr));
|
2022-11-01 17:46:03 +00:00
|
|
|
action->setProperty("componentName", QStringLiteral("kwin"));
|
2018-12-02 12:09:37 +00:00
|
|
|
action->setObjectName(QStringLiteral("globalshortcuts-test-meta-shift-w"));
|
2022-08-01 21:29:02 +00:00
|
|
|
QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
|
|
|
|
KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::META | Qt::SHIFT | Qt::Key_W}, KGlobalAccel::NoAutoloading);
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
// press meta+shift+w
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::MetaModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier | Qt::MetaModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_W, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_W, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
// release meta+shift
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
|
2023-01-11 22:24:42 +00:00
|
|
|
QVERIFY(!triggeredSpy.wait(100));
|
2018-12-02 12:09:37 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::testPointerShortcut()
|
|
|
|
{
|
|
|
|
// based on LockScreenTest::testPointerShortcut
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QAction> action(new QAction(nullptr));
|
|
|
|
QSignalSpy actionSpy(action.get(), &QAction::triggered);
|
|
|
|
input()->registerPointerShortcut(Qt::MetaModifier, Qt::LeftButton, action.get());
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
// try to trigger the shortcut
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
|
|
|
Test::pointerButtonPressed(BTN_LEFT, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCoreApplication::instance()->processEvents();
|
|
|
|
QCOMPARE(actionSpy.count(), 0);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerButtonReleased(BTN_LEFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCoreApplication::instance()->processEvents();
|
|
|
|
QCOMPARE(actionSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::testAxisShortcut_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::Orientation>("direction");
|
|
|
|
QTest::addColumn<int>("sign");
|
|
|
|
|
|
|
|
QTest::newRow("up") << Qt::Vertical << 1;
|
|
|
|
QTest::newRow("down") << Qt::Vertical << -1;
|
|
|
|
QTest::newRow("left") << Qt::Horizontal << 1;
|
|
|
|
QTest::newRow("right") << Qt::Horizontal << -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::testAxisShortcut()
|
|
|
|
{
|
|
|
|
// based on LockScreenTest::testAxisShortcut
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QAction> action(new QAction(nullptr));
|
|
|
|
QSignalSpy actionSpy(action.get(), &QAction::triggered);
|
2018-12-02 12:09:37 +00:00
|
|
|
QFETCH(Qt::Orientation, direction);
|
|
|
|
QFETCH(int, sign);
|
|
|
|
PointerAxisDirection axisDirection = PointerAxisUp;
|
|
|
|
if (direction == Qt::Vertical) {
|
|
|
|
axisDirection = sign > 0 ? PointerAxisUp : PointerAxisDown;
|
|
|
|
} else {
|
|
|
|
axisDirection = sign > 0 ? PointerAxisLeft : PointerAxisRight;
|
|
|
|
}
|
2022-08-01 21:29:02 +00:00
|
|
|
input()->registerAxisShortcut(Qt::MetaModifier, axisDirection, action.get());
|
2018-12-02 12:09:37 +00:00
|
|
|
|
|
|
|
// try to trigger the shortcut
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
2022-03-25 12:20:32 +00:00
|
|
|
if (direction == Qt::Vertical) {
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerAxisVertical(sign * 5.0, timestamp++);
|
2022-03-25 12:20:32 +00:00
|
|
|
} else {
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerAxisHorizontal(sign * 5.0, timestamp++);
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2018-12-02 12:09:37 +00:00
|
|
|
QCoreApplication::instance()->processEvents();
|
|
|
|
QCOMPARE(actionSpy.count(), 0);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCoreApplication::instance()->processEvents();
|
|
|
|
QCOMPARE(actionSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NoGlobalShortcutsTest::testScreenEdge()
|
|
|
|
{
|
|
|
|
// based on LockScreenTest::testScreenEdge
|
2022-07-30 22:55:56 +00:00
|
|
|
QSignalSpy screenEdgeSpy(workspace()->screenEdges(), &ScreenEdges::approaching);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCOMPARE(screenEdgeSpy.count(), 0);
|
|
|
|
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerMotion({5, 5}, timestamp++);
|
2018-12-02 12:09:37 +00:00
|
|
|
QCOMPARE(screenEdgeSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(NoGlobalShortcutsTest)
|
|
|
|
#include "no_global_shortcuts_test.moc"
|