diff --git a/autotests/integration/keyboard_layout_test.cpp b/autotests/integration/keyboard_layout_test.cpp --- a/autotests/integration/keyboard_layout_test.cpp +++ b/autotests/integration/keyboard_layout_test.cpp @@ -19,6 +19,7 @@ *********************************************************************/ #include "kwin_wayland_test.h" #include "keyboard_input.h" +#include "keyboard_layout.h" #include "platform.h" #include "wayland_server.h" @@ -78,6 +79,20 @@ { } +class LayoutChangedSignalWrapper : public QObject +{ + Q_OBJECT +public: + LayoutChangedSignalWrapper() + : QObject() + { + QDBusConnection::sessionBus().connect(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("currentLayoutChanged"), this, SIGNAL(layoutChanged(QString))); + } + +Q_SIGNALS: + void layoutChanged(const QString &name); +}; + void KeyboardLayoutTest::testReconfigure() { // verifies that we can change the keymap @@ -124,6 +139,10 @@ xkb->switchToLayout(0); QCOMPARE(xkb->layoutName(), QStringLiteral("German")); + LayoutChangedSignalWrapper wrapper; + QSignalSpy layoutChangedSpy(&wrapper, &LayoutChangedSignalWrapper::layoutChanged); + QVERIFY(layoutChangedSpy.isValid()); + // now change through DBus to english auto changeLayout = [] (const QString &layoutName) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); @@ -135,24 +154,34 @@ QVERIFY(!reply.isError()); QCOMPARE(reply.reply().arguments().first().toBool(), true); QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)")); + QVERIFY(layoutChangedSpy.wait()); + QCOMPARE(layoutChangedSpy.count(), 1); + layoutChangedSpy.clear(); // switch to a layout which does not exist reply = changeLayout(QStringLiteral("French")); QVERIFY(!reply.isError()); QCOMPARE(reply.reply().arguments().first().toBool(), false); QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)")); + QVERIFY(!layoutChangedSpy.wait()); + QVERIFY(layoutChangedSpy.isEmpty()); // switch to another layout should work reply = changeLayout(QStringLiteral("German")); QVERIFY(!reply.isError()); QCOMPARE(reply.reply().arguments().first().toBool(), true); QCOMPARE(xkb->layoutName(), QStringLiteral("German")); + QVERIFY(layoutChangedSpy.wait()); + QCOMPARE(layoutChangedSpy.count(), 1); + layoutChangedSpy.clear(); // switching to same layout should also work reply = changeLayout(QStringLiteral("German")); QVERIFY(!reply.isError()); QCOMPARE(reply.reply().arguments().first().toBool(), true); QCOMPARE(xkb->layoutName(), QStringLiteral("German")); + QVERIFY(!layoutChangedSpy.wait()); + QVERIFY(layoutChangedSpy.isEmpty()); } WAYLANDTEST_MAIN(KeyboardLayoutTest) diff --git a/keyboard_layout.h b/keyboard_layout.h --- a/keyboard_layout.h +++ b/keyboard_layout.h @@ -82,7 +82,7 @@ Q_CLASSINFO("D-Bus Interface", "org.kde.KeyboardLayouts") public: - explicit KeyboardLayoutDBusInterface(Xkb *xkb, QObject *parent); + explicit KeyboardLayoutDBusInterface(Xkb *xkb, KeyboardLayout *parent); ~KeyboardLayoutDBusInterface() override; public Q_SLOTS: @@ -97,6 +97,7 @@ private: Xkb *m_xkb; + KeyboardLayout *m_keyboardLayout; }; } diff --git a/keyboard_layout.cpp b/keyboard_layout.cpp --- a/keyboard_layout.cpp +++ b/keyboard_layout.cpp @@ -274,9 +274,10 @@ static const QString s_keyboardService = QStringLiteral("org.kde.keyboard"); static const QString s_keyboardObject = QStringLiteral("/Layouts"); -KeyboardLayoutDBusInterface::KeyboardLayoutDBusInterface(Xkb *xkb, QObject *parent) +KeyboardLayoutDBusInterface::KeyboardLayoutDBusInterface(Xkb *xkb, KeyboardLayout *parent) : QObject(parent) , m_xkb(xkb) + , m_keyboardLayout(parent) { QDBusConnection::sessionBus().registerService(s_keyboardService); QDBusConnection::sessionBus().registerObject(s_keyboardObject, this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals); @@ -300,6 +301,7 @@ return false; } m_xkb->switchToLayout(it.key()); + m_keyboardLayout->checkLayoutChange(); return true; }