diff --git a/autotests/wayland/maximize_test.cpp b/autotests/wayland/maximize_test.cpp index 7e6bea13ba..24fbf9d0b2 100644 --- a/autotests/wayland/maximize_test.cpp +++ b/autotests/wayland/maximize_test.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include "shell_client.h" #include "screens.h" #include "wayland_server.h" +#include "workspace.h" #include #include @@ -31,9 +32,13 @@ along with this program. If not, see . #include #include #include +#include #include +#include +#include + #include using namespace KWin; @@ -49,6 +54,7 @@ private Q_SLOTS: void init(); void cleanup(); + void testMaximizedPassedToDeco(); void testInitiallyMaximized(); private: @@ -56,6 +62,7 @@ private: Shell *m_shell = nullptr; ShmPool *m_shm = nullptr; EventQueue *m_queue = nullptr; + ServerSideDecorationManager *m_ssd = nullptr; ConnectionThread *m_connection = nullptr; QThread *m_thread = nullptr; }; @@ -119,6 +126,10 @@ void TestMaximized::init() registry.interface(Registry::Interface::Shell).version, this); QVERIFY(m_shell->isValid()); + m_ssd = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, + registry.interface(Registry::Interface::ServerSideDecorationManager).version, + this); + QVERIFY(m_ssd); screens()->setCurrent(0); KWin::Cursor::setPos(QPoint(1280, 512)); @@ -134,6 +145,7 @@ void TestMaximized::cleanup() CLEANUP(m_compositor) CLEANUP(m_shm) CLEANUP(m_shell) + CLEANUP(m_ssd) CLEANUP(m_queue) if (m_connection) { @@ -149,6 +161,45 @@ void TestMaximized::cleanup() #undef CLEANUP } +void TestMaximized::testMaximizedPassedToDeco() +{ + // this test verifies that when a ShellClient gets maximized the Decoration receives the signal + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer ssd(m_ssd->create(surface.data())); + + 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(Surface::CommitFlag::None); + + QVERIFY(clientAddedSpy.isEmpty()); + QVERIFY(clientAddedSpy.wait()); + auto client = clientAddedSpy.first().first().value(); + QVERIFY(client); + QVERIFY(client->isDecorated()); + auto decoration = client->decoration(); + QVERIFY(decoration); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore); + + // now maximize + QSignalSpy maximizedChangedSpy(decoration->client().data(), &KDecoration2::DecoratedClient::maximizedChanged); + QVERIFY(maximizedChangedSpy.isValid()); + workspace()->slotWindowMaximize(); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeFull); + QCOMPARE(maximizedChangedSpy.count(), 1); + QCOMPARE(maximizedChangedSpy.last().first().toBool(), true); + + // now unmaximize again + workspace()->slotWindowMaximize(); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore); + QCOMPARE(maximizedChangedSpy.count(), 2); + QCOMPARE(maximizedChangedSpy.last().first().toBool(), false); +} + void TestMaximized::testInitiallyMaximized() { // this test verifies that a window created as maximized, will be maximized diff --git a/decorations/decoratedclient.cpp b/decorations/decoratedclient.cpp index f8c2426604..083c23ecf8 100644 --- a/decorations/decoratedclient.cpp +++ b/decorations/decoratedclient.cpp @@ -99,6 +99,14 @@ DecoratedClientImpl::DecoratedClientImpl(AbstractClient *client, KDecoration2::D connect(client, &AbstractClient::minimizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::minimizeableChanged); connect(client, &AbstractClient::maximizeableChanged, decoratedClient, &KDecoration2::DecoratedClient::maximizeableChanged); + auto signalMaximizeChanged = static_cast(&AbstractClient::clientMaximizedStateChanged); + connect(client, signalMaximizeChanged, decoratedClient, + [this, decoratedClient] (AbstractClient *client, MaximizeMode mode) { + Q_UNUSED(client) + emit decoratedClient->maximizedChanged(mode == MaximizeMode::MaximizeFull); + } + ); + connect(client, &AbstractClient::paletteChanged, decoratedClient, &KDecoration2::DecoratedClient::paletteChanged); }