Commit 07192041 authored by Andrey Butirsky's avatar Andrey Butirsky

fix: KeyboardLayoutTest fails on updated DBus API

Adress changes in methods:
- setLayout()
- layoutNames()
- layoutChanged() signal
parent 73aa6fba
......@@ -45,11 +45,11 @@ public:
QVERIFY(layoutChangedSpy.isValid());
QVERIFY(QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("layoutListChanged"), this, SIGNAL(layoutListChanged())));
QVERIFY(QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("layoutChanged"), this, SIGNAL(layoutChanged(QString))));
QVERIFY(QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("layoutChanged"), this, SIGNAL(layoutChanged(uint))));
}
Q_SIGNALS:
void layoutChanged(const QString &name);
void layoutChanged(uint index);
void layoutListChanged();
private Q_SLOTS:
......@@ -69,7 +69,7 @@ private Q_SLOTS:
private:
void reconfigureLayouts();
void resetLayouts();
auto changeLayout(const QString &layoutName);
auto changeLayout(uint index);
void callSession(const QString &method);
QSignalSpy layoutsReconfiguredSpy;
QSignalSpy layoutChangedSpy;
......@@ -109,9 +109,9 @@ void KeyboardLayoutTest::resetLayouts()
callSession(QStringLiteral("loadSession"));
}
auto KeyboardLayoutTest::changeLayout(const QString &layoutName) {
auto KeyboardLayoutTest::changeLayout(uint index) {
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout"));
msg << layoutName;
msg << index;
return QDBusConnection::sessionBus().asyncCall(msg);
}
......@@ -167,10 +167,8 @@ void KeyboardLayoutTest::testReconfigure()
auto xkb = input()->keyboard()->xkb();
QCOMPARE(xkb->numberOfLayouts(), 1u);
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
auto layouts = xkb->layoutNames();
QCOMPARE(layouts.size(), 1);
QVERIFY(layouts.contains(0));
QCOMPARE(layouts[0], QStringLiteral("English (US)"));
QCOMPARE(xkb->numberOfLayouts(), 1);
QCOMPARE(xkb->layoutName(0), QStringLiteral("English (US)"));
// create a new keymap
KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
......@@ -182,18 +180,16 @@ void KeyboardLayoutTest::testReconfigure()
QCOMPARE(xkb->numberOfLayouts(), 2u);
// default layout is German
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
layouts = xkb->layoutNames();
QCOMPARE(layouts.size(), 2);
QVERIFY(layouts.contains(0));
QVERIFY(layouts.contains(1));
QCOMPARE(layouts[0], QStringLiteral("German"));
QCOMPARE(layouts[1], QStringLiteral("English (US)"));
QCOMPARE(xkb->numberOfLayouts(), 2);
QCOMPARE(xkb->layoutName(0), QStringLiteral("German"));
QCOMPARE(xkb->layoutName(1), QStringLiteral("English (US)"));
}
void KeyboardLayoutTest::testChangeLayoutThroughDBus()
{
// this test verifies that the layout can be changed through DBus
// first configure layouts
enum Layout {de, us, de_neo, bad};
layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us,de(neo)"));
layoutGroup.sync();
reconfigureLayouts();
......@@ -211,7 +207,7 @@ void KeyboardLayoutTest::testChangeLayoutThroughDBus()
QVERIFY(!layoutGroup.hasKey("LayoutDefaultFoo"));
// now change through DBus to English
auto reply = changeLayout(QStringLiteral("English (US)"));
auto reply = changeLayout(Layout::us);
reply.waitForFinished();
QVERIFY(!reply.isError());
QCOMPARE(reply.reply().arguments().first().toBool(), true);
......@@ -227,14 +223,14 @@ void KeyboardLayoutTest::testChangeLayoutThroughDBus()
layoutChangedSpy.clear();
// switch to a layout which does not exist
reply = changeLayout(QStringLiteral("French"));
reply = changeLayout(Layout::bad);
QVERIFY(!reply.isError());
QCOMPARE(reply.reply().arguments().first().toBool(), false);
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
QVERIFY(!layoutChangedSpy.wait(1000));
// switch to another layout should work
reply = changeLayout(QStringLiteral("German"));
reply = changeLayout(Layout::de);
QVERIFY(!reply.isError());
QCOMPARE(reply.reply().arguments().first().toBool(), true);
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
......@@ -242,7 +238,7 @@ void KeyboardLayoutTest::testChangeLayoutThroughDBus()
QCOMPARE(layoutChangedSpy.count(), 1);
// switching to same layout should also work
reply = changeLayout(QStringLiteral("German"));
reply = changeLayout(Layout::de);
QVERIFY(!reply.isError());
QCOMPARE(reply.reply().arguments().first().toBool(), true);
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
......@@ -352,7 +348,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
QCOMPARE(xkb->currentLayout(), 0);
// change first desktop to German
layout = (desktop + 1) % xkb->numberOfLayouts();
changeLayout(xkb->layoutNames()[layout]).waitForFinished();
changeLayout(layout).waitForFinished();
QCOMPARE(xkb->currentLayout(), layout);
}
......@@ -395,6 +391,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
void KeyboardLayoutTest::testWindowPolicy()
{
enum Layout {us, de, de_neo, bad};
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
layoutGroup.writeEntry("SwitchMode", QStringLiteral("Window"));
layoutGroup.sync();
......@@ -411,7 +408,7 @@ void KeyboardLayoutTest::testWindowPolicy()
QVERIFY(c1);
// now switch layout
auto reply = changeLayout(QStringLiteral("German"));
auto reply = changeLayout(Layout::de);
reply.waitForFinished();
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
......@@ -423,7 +420,7 @@ void KeyboardLayoutTest::testWindowPolicy()
// this should have switched back to English
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
// now change to another layout
reply = changeLayout(QStringLiteral("German (Neo 2)"));
reply = changeLayout(Layout::de_neo);
reply.waitForFinished();
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
......@@ -436,6 +433,7 @@ void KeyboardLayoutTest::testWindowPolicy()
void KeyboardLayoutTest::testApplicationPolicy()
{
enum Layout {us, de, de_neo, bad};
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)"));
layoutGroup.writeEntry("SwitchMode", QStringLiteral("WinClass"));
layoutGroup.sync();
......@@ -460,7 +458,7 @@ void KeyboardLayoutTest::testApplicationPolicy()
QVERIFY(c2);
// now switch layout
layoutChangedSpy.clear();
changeLayout(QStringLiteral("German (Neo 2)"));
changeLayout(Layout::de_neo);
QVERIFY(layoutChangedSpy.wait());
QCOMPARE(layoutChangedSpy.count(), 1);
layoutChangedSpy.clear();
......
......@@ -210,7 +210,9 @@ void KeyboardLayoutDBusInterface::switchToPreviousLayout()
bool KeyboardLayoutDBusInterface::setLayout(uint index)
{
const quint32 previousLayout = m_xkb->currentLayout();
m_xkb->switchToLayout(index);
if ( !m_xkb->switchToLayout(index) ) {
return false;
}
m_keyboardLayout->checkLayoutChange(previousLayout);
return true;
}
......
......@@ -527,13 +527,10 @@ void Xkb::switchToPreviousLayout()
switchToLayout(previousLayout);
}
void Xkb::switchToLayout(xkb_layout_index_t layout)
bool Xkb::switchToLayout(xkb_layout_index_t layout)
{
if (!m_keymap || !m_state) {
return;
}
if (layout >= numberOfLayouts()) {
return;
if (!m_keymap || !m_state || layout >= numberOfLayouts()) {
return false;
}
const xkb_mod_mask_t depressed = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED));
const xkb_mod_mask_t latched = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED));
......@@ -541,6 +538,7 @@ void Xkb::switchToLayout(xkb_layout_index_t layout)
xkb_state_update_mask(m_state, depressed, latched, locked, 0, 0, layout);
updateModifiers();
forwardModifiers();
return true;
}
quint32 Xkb::numberOfLayouts() const
......
......@@ -63,7 +63,7 @@ public:
void switchToNextLayout();
void switchToPreviousLayout();
void switchToLayout(xkb_layout_index_t layout);
bool switchToLayout(xkb_layout_index_t layout);
enum class LED {
NumLock = 1 << 0,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment