File indexing completed on 2024-12-22 05:09:19
0001 /* 0002 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 #ifndef KWAYLAND_BLUR_H 0008 #define KWAYLAND_BLUR_H 0009 0010 #include "buffer.h" 0011 0012 #include <QObject> 0013 #include <QPoint> 0014 #include <QSize> 0015 0016 #include "KWayland/Client/kwaylandclient_export.h" 0017 0018 struct wl_buffer; 0019 struct wl_region; 0020 struct org_kde_kwin_blur; 0021 struct org_kde_kwin_blur_manager; 0022 0023 0024 namespace KWayland 0025 { 0026 namespace Client 0027 { 0028 class EventQueue; 0029 class Blur; 0030 class Surface; 0031 class Region; 0032 0033 /** 0034 * TODO 0035 */ 0036 class KWAYLANDCLIENT_EXPORT BlurManager : public QObject 0037 { 0038 Q_OBJECT 0039 public: 0040 /** 0041 * Creates a new BlurManager. 0042 * Note: after constructing the BlurManager it is not yet valid and one needs 0043 * to call setup. In order to get a ready to use BlurManager prefer using 0044 * Registry::createBlurManager. 0045 **/ 0046 explicit BlurManager(QObject *parent = nullptr); 0047 ~BlurManager() override; 0048 0049 /** 0050 * @returns @c true if managing a org_kde_kwin_blur_manager. 0051 **/ 0052 bool isValid() const; 0053 /** 0054 * Setup this BlurManager to manage the @p compositor. 0055 * When using Registry::createBlurManager there is no need to call this 0056 * method. 0057 **/ 0058 void setup(org_kde_kwin_blur_manager *compositor); 0059 /** 0060 * Releases the org_kde_kwin_blur_manager interface. 0061 * After the interface has been released the BlurManager instance is no 0062 * longer valid and can be setup with another org_kde_kwin_blur_manager interface. 0063 **/ 0064 void release(); 0065 /** 0066 * Destroys the data held by this BlurManager. 0067 * This method is supposed to be used when the connection to the Wayland 0068 * server goes away. If the connection is not valid anymore, it's not 0069 * possible to call release anymore as that calls into the Wayland 0070 * connection and the call would fail. This method cleans up the data, so 0071 * that the instance can be deleted or set up to a new org_kde_kwin_blur_manager interface 0072 * once there is a new connection available. 0073 * 0074 * It is suggested to connect this method to ConnectionThread::connectionDied: 0075 * @code 0076 * connect(connection, &ConnectionThread::connectionDied, compositor, &BlurManager::destroy); 0077 * @endcode 0078 * 0079 * @see release 0080 **/ 0081 void destroy(); 0082 0083 /** 0084 * Sets the @p queue to use for creating a Blur. 0085 **/ 0086 void setEventQueue(EventQueue *queue); 0087 /** 0088 * @returns The event queue to use for creating a Blur. 0089 **/ 0090 EventQueue *eventQueue(); 0091 0092 /** 0093 * Creates and setup a new Blur with @p parent. 0094 * @param parent The parent to pass to the Blur. 0095 * @returns The new created Blur 0096 **/ 0097 Blur *createBlur(Surface *surface, QObject *parent = nullptr); 0098 void removeBlur(Surface *surface); 0099 0100 operator org_kde_kwin_blur_manager *(); 0101 operator org_kde_kwin_blur_manager *() const; 0102 0103 Q_SIGNALS: 0104 /** 0105 * The corresponding global for this interface on the Registry got removed. 0106 * 0107 * This signal gets only emitted if the BlurManager got created by 0108 * Registry::createBlurManager 0109 * 0110 * @since 5.5 0111 **/ 0112 void removed(); 0113 0114 private: 0115 class Private; 0116 QScopedPointer<Private> d; 0117 }; 0118 0119 /** 0120 * @short Wrapper for the org_kde_kwin_blur interface. 0121 * 0122 * This class is a convenient wrapper for the org_kde_kwin_blur interface. 0123 * To create a Blur call BlurManager::createBlur. 0124 * 0125 * The main purpose of this class is to setup the next frame which 0126 * should be rendered. Therefore it provides methods to add damage 0127 * and to attach a new Buffer and to finalize the frame by calling 0128 * commit. 0129 * 0130 * @see BlurManager 0131 **/ 0132 class KWAYLANDCLIENT_EXPORT Blur : public QObject 0133 { 0134 Q_OBJECT 0135 public: 0136 ~Blur() override; 0137 0138 /** 0139 * Setup this Blur to manage the @p blur. 0140 * When using BlurManager::createBlur there is no need to call this 0141 * method. 0142 **/ 0143 void setup(org_kde_kwin_blur *blur); 0144 /** 0145 * Releases the org_kde_kwin_blur interface. 0146 * After the interface has been released the Blur instance is no 0147 * longer valid and can be setup with another org_kde_kwin_blur interface. 0148 **/ 0149 void release(); 0150 /** 0151 * Destroys the data held by this Blur. 0152 * This method is supposed to be used when the connection to the Wayland 0153 * server goes away. If the connection is not valid anymore, it's not 0154 * possible to call release anymore as that calls into the Wayland 0155 * connection and the call would fail. This method cleans up the data, so 0156 * that the instance can be deleted or set up to a new org_kde_kwin_blur interface 0157 * once there is a new connection available. 0158 * 0159 * This method is automatically invoked when the Registry which created this 0160 * Blur gets destroyed. 0161 * 0162 * @see release 0163 **/ 0164 void destroy(); 0165 /** 0166 * @returns @c true if managing a org_kde_kwin_blur. 0167 **/ 0168 bool isValid() const; 0169 0170 void commit(); 0171 0172 /** 0173 * Sets the area of the window that will have a blurred 0174 * background. 0175 * The region will have to be created with 0176 * Compositor::createRegion(QRegion) 0177 */ 0178 void setRegion(Region *region); 0179 0180 operator org_kde_kwin_blur *(); 0181 operator org_kde_kwin_blur *() const; 0182 0183 private: 0184 friend class BlurManager; 0185 explicit Blur(QObject *parent = nullptr); 0186 class Private; 0187 QScopedPointer<Private> d; 0188 }; 0189 0190 } 0191 } 0192 0193 #endif