From d6af43763c9157576c13dc330096e344dad98330 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 5 Apr 2022 20:48:05 +0300 Subject: [PATCH] Add convenience AbstractOutput::rect() function Foobar::rect() is a common Qt API convention which is very handy when you need a rect that looks like rect(0, 0, w, h). --- src/abstract_output.h | 10 ++++++++++ src/backends/drm/drm_abstract_output.cpp | 2 +- src/backends/wayland/egl_wayland_backend.cpp | 2 +- src/backends/x11/windowed/egl_x11_backend.cpp | 2 +- .../x11/windowed/scene_qpainter_x11_backend.cpp | 2 +- src/composite.cpp | 4 ++-- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/abstract_output.h b/src/abstract_output.h index a8f759c0c4..718d508b74 100644 --- a/src/abstract_output.h +++ b/src/abstract_output.h @@ -137,6 +137,11 @@ public: */ virtual QRect geometry() const = 0; + /** + * Equivalent to `QRect(QPoint(0, 0), geometry().size())` + */ + QRect rect() const; + /** * Returns the approximate vertical refresh rate of this output, in mHz. */ @@ -285,6 +290,11 @@ private: friend class EffectScreenImpl; // to access m_effectScreen }; +inline QRect AbstractOutput::rect() const +{ + return QRect(QPoint(0, 0), geometry().size()); +} + KWIN_EXPORT QDebug operator<<(QDebug debug, const AbstractOutput *output); } // namespace KWin diff --git a/src/backends/drm/drm_abstract_output.cpp b/src/backends/drm/drm_abstract_output.cpp index 81690b1445..f660315b46 100644 --- a/src/backends/drm/drm_abstract_output.cpp +++ b/src/backends/drm/drm_abstract_output.cpp @@ -39,7 +39,7 @@ void DrmAbstractOutput::pageFlipped(std::chrono::nanoseconds timestamp) const QVector DrmAbstractOutput::regionToRects(const QRegion ®ion) const { const int height = pixelSize().height(); - const QMatrix4x4 matrix = AbstractWaylandOutput::logicalToNativeMatrix(QRect(QPoint(0, 0), geometry().size()), scale(), transform()); + const QMatrix4x4 matrix = AbstractWaylandOutput::logicalToNativeMatrix(rect(), scale(), transform()); QVector rects; rects.reserve(region.rectCount() * 4); for (const QRect &_rect : region) { diff --git a/src/backends/wayland/egl_wayland_backend.cpp b/src/backends/wayland/egl_wayland_backend.cpp index bea12a69c8..bc3b1111cd 100644 --- a/src/backends/wayland/egl_wayland_backend.cpp +++ b/src/backends/wayland/egl_wayland_backend.cpp @@ -297,7 +297,7 @@ bool EglWaylandBackend::initBufferConfigs() static QVector regionToRects(const QRegion ®ion, AbstractWaylandOutput *output) { const int height = output->modeSize().height(); - const QMatrix4x4 matrix = WaylandOutput::logicalToNativeMatrix(QRect(QPoint(0, 0), output->geometry().size()), + const QMatrix4x4 matrix = WaylandOutput::logicalToNativeMatrix(output->rect(), output->scale(), output->transform()); diff --git a/src/backends/x11/windowed/egl_x11_backend.cpp b/src/backends/x11/windowed/egl_x11_backend.cpp index bef3170d8a..a22237c032 100644 --- a/src/backends/x11/windowed/egl_x11_backend.cpp +++ b/src/backends/x11/windowed/egl_x11_backend.cpp @@ -71,7 +71,7 @@ QRegion EglX11Backend::beginFrame(AbstractOutput *output) const EglX11Output *rendererOutput = m_outputs[output]; makeContextCurrent(rendererOutput->m_eglSurface); GLRenderTarget::pushRenderTarget(rendererOutput->m_renderTarget.data()); - return QRect(QPoint(0, 0), output->geometry().size()); + return output->rect(); } void EglX11Backend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damagedRegion) diff --git a/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp b/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp index b981405f1b..361421cf86 100644 --- a/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp +++ b/src/backends/x11/windowed/scene_qpainter_x11_backend.cpp @@ -52,7 +52,7 @@ QImage *X11WindowedQPainterBackend::bufferForScreen(AbstractOutput *output) QRegion X11WindowedQPainterBackend::beginFrame(AbstractOutput *output) { - return QRect(QPoint(0, 0), output->geometry().size()); + return output->rect(); } void X11WindowedQPainterBackend::endFrame(AbstractOutput *output, const QRegion &renderedRegion, const QRegion &damagedRegion) diff --git a/src/composite.cpp b/src/composite.cpp index b7ae35c26b..20ff66e230 100644 --- a/src/composite.cpp +++ b/src/composite.cpp @@ -434,9 +434,9 @@ void Compositor::addOutput(AbstractOutput *output) auto workspaceLayer = new RenderLayer(output->renderLoop()); workspaceLayer->setDelegate(new SceneDelegate(m_scene, output)); - workspaceLayer->setGeometry(QRect(QPoint(0, 0), output->geometry().size())); + workspaceLayer->setGeometry(output->rect()); connect(output, &AbstractOutput::geometryChanged, workspaceLayer, [output, workspaceLayer]() { - workspaceLayer->setGeometry(QRect(QPoint(0, 0), output->geometry().size())); + workspaceLayer->setGeometry(output->rect()); }); auto cursorLayer = new RenderLayer(output->renderLoop());