18#include <KConfigGroup>
19#include <KGlobalAccel>
22#include <QDBusConnection>
24#include <linux/input.h>
28static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_no_global_shortcuts-0");
29static const QString s_serviceName = QStringLiteral(
"org.kde.KWin.Test.ModifierOnlyShortcut");
30static const QString
s_path = QStringLiteral(
"/Test");
45 void testTrigger_data();
47 void testKGlobalAccel();
48 void testPointerShortcut();
49 void testAxisShortcut_data();
50 void testAxisShortcut();
51 void testScreenEdge();
54class Target :
public QObject
57 Q_CLASSINFO(
"D-Bus Interface",
"org.kde.KWin.Test.ModifierOnlyShortcut")
73 QDBusConnection::sessionBus().registerService(s_serviceName);
74 QDBusConnection::sessionBus().registerObject(
s_path, s_serviceName,
this, QDBusConnection::ExportScriptableSlots);
79 QDBusConnection::sessionBus().unregisterObject(s_path);
80 QDBusConnection::sessionBus().unregisterService(s_serviceName);
88void NoGlobalShortcutsTest::initTestCase()
90 qRegisterMetaType<KWin::ElectricBorder>(
"ElectricBorder");
94 QRect(0, 0, 1280, 1024),
95 QRect(1280, 0, 1280, 1024),
98 kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
99 qputenv(
"KWIN_XKB_DEFAULT_KEYMAP",
"1");
100 qputenv(
"XKB_DEFAULT_RULES",
"evdev");
103 QVERIFY(applicationStartedSpy.wait());
106void NoGlobalShortcutsTest::init()
112void NoGlobalShortcutsTest::cleanup()
116void NoGlobalShortcutsTest::testTrigger_data()
118 QTest::addColumn<QStringList>(
"metaConfig");
119 QTest::addColumn<QStringList>(
"altConfig");
120 QTest::addColumn<QStringList>(
"controlConfig");
121 QTest::addColumn<QStringList>(
"shiftConfig");
122 QTest::addColumn<int>(
"modifier");
123 QTest::addColumn<QList<int>>(
"nonTriggeringMods");
125 const QStringList trigger = QStringList{s_serviceName,
s_path, s_serviceName, QStringLiteral(
"shortcut")};
126 const QStringList e = QStringList();
128 QTest::newRow(
"leftMeta") << trigger << e << e << e << KEY_LEFTMETA << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
129 QTest::newRow(
"rightMeta") << trigger << e << e << e << KEY_RIGHTMETA << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
130 QTest::newRow(
"leftAlt") << e << trigger << e << e << KEY_LEFTALT << QList<int>{KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
131 QTest::newRow(
"rightAlt") << e << trigger << e << e << KEY_RIGHTALT << QList<int>{KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
132 QTest::newRow(
"leftControl") << e << e << trigger << e << KEY_LEFTCTRL << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
133 QTest::newRow(
"rightControl") << e << e << trigger << e << KEY_RIGHTCTRL << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTMETA, KEY_RIGHTMETA, KEY_LEFTSHIFT, KEY_RIGHTSHIFT};
134 QTest::newRow(
"leftShift") << e << e << e << trigger << KEY_LEFTSHIFT << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTMETA, KEY_RIGHTMETA};
135 QTest::newRow(
"rightShift") << e << e << e << trigger << KEY_RIGHTSHIFT << QList<int>{KEY_LEFTALT, KEY_RIGHTALT, KEY_LEFTCTRL, KEY_RIGHTCTRL, KEY_LEFTMETA, KEY_RIGHTMETA};
138void NoGlobalShortcutsTest::testTrigger()
144 KConfigGroup group = kwinApp()->config()->group(QStringLiteral(
"ModifierOnlyShortcuts"));
145 QFETCH(QStringList, metaConfig);
146 QFETCH(QStringList, altConfig);
147 QFETCH(QStringList, shiftConfig);
148 QFETCH(QStringList, controlConfig);
149 group.writeEntry(
"Meta", metaConfig);
150 group.writeEntry(
"Alt", altConfig);
151 group.writeEntry(
"Shift", shiftConfig);
152 group.writeEntry(
"Control", controlConfig);
157 quint32 timestamp = 1;
158 QFETCH(
int, modifier);
161 QCOMPARE(triggeredSpy.count(), 0);
164 QFETCH(QList<int>, nonTriggeringMods);
165 for (
auto it = nonTriggeringMods.constBegin(), end = nonTriggeringMods.constEnd(); it != end; it++) {
168 QCOMPARE(triggeredSpy.count(), 0);
172void NoGlobalShortcutsTest::testKGlobalAccel()
174 std::unique_ptr<QAction> action(
new QAction(
nullptr));
175 action->setProperty(
"componentName", QStringLiteral(
"kwin"));
176 action->setObjectName(QStringLiteral(
"globalshortcuts-test-meta-shift-w"));
177 QSignalSpy triggeredSpy(action.get(), &QAction::triggered);
178 KGlobalAccel::self()->setShortcut(action.get(), QList<QKeySequence>{Qt::META | Qt::SHIFT | Qt::Key_W}, KGlobalAccel::NoAutoloading);
181 quint32 timestamp = 0;
183 QCOMPARE(
input()->keyboardModifiers(), Qt::MetaModifier);
185 QCOMPARE(
input()->keyboardModifiers(), Qt::ShiftModifier | Qt::MetaModifier);
193 QVERIFY(!triggeredSpy.wait(100));
194 QCOMPARE(triggeredSpy.count(), 0);
197void NoGlobalShortcutsTest::testPointerShortcut()
200 std::unique_ptr<QAction> action(
new QAction(
nullptr));
201 QSignalSpy actionSpy(action.get(), &QAction::triggered);
205 quint32 timestamp = 1;
208 QCoreApplication::instance()->processEvents();
209 QCOMPARE(actionSpy.count(), 0);
212 QCoreApplication::instance()->processEvents();
213 QCOMPARE(actionSpy.count(), 0);
216void NoGlobalShortcutsTest::testAxisShortcut_data()
218 QTest::addColumn<Qt::Orientation>(
"direction");
219 QTest::addColumn<int>(
"sign");
221 QTest::newRow(
"up") << Qt::Vertical << 1;
222 QTest::newRow(
"down") << Qt::Vertical << -1;
223 QTest::newRow(
"left") << Qt::Horizontal << 1;
224 QTest::newRow(
"right") << Qt::Horizontal << -1;
227void NoGlobalShortcutsTest::testAxisShortcut()
230 std::unique_ptr<QAction> action(
new QAction(
nullptr));
231 QSignalSpy actionSpy(action.get(), &QAction::triggered);
232 QFETCH(Qt::Orientation, direction);
235 if (direction == Qt::Vertical) {
243 quint32 timestamp = 1;
245 if (direction == Qt::Vertical) {
250 QCoreApplication::instance()->processEvents();
251 QCOMPARE(actionSpy.count(), 0);
253 QCoreApplication::instance()->processEvents();
254 QCOMPARE(actionSpy.count(), 0);
257void NoGlobalShortcutsTest::testScreenEdge()
261 QCOMPARE(screenEdgeSpy.count(), 0);
263 quint32 timestamp = 1;
265 QCOMPARE(screenEdgeSpy.count(), 0);
269#include "no_global_shortcuts_test.moc"
void approaching(ElectricBorder border, qreal factor, const QRect &geometry)
void setActiveOutput(Output *output)
Q_SCRIPTABLE void shortcut()
#define WAYLANDTEST_MAIN(TestObject)
void keyboardKeyReleased(quint32 key, quint32 time)
void setOutputConfig(const QList< QRect > &geometries)
void pointerAxisVertical(qreal delta, quint32 time, qint32 discreteDelta=0, InputRedirection::PointerAxisSource source=InputRedirection::PointerAxisSourceUnknown)
void keyboardKeyPressed(quint32 key, quint32 time)
void pointerAxisHorizontal(qreal delta, quint32 time, qint32 discreteDelta=0, InputRedirection::PointerAxisSource source=InputRedirection::PointerAxisSourceUnknown)
void pointerButtonPressed(quint32 button, quint32 time)
void pointerMotion(const QPointF &position, quint32 time)
void pointerButtonReleased(quint32 button, quint32 time)
void init(xcb_connection_t *connection, xcb_window_t rootWindow)
PointerAxisDirection
The direction in which a pointer axis is moved.
WaylandServer * waylandServer()
InputRedirection * input()