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_BLUR_H
22 #define WRAPLAND_BLUR_H
23 
24 #include "buffer.h"
25 
26 #include <QObject>
27 #include <QPoint>
28 #include <QSize>
29 
30 // STD
31 #include <memory>
32 
33 #include <Wrapland/Client/wraplandclient_export.h>
34 
35 struct wl_buffer;
36 struct wl_region;
37 struct org_kde_kwin_blur;
38 struct org_kde_kwin_blur_manager;
39 
40 class QMarginsF;
41 class QWindow;
42 
43 namespace Wrapland
44 {
45 namespace Client
46 {
47 
48 class EventQueue;
49 class Blur;
50 class Surface;
51 class Region;
52 
53 /**
54  * TODO
55  */
56 class WRAPLANDCLIENT_EXPORT BlurManager : public QObject
57 {
58     Q_OBJECT
59 public:
60     /**
61      * Creates a new BlurManager.
62      * Note: after constructing the BlurManager it is not yet valid and one needs
63      * to call setup. In order to get a ready to use BlurManager prefer using
64      * Registry::createBlurManager.
65      **/
66     explicit BlurManager(QObject* parent = nullptr);
67     virtual ~BlurManager();
68 
69     /**
70      * @returns @c true if managing a org_kde_kwin_blur_manager.
71      **/
72     bool isValid() const;
73     /**
74      * Setup this BlurManager to manage the @p compositor.
75      * When using Registry::createBlurManager there is no need to call this
76      * method.
77      **/
78     void setup(org_kde_kwin_blur_manager* compositor);
79     /**
80      * Releases the org_kde_kwin_blur_manager interface.
81      * After the interface has been released the BlurManager instance is no
82      * longer valid and can be setup with another org_kde_kwin_blur_manager interface.
83      **/
84     void release();
85 
86     /**
87      * Sets the @p queue to use for creating a Blur.
88      **/
89     void setEventQueue(EventQueue* queue);
90     /**
91      * @returns The event queue to use for creating a Blur.
92      **/
93     EventQueue* eventQueue();
94 
95     /**
96      * Creates and setup a new Blur with @p parent.
97      * @param parent The parent to pass to the Blur.
98      * @returns The new created Blur
99      **/
100     Blur* createBlur(Surface* surface, QObject* parent = nullptr);
101     void removeBlur(Surface* surface);
102 
103     operator org_kde_kwin_blur_manager*();
104     operator org_kde_kwin_blur_manager*() const;
105 
106 Q_SIGNALS:
107     /**
108      * The corresponding global for this interface on the Registry got removed.
109      *
110      * This signal gets only emitted if the BlurManager got created by
111      * Registry::createBlurManager
112      *
113      * @since 5.5
114      **/
115     void removed();
116 
117 private:
118     class Private;
119     std::unique_ptr<Private> d;
120 };
121 
122 /**
123  * @short Wrapper for the org_kde_kwin_blur interface.
124  *
125  * This class is a convenient wrapper for the org_kde_kwin_blur interface.
126  * To create a Blur call BlurManager::createBlur.
127  *
128  * The main purpose of this class is to setup the next frame which
129  * should be rendered. Therefore it provides methods to add damage
130  * and to attach a new Buffer and to finalize the frame by calling
131  * commit.
132  *
133  * @see BlurManager
134  **/
135 class WRAPLANDCLIENT_EXPORT Blur : public QObject
136 {
137     Q_OBJECT
138 public:
139     virtual ~Blur();
140 
141     /**
142      * Setup this Blur to manage the @p blur.
143      * When using BlurManager::createBlur there is no need to call this
144      * method.
145      **/
146     void setup(org_kde_kwin_blur* blur);
147     /**
148      * Releases the org_kde_kwin_blur interface.
149      * After the interface has been released the Blur instance is no
150      * longer valid and can be setup with another org_kde_kwin_blur interface.
151      **/
152     void release();
153 
154     /**
155      * @returns @c true if managing a org_kde_kwin_blur.
156      **/
157     bool isValid() const;
158 
159     void commit();
160 
161     /**
162      * Sets the area of the window that will have a blurred
163      * background.
164      * The region will have to be created with
165      * Compositor::createRegion(QRegion)
166      */
167     void setRegion(Region* region);
168 
169     operator org_kde_kwin_blur*();
170     operator org_kde_kwin_blur*() const;
171 
172 private:
173     friend class BlurManager;
174     explicit Blur(QObject* parent = nullptr);
175     class Private;
176     std::unique_ptr<Private> d;
177 };
178 
179 }
180 }
181 
182 #endif
183