From 95956415c6285b5b8c58b050e280fa0247a109eb Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 30 Dec 2019 15:44:09 +0000 Subject: [PATCH] [plasmashell] Add signal for panelTakesFocus changing Test Plan: Attached unit test Reviewers: apol Reviewed By: apol Subscribers: apol, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D25965 --- src/wayland/autotests/client/test_plasmashell.cpp | 11 +++++++++-- src/wayland/plasmashell_interface.cpp | 4 ++++ src/wayland/plasmashell_interface.h | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/wayland/autotests/client/test_plasmashell.cpp b/src/wayland/autotests/client/test_plasmashell.cpp index 7c6082d04e..e14d9530d8 100644 --- a/src/wayland/autotests/client/test_plasmashell.cpp +++ b/src/wayland/autotests/client/test_plasmashell.cpp @@ -438,6 +438,7 @@ void TestPlasmaShell::testPanelTakesFocus() { // this test verifies that whether a panel wants to take focus is passed through correctly QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated); + QVERIFY(plasmaSurfaceCreatedSpy.isValid()); QScopedPointer s(m_compositor->createSurface()); QScopedPointer ps(m_plasmaShell->createSurface(s.data())); @@ -445,16 +446,22 @@ void TestPlasmaShell::testPanelTakesFocus() QVERIFY(plasmaSurfaceCreatedSpy.wait()); QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1); auto sps = plasmaSurfaceCreatedSpy.first().first().value(); + QSignalSpy plasmaSurfaceTakesFocusSpy(sps, &PlasmaShellSurfaceInterface::panelTakesFocusChanged); + QVERIFY(sps); QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Panel); QCOMPARE(sps->panelTakesFocus(), false); ps->setPanelTakesFocus(true); m_connection->flush(); - QTRY_COMPARE(sps->panelTakesFocus(), true); + QVERIFY(plasmaSurfaceTakesFocusSpy.wait()); + QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 1); + QCOMPARE(sps->panelTakesFocus(), true); ps->setPanelTakesFocus(false); m_connection->flush(); - QTRY_COMPARE(sps->panelTakesFocus(), false); + QVERIFY(plasmaSurfaceTakesFocusSpy.wait()); + QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 2); + QCOMPARE(sps->panelTakesFocus(), false); } void TestPlasmaShell::testDisconnect() diff --git a/src/wayland/plasmashell_interface.cpp b/src/wayland/plasmashell_interface.cpp index 2a020bd327..046c526404 100644 --- a/src/wayland/plasmashell_interface.cpp +++ b/src/wayland/plasmashell_interface.cpp @@ -317,7 +317,11 @@ void PlasmaShellSurfaceInterface::Private::panelTakesFocusCallback(wl_client *cl { auto s = cast(resource); Q_ASSERT(client == *s->client); + if (s->panelTakesFocus == takesFocus) { + return; + } s->panelTakesFocus = takesFocus; + emit s->q_func()->panelTakesFocusChanged(); } void PlasmaShellSurfaceInterface::Private::setPanelBehavior(org_kde_plasma_surface_panel_behavior behavior) diff --git a/src/wayland/plasmashell_interface.h b/src/wayland/plasmashell_interface.h index 7e00611820..8daf08626e 100644 --- a/src/wayland/plasmashell_interface.h +++ b/src/wayland/plasmashell_interface.h @@ -234,6 +234,13 @@ Q_SIGNALS: **/ void panelAutoHideShowRequested(); + /* + * Emitted when panelTakesFocus changes + * @see panelTakesFocus + * @since 5.66 + */ + void panelTakesFocusChanged(); + private: friend class PlasmaShellInterface; explicit PlasmaShellSurfaceInterface(PlasmaShellInterface *shell, SurfaceInterface *parent, wl_resource *parentResource);