| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> |
| 3 | SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> |
| 4 | |
| 5 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | #ifndef KWAYLAND_CONTRAST_H |
| 8 | #define KWAYLAND_CONTRAST_H |
| 9 | |
| 10 | #include <optional> |
| 11 | |
| 12 | #include <QObject> |
| 13 | #include <QPoint> |
| 14 | #include <QSize> |
| 15 | #include <QColor> |
| 16 | |
| 17 | #include "KWayland/Client/kwaylandclient_export.h" |
| 18 | |
| 19 | struct org_kde_kwin_contrast; |
| 20 | struct org_kde_kwin_contrast_manager; |
| 21 | |
| 22 | namespace KWayland |
| 23 | { |
| 24 | namespace Client |
| 25 | { |
| 26 | class EventQueue; |
| 27 | class Contrast; |
| 28 | class Surface; |
| 29 | class Region; |
| 30 | |
| 31 | /** |
| 32 | * TODO |
| 33 | */ |
| 34 | class KWAYLANDCLIENT_EXPORT ContrastManager : public QObject |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | public: |
| 38 | /** |
| 39 | * Creates a new ContrastManager. |
| 40 | * Note: after constructing the ContrastManager it is not yet valid and one needs |
| 41 | * to call setup. In order to get a ready to use ContrastManager prefer using |
| 42 | * Registry::createContrastManager. |
| 43 | **/ |
| 44 | explicit ContrastManager(QObject *parent = nullptr); |
| 45 | ~ContrastManager() override; |
| 46 | |
| 47 | /** |
| 48 | * @returns @c true if managing a org_kde_kwin_contrast_manager. |
| 49 | **/ |
| 50 | bool isValid() const; |
| 51 | /** |
| 52 | * Setup this ContrastManager to manage the @p contrastManager. |
| 53 | * When using Registry::createContrastManager there is no need to call this |
| 54 | * method. |
| 55 | **/ |
| 56 | void setup(org_kde_kwin_contrast_manager *contrastManager); |
| 57 | /** |
| 58 | * Releases the org_kde_kwin_contrast_manager interface. |
| 59 | * After the interface has been released the ContrastManager instance is no |
| 60 | * longer valid and can be setup with another org_kde_kwin_contrast_manager interface. |
| 61 | **/ |
| 62 | void release(); |
| 63 | /** |
| 64 | * Destroys the data held by this ContrastManager. |
| 65 | * This method is supposed to be used when the connection to the Wayland |
| 66 | * server goes away. If the connection is not valid anymore, it's not |
| 67 | * possible to call release anymore as that calls into the Wayland |
| 68 | * connection and the call would fail. This method cleans up the data, so |
| 69 | * that the instance can be deleted or set up to a new org_kde_kwin_contrast_manager interface |
| 70 | * once there is a new connection available. |
| 71 | * |
| 72 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 73 | * @code |
| 74 | * connect(connection, &ConnectionThread::connectionDied, contrastManager, &ContrastManager::destroy); |
| 75 | * @endcode |
| 76 | * |
| 77 | * @see release |
| 78 | **/ |
| 79 | void destroy(); |
| 80 | |
| 81 | /** |
| 82 | * Sets the @p queue to use for creating a Contrast. |
| 83 | **/ |
| 84 | void setEventQueue(EventQueue *queue); |
| 85 | /** |
| 86 | * @returns The event queue to use for creating a Contrast. |
| 87 | **/ |
| 88 | EventQueue *eventQueue(); |
| 89 | |
| 90 | /** |
| 91 | * Creates and setup a new Contrast with @p parent. |
| 92 | * @param parent The parent to pass to the Contrast. |
| 93 | * @returns The new created Contrast |
| 94 | **/ |
| 95 | Contrast *createContrast(Surface *surface, QObject *parent = nullptr); |
| 96 | void removeContrast(Surface *surface); |
| 97 | |
| 98 | operator org_kde_kwin_contrast_manager *(); |
| 99 | operator org_kde_kwin_contrast_manager *() const; |
| 100 | |
| 101 | Q_SIGNALS: |
| 102 | /** |
| 103 | * The corresponding global for this interface on the Registry got removed. |
| 104 | * |
| 105 | * This signal gets only emitted if the ContrastManager got created by |
| 106 | * Registry::createContrastManager |
| 107 | * |
| 108 | * @since 5.5 |
| 109 | **/ |
| 110 | void removed(); |
| 111 | |
| 112 | private: |
| 113 | class Private; |
| 114 | QScopedPointer<Private> d; |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * @short Wrapper for the org_kde_kwin_contrast interface. |
| 119 | * |
| 120 | * This class is a convenient wrapper for the org_kde_kwin_contrast interface. |
| 121 | * To create a Contrast call ContrastManager::createContrast. |
| 122 | * |
| 123 | * The main purpose of this class is to setup the next frame which |
| 124 | * should be rendered. Therefore it provides methods to add damage |
| 125 | * and to attach a new Buffer and to finalize the frame by calling |
| 126 | * commit. |
| 127 | * |
| 128 | * @see ContrastManager |
| 129 | **/ |
| 130 | class KWAYLANDCLIENT_EXPORT Contrast : public QObject |
| 131 | { |
| 132 | Q_OBJECT |
| 133 | public: |
| 134 | ~Contrast() override; |
| 135 | |
| 136 | /** |
| 137 | * Setup this Contrast to manage the @p contrast. |
| 138 | * When using ContrastManager::createContrast there is no need to call this |
| 139 | * method. |
| 140 | **/ |
| 141 | void setup(org_kde_kwin_contrast *contrast); |
| 142 | /** |
| 143 | * Releases the org_kde_kwin_contrast interface. |
| 144 | * After the interface has been released the Contrast instance is no |
| 145 | * longer valid and can be setup with another org_kde_kwin_contrast interface. |
| 146 | **/ |
| 147 | void release(); |
| 148 | /** |
| 149 | * Destroys the data held by this Contrast. |
| 150 | * This method is supposed to be used when the connection to the Wayland |
| 151 | * server goes away. If the connection is not valid anymore, it's not |
| 152 | * possible to call release anymore as that calls into the Wayland |
| 153 | * connection and the call would fail. This method cleans up the data, so |
| 154 | * that the instance can be deleted or set up to a new org_kde_kwin_contrast interface |
| 155 | * once there is a new connection available. |
| 156 | * |
| 157 | * This method is automatically invoked when the Registry which created this |
| 158 | * Contrast gets destroyed. |
| 159 | * |
| 160 | * @see release |
| 161 | **/ |
| 162 | void destroy(); |
| 163 | /** |
| 164 | * @returns @c true if managing a org_kde_kwin_contrast. |
| 165 | **/ |
| 166 | bool isValid() const; |
| 167 | |
| 168 | void commit(); |
| 169 | |
| 170 | /** |
| 171 | * Sets the area of the window that will have a contrasted |
| 172 | * background. |
| 173 | * The region will have to be created with |
| 174 | * Compositor::createRegion(QRegion) |
| 175 | */ |
| 176 | void setRegion(Region *region); |
| 177 | void setContrast(qreal contrast); |
| 178 | void setIntensity(qreal intensity); |
| 179 | void setSaturation(qreal saturation); |
| 180 | |
| 181 | void setFrost(QColor frost); |
| 182 | |
| 183 | operator org_kde_kwin_contrast *(); |
| 184 | operator org_kde_kwin_contrast *() const; |
| 185 | |
| 186 | private: |
| 187 | friend class ContrastManager; |
| 188 | explicit Contrast(QObject *parent = nullptr); |
| 189 | class Private; |
| 190 | QScopedPointer<Private> d; |
| 191 | }; |
| 192 | |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | #endif |
| 197 | |