make keyboard layout DBus API more reliable
having deferred m_dbusInterface deletion allows to send DBus signal in more cases. That addressed in unit tests.
This commit is contained in:
parent
8e1018de2c
commit
0bb05d4b1a
2 changed files with 23 additions and 24 deletions
|
@ -93,12 +93,9 @@ void KeyboardLayoutTest::reconfigureLayouts()
|
||||||
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig"));
|
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig"));
|
||||||
QVERIFY(QDBusConnection::sessionBus().send(message));
|
QVERIFY(QDBusConnection::sessionBus().send(message));
|
||||||
|
|
||||||
// we don't get the signal when traversing to one-layout configuration
|
QVERIFY(layoutsReconfiguredSpy.wait(1000));
|
||||||
if ( layoutGroup.readEntry("LayoutList").contains(',') ) {
|
QCOMPARE(layoutsReconfiguredSpy.count(), 1);
|
||||||
QVERIFY(layoutsReconfiguredSpy.wait(1000));
|
layoutsReconfiguredSpy.clear();
|
||||||
QCOMPARE(layoutsReconfiguredSpy.count(), 1);
|
|
||||||
layoutsReconfiguredSpy.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardLayoutTest::resetLayouts()
|
void KeyboardLayoutTest::resetLayouts()
|
||||||
|
@ -193,7 +190,7 @@ void KeyboardLayoutTest::testReconfigure()
|
||||||
|
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
// now we should have two layouts
|
// now we should have two layouts
|
||||||
QTRY_COMPARE(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();
|
layouts = xkb->layoutNames();
|
||||||
|
@ -213,7 +210,7 @@ void KeyboardLayoutTest::testChangeLayoutThroughDBus()
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
// now we should have three layouts
|
// now we should have three layouts
|
||||||
auto xkb = input()->keyboard()->xkb();
|
auto xkb = input()->keyboard()->xkb();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 3u);
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
||||||
// default layout is German
|
// default layout is German
|
||||||
xkb->switchToLayout(0);
|
xkb->switchToLayout(0);
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
||||||
|
@ -322,25 +319,25 @@ void KeyboardLayoutTest::testDBusServiceExport()
|
||||||
layoutGroup.sync();
|
layoutGroup.sync();
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
auto xkb = input()->keyboard()->xkb();
|
auto xkb = input()->keyboard()->xkb();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 1u);
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
||||||
// default layout is English
|
// default layout is English
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
||||||
// with one layout we should not have the dbus interface
|
// with one layout we should not have the dbus interface
|
||||||
QTRY_VERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
||||||
|
|
||||||
// reconfigure to two layouts
|
// reconfigure to two layouts
|
||||||
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de"));
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de"));
|
||||||
layoutGroup.sync();
|
layoutGroup.sync();
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 2u);
|
QCOMPARE(xkb->numberOfLayouts(), 2u);
|
||||||
QTRY_VERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
QVERIFY(QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
||||||
|
|
||||||
// and back to one layout
|
// and back to one layout
|
||||||
layoutGroup.writeEntry("LayoutList", QStringLiteral("us"));
|
layoutGroup.writeEntry("LayoutList", QStringLiteral("us"));
|
||||||
layoutGroup.sync();
|
layoutGroup.sync();
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 1u);
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
||||||
QTRY_VERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
QVERIFY(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.keyboard")).value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
||||||
|
@ -350,7 +347,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
||||||
layoutGroup.sync();
|
layoutGroup.sync();
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
auto xkb = input()->keyboard()->xkb();
|
auto xkb = input()->keyboard()->xkb();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 3u);
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
||||||
|
|
||||||
VirtualDesktopManager::self()->setCount(4);
|
VirtualDesktopManager::self()->setCount(4);
|
||||||
|
@ -365,7 +362,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
||||||
VirtualDesktopManager::self()->setCurrent(desktops.at(desktop));
|
VirtualDesktopManager::self()->setCurrent(desktops.at(desktop));
|
||||||
QCOMPARE(desktops.at(desktop), VirtualDesktopManager::self()->currentDesktop());
|
QCOMPARE(desktops.at(desktop), VirtualDesktopManager::self()->currentDesktop());
|
||||||
// should be reset to English
|
// should be reset to English
|
||||||
QTRY_COMPARE(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(xkb->layoutNames()[layout]).waitForFinished();
|
||||||
|
@ -389,7 +386,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
||||||
desktop = 0;
|
desktop = 0;
|
||||||
const KWin::VirtualDesktop* deletedDesktop = desktops.last();
|
const KWin::VirtualDesktop* deletedDesktop = desktops.last();
|
||||||
VirtualDesktopManager::self()->setCount(1);
|
VirtualDesktopManager::self()->setCount(1);
|
||||||
QTRY_COMPARE(xkb->currentLayout(), layout = (desktop + 1) % xkb->numberOfLayouts());
|
QCOMPARE(xkb->currentLayout(), layout = (desktop + 1) % xkb->numberOfLayouts());
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
||||||
|
|
||||||
// add another desktop
|
// add another desktop
|
||||||
|
@ -399,7 +396,7 @@ void KeyboardLayoutTest::testVirtualDesktopPolicy()
|
||||||
QCOMPARE(desktops.count(), 2);
|
QCOMPARE(desktops.count(), 2);
|
||||||
QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop());
|
QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop());
|
||||||
VirtualDesktopManager::self()->setCurrent(desktops.last());
|
VirtualDesktopManager::self()->setCurrent(desktops.last());
|
||||||
QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
||||||
|
|
||||||
// check there are no more layouts left in config than the last actual non-default layouts number
|
// check there are no more layouts left in config than the last actual non-default layouts number
|
||||||
QSignalSpy deletedDesktopSpy(deletedDesktop, &VirtualDesktop::aboutToBeDestroyed);
|
QSignalSpy deletedDesktopSpy(deletedDesktop, &VirtualDesktop::aboutToBeDestroyed);
|
||||||
|
@ -416,7 +413,7 @@ void KeyboardLayoutTest::testWindowPolicy()
|
||||||
layoutGroup.sync();
|
layoutGroup.sync();
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
auto xkb = input()->keyboard()->xkb();
|
auto xkb = input()->keyboard()->xkb();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 3u);
|
QCOMPARE(xkb->numberOfLayouts(), 3u);
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
||||||
|
|
||||||
// create a window
|
// create a window
|
||||||
|
@ -445,9 +442,9 @@ void KeyboardLayoutTest::testWindowPolicy()
|
||||||
|
|
||||||
// activate other window
|
// activate other window
|
||||||
workspace()->activateClient(c1);
|
workspace()->activateClient(c1);
|
||||||
QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German"));
|
||||||
workspace()->activateClient(c2);
|
workspace()->activateClient(c2);
|
||||||
QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardLayoutTest::testApplicationPolicy()
|
void KeyboardLayoutTest::testApplicationPolicy()
|
||||||
|
@ -515,7 +512,7 @@ void KeyboardLayoutTest::testNumLock()
|
||||||
reconfigureLayouts();
|
reconfigureLayouts();
|
||||||
|
|
||||||
auto xkb = input()->keyboard()->xkb();
|
auto xkb = input()->keyboard()->xkb();
|
||||||
QTRY_COMPARE(xkb->numberOfLayouts(), 1u);
|
QCOMPARE(xkb->numberOfLayouts(), 1u);
|
||||||
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
QCOMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
|
||||||
|
|
||||||
// by default not set
|
// by default not set
|
||||||
|
|
|
@ -76,8 +76,10 @@ void KeyboardLayout::init()
|
||||||
void KeyboardLayout::initDBusInterface()
|
void KeyboardLayout::initDBusInterface()
|
||||||
{
|
{
|
||||||
if (m_xkb->numberOfLayouts() <= 1) {
|
if (m_xkb->numberOfLayouts() <= 1) {
|
||||||
delete m_dbusInterface;
|
if (m_dbusInterface) {
|
||||||
m_dbusInterface = nullptr;
|
m_dbusInterface->deleteLater();
|
||||||
|
m_dbusInterface = nullptr;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_dbusInterface) {
|
if (m_dbusInterface) {
|
||||||
|
|
Loading…
Reference in a new issue