2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-01-27 16:15:32 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Gräßlin <mgraesslin@kde.org>
|
2017-01-27 16:15:32 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-01-27 16:15:32 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
#include "keyboard_input.h"
|
2017-02-01 05:49:32 +00:00
|
|
|
#include "keyboard_layout.h"
|
2017-04-04 16:56:10 +00:00
|
|
|
#include "virtualdesktops.h"
|
2017-01-27 16:15:32 +00:00
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2017-04-06 05:13:44 +00:00
|
|
|
#include "workspace.h"
|
2022-10-31 21:14:40 +00:00
|
|
|
#include "xkb.h"
|
2017-01-27 16:15:32 +00:00
|
|
|
|
|
|
|
#include <KConfigGroup>
|
2017-02-11 08:46:33 +00:00
|
|
|
#include <KGlobalAccel>
|
2017-01-27 16:15:32 +00:00
|
|
|
|
2017-04-06 05:13:44 +00:00
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
2017-02-11 08:46:33 +00:00
|
|
|
#include <QAction>
|
2017-01-27 16:15:32 +00:00
|
|
|
#include <QDBusConnection>
|
2017-02-11 10:34:49 +00:00
|
|
|
#include <QDBusConnectionInterface>
|
2017-01-27 16:15:32 +00:00
|
|
|
#include <QDBusMessage>
|
2017-01-31 18:42:55 +00:00
|
|
|
#include <QDBusPendingCall>
|
2017-01-27 16:15:32 +00:00
|
|
|
|
2017-02-11 08:46:33 +00:00
|
|
|
#include <linux/input.h>
|
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_keyboard_laout-0");
|
|
|
|
|
|
|
|
class KeyboardLayoutTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-05-29 17:08:24 +00:00
|
|
|
public:
|
|
|
|
KeyboardLayoutTest()
|
|
|
|
: layoutsReconfiguredSpy(this, &KeyboardLayoutTest::layoutListChanged)
|
|
|
|
, layoutChangedSpy(this, &KeyboardLayoutTest::layoutChanged)
|
|
|
|
{
|
|
|
|
|
|
|
|
QVERIFY(QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("layoutListChanged"), this, SIGNAL(layoutListChanged())));
|
2021-01-09 17:41:32 +00:00
|
|
|
QVERIFY(QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("layoutChanged"), this, SIGNAL(layoutChanged(uint))));
|
2020-05-29 17:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2021-01-09 17:41:32 +00:00
|
|
|
void layoutChanged(uint index);
|
2020-05-29 17:08:24 +00:00
|
|
|
void layoutListChanged();
|
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testReconfigure();
|
2017-01-31 18:42:55 +00:00
|
|
|
void testChangeLayoutThroughDBus();
|
2017-02-11 08:46:33 +00:00
|
|
|
void testPerLayoutShortcut();
|
2017-02-11 10:34:49 +00:00
|
|
|
void testDBusServiceExport();
|
2017-04-04 16:56:10 +00:00
|
|
|
void testVirtualDesktopPolicy();
|
2017-04-06 05:13:44 +00:00
|
|
|
void testWindowPolicy();
|
2017-04-09 15:57:59 +00:00
|
|
|
void testApplicationPolicy();
|
2018-10-25 17:46:36 +00:00
|
|
|
void testNumLock();
|
2017-01-31 18:42:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void reconfigureLayouts();
|
2020-05-29 17:08:24 +00:00
|
|
|
void resetLayouts();
|
2021-01-09 17:41:32 +00:00
|
|
|
auto changeLayout(uint index);
|
2020-05-29 17:08:24 +00:00
|
|
|
void callSession(const QString &method);
|
|
|
|
QSignalSpy layoutsReconfiguredSpy;
|
|
|
|
QSignalSpy layoutChangedSpy;
|
|
|
|
KConfigGroup layoutGroup;
|
2017-01-27 16:15:32 +00:00
|
|
|
};
|
|
|
|
|
2017-01-31 18:42:55 +00:00
|
|
|
void KeyboardLayoutTest::reconfigureLayouts()
|
|
|
|
{
|
|
|
|
// create DBus signal to reload
|
|
|
|
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig"));
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(QDBusConnection::sessionBus().send(message));
|
|
|
|
|
2020-06-25 15:21:08 +00:00
|
|
|
QVERIFY(layoutsReconfiguredSpy.wait(1000));
|
|
|
|
QCOMPARE(layoutsReconfiguredSpy.count(), 1);
|
|
|
|
layoutsReconfiguredSpy.clear();
|
2020-05-29 17:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardLayoutTest::resetLayouts()
|
|
|
|
{
|
|
|
|
/* Switch Policy to destroy layouts from memory.
|
|
|
|
* On return to original Policy they should reload from disk.
|
|
|
|
*/
|
|
|
|
callSession(QStringLiteral("aboutToSaveSession"));
|
|
|
|
|
|
|
|
const QString policy = layoutGroup.readEntry("SwitchMode", "Global");
|
|
|
|
|
|
|
|
if (policy == QLatin1String("Global")) {
|
|
|
|
layoutGroup.writeEntry("SwitchMode", "Desktop");
|
|
|
|
} else {
|
|
|
|
layoutGroup.deleteEntry("SwitchMode");
|
|
|
|
}
|
|
|
|
reconfigureLayouts();
|
|
|
|
|
|
|
|
layoutGroup.writeEntry("SwitchMode", policy);
|
|
|
|
reconfigureLayouts();
|
|
|
|
|
|
|
|
callSession(QStringLiteral("loadSession"));
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
auto KeyboardLayoutTest::changeLayout(uint index)
|
|
|
|
{
|
|
|
|
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"),
|
|
|
|
QStringLiteral("/Layouts"),
|
|
|
|
QStringLiteral("org.kde.KeyboardLayouts"),
|
|
|
|
QStringLiteral("setLayout"));
|
2021-01-09 17:41:32 +00:00
|
|
|
msg << index;
|
2020-05-29 17:08:24 +00:00
|
|
|
return QDBusConnection::sessionBus().asyncCall(msg);
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
void KeyboardLayoutTest::callSession(const QString &method)
|
|
|
|
{
|
|
|
|
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
|
|
|
|
QStringLiteral("/Session"),
|
|
|
|
QStringLiteral("org.kde.KWin.Session"),
|
|
|
|
method);
|
|
|
|
msg << QLatin1String(); // session name
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(QDBusConnection::sessionBus().call(msg).type() != QDBusMessage::ErrorMessage);
|
2017-01-31 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
void KeyboardLayoutTest::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);
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2023-05-08 10:16:00 +00:00
|
|
|
Test::setOutputConfig({
|
|
|
|
QRect(0, 0, 1280, 1024),
|
|
|
|
QRect(1280, 0, 1280, 1024),
|
|
|
|
});
|
2017-01-27 16:15:32 +00:00
|
|
|
|
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
|
|
|
kwinApp()->setKxkbConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
|
|
|
|
layoutGroup.deleteGroup();
|
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2020-05-29 17:08:24 +00:00
|
|
|
|
|
|
|
// don't get DBus signal on one-layout configuration
|
2022-03-23 10:13:38 +00:00
|
|
|
// QVERIFY(layoutsReconfiguredSpy.wait());
|
|
|
|
// QCOMPARE(layoutsReconfiguredSpy.count(), 1);
|
|
|
|
// layoutsReconfiguredSpy.clear();
|
2017-01-27 16:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardLayoutTest::init()
|
|
|
|
{
|
2017-04-06 05:13:44 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2017-01-27 16:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardLayoutTest::cleanup()
|
|
|
|
{
|
2017-04-06 05:13:44 +00:00
|
|
|
Test::destroyWaylandConnection();
|
2017-01-27 16:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KeyboardLayoutTest::testReconfigure()
|
|
|
|
{
|
|
|
|
// verifies that we can change the keymap
|
|
|
|
|
|
|
|
// default should be a keymap with only us layout
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2021-01-09 17:41:32 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 1);
|
|
|
|
QCOMPARE(xkb->layoutName(0), QStringLiteral("English (US)"));
|
2017-01-27 16:15:32 +00:00
|
|
|
|
|
|
|
// create a new keymap
|
|
|
|
KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
|
2017-01-31 18:42:55 +00:00
|
|
|
reconfigureLayouts();
|
2017-01-27 16:15:32 +00:00
|
|
|
// now we should have two layouts
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 2u);
|
2017-01-27 16:15:32 +00:00
|
|
|
// default layout is German
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2021-01-09 17:41:32 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 2);
|
|
|
|
QCOMPARE(xkb->layoutName(0), QStringLiteral("German"));
|
|
|
|
QCOMPARE(xkb->layoutName(1), QStringLiteral("English (US)"));
|
2017-01-27 16:15:32 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 18:42:55 +00:00
|
|
|
void KeyboardLayoutTest::testChangeLayoutThroughDBus()
|
|
|
|
{
|
|
|
|
// this test verifies that the layout can be changed through DBus
|
|
|
|
// first configure layouts
|
2022-03-23 10:13:38 +00:00
|
|
|
enum Layout {
|
|
|
|
de,
|
|
|
|
us,
|
|
|
|
de_neo,
|
|
|
|
bad,
|
|
|
|
};
|
2017-01-31 18:42:55 +00:00
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us,de(neo)"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
2020-05-29 17:08:24 +00:00
|
|
|
// now we should have three layouts
|
2017-01-31 18:42:55 +00:00
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
2017-01-31 18:42:55 +00:00
|
|
|
// default layout is German
|
|
|
|
xkb->switchToLayout(0);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
// place garbage to layout entry
|
|
|
|
layoutGroup.writeEntry("LayoutDefaultFoo", "garbage");
|
|
|
|
// make sure the garbage is wiped out on saving
|
|
|
|
resetLayouts();
|
|
|
|
QVERIFY(!layoutGroup.hasKey("LayoutDefaultFoo"));
|
2017-02-01 05:49:32 +00:00
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
// now change through DBus to English
|
2021-01-09 17:41:32 +00:00
|
|
|
auto reply = changeLayout(Layout::us);
|
2017-01-31 18:42:55 +00:00
|
|
|
reply.waitForFinished();
|
|
|
|
QVERIFY(!reply.isError());
|
|
|
|
QCOMPARE(reply.reply().arguments().first().toBool(), true);
|
2017-02-01 05:49:32 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
|
|
|
QCOMPARE(layoutChangedSpy.count(), 1);
|
|
|
|
layoutChangedSpy.clear();
|
2017-01-31 18:42:55 +00:00
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
// layout should persist after reset
|
|
|
|
resetLayouts();
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2020-12-17 16:06:18 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
|
|
|
QCOMPARE(layoutChangedSpy.count(), 1);
|
|
|
|
layoutChangedSpy.clear();
|
2020-05-29 17:08:24 +00:00
|
|
|
|
2017-01-31 18:42:55 +00:00
|
|
|
// switch to a layout which does not exist
|
2021-01-09 17:41:32 +00:00
|
|
|
reply = changeLayout(Layout::bad);
|
2017-01-31 18:42:55 +00:00
|
|
|
QVERIFY(!reply.isError());
|
|
|
|
QCOMPARE(reply.reply().arguments().first().toBool(), false);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(!layoutChangedSpy.wait(1000));
|
2017-01-31 18:42:55 +00:00
|
|
|
|
|
|
|
// switch to another layout should work
|
2021-01-09 17:41:32 +00:00
|
|
|
reply = changeLayout(Layout::de);
|
2017-01-31 18:42:55 +00:00
|
|
|
QVERIFY(!reply.isError());
|
|
|
|
QCOMPARE(reply.reply().arguments().first().toBool(), true);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2020-10-20 20:41:43 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait(1000));
|
|
|
|
QCOMPARE(layoutChangedSpy.count(), 1);
|
2017-01-31 18:42:55 +00:00
|
|
|
|
|
|
|
// switching to same layout should also work
|
2021-01-09 17:41:32 +00:00
|
|
|
reply = changeLayout(Layout::de);
|
2017-01-31 18:42:55 +00:00
|
|
|
QVERIFY(!reply.isError());
|
|
|
|
QCOMPARE(reply.reply().arguments().first().toBool(), true);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(!layoutChangedSpy.wait(1000));
|
2017-01-31 18:42:55 +00:00
|
|
|
}
|
|
|
|
|
2017-02-11 08:46:33 +00:00
|
|
|
void KeyboardLayoutTest::testPerLayoutShortcut()
|
|
|
|
{
|
|
|
|
// this test verifies that per-layout global shortcuts are working correctly.
|
|
|
|
// first configure layouts
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
|
|
|
|
// and create the global shortcuts
|
|
|
|
const QString componentName = QStringLiteral("KDE Keyboard Layout Switcher");
|
|
|
|
QAction *a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("Switch keyboard layout to English (US)"));
|
|
|
|
a->setProperty("componentName", componentName);
|
2022-03-23 10:13:38 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{Qt::CTRL | Qt::ALT | Qt::Key_1}, KGlobalAccel::NoAutoloading);
|
2017-02-11 08:46:33 +00:00
|
|
|
delete a;
|
|
|
|
a = new QAction(this);
|
|
|
|
a->setObjectName(QStringLiteral("Switch keyboard layout to German"));
|
|
|
|
a->setProperty("componentName", componentName);
|
2022-03-23 10:13:38 +00:00
|
|
|
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{Qt::CTRL | Qt::ALT | Qt::Key_2}, KGlobalAccel::NoAutoloading);
|
2017-02-11 08:46:33 +00:00
|
|
|
delete a;
|
|
|
|
|
|
|
|
// now we should have three layouts
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-05-29 17:08:24 +00:00
|
|
|
reconfigureLayouts();
|
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
2017-02-11 08:46:33 +00:00
|
|
|
// default layout is English
|
|
|
|
xkb->switchToLayout(0);
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-02-11 08:46:33 +00:00
|
|
|
|
|
|
|
// now switch to English through the global shortcut
|
|
|
|
quint32 timestamp = 1;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
Test::keyboardKeyPressed(KEY_2, timestamp++);
|
2017-02-11 08:46:33 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
|
|
|
// now layout should be German
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
|
|
|
// release keys again
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_2, timestamp++);
|
2017-02-11 08:46:33 +00:00
|
|
|
// switch back to English
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_1, timestamp++);
|
2017-02-11 08:46:33 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
|
|
|
// release keys again
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_1, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_LEFTCTRL, timestamp++);
|
2017-02-11 08:46:33 +00:00
|
|
|
}
|
|
|
|
|
2017-02-11 10:34:49 +00:00
|
|
|
void KeyboardLayoutTest::testDBusServiceExport()
|
|
|
|
{
|
|
|
|
// verifies that the dbus service is only exported if there are at least two layouts
|
|
|
|
|
|
|
|
// first configure layouts, with just one layout
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
2017-02-11 10:34:49 +00:00
|
|
|
// default layout is English
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-02-11 10:34:49 +00:00
|
|
|
// with one layout we should not have the dbus interface
|
2020-06-25 15:21:08 +00:00
|
|
|
QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
2017-02-11 10:34:49 +00:00
|
|
|
|
|
|
|
// reconfigure to two layouts
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 2u);
|
|
|
|
QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
2017-02-11 10:34:49 +00:00
|
|
|
|
|
|
|
// and back to one layout
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
|
|
|
QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
2017-02-11 10:34:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 16:56:10 +00:00
|
|
|
void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
|
|
|
{
|
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
|
|
|
|
layoutGroup.writeEntry("SwitchMode", QStringLiteral("Desktop"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-04-04 16:56:10 +00:00
|
|
|
|
|
|
|
VirtualDesktopManager::self()->setCount(4);
|
|
|
|
QCOMPARE(VirtualDesktopManager::self()->count(), 4u);
|
|
|
|
auto desktops = VirtualDesktopManager::self()->desktops();
|
|
|
|
QCOMPARE(desktops.count(), 4);
|
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
// give desktops different layouts
|
|
|
|
uint desktop, layout;
|
|
|
|
for (desktop = 0; desktop < VirtualDesktopManager::self()->count(); ++desktop) {
|
|
|
|
// switch to another virtual desktop
|
|
|
|
VirtualDesktopManager::self()->setCurrent(desktops.at(desktop));
|
|
|
|
QCOMPARE(desktops.at(desktop), VirtualDesktopManager::self()->currentDesktop());
|
|
|
|
// should be reset to English
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->currentLayout(), 0);
|
2020-05-29 17:08:24 +00:00
|
|
|
// change first desktop to German
|
|
|
|
layout = (desktop + 1) % xkb->numberOfLayouts();
|
2021-01-09 17:41:32 +00:00
|
|
|
changeLayout(layout).waitForFinished();
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->currentLayout(), layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
// imitate app restart to test layouts saving feature
|
|
|
|
resetLayouts();
|
|
|
|
|
|
|
|
// check layout set on desktop switching as intended
|
2022-03-23 10:13:38 +00:00
|
|
|
for (--desktop;;) {
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(desktops.at(desktop), VirtualDesktopManager::self()->currentDesktop());
|
|
|
|
layout = (desktop + 1) % xkb->numberOfLayouts();
|
|
|
|
QCOMPARE(xkb->currentLayout(), layout);
|
2022-03-25 12:20:32 +00:00
|
|
|
if (--desktop >= VirtualDesktopManager::self()->count()) { // overflow
|
2020-05-29 17:08:24 +00:00
|
|
|
break;
|
2022-03-25 12:20:32 +00:00
|
|
|
}
|
2020-05-29 17:08:24 +00:00
|
|
|
VirtualDesktopManager::self()->setCurrent(desktops.at(desktop));
|
|
|
|
}
|
2017-04-04 16:56:10 +00:00
|
|
|
|
|
|
|
// remove virtual desktops
|
2020-05-29 17:08:24 +00:00
|
|
|
desktop = 0;
|
2022-03-23 10:13:38 +00:00
|
|
|
const KWin::VirtualDesktop *deletedDesktop = desktops.last();
|
2017-04-04 16:56:10 +00:00
|
|
|
VirtualDesktopManager::self()->setCount(1);
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->currentLayout(), layout = (desktop + 1) % xkb->numberOfLayouts());
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2017-04-04 16:56:10 +00:00
|
|
|
|
|
|
|
// add another desktop
|
|
|
|
VirtualDesktopManager::self()->setCount(2);
|
|
|
|
// switching to it should result in going to default
|
|
|
|
desktops = VirtualDesktopManager::self()->desktops();
|
|
|
|
QCOMPARE(desktops.count(), 2);
|
|
|
|
QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop());
|
|
|
|
VirtualDesktopManager::self()->setCurrent(desktops.last());
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-04-04 16:56:10 +00:00
|
|
|
|
2020-05-29 17:08:24 +00:00
|
|
|
// check there are no more layouts left in config than the last actual non-default layouts number
|
|
|
|
QSignalSpy deletedDesktopSpy(deletedDesktop, &VirtualDesktop::aboutToBeDestroyed);
|
|
|
|
QVERIFY(deletedDesktopSpy.wait());
|
|
|
|
resetLayouts();
|
2022-03-23 10:13:38 +00:00
|
|
|
QCOMPARE(layoutGroup.keyList().filter(QStringLiteral("LayoutDefault")).count(), 1);
|
2017-04-04 16:56:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-06 05:13:44 +00:00
|
|
|
void KeyboardLayoutTest::testWindowPolicy()
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
enum Layout {
|
|
|
|
us,
|
|
|
|
de,
|
|
|
|
de_neo,
|
|
|
|
bad,
|
|
|
|
};
|
2017-04-06 05:13:44 +00:00
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
|
|
|
|
layoutGroup.writeEntry("SwitchMode", QStringLiteral("Window"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-04-06 05:13:44 +00:00
|
|
|
|
|
|
|
// create a window
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
auto c1 = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue);
|
2017-04-06 05:13:44 +00:00
|
|
|
QVERIFY(c1);
|
|
|
|
|
|
|
|
// now switch layout
|
2021-01-09 17:41:32 +00:00
|
|
|
auto reply = changeLayout(Layout::de);
|
2017-04-06 05:13:44 +00:00
|
|
|
reply.waitForFinished();
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2017-04-06 05:13:44 +00:00
|
|
|
|
|
|
|
// create a second window
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 100), Qt::red);
|
2017-04-06 05:13:44 +00:00
|
|
|
QVERIFY(c2);
|
|
|
|
// this should have switched back to English
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-04-06 05:13:44 +00:00
|
|
|
// now change to another layout
|
2021-01-09 17:41:32 +00:00
|
|
|
reply = changeLayout(Layout::de_neo);
|
2017-04-06 05:13:44 +00:00
|
|
|
reply.waitForFinished();
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
2017-04-06 05:13:44 +00:00
|
|
|
|
|
|
|
// activate other window
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(c1);
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(c2);
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
2017-04-06 05:13:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 15:57:59 +00:00
|
|
|
void KeyboardLayoutTest::testApplicationPolicy()
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
enum Layout {
|
|
|
|
us,
|
|
|
|
de,
|
|
|
|
de_neo,
|
|
|
|
bad,
|
|
|
|
};
|
2017-04-09 15:57:59 +00:00
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
|
|
|
|
layoutGroup.writeEntry("SwitchMode", QStringLiteral("WinClass"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2017-04-09 15:57:59 +00:00
|
|
|
|
|
|
|
// create a window
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
2021-05-11 05:26:51 +00:00
|
|
|
shellSurface->set_app_id(QStringLiteral("org.kde.foo"));
|
2022-08-01 21:29:02 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface.get(), QSize(100, 100), Qt::blue);
|
2017-04-09 15:57:59 +00:00
|
|
|
QVERIFY(c1);
|
|
|
|
|
|
|
|
// create a second window
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
2021-05-11 05:26:51 +00:00
|
|
|
shellSurface2->set_app_id(QStringLiteral("org.kde.foo"));
|
2022-08-01 21:29:02 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 100), Qt::red);
|
2017-04-09 15:57:59 +00:00
|
|
|
QVERIFY(c2);
|
2020-05-29 17:08:24 +00:00
|
|
|
// now switch layout
|
|
|
|
layoutChangedSpy.clear();
|
2021-01-09 17:41:32 +00:00
|
|
|
changeLayout(Layout::de_neo);
|
2017-04-09 15:57:59 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(layoutChangedSpy.count(), 1);
|
2020-12-17 16:06:18 +00:00
|
|
|
layoutChangedSpy.clear();
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
|
|
|
|
|
|
|
resetLayouts();
|
2020-12-17 16:06:18 +00:00
|
|
|
// to trigger layout application for current client
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(c1);
|
|
|
|
workspace()->activateWindow(c2);
|
2020-12-17 16:06:18 +00:00
|
|
|
QVERIFY(layoutChangedSpy.wait());
|
|
|
|
QCOMPARE(layoutChangedSpy.count(), 1);
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
2017-04-09 15:57:59 +00:00
|
|
|
|
|
|
|
// activate other window
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(c1);
|
2020-05-29 17:08:24 +00:00
|
|
|
// it is the same application and should not switch the layout
|
|
|
|
QVERIFY(!layoutChangedSpy.wait(1000));
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
2022-04-23 08:33:23 +00:00
|
|
|
workspace()->activateWindow(c2);
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(!layoutChangedSpy.wait(1000));
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
2017-04-09 15:57:59 +00:00
|
|
|
|
|
|
|
shellSurface2.reset();
|
|
|
|
surface2.reset();
|
2023-04-21 20:28:48 +00:00
|
|
|
QVERIFY(Test::waitForWindowClosed(c2));
|
2020-05-29 17:08:24 +00:00
|
|
|
QVERIFY(!layoutChangedSpy.wait(1000));
|
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
|
|
|
|
|
|
|
resetLayouts();
|
2022-03-23 10:13:38 +00:00
|
|
|
QCOMPARE(layoutGroup.keyList().filter(QStringLiteral("LayoutDefault")).count(), 1);
|
2017-04-09 15:57:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 17:46:36 +00:00
|
|
|
void KeyboardLayoutTest::testNumLock()
|
|
|
|
{
|
|
|
|
qputenv("KWIN_FORCE_NUM_LOCK_EVALUATION", "1");
|
2018-11-15 16:56:07 +00:00
|
|
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us"));
|
|
|
|
layoutGroup.sync();
|
|
|
|
reconfigureLayouts();
|
|
|
|
|
2018-10-25 17:46:36 +00:00
|
|
|
auto xkb = input()->keyboard()->xkb();
|
2020-06-25 15:21:08 +00:00
|
|
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
2020-05-29 17:08:24 +00:00
|
|
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
2018-11-15 16:56:07 +00:00
|
|
|
|
2018-10-25 17:46:36 +00:00
|
|
|
// by default not set
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(!xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
|
2018-10-25 17:46:36 +00:00
|
|
|
// now it should be on
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
// and back to off
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(!xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
|
|
|
|
// let's reconfigure to enable through config
|
2020-07-13 01:56:45 +00:00
|
|
|
auto group = InputConfig::self()->inputConfig()->group("Keyboard");
|
2018-10-25 17:46:36 +00:00
|
|
|
group.writeEntry("NumLock", 0);
|
|
|
|
group.sync();
|
|
|
|
xkb->reconfigure();
|
|
|
|
// now it should be on
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
// pressing should result in it being off
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(!xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
|
|
|
|
// pressing again should enable it
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
|
|
|
|
// now reconfigure to disable on load
|
|
|
|
group.writeEntry("NumLock", 1);
|
|
|
|
group.sync();
|
|
|
|
xkb->reconfigure();
|
2021-10-04 16:36:32 +00:00
|
|
|
QVERIFY(!xkb->leds().testFlag(LED::NumLock));
|
2018-10-25 17:46:36 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 16:15:32 +00:00
|
|
|
WAYLANDTEST_MAIN(KeyboardLayoutTest)
|
|
|
|
#include "keyboard_layout_test.moc"
|