diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 704324af91..a2b4953308 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -119,7 +119,7 @@ target_sources(kwin PRIVATE scripting/scripting.cpp scripting/scripting_logging.cpp scripting/scriptingutils.cpp - scripting/thumbnailitem.cpp + scripting/windowthumbnailitem.cpp scripting/workspace_wrapper.cpp session.cpp session_consolekit.cpp diff --git a/src/scripting/desktopbackgrounditem.h b/src/scripting/desktopbackgrounditem.h index a6d8e624ca..1cd6b568ca 100644 --- a/src/scripting/desktopbackgrounditem.h +++ b/src/scripting/desktopbackgrounditem.h @@ -6,7 +6,7 @@ #pragma once -#include "thumbnailitem.h" +#include "windowthumbnailitem.h" namespace KWin { diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 43ea3d6ac9..a990c9aac4 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -16,7 +16,7 @@ #include "screenedgeitem.h" #include "scripting_logging.h" #include "scriptingutils.h" -#include "thumbnailitem.h" +#include "windowthumbnailitem.h" #include "workspace_wrapper.h" #include "v2/clientmodel.h" diff --git a/src/scripting/thumbnailitem.cpp b/src/scripting/windowthumbnailitem.cpp similarity index 91% rename from src/scripting/thumbnailitem.cpp rename to src/scripting/windowthumbnailitem.cpp index 61b6df627d..52a7c17216 100644 --- a/src/scripting/thumbnailitem.cpp +++ b/src/scripting/windowthumbnailitem.cpp @@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#include "thumbnailitem.h" +#include "windowthumbnailitem.h" #include "composite.h" #include "effects.h" #include "renderbackend.h" @@ -100,21 +100,21 @@ private: QScopedPointer m_provider; }; -ThumbnailItemBase::ThumbnailItemBase(QQuickItem *parent) +WindowThumbnailItem::WindowThumbnailItem(QQuickItem *parent) : QQuickItem(parent) { setFlag(ItemHasContents); updateFrameRenderingConnection(); connect(Compositor::self(), &Compositor::aboutToToggleCompositing, - this, &ThumbnailItemBase::destroyOffscreenTexture); + this, &WindowThumbnailItem::destroyOffscreenTexture); connect(Compositor::self(), &Compositor::compositingToggled, - this, &ThumbnailItemBase::updateFrameRenderingConnection); + this, &WindowThumbnailItem::updateFrameRenderingConnection); connect(this, &QQuickItem::windowChanged, - this, &ThumbnailItemBase::updateFrameRenderingConnection); + this, &WindowThumbnailItem::updateFrameRenderingConnection); } -ThumbnailItemBase::~ThumbnailItemBase() +WindowThumbnailItem::~WindowThumbnailItem() { destroyOffscreenTexture(); @@ -128,7 +128,7 @@ ThumbnailItemBase::~ThumbnailItemBase() } } -void ThumbnailItemBase::releaseResources() +void WindowThumbnailItem::releaseResources() { if (m_provider) { window()->scheduleRenderJob(new ThumbnailTextureProviderCleanupJob(m_provider), @@ -137,12 +137,12 @@ void ThumbnailItemBase::releaseResources() } } -bool ThumbnailItemBase::isTextureProvider() const +bool WindowThumbnailItem::isTextureProvider() const { return true; } -QSGTextureProvider *ThumbnailItemBase::textureProvider() const +QSGTextureProvider *WindowThumbnailItem::textureProvider() const { if (QQuickItem::isTextureProvider()) { return QQuickItem::textureProvider(); @@ -153,7 +153,7 @@ QSGTextureProvider *ThumbnailItemBase::textureProvider() const return m_provider; } -void ThumbnailItemBase::updateFrameRenderingConnection() +void WindowThumbnailItem::updateFrameRenderingConnection() { disconnect(m_frameRenderingConnection); @@ -165,16 +165,16 @@ void ThumbnailItemBase::updateFrameRenderingConnection() } if (Compositor::self()->backend()->compositingType() == OpenGLCompositing) { - m_frameRenderingConnection = connect(Compositor::self()->scene(), &Scene::frameRendered, this, &ThumbnailItemBase::updateOffscreenTexture); + m_frameRenderingConnection = connect(Compositor::self()->scene(), &Scene::frameRendered, this, &WindowThumbnailItem::updateOffscreenTexture); } } -QSize ThumbnailItemBase::sourceSize() const +QSize WindowThumbnailItem::sourceSize() const { return m_sourceSize; } -void ThumbnailItemBase::setSourceSize(const QSize &sourceSize) +void WindowThumbnailItem::setSourceSize(const QSize &sourceSize) { if (m_sourceSize != sourceSize) { m_sourceSize = sourceSize; @@ -183,7 +183,7 @@ void ThumbnailItemBase::setSourceSize(const QSize &sourceSize) } } -void ThumbnailItemBase::destroyOffscreenTexture() +void WindowThumbnailItem::destroyOffscreenTexture() { if (!Compositor::compositing()) { return; @@ -206,7 +206,7 @@ void ThumbnailItemBase::destroyOffscreenTexture() } } -QSGNode *ThumbnailItemBase::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) +QSGNode *WindowThumbnailItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) { if (Compositor::compositing() && !m_offscreenTexture) { return oldNode; @@ -249,29 +249,39 @@ QSGNode *ThumbnailItemBase::updatePaintNode(QSGNode *oldNode, QQuickItem::Update return node; } -void ThumbnailItemBase::setSaturation(qreal saturation) +qreal WindowThumbnailItem::saturation() const +{ + return 1; +} + +void WindowThumbnailItem::setSaturation(qreal saturation) { Q_UNUSED(saturation) qCWarning(KWIN_SCRIPTING) << "ThumbnailItem.saturation is removed. Use a shader effect to change saturation"; } -void ThumbnailItemBase::setBrightness(qreal brightness) +qreal WindowThumbnailItem::brightness() const +{ + return 1; +} + +void WindowThumbnailItem::setBrightness(qreal brightness) { Q_UNUSED(brightness) qCWarning(KWIN_SCRIPTING) << "ThumbnailItem.brightness is removed. Use a shader effect to change brightness"; } -void ThumbnailItemBase::setClipTo(QQuickItem *clip) +QQuickItem *WindowThumbnailItem::clipTo() const +{ + return nullptr; +} + +void WindowThumbnailItem::setClipTo(QQuickItem *clip) { Q_UNUSED(clip) qCWarning(KWIN_SCRIPTING) << "ThumbnailItem.clipTo is removed and it has no replacements"; } -WindowThumbnailItem::WindowThumbnailItem(QQuickItem *parent) - : ThumbnailItemBase(parent) -{ -} - QUuid WindowThumbnailItem::wId() const { return m_wId; diff --git a/src/scripting/thumbnailitem.h b/src/scripting/windowthumbnailitem.h similarity index 76% rename from src/scripting/thumbnailitem.h rename to src/scripting/windowthumbnailitem.h index 06c033b707..89bc770fa1 100644 --- a/src/scripting/thumbnailitem.h +++ b/src/scripting/windowthumbnailitem.h @@ -19,9 +19,12 @@ class GLFramebuffer; class GLTexture; class ThumbnailTextureProvider; -class ThumbnailItemBase : public QQuickItem +class WindowThumbnailItem : public QQuickItem { Q_OBJECT + Q_PROPERTY(QUuid wId READ wId WRITE setWId NOTIFY wIdChanged) + Q_PROPERTY(KWin::Window *client READ client WRITE setClient NOTIFY clientChanged) + Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged) /** * TODO Plasma 6: Remove. @@ -40,25 +43,22 @@ class ThumbnailItemBase : public QQuickItem Q_PROPERTY(QQuickItem *clipTo READ clipTo WRITE setClipTo NOTIFY clipToChanged) public: - explicit ThumbnailItemBase(QQuickItem *parent = nullptr); - ~ThumbnailItemBase() override; + explicit WindowThumbnailItem(QQuickItem *parent = nullptr); + ~WindowThumbnailItem() override; - qreal brightness() const - { - return 1; - } + QUuid wId() const; + void setWId(const QUuid &wId); + + Window *client() const; + void setClient(Window *client); + + qreal brightness() const; void setBrightness(qreal brightness); - qreal saturation() const - { - return 1; - } + qreal saturation() const; void setSaturation(qreal saturation); - QQuickItem *clipTo() const - { - return nullptr; - } + QQuickItem *clipTo() const; void setClipTo(QQuickItem *clip); QSize sourceSize() const; @@ -68,20 +68,30 @@ public: bool isTextureProvider() const override; QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) override; +protected: + void releaseResources() override; + Q_SIGNALS: + void wIdChanged(); + void clientChanged(); void brightnessChanged(); void saturationChanged(); void clipToChanged(); void sourceSizeChanged(); -protected: - void releaseResources() override; - - virtual QImage fallbackImage() const = 0; - virtual QRectF paintedRect() const = 0; - virtual void invalidateOffscreenTexture() = 0; - virtual void updateOffscreenTexture() = 0; +private: + QImage fallbackImage() const; + QRectF paintedRect() const; + void invalidateOffscreenTexture(); + void updateOffscreenTexture(); void destroyOffscreenTexture(); + void updateImplicitSize(); + void updateFrameRenderingConnection(); + + QSize m_sourceSize; + QUuid m_wId; + QPointer m_client; + bool m_dirty = false; mutable ThumbnailTextureProvider *m_provider = nullptr; QSharedPointer m_offscreenTexture; @@ -89,43 +99,7 @@ protected: GLsync m_acquireFence = 0; qreal m_devicePixelRatio = 1; -private: - void updateFrameRenderingConnection(); QMetaObject::Connection m_frameRenderingConnection; - - QSize m_sourceSize; -}; - -class WindowThumbnailItem : public ThumbnailItemBase -{ - Q_OBJECT - Q_PROPERTY(QUuid wId READ wId WRITE setWId NOTIFY wIdChanged) - Q_PROPERTY(KWin::Window *client READ client WRITE setClient NOTIFY clientChanged) - -public: - explicit WindowThumbnailItem(QQuickItem *parent = nullptr); - - QUuid wId() const; - void setWId(const QUuid &wId); - - Window *client() const; - void setClient(Window *client); - -Q_SIGNALS: - void wIdChanged(); - void clientChanged(); - -protected: - QImage fallbackImage() const override; - QRectF paintedRect() const override; - void invalidateOffscreenTexture() override; - void updateOffscreenTexture() override; - void updateImplicitSize(); - -private: - QUuid m_wId; - QPointer m_client; - bool m_dirty = false; }; } // namespace KWin