diff --git a/src/wayland/autotests/client/test_wayland_shell.cpp b/src/wayland/autotests/client/test_wayland_shell.cpp index 2957baf426..34d0459050 100644 --- a/src/wayland/autotests/client/test_wayland_shell.cpp +++ b/src/wayland/autotests/client/test_wayland_shell.cpp @@ -45,6 +45,7 @@ private Q_SLOTS: void testCreateMultiple(); void testFullscreen(); + void testMaximize(); void testPing(); void testTitle(); void testWindowClass(); @@ -247,6 +248,46 @@ void TestWaylandShell::testFullscreen() QVERIFY(!fullscreenSpy.first().first().toBool()); } +void TestWaylandShell::testMaximize() +{ + using namespace KWayland::Server; + QScopedPointer s(m_compositor->createSurface()); + QVERIFY(!s.isNull()); + QVERIFY(s->isValid()); + KWayland::Client::ShellSurface *surface = m_shell->createSurface(s.data(), m_shell); + QSignalSpy sizeSpy(surface, SIGNAL(sizeChanged(QSize))); + QVERIFY(sizeSpy.isValid()); + QCOMPARE(surface->size(), QSize()); + + QSignalSpy serverSurfaceSpy(m_shellInterface, SIGNAL(surfaceCreated(KWayland::Server::ShellSurfaceInterface*))); + QVERIFY(serverSurfaceSpy.isValid()); + QVERIFY(serverSurfaceSpy.wait()); + ShellSurfaceInterface *serverSurface = serverSurfaceSpy.first().first().value(); + QVERIFY(serverSurface); + QVERIFY(serverSurface->parentResource()); + + QSignalSpy maximizedSpy(serverSurface, SIGNAL(maximizedChanged(bool))); + QVERIFY(maximizedSpy.isValid()); + + surface->setMaximized(); + QVERIFY(maximizedSpy.wait()); + QCOMPARE(maximizedSpy.count(), 1); + QVERIFY(maximizedSpy.first().first().toBool()); + serverSurface->requestSize(QSize(1024, 768)); + + QVERIFY(sizeSpy.wait()); + QCOMPARE(sizeSpy.count(), 1); + QCOMPARE(sizeSpy.first().first().toSize(), QSize(1024, 768)); + QCOMPARE(surface->size(), QSize(1024, 768)); + + // set back to toplevel + maximizedSpy.clear(); + wl_shell_surface_set_toplevel(*surface); + QVERIFY(maximizedSpy.wait()); + QCOMPARE(maximizedSpy.count(), 1); + QVERIFY(!maximizedSpy.first().first().toBool()); +} + void TestWaylandShell::testPing() { using namespace KWayland::Server; diff --git a/src/wayland/server/shell_interface.cpp b/src/wayland/server/shell_interface.cpp index 0360aecee0..1839fa3338 100644 --- a/src/wayland/server/shell_interface.cpp +++ b/src/wayland/server/shell_interface.cpp @@ -68,6 +68,7 @@ public: Private(ShellSurfaceInterface *q, ShellInterface *shell, SurfaceInterface *surface, wl_resource *parentResource); void setFullscreen(bool fullscreen); void setToplevel(bool toplevel); + void setMaximized(bool maximized); void ping(); SurfaceInterface *surface; @@ -77,6 +78,7 @@ public: quint32 pingSerial = 0; bool fullscreen = false; bool toplevel = false; + bool maximized = false; private: // interface callbacks @@ -188,6 +190,7 @@ ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInter } Q_D(); d->setToplevel(false); + d->setMaximized(false); } ); connect(this, &ShellSurfaceInterface::toplevelChanged, this, @@ -197,6 +200,17 @@ ShellSurfaceInterface::ShellSurfaceInterface(ShellInterface *shell, SurfaceInter } Q_D(); d->setFullscreen(false); + d->setMaximized(false); + } + ); + connect(this, &ShellSurfaceInterface::maximizedChanged, this, + [this] (bool maximized) { + if (!maximized) { + return; + } + Q_D(); + d->setFullscreen(false); + d->setToplevel(false); } ); } @@ -345,7 +359,17 @@ void ShellSurfaceInterface::Private::setMaximizedCallback(wl_client *client, wl_ Q_UNUSED(output) auto s = cast(resource); Q_ASSERT(client == *s->client); - // TODO: implement + s->setMaximized(true); +} + +void ShellSurfaceInterface::Private::setMaximized(bool set) +{ + if (maximized == set) { + return; + } + maximized = set; + Q_Q(ShellSurfaceInterface); + emit q->maximizedChanged(maximized); } void ShellSurfaceInterface::Private::setTitleCallback(wl_client *client, wl_resource *resource, const char *title) @@ -412,6 +436,11 @@ bool ShellSurfaceInterface::isToplevel() const { return d->toplevel; } +bool ShellSurfaceInterface::isMaximized() const { + Q_D(); + return d->maximized; +} + ShellSurfaceInterface::Private *ShellSurfaceInterface::d_func() const { return reinterpret_cast(d.data()); diff --git a/src/wayland/server/shell_interface.h b/src/wayland/server/shell_interface.h index 4a70a37d39..4d80045ba1 100644 --- a/src/wayland/server/shell_interface.h +++ b/src/wayland/server/shell_interface.h @@ -61,6 +61,7 @@ class KWAYLANDSERVER_EXPORT ShellSurfaceInterface : public Resource Q_PROPERTY(QByteArray windowClass READ windowClass NOTIFY windowClassChanged) Q_PROPERTY(bool fullscreen READ isFullscreen NOTIFY fullscreenChanged) Q_PROPERTY(bool toplevel READ isToplevel NOTIFY toplevelChanged) + Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged) public: virtual ~ShellSurfaceInterface(); @@ -76,6 +77,7 @@ public: QByteArray windowClass() const; bool isFullscreen() const; bool isToplevel() const; + bool isMaximized() const; Q_SIGNALS: void titleChanged(const QString&); @@ -84,6 +86,7 @@ Q_SIGNALS: void pongReceived(); void fullscreenChanged(bool); void toplevelChanged(bool); + void maximizedChanged(bool); private: friend class ShellInterface;