From 4cc1b9cbaa3ff3da19cf29c1b726b3e8b4ab3362 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 4 Sep 2023 23:08:09 +0300 Subject: [PATCH] Introduce Window::desiredSize property --- src/interfaces/window.cpp | 14 ++++++++++++++ src/interfaces/window.h | 8 ++++++++ src/qwaylandlayersurface.cpp | 27 +++++---------------------- src/qwaylandlayersurface_p.h | 2 +- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index 97233e6..2f15a86 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -29,6 +29,7 @@ public: QWindow *parentWindow; QString scope = QStringLiteral("window"); + QSize desiredSize = QSize(0, 0); Window::Anchors anchors = {Window::AnchorTop | Window::AnchorBottom | Window::AnchorLeft | Window::AnchorRight}; int32_t exclusionZone = 0; Window::KeyboardInteractivity keyboardInteractivity = Window::KeyboardInteractivityNone; @@ -141,6 +142,19 @@ void Window::setCloseOnDismissed(bool close) d->closeOnDismissed = close; } +void Window::setDesiredSize(const QSize &size) +{ + if (d->desiredSize != size) { + d->desiredSize = size; + Q_EMIT desiredSizeChanged(); + } +} + +QSize Window::desiredSize() const +{ + return d->desiredSize; +} + #if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) void Window::attachPopup(QWindow *window, xdg_popup *popup) { diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 3f3ae80..9d6520d 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -114,6 +114,13 @@ public: void setCloseOnDismissed(bool close); bool closeOnDismissed() const; + /** + * Sets the desired window size. This size indicates how much space the compositor is going + * to reserve for the window. + */ + void setDesiredSize(const QSize &size); + QSize desiredSize() const; + /** * Gets the LayerShell Window for a given Qt Window * Ownership is not transferred @@ -132,6 +139,7 @@ Q_SIGNALS: void marginsChanged(); void keyboardInteractivityChanged(); void layerChanged(); + void desiredSizeChanged(); private: Window(QWindow *window); diff --git a/src/qwaylandlayersurface.cpp b/src/qwaylandlayersurface.cpp index cd1e1e0..2a77eb6 100644 --- a/src/qwaylandlayersurface.cpp +++ b/src/qwaylandlayersurface.cpp @@ -55,17 +55,10 @@ QWaylandLayerSurface::QWaylandLayerSurface(QtWayland::zwlr_layer_shell_v1 *shell setKeyboardInteractivity(m_interface->keyboardInteractivity()); }); - QSize size = window->surfaceSize(); - const Window::Anchors anchors = m_interface->anchors(); - if ((anchors & Window::AnchorLeft) && (anchors & Window::AnchorRight)) { - size.setWidth(0); - } - if ((anchors & Window::AnchorTop) && (anchors & Window::AnchorBottom)) { - size.setHeight(0); - } - if (size.isValid() && size != QSize(0, 0)) { - set_size(size.width(), size.height()); - } + setDesiredSize(m_interface->desiredSize()); + connect(m_interface, &Window::desiredSizeChanged, this, [this]() { + setDesiredSize(m_interface->desiredSize()); + }); } QWaylandLayerSurface::~QWaylandLayerSurface() @@ -141,18 +134,8 @@ void QWaylandLayerSurface::setLayer(uint32_t layer) set_layer(layer); } -void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry) +void QWaylandLayerSurface::setDesiredSize(const QSize &size) { - const bool horizontallyConstrained = m_interface->anchors() & (Window::AnchorLeft & Window::AnchorRight); - const bool verticallyConstrained = m_interface->anchors() & (Window::AnchorTop & Window::AnchorBottom); - - QSize size = geometry.size(); - if (horizontallyConstrained) { - size.setWidth(0); - } - if (verticallyConstrained) { - size.setHeight(0); - } set_size(size.width(), size.height()); } diff --git a/src/qwaylandlayersurface_p.h b/src/qwaylandlayersurface_p.h index dec2da0..1e83287 100644 --- a/src/qwaylandlayersurface_p.h +++ b/src/qwaylandlayersurface_p.h @@ -39,9 +39,9 @@ public: void setMargins(const QMargins &margins); void setKeyboardInteractivity(uint32_t interactivity); void setLayer(uint32_t layer); + void setDesiredSize(const QSize &size); void applyConfigure() override; - void setWindowGeometry(const QRect &geometry) override; private: void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override;