From 6bdd0e96f6b446d62208bfc7594af93e34bc99a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 28 Nov 2014 16:28:39 +0100 Subject: [PATCH] [kdecoration] Decoration::client returns a QWeakPointer In aurorae a wrapper property is added. --- clients/aurorae/src/aurorae.cpp | 15 ++++++++++----- clients/aurorae/src/aurorae.h | 3 +++ clients/aurorae/src/decorationoptions.cpp | 4 ++-- geometry.cpp | 9 +++++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index 2cf1f423b9..6c14324822 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -283,7 +283,7 @@ void Decoration::init() visualParent.value()->setProperty("drawBackground", false); } else { // we need a QQuickWindow till we depend on Qt 5.4 - m_decorationWindow.reset(QWindow::fromWinId(client()->decorationId())); + m_decorationWindow.reset(QWindow::fromWinId(client().data()->decorationId())); m_view = new QQuickWindow(m_decorationWindow.data()); m_view->setFlags(Qt::WindowDoesNotAcceptFocus | Qt::WindowTransparentForInput); m_view->setColor(Qt::transparent); @@ -332,7 +332,7 @@ void Decoration::init() m_view->setVisible(true); auto resizeWindow = [this] { QRect rect(QPoint(0, 0), size()); - if (m_padding && !client()->isMaximized()) { + if (m_padding && !client().data()->isMaximized()) { rect = rect.adjusted(-m_padding->left(), -m_padding->top(), m_padding->right(), m_padding->bottom()); } m_view->setGeometry(rect); @@ -372,7 +372,7 @@ void Decoration::setupBorders(QQuickItem *item) void Decoration::updateBorders() { KWin::Borders *b = m_borders; - if (client()->isMaximized() && m_maximizedBorders) { + if (client().data()->isMaximized() && m_maximizedBorders) { b = m_maximizedBorders; } if (!b) { @@ -392,7 +392,7 @@ void Decoration::paint(QPainter *painter, const QRect &repaintRegion) QRectF r(QPointF(0, 0), m_buffer.size()); if (m_padding && (m_padding->left() > 0 || m_padding->top() > 0 || m_padding->right() > 0 || m_padding->bottom() > 0) && - !client()->isMaximized()) { + !client().data()->isMaximized()) { r = r.adjusted(m_padding->left(), m_padding->top(), -m_padding->right(), -m_padding->bottom()); KDecoration2::DecorationShadow *s = new KDecoration2::DecorationShadow(this); s->setShadow(m_buffer); @@ -414,7 +414,7 @@ void Decoration::paint(QPainter *painter, const QRect &repaintRegion) QMouseEvent Decoration::translatedMouseEvent(QMouseEvent *orig) { - if (!m_padding || client()->isMaximized()) { + if (!m_padding || client().data()->isMaximized()) { orig->setAccepted(false); return *orig; } @@ -498,6 +498,11 @@ void Decoration::installTitleItem(QQuickItem *item) connect(item, &QQuickItem::yChanged, this, update); } +KDecoration2::DecoratedClient *Decoration::clientPointer() const +{ + return client().data(); +} + ThemeFinder::ThemeFinder(QObject *parent, const QVariantList &args) : QObject(parent) { diff --git a/clients/aurorae/src/aurorae.h b/clients/aurorae/src/aurorae.h index 802025a342..4dfdc56e46 100644 --- a/clients/aurorae/src/aurorae.h +++ b/clients/aurorae/src/aurorae.h @@ -40,6 +40,7 @@ namespace Aurorae class Decoration : public KDecoration2::Decoration { Q_OBJECT + Q_PROPERTY(KDecoration2::DecoratedClient* client READ clientPointer CONSTANT) public: explicit Decoration(QObject *parent = nullptr, const QVariantList &args = QVariantList()); virtual ~Decoration(); @@ -48,6 +49,8 @@ public: Q_INVOKABLE QVariant readConfig(const QString &key, const QVariant &defaultValue = QVariant()); + KDecoration2::DecoratedClient *clientPointer() const; + public Q_SLOTS: void init() override; void installTitleItem(QQuickItem *item); diff --git a/clients/aurorae/src/decorationoptions.cpp b/clients/aurorae/src/decorationoptions.cpp index 309ed78254..0dc5f1f301 100644 --- a/clients/aurorae/src/decorationoptions.cpp +++ b/clients/aurorae/src/decorationoptions.cpp @@ -185,10 +185,10 @@ void DecorationOptions::slotActiveChanged() if (!m_decoration) { return; } - if (m_active == m_decoration->client()->isActive()) { + if (m_active == m_decoration->client().data()->isActive()) { return; } - m_active = m_decoration->client()->isActive(); + m_active = m_decoration->client().data()->isActive(); emit colorsChanged(); emit fontChanged(); } diff --git a/geometry.cpp b/geometry.cpp index deb66a4bc3..0d5895f81a 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -2213,15 +2213,16 @@ void Client::changeMaximize(bool vertical, bool horizontal, bool adjust) } // call into decoration update borders - if (m_decoration) { + if (m_decoration && m_decoration->client()) { + const auto c = m_decoration->client().data(); if ((max_mode & KDecorationDefines::MaximizeVertical) != (old_mode & KDecorationDefines::MaximizeVertical)) { - emit m_decoration->client()->maximizedVerticallyChanged(max_mode & KDecorationDefines::MaximizeVertical); + emit c->maximizedVerticallyChanged(max_mode & KDecorationDefines::MaximizeVertical); } if ((max_mode & KDecorationDefines::MaximizeHorizontal) != (old_mode & KDecorationDefines::MaximizeHorizontal)) { - emit m_decoration->client()->maximizedHorizontallyChanged(max_mode & KDecorationDefines::MaximizeHorizontal); + emit c->maximizedHorizontallyChanged(max_mode & KDecorationDefines::MaximizeHorizontal); } if ((max_mode == KDecorationDefines::MaximizeFull) != (old_mode == KDecorationDefines::MaximizeFull)) { - emit m_decoration->client()->maximizedChanged(max_mode & KDecorationDefines::MaximizeFull); + emit c->maximizedChanged(max_mode & KDecorationDefines::MaximizeFull); } }