2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-13 12:35:01 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-08-13 12:35:01 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2022-02-23 13:27:05 +00:00
|
|
|
#include <config-kwin.h>
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2016-08-13 12:35:01 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2016-08-13 12:35:01 +00:00
|
|
|
#include "cursor.h"
|
2016-08-13 13:09:21 +00:00
|
|
|
#include "input.h"
|
2017-01-21 19:13:09 +00:00
|
|
|
#include "keyboard_input.h"
|
2016-08-13 12:35:01 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_modifier_only_shortcut-0");
|
|
|
|
static const QString s_serviceName = QStringLiteral("org.kde.KWin.Test.ModifierOnlyShortcut");
|
|
|
|
static const QString s_path = QStringLiteral("/Test");
|
|
|
|
|
|
|
|
class ModifierOnlyShortcutTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testTrigger_data();
|
|
|
|
void testTrigger();
|
2016-08-17 06:39:51 +00:00
|
|
|
void testCapsLock();
|
2016-10-06 05:36:12 +00:00
|
|
|
void testGlobalShortcutsDisabled_data();
|
|
|
|
void testGlobalShortcutsDisabled();
|
2016-08-13 12:35:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Target : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.Test.ModifierOnlyShortcut")
|
|
|
|
|
|
|
|
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;
|
2016-08-13 12:35:01 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
Q_SCRIPTABLE void shortcut();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void shortcutTriggered();
|
|
|
|
};
|
|
|
|
|
|
|
|
Target::Target()
|
|
|
|
: QObject()
|
|
|
|
{
|
|
|
|
QDBusConnection::sessionBus().registerService(s_serviceName);
|
|
|
|
QDBusConnection::sessionBus().registerObject(s_path, s_serviceName, this, QDBusConnection::ExportScriptableSlots);
|
|
|
|
}
|
|
|
|
|
|
|
|
Target::~Target()
|
|
|
|
{
|
|
|
|
QDBusConnection::sessionBus().unregisterObject(s_path);
|
|
|
|
QDBusConnection::sessionBus().unregisterService(s_serviceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Target::shortcut()
|
|
|
|
{
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT shortcutTriggered();
|
2016-08-13 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::initTestCase()
|
|
|
|
{
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-08-13 12:35:01 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2016-08-13 12:35:01 +00:00
|
|
|
|
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
2016-08-17 06:35:15 +00:00
|
|
|
qputenv("KWIN_XKB_DEFAULT_KEYMAP", "1");
|
2017-09-17 18:54:32 +00:00
|
|
|
qputenv("XKB_DEFAULT_RULES", "evdev");
|
2016-08-13 12:35:01 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
2016-08-13 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::init()
|
|
|
|
{
|
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));
|
2016-08-13 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::cleanup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::testTrigger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("metaConfig");
|
|
|
|
QTest::addColumn<QStringList>("altConfig");
|
|
|
|
QTest::addColumn<QStringList>("controlConfig");
|
|
|
|
QTest::addColumn<QStringList>("shiftConfig");
|
|
|
|
QTest::addColumn<int>("modifier");
|
|
|
|
QTest::addColumn<QList<int>>("nonTriggeringMods");
|
|
|
|
|
|
|
|
const QStringList trigger = QStringList{s_serviceName, s_path, s_serviceName, QStringLiteral("shortcut")};
|
|
|
|
const QStringList e = QStringList();
|
|
|
|
|
|
|
|
QTest::newRow("leftMeta") << trigger << e << e << e << KEY_LEFTMETA << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("rightMeta") << trigger << e << e << e << KEY_RIGHTMETA << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("leftAlt") << e << trigger << e << e << KEY_LEFTALT << QList<int>{KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("rightAlt") << e << trigger << e << e << KEY_RIGHTALT << QList<int>{KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("leftControl") << e << e << trigger << e << KEY_LEFTCTRL << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("rightControl") << e << e << trigger << e << KEY_RIGHTCTRL << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
|
|
|
|
QTest::newRow("leftShift") << e << e << e << trigger << KEY_LEFTSHIFT << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTMETA, KEY_RIGHTMETA};
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("rightShift") << e << e << e << trigger << KEY_RIGHTSHIFT << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTMETA, KEY_RIGHTMETA};
|
2016-08-13 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::testTrigger()
|
|
|
|
{
|
|
|
|
// this test verifies that modifier only shortcut triggers correctly
|
|
|
|
Target target;
|
|
|
|
QSignalSpy triggeredSpy(&target, &Target::shortcutTriggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
|
|
|
|
KConfigGroup group = kwinApp()->config()->group("ModifierOnlyShortcuts");
|
|
|
|
QFETCH(QStringList, metaConfig);
|
|
|
|
QFETCH(QStringList, altConfig);
|
|
|
|
QFETCH(QStringList, shiftConfig);
|
|
|
|
QFETCH(QStringList, controlConfig);
|
|
|
|
group.writeEntry("Meta", metaConfig);
|
|
|
|
group.writeEntry("Alt", altConfig);
|
|
|
|
group.writeEntry("Shift", shiftConfig);
|
|
|
|
group.writeEntry("Control", controlConfig);
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
|
|
|
|
|
|
|
// configured shortcut should trigger
|
|
|
|
quint32 timestamp = 1;
|
|
|
|
QFETCH(int, modifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
|
|
|
|
// the other shortcuts should not trigger
|
|
|
|
QFETCH(QList<int>, nonTriggeringMods);
|
|
|
|
for (auto it = nonTriggeringMods.constBegin(), end = nonTriggeringMods.constEnd(); it != end; it++) {
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(*it, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(*it, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try configured again
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// click another key while modifier is held
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_A, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_A, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// release other key after modifier release
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_A, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_A, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// press key before pressing modifier
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_A, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_A, timestamp++);
|
2016-08-13 12:35:01 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
2016-08-13 13:09:21 +00:00
|
|
|
|
|
|
|
// mouse button pressed before clicking modifier
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerButtonPressed(BTN_LEFT, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::LeftButton);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
|
|
|
Test::pointerButtonReleased(BTN_LEFT, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// mouse button press before mod press, release before mod release
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerButtonPressed(BTN_LEFT, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::LeftButton);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::pointerButtonReleased(BTN_LEFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// mouse button click while mod is pressed
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::pointerButtonPressed(BTN_LEFT, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::LeftButton);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::pointerButtonReleased(BTN_LEFT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 13:09:21 +00:00
|
|
|
QCOMPARE(input()->qtButtonStates(), Qt::NoButton);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
2016-08-13 13:15:54 +00:00
|
|
|
|
|
|
|
// scroll while mod is pressed
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::pointerAxisVertical(5.0, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 13:15:54 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// same for horizontal
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::pointerAxisHorizontal(5.0, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-13 13:15:54 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
2016-08-16 06:19:45 +00:00
|
|
|
|
2022-02-28 18:58:35 +00:00
|
|
|
#if KWIN_BUILD_SCREENLOCKER
|
2016-08-16 06:19:45 +00:00
|
|
|
// now try to lock the screen while modifier key is pressed
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
2016-08-16 06:19:45 +00:00
|
|
|
QVERIFY(Test::lockScreen());
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-16 06:19:45 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
// now trigger while screen is locked, should also not work
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-16 06:19:45 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
|
|
|
|
|
|
|
QVERIFY(Test::unlockScreen());
|
2022-02-23 13:27:05 +00:00
|
|
|
#endif
|
2016-08-13 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:39:51 +00:00
|
|
|
void ModifierOnlyShortcutTest::testCapsLock()
|
|
|
|
{
|
|
|
|
// this test verifies that Capslock does not trigger the shift shortcut
|
2017-01-22 08:44:15 +00:00
|
|
|
// but other shortcuts still trigger even when Capslock is on
|
2016-08-17 06:39:51 +00:00
|
|
|
Target target;
|
|
|
|
QSignalSpy triggeredSpy(&target, &Target::shortcutTriggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
|
|
|
|
KConfigGroup group = kwinApp()->config()->group("ModifierOnlyShortcuts");
|
|
|
|
group.writeEntry("Meta", QStringList());
|
|
|
|
group.writeEntry("Alt", QStringList());
|
|
|
|
group.writeEntry("Shift", QStringList{s_serviceName, s_path, s_serviceName, QStringLiteral("shortcut")});
|
|
|
|
group.writeEntry("Control", QStringList());
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
|
|
|
|
|
|
|
// first test that the normal shortcut triggers
|
|
|
|
quint32 timestamp = 1;
|
|
|
|
const int modifier = KEY_LEFTSHIFT;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-17 06:39:51 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
|
|
|
|
// now capslock
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
2016-08-17 06:39:51 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier);
|
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
|
|
|
|
// currently caps lock is on
|
2017-01-22 08:44:15 +00:00
|
|
|
// shift still triggers
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-08-17 06:39:51 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier);
|
2017-01-22 08:44:15 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 2);
|
2016-08-17 06:39:51 +00:00
|
|
|
|
2017-01-22 08:44:15 +00:00
|
|
|
// meta should also trigger
|
2017-01-21 19:13:09 +00:00
|
|
|
group.writeEntry("Meta", QStringList{s_serviceName, s_path, s_serviceName, QStringLiteral("shortcut")});
|
|
|
|
group.writeEntry("Alt", QStringList());
|
|
|
|
group.writeEntry("Shift", QStringList{});
|
|
|
|
group.writeEntry("Control", QStringList());
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTMETA, timestamp++);
|
2017-01-21 19:13:09 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier | Qt::MetaModifier);
|
|
|
|
QCOMPARE(input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts(), Qt::MetaModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTMETA, timestamp++);
|
2017-01-22 08:44:15 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 3);
|
|
|
|
|
|
|
|
// set back to shift to ensure we don't trigger with capslock
|
|
|
|
group.writeEntry("Meta", QStringList());
|
|
|
|
group.writeEntry("Alt", QStringList());
|
|
|
|
group.writeEntry("Shift", QStringList{s_serviceName, s_path, s_serviceName, QStringLiteral("shortcut")});
|
|
|
|
group.writeEntry("Control", QStringList());
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
2017-01-21 19:13:09 +00:00
|
|
|
|
2016-08-17 06:39:51 +00:00
|
|
|
// release caps lock
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
2016-08-17 06:39:51 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::NoModifier);
|
2017-01-22 08:44:15 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 3);
|
2016-08-17 06:39:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 05:36:12 +00:00
|
|
|
void ModifierOnlyShortcutTest::testGlobalShortcutsDisabled_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QStringList>("metaConfig");
|
|
|
|
QTest::addColumn<QStringList>("altConfig");
|
|
|
|
QTest::addColumn<QStringList>("controlConfig");
|
|
|
|
QTest::addColumn<QStringList>("shiftConfig");
|
|
|
|
QTest::addColumn<int>("modifier");
|
|
|
|
|
|
|
|
const QStringList trigger = QStringList{s_serviceName, s_path, s_serviceName, QStringLiteral("shortcut")};
|
|
|
|
const QStringList e = QStringList();
|
|
|
|
|
|
|
|
QTest::newRow("leftMeta") << trigger << e << e << e << KEY_LEFTMETA;
|
|
|
|
QTest::newRow("rightMeta") << trigger << e << e << e << KEY_RIGHTMETA;
|
|
|
|
QTest::newRow("leftAlt") << e << trigger << e << e << KEY_LEFTALT;
|
|
|
|
QTest::newRow("rightAlt") << e << trigger << e << e << KEY_RIGHTALT;
|
|
|
|
QTest::newRow("leftControl") << e << e << trigger << e << KEY_LEFTCTRL;
|
|
|
|
QTest::newRow("rightControl") << e << e << trigger << e << KEY_RIGHTCTRL;
|
|
|
|
QTest::newRow("leftShift") << e << e << e << trigger << KEY_LEFTSHIFT;
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("rightShift") << e << e << e << trigger << KEY_RIGHTSHIFT;
|
2016-10-06 05:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModifierOnlyShortcutTest::testGlobalShortcutsDisabled()
|
|
|
|
{
|
|
|
|
// this test verifies that when global shortcuts are disabled inside KWin (e.g. through a window rule)
|
|
|
|
// the modifier only shortcuts do not trigger.
|
|
|
|
// see BUG: 370146
|
|
|
|
Target target;
|
|
|
|
QSignalSpy triggeredSpy(&target, &Target::shortcutTriggered);
|
|
|
|
QVERIFY(triggeredSpy.isValid());
|
|
|
|
|
|
|
|
KConfigGroup group = kwinApp()->config()->group("ModifierOnlyShortcuts");
|
|
|
|
QFETCH(QStringList, metaConfig);
|
|
|
|
QFETCH(QStringList, altConfig);
|
|
|
|
QFETCH(QStringList, shiftConfig);
|
|
|
|
QFETCH(QStringList, controlConfig);
|
|
|
|
group.writeEntry("Meta", metaConfig);
|
|
|
|
group.writeEntry("Alt", altConfig);
|
|
|
|
group.writeEntry("Shift", shiftConfig);
|
|
|
|
group.writeEntry("Control", controlConfig);
|
|
|
|
group.sync();
|
|
|
|
workspace()->slotReconfigure();
|
|
|
|
|
|
|
|
// trigger once to verify the shortcut works
|
|
|
|
quint32 timestamp = 1;
|
|
|
|
QFETCH(int, modifier);
|
|
|
|
QVERIFY(!workspace()->globalShortcutsDisabled());
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-10-06 05:36:12 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
triggeredSpy.clear();
|
|
|
|
|
|
|
|
// now disable global shortcuts
|
|
|
|
workspace()->disableGlobalShortcutsForClient(true);
|
|
|
|
QVERIFY(workspace()->globalShortcutsDisabled());
|
|
|
|
// Should not get triggered
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-10-06 05:36:12 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 0);
|
|
|
|
triggeredSpy.clear();
|
|
|
|
|
|
|
|
// enable again
|
|
|
|
workspace()->disableGlobalShortcutsForClient(false);
|
|
|
|
QVERIFY(!workspace()->globalShortcutsDisabled());
|
|
|
|
// should get triggered again
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(modifier, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(modifier, timestamp++);
|
2016-10-06 05:36:12 +00:00
|
|
|
QCOMPARE(triggeredSpy.count(), 1);
|
|
|
|
}
|
|
|
|
|
2016-08-13 12:35:01 +00:00
|
|
|
WAYLANDTEST_MAIN(ModifierOnlyShortcutTest)
|
|
|
|
#include "modifier_only_shortcut_test.moc"
|