Do not activate on-screen-display windows

Summary:
Plasma's OSD windows were stealing focus on Wayland. We can be sure
that they should not get keyboard focus, so a check to acceptsFocus
is added.

Reviewers: #plasma_on_wayland, #kwin

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D1927
This commit is contained in:
Martin Gräßlin 2016-06-17 08:32:15 +02:00
parent 74f98d4c12
commit 8a85cc5f9c
2 changed files with 48 additions and 0 deletions

View file

@ -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<PlasmaShellSurface::Role>("role");
QTest::addColumn<bool>("wantsInput");
QTest::addColumn<bool>("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> surface(m_compositor->createSurface());
QVERIFY(!surface.isNull());
QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data()));
QVERIFY(!shellSurface.isNull());
QScopedPointer<PlasmaShellSurface> 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<ShellClient*>();
QVERIFY(c);
QTEST(c->wantsInput(), "wantsInput");
QTEST(c->isActive(), "active");
}
WAYLANDTEST_MAIN(PlasmaSurfaceTest)
#include "plasma_surface_test.moc"

View file

@ -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;