Libplasma

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 QML_ELEMENT
72 Q_PROPERTY(uint winId READ winId WRITE setWinId RESET resetWinId NOTIFY winIdChanged)
73 Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedSizeChanged)
74 Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedSizeChanged)
75 Q_PROPERTY(bool thumbnailAvailable READ thumbnailAvailable NOTIFY thumbnailAvailableChanged)
76
77public:
78 explicit WindowThumbnail(QQuickItem *parent = nullptr);
79 ~WindowThumbnail() override;
80 bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
81 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
82
83 uint32_t winId() const;
84 void setWinId(uint32_t winId);
85 void resetWinId();
86
87 qreal paintedWidth() const;
88 qreal paintedHeight() const;
89 bool thumbnailAvailable() const;
90
91 bool isTextureProvider() const override;
92 QSGTextureProvider *textureProvider() const override;
93
95 void winIdChanged();
96 void paintedSizeChanged();
97 void thumbnailAvailableChanged();
98
99private Q_SLOTS:
100 void invalidateSceneGraph();
101
102protected:
103 void itemChange(ItemChange change, const ItemChangeData &data) override;
104 void releaseResources() override;
105
106private:
107 void iconToTexture(WindowTextureProvider *textureProvider);
108 void windowToTexture(WindowTextureProvider *textureProvider);
109 bool startRedirecting();
110 void stopRedirecting();
111 void resetDamaged();
112 void setThumbnailAvailable(bool thumbnailAvailable);
113 void sceneVisibilityChanged(bool visible);
114 bool m_xcb = false;
115 bool m_composite = false;
116 QPointer<QWindow> m_scene;
117 uint32_t m_winId = 0;
118 QSizeF m_paintedSize;
119 bool m_thumbnailAvailable = false;
120 bool m_redirecting = false;
121 bool m_damaged = false;
122 mutable WindowTextureProvider *m_textureProvider = nullptr;
123#if HAVE_XCB_COMPOSITE
124 xcb_pixmap_t pixmapForWindow();
125 static std::optional<bool> s_hasPixmapExtension;
126 bool m_openGLFunctionsResolved = false;
127 uint8_t m_damageEventBase = 0;
128 xcb_damage_damage_t m_damage = XCB_NONE;
129 xcb_pixmap_t m_pixmap = XCB_PIXMAP_NONE;
130
131 /*The following must *only* be used from the render thread*/
132 uint m_texture;
133#if HAVE_GLX
134 bool windowToTextureGLX(WindowTextureProvider *textureProvider);
135 void resolveGLXFunctions();
136 bool loadGLXTexture();
137 void bindGLXTexture();
138 int m_depth = 0;
139 xcb_pixmap_t m_glxPixmap = XCB_PIXMAP_NONE;
140 xcb_visualid_t m_visualid = XCB_NONE;
141 QFunctionPointer m_bindTexImage = nullptr;
142 QFunctionPointer m_releaseTexImage = nullptr;
143#endif // HAVE_GLX
144#if HAVE_EGL
145 bool xcbWindowToTextureEGL(WindowTextureProvider *textureProvider);
146 void resolveEGLFunctions();
147 void bindEGLTexture();
148 bool m_eglFunctionsResolved = false;
149 EGLImageKHR m_image = EGL_NO_IMAGE_KHR;
150 QFunctionPointer m_eglCreateImageKHR = nullptr;
151 QFunctionPointer m_eglDestroyImageKHR = nullptr;
152 QFunctionPointer m_glEGLImageTargetTexture2DOES = nullptr;
153#endif // HAVE_EGL
154#endif
155};
156
157class WindowTextureProvider : public QSGTextureProvider
158{
160
161public:
162 QSGTexture *texture() const override;
163 void setTexture(QSGTexture *texture);
164
165private:
166 std::unique_ptr<QSGTexture> m_texture;
167};
168
169}
170
171#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 Sat Dec 21 2024 17:01:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.