diff --git a/thumbnailitem.cpp b/thumbnailitem.cpp index 3982a9dd8..b3cf84cad 100644 --- a/thumbnailitem.cpp +++ b/thumbnailitem.cpp @@ -1,222 +1,221 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "thumbnailitem.h" // KWin #include "client.h" #include "composite.h" #include "effects.h" #include "workspace.h" #include "shell_client.h" #include "wayland_server.h" // Qt #include #include #include namespace KWin { AbstractThumbnailItem::AbstractThumbnailItem(QQuickItem *parent) : QQuickPaintedItem(parent) - , m_parent(QWeakPointer()) , m_brightness(1.0) , m_saturation(1.0) , m_clipToItem() { connect(Compositor::self(), SIGNAL(compositingToggled(bool)), SLOT(compositingToggled())); compositingToggled(); QTimer::singleShot(0, this, SLOT(init())); } AbstractThumbnailItem::~AbstractThumbnailItem() { } void AbstractThumbnailItem::compositingToggled() { m_parent.clear(); if (effects) { connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), SLOT(effectWindowAdded())); connect(effects, SIGNAL(windowDamaged(KWin::EffectWindow*,QRect)), SLOT(repaint(KWin::EffectWindow*))); effectWindowAdded(); } } void AbstractThumbnailItem::init() { findParentEffectWindow(); - if (!m_parent.isNull()) { - m_parent.data()->registerThumbnail(this); + if (m_parent) { + m_parent->registerThumbnail(this); } } void AbstractThumbnailItem::findParentEffectWindow() { if (effects) { QQuickWindow *qw = window(); if (!qw) { qCDebug(KWIN_CORE) << "No QQuickWindow assigned yet"; return; } if (auto *w = static_cast(effects->findWindow(qw))) { - m_parent = QWeakPointer(w); + m_parent = QPointer(w); } } } void AbstractThumbnailItem::effectWindowAdded() { // the window might be added before the EffectWindow is created // by using this slot we can register the thumbnail when it is finally created if (m_parent.isNull()) { findParentEffectWindow(); - if (!m_parent.isNull()) { - m_parent.data()->registerThumbnail(this); + if (m_parent) { + m_parent->registerThumbnail(this); } } } void AbstractThumbnailItem::setBrightness(qreal brightness) { if (qFuzzyCompare(brightness, m_brightness)) { return; } m_brightness = brightness; update(); emit brightnessChanged(); } void AbstractThumbnailItem::setSaturation(qreal saturation) { if (qFuzzyCompare(saturation, m_saturation)) { return; } m_saturation = saturation; update(); emit saturationChanged(); } void AbstractThumbnailItem::setClipTo(QQuickItem *clip) { m_clipToItem = QPointer(clip); emit clipToChanged(); } WindowThumbnailItem::WindowThumbnailItem(QQuickItem* parent) : AbstractThumbnailItem(parent) , m_wId(0) , m_client(NULL) { } WindowThumbnailItem::~WindowThumbnailItem() { } void WindowThumbnailItem::setWId(const QUuid &wId) { if (m_wId == wId) { return; } m_wId = wId; if (m_wId != 0) { setClient(workspace()->findAbstractClient([this] (const AbstractClient *c) { return c->internalId() == m_wId; })); } else if (m_client) { m_client = NULL; emit clientChanged(); } emit wIdChanged(wId); } void WindowThumbnailItem::setClient(AbstractClient *client) { if (m_client == client) { return; } m_client = client; if (m_client) { setWId(m_client->internalId()); } else { setWId({}); } emit clientChanged(); } void WindowThumbnailItem::paint(QPainter *painter) { if (effects) { return; } auto client = workspace()->findAbstractClient([this] (const AbstractClient *c) { return c->internalId() == m_wId; }); if (!client) { return; } QPixmap pixmap = client->icon().pixmap(boundingRect().size().toSize()); const QSize size(boundingRect().size().toSize() - pixmap.size()); painter->drawPixmap(boundingRect().adjusted(size.width()/2.0, size.height()/2.0, -size.width()/2.0, -size.height()/2.0).toRect(), pixmap); } void WindowThumbnailItem::repaint(KWin::EffectWindow *w) { if (static_cast(w)->window()->internalId() == m_wId) { update(); } } DesktopThumbnailItem::DesktopThumbnailItem(QQuickItem *parent) : AbstractThumbnailItem(parent) , m_desktop(0) { } DesktopThumbnailItem::~DesktopThumbnailItem() { } void DesktopThumbnailItem::setDesktop(int desktop) { desktop = qBound(1, desktop, VirtualDesktopManager::self()->count()); if (desktop == m_desktop) { return; } m_desktop = desktop; update(); emit desktopChanged(m_desktop); } void DesktopThumbnailItem::paint(QPainter *painter) { Q_UNUSED(painter) if (effects) { return; } // TODO: render icon } void DesktopThumbnailItem::repaint(EffectWindow *w) { if (w->isOnDesktop(m_desktop)) { update(); } } } // namespace KWin diff --git a/thumbnailitem.h b/thumbnailitem.h index 8cbee2cb8..2c2cc065a 100644 --- a/thumbnailitem.h +++ b/thumbnailitem.h @@ -1,150 +1,150 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2011 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_THUMBNAILITEM_H #define KWIN_THUMBNAILITEM_H #include #include #include #include namespace KWin { class AbstractClient; class EffectWindow; class EffectWindowImpl; class AbstractThumbnailItem : public QQuickPaintedItem { Q_OBJECT Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged) Q_PROPERTY(QQuickItem *clipTo READ clipTo WRITE setClipTo NOTIFY clipToChanged) public: ~AbstractThumbnailItem() override; qreal brightness() const; qreal saturation() const; QQuickItem *clipTo() const; public Q_SLOTS: void setBrightness(qreal brightness); void setSaturation(qreal saturation); void setClipTo(QQuickItem *clip); Q_SIGNALS: void brightnessChanged(); void saturationChanged(); void clipToChanged(); protected: explicit AbstractThumbnailItem(QQuickItem *parent = 0); protected Q_SLOTS: virtual void repaint(KWin::EffectWindow* w) = 0; private Q_SLOTS: void init(); void effectWindowAdded(); void compositingToggled(); private: void findParentEffectWindow(); - QWeakPointer m_parent; + QPointer m_parent; qreal m_brightness; qreal m_saturation; QPointer m_clipToItem; }; class WindowThumbnailItem : public AbstractThumbnailItem { Q_OBJECT Q_PROPERTY(QUuid wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true) Q_PROPERTY(KWin::AbstractClient *client READ client WRITE setClient NOTIFY clientChanged) public: explicit WindowThumbnailItem(QQuickItem *parent = 0); ~WindowThumbnailItem() override; QUuid wId() const { return m_wId; } void setWId(const QUuid &wId); AbstractClient *client() const; void setClient(AbstractClient *client); void paint(QPainter *painter) override; Q_SIGNALS: void wIdChanged(const QUuid &wid); void clientChanged(); protected Q_SLOTS: void repaint(KWin::EffectWindow* w) override; private: QUuid m_wId; AbstractClient *m_client; }; class DesktopThumbnailItem : public AbstractThumbnailItem { Q_OBJECT Q_PROPERTY(int desktop READ desktop WRITE setDesktop NOTIFY desktopChanged) public: DesktopThumbnailItem(QQuickItem *parent = 0); ~DesktopThumbnailItem() override; int desktop() const { return m_desktop; } void setDesktop(int desktop); void paint(QPainter *painter) override; Q_SIGNALS: void desktopChanged(int desktop); protected Q_SLOTS: void repaint(KWin::EffectWindow* w) override; private: int m_desktop; }; inline qreal AbstractThumbnailItem::brightness() const { return m_brightness; } inline qreal AbstractThumbnailItem::saturation() const { return m_saturation; } inline QQuickItem* AbstractThumbnailItem::clipTo() const { return m_clipToItem.data(); } inline AbstractClient *WindowThumbnailItem::client() const { return m_client; } } // KWin #endif // KWIN_THUMBNAILITEM_H