Changeset View
Changeset View
Standalone View
Standalone View
src/kwindowshadow.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Lesser General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Lesser General Public | ||||
15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #ifndef KWINDOWSHADOW_H | ||||
19 | #define KWINDOWSHADOW_H | ||||
20 | | ||||
21 | #include "kwindowsystem_export.h" | ||||
22 | | ||||
23 | #include <QImage> | ||||
24 | #include <QMargins> | ||||
25 | #include <QSharedPointer> | ||||
26 | #include <QWindow> | ||||
27 | | ||||
28 | class KWindowShadowPrivate; | ||||
29 | class KWindowShadowTilePrivate; | ||||
30 | | ||||
31 | /** | ||||
32 | * The KWindowShadowTile class provides a platform-indendent shadow tile representation. | ||||
33 | */ | ||||
34 | class KWINDOWSYSTEM_EXPORT KWindowShadowTile | ||||
35 | { | ||||
36 | public: | ||||
37 | using Ptr = QSharedPointer<KWindowShadowTile>; | ||||
38 | | ||||
39 | KWindowShadowTile(); | ||||
40 | ~KWindowShadowTile(); | ||||
41 | | ||||
42 | /** | ||||
43 | * Returns the image stored in the KWindowShadowTile. | ||||
44 | */ | ||||
45 | QImage image() const; | ||||
46 | | ||||
47 | /** | ||||
48 | * Sets the image on the KWindowShadowTile. | ||||
49 | * | ||||
50 | * Notice that once the native platform resouces have been allocated for the tile, you are | ||||
51 | * not allowed to change the image. In order to do so, you need to create a new tile. | ||||
52 | */ | ||||
53 | void setImage(const QImage &image); | ||||
54 | | ||||
55 | /** | ||||
56 | * Returns @c true if the platform resources associated with the tile have been allocated. | ||||
57 | */ | ||||
58 | bool isCreated() const; | ||||
59 | | ||||
60 | /** | ||||
61 | * Allocates the native platform resources associated with the KWindowShadowTile. | ||||
62 | * | ||||
63 | * Normally it should not be necessary to call this method as KWindowShadow will implicitly | ||||
64 | * call create() on your behalf. | ||||
65 | * | ||||
66 | * Returns @c true if the creation succeeded, otherwise returns @c false. | ||||
67 | */ | ||||
68 | bool create(); | ||||
69 | | ||||
70 | private: | ||||
71 | QScopedPointer<KWindowShadowTilePrivate> d; | ||||
72 | | ||||
73 | friend class KWindowShadowTilePrivate; | ||||
74 | }; | ||||
75 | | ||||
76 | /** | ||||
77 | * The KWindowShadow class represents a drop-shadow that is drawn by the compositor. | ||||
78 | * | ||||
79 | * The KWindowShadow is composed of multiple tiles. The top left tile, the top right tile, the bottom | ||||
80 | * left tile, and the bottom right tile are rendered as they are. The top tile and the bottom tile are | ||||
81 | * stretched in x direction; the left tile and the right tile are stretched in y direction. Several | ||||
82 | * KWindowShadow objects can share shadow tiles to reduce memory usage. You have to specify padding() | ||||
83 | * along the shadow tiles. The padding values indicate how much the KWindowShadow sticks outside the | ||||
84 | * decorated window. | ||||
85 | * | ||||
86 | * Once the KWindowShadow is created, you're not allowed to attach or detach any shadow tiles, change | ||||
87 | * padding(), or change window(). In order to do so, you have to destroy() the shadow first, update | ||||
88 | * relevant properties, and create() the shadow again. | ||||
89 | */ | ||||
90 | class KWINDOWSYSTEM_EXPORT KWindowShadow : public QObject | ||||
91 | { | ||||
92 | Q_OBJECT | ||||
93 | | ||||
94 | public: | ||||
95 | explicit KWindowShadow(QObject *parent = nullptr); | ||||
96 | ~KWindowShadow(); | ||||
97 | | ||||
98 | /** | ||||
99 | * Returns the left tile attached to the KWindowShadow. | ||||
100 | */ | ||||
101 | KWindowShadowTile::Ptr leftTile() const; | ||||
102 | | ||||
103 | /** | ||||
104 | * Attaches the left @p tile to the KWindowShadow. | ||||
105 | */ | ||||
106 | void setLeftTile(KWindowShadowTile::Ptr tile); | ||||
107 | | ||||
108 | /** | ||||
109 | * Returns the top-left tile attached to the KWindowShadow. | ||||
110 | */ | ||||
111 | KWindowShadowTile::Ptr topLeftTile() const; | ||||
112 | | ||||
113 | /** | ||||
114 | * Attaches the top-left @p tile to the KWindowShadow. | ||||
115 | */ | ||||
116 | void setTopLeftTile(KWindowShadowTile::Ptr tile); | ||||
117 | | ||||
118 | /** | ||||
119 | * Returns the top tile attached to the KWindowShadow. | ||||
120 | */ | ||||
121 | KWindowShadowTile::Ptr topTile() const; | ||||
122 | | ||||
123 | /** | ||||
124 | * Attaches the top @p tile to the KWindowShadow. | ||||
125 | */ | ||||
126 | void setTopTile(KWindowShadowTile::Ptr tile); | ||||
127 | | ||||
128 | /** | ||||
129 | * Returns the top-right tile attached to the KWindowShadow. | ||||
130 | */ | ||||
131 | KWindowShadowTile::Ptr topRightTile() const; | ||||
132 | | ||||
133 | /** | ||||
134 | * Attaches the top-right @p tile to the KWindowShadow. | ||||
135 | */ | ||||
136 | void setTopRightTile(KWindowShadowTile::Ptr tile); | ||||
137 | | ||||
138 | /** | ||||
139 | * Returns the right tile attached to the KWindowShadow. | ||||
140 | */ | ||||
141 | KWindowShadowTile::Ptr rightTile() const; | ||||
142 | | ||||
143 | /** | ||||
144 | * Attaches the right @p tile to the KWindowShadow. | ||||
145 | */ | ||||
146 | void setRightTile(KWindowShadowTile::Ptr tile); | ||||
147 | | ||||
148 | /** | ||||
149 | * Returns the bottom-right tile attached to the KWindowShadow. | ||||
150 | */ | ||||
151 | KWindowShadowTile::Ptr bottomRightTile() const; | ||||
152 | | ||||
153 | /** | ||||
154 | * Attaches the bottom-right tile to the KWindowShadow. | ||||
155 | */ | ||||
156 | void setBottomRightTile(KWindowShadowTile::Ptr tile); | ||||
157 | | ||||
158 | /** | ||||
159 | * Returns the bottom tile attached to the KWindowShadow. | ||||
160 | */ | ||||
161 | KWindowShadowTile::Ptr bottomTile() const; | ||||
162 | | ||||
163 | /** | ||||
164 | * Attaches the bottom @p tile to the KWindowShadow. | ||||
165 | */ | ||||
166 | void setBottomTile(KWindowShadowTile::Ptr tile); | ||||
167 | | ||||
168 | /** | ||||
169 | * Returns the bottom-left tile attached to the KWindowShadow. | ||||
170 | */ | ||||
171 | KWindowShadowTile::Ptr bottomLeftTile() const; | ||||
172 | | ||||
173 | /** | ||||
174 | * Attaches the bottom-left @p tile to the KWindowShadow. | ||||
175 | */ | ||||
176 | void setBottomLeftTile(KWindowShadowTile::Ptr tile); | ||||
177 | | ||||
178 | /** | ||||
179 | * Returns the padding of the KWindowShadow. | ||||
180 | * | ||||
181 | * The padding values specify the visible extents of the shadow. The top left tile is rendered | ||||
182 | * with an offset of -padding().left() and -padding().top(). | ||||
183 | */ | ||||
184 | QMargins padding() const; | ||||
185 | | ||||
186 | /** | ||||
187 | * Sets the padding on the KWindowShadow. | ||||
188 | * | ||||
189 | * If the padding values are smaller than the sizes of the shadow tiles, then the shadow will | ||||
190 | * overlap with the window() and will be rendered behind window(). E.g. if all padding values | ||||
191 | * are set to 0, then the shadow will be completely occluded by the window(). | ||||
192 | */ | ||||
193 | void setPadding(const QMargins &padding); | ||||
194 | | ||||
195 | /** | ||||
196 | * Returns the window behind which the KWindowShadow will be rendered. | ||||
197 | */ | ||||
198 | QWindow *window() const; | ||||
199 | | ||||
200 | /** | ||||
201 | * Sets the window behind which the KWindowShadow will be rendered. | ||||
202 | * | ||||
davidedmundson: For KWindowEffects I did put window tracking into the wayland plugin and it improved the… | |||||
zzag: Could you please point me to that code? | |||||
kwayland-integration 0a0c3f23fce265f36e5b8fb2b4b8bd311c7c1beb davidedmundson: kwayland-integration
0a0c3f23fce265f36e5b8fb2b4b8bd311c7c1beb
src/windowsystem/windoweffects. | |||||
Oh, that one... Yeah, perhaps it will be worth to handle surface creation/destruction in kwayland-integration. zzag: Oh, that one... Yeah, perhaps it will be worth to handle surface creation/destruction in… | |||||
Okay, looks like it's do-able. However, we would need to call QWidget::winId() in Breeze::ShadowHelper::installShadows() to create a QWindow... zzag: Okay, looks like it's do-able. However, we would need to call `QWidget::winId()` in `Breeze… | |||||
203 | * Note that the KWindowShadow does not track the platform surface. If for whatever reason the | ||||
204 | * native platform surface is deleted and then created, you must to destroy() the shadow and | ||||
205 | * create() it again yourself. | ||||
206 | */ | ||||
207 | void setWindow(QWindow *window); | ||||
208 | | ||||
209 | /** | ||||
210 | * Returns @c true if the platform resources associated with the shadow have been allocated. | ||||
211 | */ | ||||
212 | bool isCreated() const; | ||||
213 | | ||||
214 | /** | ||||
215 | * Allocates the platform resources associated with the KWindowShadow. | ||||
216 | * | ||||
217 | * Once the native platform resouces have been allocated, you're not allowed to attach or | ||||
218 | * detach shadow tiles, change the padding or the target window. If you want to do so, you | ||||
219 | * must destroy() the shadow, change relevant attributes and call create() again. | ||||
220 | * | ||||
221 | * Returns @c true if the creation succeeded, otherwise returns @c false. | ||||
222 | */ | ||||
223 | bool create(); | ||||
224 | | ||||
225 | /** | ||||
226 | * Releases the platform resources associated with the KWindowShadow. | ||||
227 | * | ||||
228 | * Calling destroy() after window() had been destroyed will result in a no-op. | ||||
229 | */ | ||||
230 | void destroy(); | ||||
231 | | ||||
232 | private: | ||||
233 | QScopedPointer<KWindowShadowPrivate> d; | ||||
234 | }; | ||||
235 | | ||||
236 | #endif // KWINDOWSHADOW_H |
For KWindowEffects I did put window tracking into the wayland plugin and it improved the readability of all the client code considerably.
I would recommend looking at doing so, especially as we could probably even share the implementation that kwayland-integration windoweffects.cpp has.