From f073c773da6801096ecab9454cba3ecd47d69bf6 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 21 Feb 2020 12:16:38 +0200 Subject: [PATCH] [server] Introduce SurfaceInterface::boundingRect() Summary: The new method provides a convenient way for determining the rectangle that bounds the given surface and all of its sub-surfaces. This can be very handy when determining the effective window geometry. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: apol, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D27828 --- src/wayland/surface_interface.cpp | 13 +++++++++++++ src/wayland/surface_interface.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/wayland/surface_interface.cpp b/src/wayland/surface_interface.cpp index 0690b19749..baa7c85441 100644 --- a/src/wayland/surface_interface.cpp +++ b/src/wayland/surface_interface.cpp @@ -772,6 +772,19 @@ QSize SurfaceInterface::size() const return QSize(); } +QRect SurfaceInterface::boundingRect() const +{ + QRect rect(QPoint(0, 0), size()); + + const QList> subSurfaces = childSubSurfaces(); + for (const SubSurfaceInterface *subSurface : subSurfaces) { + const SurfaceInterface *childSurface = subSurface->surface(); + rect |= childSurface->boundingRect().translated(subSurface->position()); + } + + return rect; +} + QPointer< ShadowInterface > SurfaceInterface::shadow() const { Q_D(); diff --git a/src/wayland/surface_interface.h b/src/wayland/surface_interface.h index 632bbc8a5c..fb61978fda 100644 --- a/src/wayland/surface_interface.h +++ b/src/wayland/surface_interface.h @@ -112,6 +112,14 @@ public: * @since 5.3 **/ QSize size() const; + /** + * Returns the rectangle that bounds this surface and all of its sub-surfaces. + * + * QPoint(0, 0) corresponds to the upper left corner of this surface. + * + * @since 5.69 + */ + QRect boundingRect() const; /** * @returns The SubSurface for this Surface in case there is one.