From 21dca7ac14572fc6f7c888025388a65157f30a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 21 Oct 2014 07:46:44 +0200 Subject: [PATCH] Keep a QPointer in Client This allows to remove the internal access to the DecoratedClientPrivate in the KDecoration API. --- client.cpp | 12 +++++++----- client.h | 7 ++++++- composite.cpp | 4 ++-- decorations/decoratedclient.cpp | 1 + deleted.cpp | 4 ++-- scene_opengl.cpp | 11 ++++++----- scene_qpainter.cpp | 4 ++-- scene_xrender.cpp | 4 ++-- 8 files changed, 28 insertions(+), 19 deletions(-) diff --git a/client.cpp b/client.cpp index a0b2bada6f..529b32fa2c 100644 --- a/client.cpp +++ b/client.cpp @@ -2492,12 +2492,14 @@ BORDER(Right) BORDER(Top) #undef BORDER -Decoration::DecoratedClientImpl *Client::decoratedClient() +QPointer Client::decoratedClient() const { - if (!m_decoration) { - return nullptr; - } - return static_cast(m_decoration->client()->handle()); + return m_decoratedClient; +} + +void Client::setDecoratedClient(QPointer< Decoration::DecoratedClientImpl > client) +{ + m_decoratedClient = client; } } // namespace diff --git a/client.h b/client.h index d74c588e07..c2b814e5a0 100644 --- a/client.h +++ b/client.h @@ -596,7 +596,11 @@ public: const KDecoration2::Decoration *decoration() const { return m_decoration; } - Decoration::DecoratedClientImpl *decoratedClient(); + QPointer decoratedClient() const; + bool isDecorated() const { + return m_decoration != nullptr; + } + void setDecoratedClient(QPointer client); QRect decorationRect() const; @@ -863,6 +867,7 @@ private: // wrapper around m_frame to use as a parent for the decoration QScopedPointer m_frameWrapper; KDecoration2::Decoration *m_decoration; + QPointer m_decoratedClient; int desk; QStringList activityList; int m_activityUpdatesBlocked; diff --git a/composite.cpp b/composite.cpp index d1fb886d33..d961d8c66b 100644 --- a/composite.cpp +++ b/composite.cpp @@ -1128,7 +1128,7 @@ bool Client::setupCompositing() if (!Toplevel::setupCompositing()){ return false; } - if (decoratedClient()) { + if (isDecorated()) { decoratedClient()->destroyRenderer(); } updateVisibility(); // for internalKeep() @@ -1140,7 +1140,7 @@ void Client::finishCompositing(ReleaseReason releaseReason) Toplevel::finishCompositing(releaseReason); updateVisibility(); if (!deleting) { - if (decoratedClient()) { + if (isDecorated()) { decoratedClient()->destroyRenderer(); } } diff --git a/decorations/decoratedclient.cpp b/decorations/decoratedclient.cpp index 1abc0f21db..d6ba5cfd1c 100644 --- a/decorations/decoratedclient.cpp +++ b/decorations/decoratedclient.cpp @@ -43,6 +43,7 @@ DecoratedClientImpl::DecoratedClientImpl(Client *client, KDecoration2::Decorated , m_renderer(nullptr) { createRenderer(); + client->setDecoratedClient(QPointer(this)); connect(client, &Client::activeChanged, this, [decoratedClient, client]() { emit decoratedClient->activeChanged(client->isActive()); diff --git a/deleted.cpp b/deleted.cpp index c6cb2d4085..b3bd9aadaa 100644 --- a/deleted.cpp +++ b/deleted.cpp @@ -90,8 +90,8 @@ void Deleted::copyToDeleted(Toplevel* c) decoration_top, decoration_right, decoration_bottom); - if (Decoration::DecoratedClientImpl *decoClient = client->decoratedClient()) { - if (Decoration::Renderer *renderer = decoClient->renderer()) { + if (client->isDecorated()) { + if (Decoration::Renderer *renderer = client->decoratedClient()->renderer()) { m_decorationRenderer = renderer; m_decorationRenderer->reparent(this); } diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 16e1094deb..7b621eb088 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1195,11 +1195,12 @@ GLTexture *SceneOpenGL::Window::getDecorationTexture() const return nullptr; } - if (Decoration::DecoratedClientImpl *impl = client->decoratedClient()) { - if (SceneOpenGLDecorationRenderer *renderer = static_cast(impl->renderer())) { - renderer->render(); - return renderer->texture(); - } + if (!client->isDecorated()) { + return nullptr; + } + if (SceneOpenGLDecorationRenderer *renderer = static_cast(client->decoratedClient()->renderer())) { + renderer->render(); + return renderer->texture(); } } else if (toplevel->isDeleted()) { Deleted *deleted = static_cast(toplevel); diff --git a/scene_qpainter.cpp b/scene_qpainter.cpp index 210d04dd45..1e97ffd980 100644 --- a/scene_qpainter.cpp +++ b/scene_qpainter.cpp @@ -423,8 +423,8 @@ void SceneQPainter::Window::renderWindowDecorations(QPainter *painter) const SceneQPainterDecorationRenderer *renderer = nullptr; QRect dtr, dlr, drr, dbr; if (client && !client->noBorder()) { - if (Decoration::DecoratedClientImpl *impl = client->decoratedClient()) { - if (SceneQPainterDecorationRenderer *r = static_cast(impl->renderer())) { + if (client->isDecorated()) { + if (SceneQPainterDecorationRenderer *r = static_cast(client->decoratedClient()->renderer())) { r->render(); renderer = r; } diff --git a/scene_xrender.cpp b/scene_xrender.cpp index 042f571407..7445b5a885 100644 --- a/scene_xrender.cpp +++ b/scene_xrender.cpp @@ -660,8 +660,8 @@ void SceneXrender::Window::performPaint(int mask, QRegion region, WindowPaintDat const SceneXRenderDecorationRenderer *renderer = nullptr; if (client) { if (client && !client->noBorder()) { - if (Decoration::DecoratedClientImpl *impl = client->decoratedClient()) { - SceneXRenderDecorationRenderer *r = static_cast(impl->renderer()); + if (client->isDecorated()) { + SceneXRenderDecorationRenderer *r = static_cast(client->decoratedClient()->renderer()); if (r) { r->render(); renderer = r;