kwin/autotests/integration/keyboard_layout_test.cpp
Martin Gräßlin 8d9c4acf4d Provide kxbk config through kwinApp
Summary:
So far KWin parsed the kxbkrc at multiple places (once in Xkb, once
in KeyboardLayout). This is now replaced by one KSharedConfigPtr hold
by kwinApp, just like the normal kwinrc. The KSharedConfigPtr is now
passed to Xkb.

As a nice side effect this makes it easier to test keyboard layout
changes as we can now properly mock the keyboard configuration. Thus
this change also comes with an autotest for loading keyboard layout
configuration. This is becoming more and more a need as we start
getting bug reports for layout specific issues like global shortcuts
not working with Greek layout.

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D4315
2017-01-30 17:04:03 +01:00

103 lines
3.3 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwin_wayland_test.h"
#include "keyboard_input.h"
#include "platform.h"
#include "wayland_server.h"
#include <KConfigGroup>
#include <QDBusConnection>
#include <QDBusMessage>
using namespace KWin;
using namespace KWayland::Client;
static const QString s_socketName = QStringLiteral("wayland_test_kwin_keyboard_laout-0");
class KeyboardLayoutTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testReconfigure();
};
void KeyboardLayoutTest::initTestCase()
{
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
QVERIFY(workspaceCreatedSpy.isValid());
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
kwinApp()->setKxkbConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
kwinApp()->start();
QVERIFY(workspaceCreatedSpy.wait());
waylandServer()->initWorkspace();
}
void KeyboardLayoutTest::init()
{
}
void KeyboardLayoutTest::cleanup()
{
}
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)"));
auto layouts = xkb->layoutNames();
QCOMPARE(layouts.size(), 1);
QVERIFY(layouts.contains(0));
QCOMPARE(layouts[0], QStringLiteral("English (US)"));
// create a new keymap
KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout");
layoutGroup.writeEntry("LayoutList", QStringLiteral("de,us"));
layoutGroup.sync();
// create DBus signal to reload
QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig"));
QDBusConnection::sessionBus().send(message);
// now we should have two layouts
QTRY_COMPARE(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)"));
}
WAYLANDTEST_MAIN(KeyboardLayoutTest)
#include "keyboard_layout_test.moc"