Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/keyboard_layout_test.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 51 | private Q_SLOTS: | |||
---|---|---|---|---|---|
54 | void cleanup(); | 54 | void cleanup(); | ||
55 | 55 | | |||
56 | void testReconfigure(); | 56 | void testReconfigure(); | ||
57 | void testChangeLayoutThroughDBus(); | 57 | void testChangeLayoutThroughDBus(); | ||
58 | void testPerLayoutShortcut(); | 58 | void testPerLayoutShortcut(); | ||
59 | void testDBusServiceExport(); | 59 | void testDBusServiceExport(); | ||
60 | void testVirtualDesktopPolicy(); | 60 | void testVirtualDesktopPolicy(); | ||
61 | void testWindowPolicy(); | 61 | void testWindowPolicy(); | ||
62 | void testApplicationPolicy(); | ||||
62 | 63 | | |||
63 | private: | 64 | private: | ||
64 | void reconfigureLayouts(); | 65 | void reconfigureLayouts(); | ||
65 | }; | 66 | }; | ||
66 | 67 | | |||
67 | void KeyboardLayoutTest::reconfigureLayouts() | 68 | void KeyboardLayoutTest::reconfigureLayouts() | ||
68 | { | 69 | { | ||
69 | // create DBus signal to reload | 70 | // create DBus signal to reload | ||
▲ Show 20 Lines • Show All 319 Lines • ▼ Show 20 Line(s) | 352 | { | |||
389 | 390 | | |||
390 | // activate other window | 391 | // activate other window | ||
391 | workspace()->activateClient(c1); | 392 | workspace()->activateClient(c1); | ||
392 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | 393 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||
393 | workspace()->activateClient(c2); | 394 | workspace()->activateClient(c2); | ||
394 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | 395 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||
395 | } | 396 | } | ||
396 | 397 | | |||
398 | void KeyboardLayoutTest::testApplicationPolicy() | ||||
399 | { | ||||
400 | KConfigGroup layoutGroup = kwinApp()->kxkbConfig()->group("Layout"); | ||||
401 | layoutGroup.writeEntry("LayoutList", QStringLiteral("us,de,de(neo)")); | ||||
402 | layoutGroup.writeEntry("SwitchMode", QStringLiteral("WinClass")); | ||||
403 | layoutGroup.sync(); | ||||
404 | reconfigureLayouts(); | ||||
405 | auto xkb = input()->keyboard()->xkb(); | ||||
406 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | ||||
407 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||||
408 | | ||||
409 | // create a window | ||||
410 | using namespace KWayland::Client; | ||||
411 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
412 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||||
413 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | ||||
414 | QVERIFY(c1); | ||||
415 | | ||||
416 | // now switch layout | ||||
417 | auto changeLayout = [] (const QString &layoutName) { | ||||
418 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | ||||
419 | msg << layoutName; | ||||
420 | return QDBusConnection::sessionBus().asyncCall(msg); | ||||
421 | }; | ||||
422 | LayoutChangedSignalWrapper wrapper; | ||||
423 | QSignalSpy layoutChangedSpy(&wrapper, &LayoutChangedSignalWrapper::layoutChanged); | ||||
424 | QVERIFY(layoutChangedSpy.isValid()); | ||||
425 | auto reply = changeLayout(QStringLiteral("German")); | ||||
426 | QVERIFY(layoutChangedSpy.wait()); | ||||
427 | QCOMPARE(layoutChangedSpy.count(), 1); | ||||
428 | reply.waitForFinished(); | ||||
429 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||||
430 | | ||||
431 | // create a second window | ||||
432 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||||
433 | QScopedPointer<ShellSurface> shellSurface2(Test::createShellSurface(surface2.data())); | ||||
434 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | ||||
435 | QVERIFY(c2); | ||||
436 | // it is the same application and should not switch the layout | ||||
437 | QVERIFY(!layoutChangedSpy.wait()); | ||||
438 | QCOMPARE(layoutChangedSpy.count(), 1); | ||||
439 | // now change to another layout | ||||
440 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | ||||
441 | QVERIFY(layoutChangedSpy.wait()); | ||||
442 | QCOMPARE(layoutChangedSpy.count(), 2); | ||||
443 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
444 | | ||||
445 | // activate other window | ||||
446 | workspace()->activateClient(c1); | ||||
447 | QVERIFY(!layoutChangedSpy.wait()); | ||||
448 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
449 | workspace()->activateClient(c2); | ||||
450 | QVERIFY(!layoutChangedSpy.wait()); | ||||
451 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
452 | | ||||
453 | shellSurface2.reset(); | ||||
454 | surface2.reset(); | ||||
455 | QVERIFY(Test::waitForWindowDestroyed(c2)); | ||||
456 | QVERIFY(!layoutChangedSpy.wait()); | ||||
457 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||||
458 | } | ||||
459 | | ||||
397 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | 460 | WAYLANDTEST_MAIN(KeyboardLayoutTest) | ||
398 | #include "keyboard_layout_test.moc" | 461 | #include "keyboard_layout_test.moc" |