Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/keyboard_layout_test.cpp
Show All 24 Lines | |||||
25 | #include "virtualdesktops.h" | 25 | #include "virtualdesktops.h" | ||
26 | #include "wayland_server.h" | 26 | #include "wayland_server.h" | ||
27 | #include "workspace.h" | 27 | #include "workspace.h" | ||
28 | 28 | | |||
29 | #include <KConfigGroup> | 29 | #include <KConfigGroup> | ||
30 | #include <KGlobalAccel> | 30 | #include <KGlobalAccel> | ||
31 | 31 | | |||
32 | #include <KWayland/Client/surface.h> | 32 | #include <KWayland/Client/surface.h> | ||
33 | #include <KWayland/Client/shell.h> | | |||
34 | 33 | | |||
35 | #include <QAction> | 34 | #include <QAction> | ||
36 | #include <QDBusConnection> | 35 | #include <QDBusConnection> | ||
37 | #include <QDBusConnectionInterface> | 36 | #include <QDBusConnectionInterface> | ||
38 | #include <QDBusMessage> | 37 | #include <QDBusMessage> | ||
39 | #include <QDBusPendingCall> | 38 | #include <QDBusPendingCall> | ||
40 | 39 | | |||
41 | #include <linux/input.h> | 40 | #include <linux/input.h> | ||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | 353 | { | |||
359 | reconfigureLayouts(); | 358 | reconfigureLayouts(); | ||
360 | auto xkb = input()->keyboard()->xkb(); | 359 | auto xkb = input()->keyboard()->xkb(); | ||
361 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | 360 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | ||
362 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | 361 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||
363 | 362 | | |||
364 | // create a window | 363 | // create a window | ||
365 | using namespace KWayland::Client; | 364 | using namespace KWayland::Client; | ||
366 | QScopedPointer<Surface> surface(Test::createSurface()); | 365 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
367 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | 366 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
368 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | 367 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | ||
369 | QVERIFY(c1); | 368 | QVERIFY(c1); | ||
370 | 369 | | |||
371 | // now switch layout | 370 | // now switch layout | ||
372 | auto changeLayout = [] (const QString &layoutName) { | 371 | auto changeLayout = [] (const QString &layoutName) { | ||
373 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | 372 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | ||
374 | msg << layoutName; | 373 | msg << layoutName; | ||
375 | return QDBusConnection::sessionBus().asyncCall(msg); | 374 | return QDBusConnection::sessionBus().asyncCall(msg); | ||
376 | }; | 375 | }; | ||
377 | auto reply = changeLayout(QStringLiteral("German")); | 376 | auto reply = changeLayout(QStringLiteral("German")); | ||
378 | reply.waitForFinished(); | 377 | reply.waitForFinished(); | ||
379 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | 378 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||
380 | 379 | | |||
381 | // create a second window | 380 | // create a second window | ||
382 | QScopedPointer<Surface> surface2(Test::createSurface()); | 381 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
383 | QScopedPointer<ShellSurface> shellSurface2(Test::createShellSurface(surface2.data())); | 382 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
384 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | 383 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | ||
385 | QVERIFY(c2); | 384 | QVERIFY(c2); | ||
386 | // this should have switched back to English | 385 | // this should have switched back to English | ||
387 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | 386 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||
388 | // now change to another layout | 387 | // now change to another layout | ||
389 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | 388 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | ||
390 | reply.waitForFinished(); | 389 | reply.waitForFinished(); | ||
391 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | 390 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German (Neo 2)")); | ||
Show All 14 Lines | 400 | { | |||
406 | reconfigureLayouts(); | 405 | reconfigureLayouts(); | ||
407 | auto xkb = input()->keyboard()->xkb(); | 406 | auto xkb = input()->keyboard()->xkb(); | ||
408 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | 407 | QTRY_COMPARE(xkb->numberOfLayouts(), 3u); | ||
409 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | 408 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)")); | ||
410 | 409 | | |||
411 | // create a window | 410 | // create a window | ||
412 | using namespace KWayland::Client; | 411 | using namespace KWayland::Client; | ||
413 | QScopedPointer<Surface> surface(Test::createSurface()); | 412 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
414 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | 413 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||
415 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | 414 | auto c1 = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); | ||
416 | QVERIFY(c1); | 415 | QVERIFY(c1); | ||
417 | 416 | | |||
418 | // now switch layout | 417 | // now switch layout | ||
419 | auto changeLayout = [] (const QString &layoutName) { | 418 | auto changeLayout = [] (const QString &layoutName) { | ||
420 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | 419 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts"), QStringLiteral("setLayout")); | ||
421 | msg << layoutName; | 420 | msg << layoutName; | ||
422 | return QDBusConnection::sessionBus().asyncCall(msg); | 421 | return QDBusConnection::sessionBus().asyncCall(msg); | ||
423 | }; | 422 | }; | ||
424 | LayoutChangedSignalWrapper wrapper; | 423 | LayoutChangedSignalWrapper wrapper; | ||
425 | QSignalSpy layoutChangedSpy(&wrapper, &LayoutChangedSignalWrapper::layoutChanged); | 424 | QSignalSpy layoutChangedSpy(&wrapper, &LayoutChangedSignalWrapper::layoutChanged); | ||
426 | QVERIFY(layoutChangedSpy.isValid()); | 425 | QVERIFY(layoutChangedSpy.isValid()); | ||
427 | auto reply = changeLayout(QStringLiteral("German")); | 426 | auto reply = changeLayout(QStringLiteral("German")); | ||
428 | QVERIFY(layoutChangedSpy.wait()); | 427 | QVERIFY(layoutChangedSpy.wait()); | ||
429 | QCOMPARE(layoutChangedSpy.count(), 1); | 428 | QCOMPARE(layoutChangedSpy.count(), 1); | ||
430 | reply.waitForFinished(); | 429 | reply.waitForFinished(); | ||
431 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | 430 | QTRY_COMPARE(xkb->layoutName(), QStringLiteral("German")); | ||
432 | 431 | | |||
433 | // create a second window | 432 | // create a second window | ||
434 | QScopedPointer<Surface> surface2(Test::createSurface()); | 433 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
435 | QScopedPointer<ShellSurface> shellSurface2(Test::createShellSurface(surface2.data())); | 434 | QScopedPointer<XdgShellSurface> shellSurface2(Test::createXdgShellStableSurface(surface2.data())); | ||
436 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | 435 | auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 100), Qt::red); | ||
437 | QVERIFY(c2); | 436 | QVERIFY(c2); | ||
438 | // it is the same application and should not switch the layout | 437 | // it is the same application and should not switch the layout | ||
439 | QVERIFY(!layoutChangedSpy.wait()); | 438 | QVERIFY(!layoutChangedSpy.wait()); | ||
440 | QCOMPARE(layoutChangedSpy.count(), 1); | 439 | QCOMPARE(layoutChangedSpy.count(), 1); | ||
441 | // now change to another layout | 440 | // now change to another layout | ||
442 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | 441 | reply = changeLayout(QStringLiteral("German (Neo 2)")); | ||
443 | QVERIFY(layoutChangedSpy.wait()); | 442 | QVERIFY(layoutChangedSpy.wait()); | ||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |