Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/keyboard_layout_test.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "kwin_wayland_test.h" | 20 | #include "kwin_wayland_test.h" | ||
21 | #include "keyboard_input.h" | 21 | #include "keyboard_input.h" | ||
22 | #include "keyboard_layout.h" | 22 | #include "keyboard_layout.h" | ||
23 | #include "platform.h" | 23 | #include "platform.h" | ||
24 | #include "shell_client.h" | ||||
24 | #include "virtualdesktops.h" | 25 | #include "virtualdesktops.h" | ||
25 | #include "wayland_server.h" | 26 | #include "wayland_server.h" | ||
27 | #include "workspace.h" | ||||
26 | 28 | | |||
27 | #include <KConfigGroup> | 29 | #include <KConfigGroup> | ||
28 | #include <KGlobalAccel> | 30 | #include <KGlobalAccel> | ||
29 | 31 | | |||
32 | #include <KWayland/Client/surface.h> | ||||
33 | #include <KWayland/Client/shell.h> | ||||
34 | | ||||
30 | #include <QAction> | 35 | #include <QAction> | ||
31 | #include <QDBusConnection> | 36 | #include <QDBusConnection> | ||
32 | #include <QDBusConnectionInterface> | 37 | #include <QDBusConnectionInterface> | ||
33 | #include <QDBusMessage> | 38 | #include <QDBusMessage> | ||
34 | #include <QDBusPendingCall> | 39 | #include <QDBusPendingCall> | ||
35 | 40 | | |||
36 | #include <linux/input.h> | 41 | #include <linux/input.h> | ||
37 | 42 | | |||
Show All 10 Lines | 51 | private Q_SLOTS: | |||
48 | void init(); | 53 | void init(); | ||
49 | void cleanup(); | 54 | void cleanup(); | ||
50 | 55 | | |||
51 | void testReconfigure(); | 56 | void testReconfigure(); | ||
52 | void testChangeLayoutThroughDBus(); | 57 | void testChangeLayoutThroughDBus(); | ||
53 | void testPerLayoutShortcut(); | 58 | void testPerLayoutShortcut(); | ||
54 | void testDBusServiceExport(); | 59 | void testDBusServiceExport(); | ||
55 | void testVirtualDesktopPolicy(); | 60 | void testVirtualDesktopPolicy(); | ||
61 | void testWindowPolicy(); | ||||
56 | 62 | | |||
57 | private: | 63 | private: | ||
58 | void reconfigureLayouts(); | 64 | void reconfigureLayouts(); | ||
59 | }; | 65 | }; | ||
60 | 66 | | |||
61 | void KeyboardLayoutTest::reconfigureLayouts() | 67 | void KeyboardLayoutTest::reconfigureLayouts() | ||
62 | { | 68 | { | ||
63 | // create DBus signal to reload | 69 | // create DBus signal to reload | ||
64 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig")); | 70 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Layouts"), QStringLiteral("org.kde.keyboard"), QStringLiteral("reloadConfig")); | ||
65 | QDBusConnection::sessionBus().send(message); | 71 | QDBusConnection::sessionBus().send(message); | ||
66 | } | 72 | } | ||
67 | 73 | | |||
68 | void KeyboardLayoutTest::initTestCase() | 74 | void KeyboardLayoutTest::initTestCase() | ||
69 | { | 75 | { | ||
76 | qRegisterMetaType<KWin::ShellClient*>(); | ||||
77 | qRegisterMetaType<KWin::AbstractClient*>(); | ||||
70 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 78 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
71 | QVERIFY(workspaceCreatedSpy.isValid()); | 79 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
72 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 80 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
73 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 81 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
74 | 82 | | |||
75 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | 83 | kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||
76 | kwinApp()->setKxkbConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | 84 | kwinApp()->setKxkbConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)); | ||
77 | 85 | | |||
78 | kwinApp()->start(); | 86 | kwinApp()->start(); | ||
79 | QVERIFY(workspaceCreatedSpy.wait()); | 87 | QVERIFY(workspaceCreatedSpy.wait()); | ||
80 | waylandServer()->initWorkspace(); | 88 | waylandServer()->initWorkspace(); | ||
81 | } | 89 | } | ||
82 | 90 | | |||
83 | void KeyboardLayoutTest::init() | 91 | void KeyboardLayoutTest::init() | ||
84 | { | 92 | { | ||
93 | QVERIFY(Test::setupWaylandConnection()); | ||||
85 | } | 94 | } | ||
86 | 95 | | |||
87 | void KeyboardLayoutTest::cleanup() | 96 | void KeyboardLayoutTest::cleanup() | ||
88 | { | 97 | { | ||
98 | Test::destroyWaylandConnection(); | ||||
89 | } | 99 | } | ||
90 | 100 | | |||
91 | class LayoutChangedSignalWrapper : public QObject | 101 | class LayoutChangedSignalWrapper : public QObject | ||
92 | { | 102 | { | ||
93 | Q_OBJECT | 103 | Q_OBJECT | ||
94 | public: | 104 | public: | ||
95 | LayoutChangedSignalWrapper() | 105 | LayoutChangedSignalWrapper() | ||
96 | : QObject() | 106 | : QObject() | ||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Line(s) | 291 | { | |||
332 | desktops = VirtualDesktopManager::self()->desktops(); | 342 | desktops = VirtualDesktopManager::self()->desktops(); | ||
333 | QCOMPARE(desktops.count(), 2); | 343 | QCOMPARE(desktops.count(), 2); | ||
334 | QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop()); | 344 | QCOMPARE(desktops.first(), VirtualDesktopManager::self()->currentDesktop()); | ||
335 | VirtualDesktopManager::self()->setCurrent(desktops.last()); | 345 | VirtualDesktopManager::self()->setCurrent(desktops.last()); | ||
336 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | 346 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||
337 | 347 | | |||
338 | } | 348 | } | ||
339 | 349 | | |||
350 | void KeyboardLayoutTest::testWindowPolicy() | ||||
351 | { | ||||
352 | KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout"); | ||||
353 | layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)")); | ||||
354 | layoutGroup.writeEntry("SwitchMode", QStringLiteral("Window")); | ||||
355 | layoutGroup.sync(); | ||||
356 | reconfigureLayouts(); | ||||
357 | auto xkb = input()->keyboard()->xkb(); | ||||
358 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | ||||
359 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
360 | | ||||
361 | // create a window | ||||
362 | using namespace KWayland::Client; | ||||
363 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
364 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||||
365 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | ||||
366 | QVERIFY(c1); | ||||
367 | | ||||
368 | // now switch layout | ||||
369 | auto changeLayout = [] (const QString &layoutName) { | ||||
370 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | ||||
371 | msg << layoutName; | ||||
372 | return QDBusConnection::sessionBus().asyncCall(msg); | ||||
373 | }; | ||||
374 | auto reply = changeLayout(QStringLiteral("German")); | ||||
375 | reply.waitForFinished(); | ||||
376 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
377 | | ||||
378 | // create a second window | ||||
379 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||||
380 | QScopedPointer<ShellSurface> shellSurface2(Test::createShellSurface(surface2.data())); | ||||
381 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | ||||
382 | QVERIFY(c2); | ||||
383 | // this should have switched back to English | ||||
384 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
385 | // now change to another layout | ||||
386 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | ||||
387 | reply.waitForFinished(); | ||||
388 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
389 | | ||||
390 | // activate other window | ||||
391 | workspace()->activateClient(c1); | ||||
392 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
393 | workspace()->activateClient(c2); | ||||
394 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
395 | } | ||||
396 | | ||||
340 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | 397 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | ||
341 | #include "keyboard_layout_test.moc" | 398 | #include "keyboard_layout_test.moc" |