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