diff --git a/autotests/wayland/plasma_surface_test.cpp b/autotests/wayland/plasma_surface_test.cpp index 6efe216dc5..c652cffd40 100644 --- a/autotests/wayland/plasma_surface_test.cpp +++ b/autotests/wayland/plasma_surface_test.cpp @@ -46,6 +46,8 @@ private Q_SLOTS: void testRoleOnAllDesktops_data(); void testRoleOnAllDesktops(); + void testAcceptsFocus_data(); + void testAcceptsFocus(); private: ConnectionThread *m_connection = nullptr; @@ -205,5 +207,46 @@ void PlasmaSurfaceTest::testRoleOnAllDesktops() QCOMPARE(c->isOnAllDesktops(), expectedOnAllDesktops); } +void PlasmaSurfaceTest::testAcceptsFocus_data() +{ + QTest::addColumn("role"); + QTest::addColumn("wantsInput"); + QTest::addColumn("active"); + + QTest::newRow("Desktop") << PlasmaShellSurface::Role::Desktop << true << true; + QTest::newRow("Panel") << PlasmaShellSurface::Role::Panel << true << false; + QTest::newRow("OSD") << PlasmaShellSurface::Role::OnScreenDisplay << false << false; + QTest::newRow("Normal") << PlasmaShellSurface::Role::Normal << true << true; +} + +void PlasmaSurfaceTest::testAcceptsFocus() +{ + // this test verifies that some surface roles don't get focus + QScopedPointer surface(m_compositor->createSurface()); + QVERIFY(!surface.isNull()); + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QVERIFY(!shellSurface.isNull()); + QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); + QVERIFY(!plasmaSurface.isNull()); + QFETCH(PlasmaShellSurface::Role, role); + plasmaSurface->setRole(role); + + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + + // now render to map the window + QImage img(QSize(100, 50), QImage::Format_ARGB32); + img.fill(Qt::blue); + surface->attachBuffer(m_shm->createBuffer(img)); + surface->damage(QRect(0, 0, 100, 50)); + surface->commit(); + QVERIFY(clientAddedSpy.wait()); + + auto c = clientAddedSpy.first().first().value(); + QVERIFY(c); + QTEST(c->wantsInput(), "wantsInput"); + QTEST(c->isActive(), "active"); +} + WAYLANDTEST_MAIN(PlasmaSurfaceTest) #include "plasma_surface_test.moc" diff --git a/shell_client.cpp b/shell_client.cpp index 16d89a6953..2097f8a5f8 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -733,6 +733,11 @@ bool ShellClient::acceptsFocus() const if (waylandServer()->inputMethodConnection() == surface()->client()) { return false; } + if (m_plasmaShellSurface) { + if (m_plasmaShellSurface->role() == PlasmaShellSurfaceInterface::Role::OnScreenDisplay) { + return false; + } + } if (m_shellSurface) { if (m_shellSurface->isPopup()) { return false;