Plasma-framework

windowthumbnail.h
1/*
2 SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#ifndef PLASMA_WINDOWTHUMBNAIL_H
7#define PLASMA_WINDOWTHUMBNAIL_H
8#include <config-plasma.h>
9#include <config-x11.h>
10
11#include <cstdint>
12
13// Qt
14#include <QAbstractNativeEventFilter>
15#include <QPointer>
16#include <QQuickItem>
17#include <QSGSimpleTextureNode>
18#include <QSGTextureProvider>
19#include <QWindow>
20// xcb
21#if HAVE_XCB_COMPOSITE
22#include <xcb/damage.h>
23
24#if HAVE_EGL
25#include <EGL/egl.h>
26#include <EGL/eglext.h>
27#include <fixx11h.h> // egl.h could include XLib.h
28
29#endif // HAVE_EGL
30
31#endif // HAVE_XCB_COMPOSITE
32class KWindowInfo;
33
34namespace Plasma
35{
36class WindowTextureProvider;
37
38/**
39 * @brief Renders a thumbnail for the window specified by the @c winId property.
40 *
41 * This declarative item is able to render a live updating thumbnail for the
42 * window specified by the given @c winId property. If it is not possible to get
43 * the thumbnail, the window's icon is rendered instead or in case that the window
44 * Id is invalid a generic fallback icon is used.
45 *
46 * The thumbnail does not necessarily fill out the complete geometry as the
47 * thumbnail gets scaled keeping the aspect ratio. This means the thumbnail gets
48 * rendered into the center of the item's geometry.
49 *
50 * Note: live updating thumbnails are only implemented on the X11 platform. On X11
51 * a running compositor is not required as this item takes care of redirecting the
52 * window. For technical reasons the window's frame is not included on X11.
53 *
54 * If the window closes, the thumbnail does not get destroyed, which allows to have
55 * a window close animation.
56 *
57 * Example usage:
58 * @code
59 * WindowThumbnail {
60 * winId: 102760466
61 * }
62 * @endcode
63 *
64 * <b>Import Statement</b>
65 * @code import org.kde.plasma.core @endcode
66 * @version 2.0
67 */
69{
71 Q_PROPERTY(uint winId READ winId WRITE setWinId RESET resetWinId NOTIFY winIdChanged)
72 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
73 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
74 Q_PROPERTY(bool thumbnailAvailable READ thumbnailAvailable NOTIFY thumbnailAvailableChanged)
75
76public:
77 explicit WindowThumbnail(QQuickItem *parent = nullptr);
78 ~WindowThumbnail() override;
79 bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
80 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
81
82 uint32_t winId() const;
83 void setWinId(uint32_t winId);
84 void resetWinId();
85
86 qreal paintedWidth() const;
87 qreal paintedHeight() const;
88 bool thumbnailAvailable() const;
89
90 bool isTextureProvider() const override;
91 QSGTextureProvider *textureProvider() const override;
92
94 void winIdChanged();
95 void paintedSizeChanged();
96 void thumbnailAvailableChanged();
97
98private Q_SLOTS:
99 void invalidateSceneGraph();
100
101protected:
102 void itemChange(ItemChange change, const ItemChangeData &data) override;
103 void releaseResources() override;
104
105private:
106 void iconToTexture(WindowTextureProvider *textureProvider);
107 void windowToTexture(WindowTextureProvider *textureProvider);
108 bool startRedirecting();
109 void stopRedirecting();
110 void resetDamaged();
111 void setThumbnailAvailable(bool thumbnailAvailable);
112 void sceneVisibilityChanged(bool visible);
113 bool m_xcb = false;
114 bool m_composite = false;
115 QPointer<QWindow> m_scene;
116 uint32_t m_winId = 0;
117 QSizeF m_paintedSize;
118 bool m_thumbnailAvailable = false;
119 bool m_redirecting = false;
120 bool m_damaged = false;
121 mutable WindowTextureProvider *m_textureProvider = nullptr;
122#if HAVE_XCB_COMPOSITE
123 xcb_pixmap_t pixmapForWindow();
124 static std::optional<bool> s_hasPixmapExtension;
125 bool m_openGLFunctionsResolved = false;
126 uint8_t m_damageEventBase = 0;
127 xcb_damage_damage_t m_damage = XCB_NONE;
128 xcb_pixmap_t m_pixmap = XCB_PIXMAP_NONE;
129
130 /*The following must *only* be used from the render thread*/
131 uint m_texture;
132#if HAVE_GLX
133 bool windowToTextureGLX(WindowTextureProvider *textureProvider);
134 void resolveGLXFunctions();
135 bool loadGLXTexture();
136 void bindGLXTexture();
137 int m_depth = 0;
138 xcb_pixmap_t m_glxPixmap = XCB_PIXMAP_NONE;
139 xcb_visualid_t m_visualid = XCB_NONE;
140 QFunctionPointer m_bindTexImage;
141 QFunctionPointer m_releaseTexImage;
142#endif // HAVE_GLX
143#if HAVE_EGL
144 bool xcbWindowToTextureEGL(WindowTextureProvider *textureProvider);
145 void resolveEGLFunctions();
146 void bindEGLTexture();
147 bool m_eglFunctionsResolved = false;
148 EGLImageKHR m_image = EGL_NO_IMAGE_KHR;
149 QFunctionPointer m_eglCreateImageKHR;
150 QFunctionPointer m_eglDestroyImageKHR;
151 QFunctionPointer m_glEGLImageTargetTexture2DOES;
152#endif // HAVE_EGL
153#endif
154};
155
156class WindowTextureProvider : public QSGTextureProvider
157{
159
160public:
161 QSGTexture *texture() const override;
162 void setTexture(QSGTexture *texture);
163
164private:
165 std::unique_ptr<QSGTexture> m_texture;
166};
167
168}
169
170#endif // PLASMA_WINDOWTHUMBNAIL_H
Renders a thumbnail for the window specified by the winId property.
Namespace for everything in libplasma.
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.