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