1 /******************************************************************** 2 Copyright 2015 Martin Gräßlin <mgraesslin@kde.org> 3 Copyright 2015 Marco Martin <mart@kde.org> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) version 3, or any 9 later version accepted by the membership of KDE e.V. (or its 10 successor approved by the membership of KDE e.V.), which shall 11 act as a proxy defined in Section 6 of version 3 of the license. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 *********************************************************************/ 21 #ifndef WRAPLAND_CONTRAST_H 22 #define WRAPLAND_CONTRAST_H 23 24 #include <QObject> 25 #include <QPoint> 26 #include <QSize> 27 // STD 28 #include <memory> 29 30 #include <Wrapland/Client/wraplandclient_export.h> 31 32 struct org_kde_kwin_contrast; 33 struct org_kde_kwin_contrast_manager; 34 35 namespace Wrapland 36 { 37 namespace Client 38 { 39 40 class EventQueue; 41 class Contrast; 42 class Surface; 43 class Region; 44 45 /** 46 * TODO 47 */ 48 class WRAPLANDCLIENT_EXPORT ContrastManager : public QObject 49 { 50 Q_OBJECT 51 public: 52 /** 53 * Creates a new ContrastManager. 54 * Note: after constructing the ContrastManager it is not yet valid and one needs 55 * to call setup. In order to get a ready to use ContrastManager prefer using 56 * Registry::createContrastManager. 57 **/ 58 explicit ContrastManager(QObject* parent = nullptr); 59 virtual ~ContrastManager(); 60 61 /** 62 * @returns @c true if managing a org_kde_kwin_contrast_manager. 63 **/ 64 bool isValid() const; 65 /** 66 * Setup this ContrastManager to manage the @p contrastManager. 67 * When using Registry::createContrastManager there is no need to call this 68 * method. 69 **/ 70 void setup(org_kde_kwin_contrast_manager* contrastManager); 71 /** 72 * Releases the org_kde_kwin_contrast_manager interface. 73 * After the interface has been released the ContrastManager instance is no 74 * longer valid and can be setup with another org_kde_kwin_contrast_manager interface. 75 **/ 76 void release(); 77 78 /** 79 * Sets the @p queue to use for creating a Contrast. 80 **/ 81 void setEventQueue(EventQueue* queue); 82 /** 83 * @returns The event queue to use for creating a Contrast. 84 **/ 85 EventQueue* eventQueue(); 86 87 /** 88 * Creates and setup a new Contrast with @p parent. 89 * @param parent The parent to pass to the Contrast. 90 * @returns The new created Contrast 91 **/ 92 Contrast* createContrast(Surface* surface, QObject* parent = nullptr); 93 void removeContrast(Surface* surface); 94 95 operator org_kde_kwin_contrast_manager*(); 96 operator org_kde_kwin_contrast_manager*() const; 97 98 Q_SIGNALS: 99 /** 100 * The corresponding global for this interface on the Registry got removed. 101 * 102 * This signal gets only emitted if the ContrastManager got created by 103 * Registry::createContrastManager 104 * 105 * @since 5.5 106 **/ 107 void removed(); 108 109 private: 110 class Private; 111 std::unique_ptr<Private> d; 112 }; 113 114 /** 115 * @short Wrapper for the org_kde_kwin_contrast interface. 116 * 117 * This class is a convenient wrapper for the org_kde_kwin_contrast interface. 118 * To create a Contrast call ContrastManager::createContrast. 119 * 120 * The main purpose of this class is to setup the next frame which 121 * should be rendered. Therefore it provides methods to add damage 122 * and to attach a new Buffer and to finalize the frame by calling 123 * commit. 124 * 125 * @see ContrastManager 126 **/ 127 class WRAPLANDCLIENT_EXPORT Contrast : public QObject 128 { 129 Q_OBJECT 130 public: 131 virtual ~Contrast(); 132 133 /** 134 * Setup this Contrast to manage the @p contrast. 135 * When using ContrastManager::createContrast there is no need to call this 136 * method. 137 **/ 138 void setup(org_kde_kwin_contrast* contrast); 139 /** 140 * Releases the org_kde_kwin_contrast interface. 141 * After the interface has been released the Contrast instance is no 142 * longer valid and can be setup with another org_kde_kwin_contrast interface. 143 **/ 144 void release(); 145 /** 146 * Destroys the data held by this Contrast. 147 * This method is supposed to be used when the connection to the Wayland 148 * server goes away. If the connection is not valid anymore, it's not 149 * possible to call release anymore as that calls into the Wayland 150 * connection and the call would fail. This method cleans up the data, so 151 * that the instance can be deleted or set up to a new org_kde_kwin_contrast interface 152 * once there is a new connection available. 153 * 154 * This method is automatically invoked when the Registry which created this 155 * Contrast gets destroyed. 156 * 157 * @see release 158 **/ 159 void destroy(); 160 /** 161 * @returns @c true if managing a org_kde_kwin_contrast. 162 **/ 163 bool isValid() const; 164 165 void commit(); 166 167 /** 168 * Sets the area of the window that will have a contrasted 169 * background. 170 * The region will have to be created with 171 * Compositor::createRegion(QRegion) 172 */ 173 void setRegion(Region* region); 174 void setContrast(qreal contrast); 175 void setIntensity(qreal intensity); 176 void setSaturation(qreal saturation); 177 178 operator org_kde_kwin_contrast*(); 179 operator org_kde_kwin_contrast*() const; 180 181 private: 182 friend class ContrastManager; 183 explicit Contrast(QObject* parent = nullptr); 184 class Private; 185 std::unique_ptr<Private> d; 186 }; 187 188 } 189 } 190 191 #endif 192