-
Notifications
You must be signed in to change notification settings - Fork 18
/
deleted.cpp
317 lines (271 loc) · 7.83 KB
/
deleted.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2006 Lubos Lunak <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "deleted.h"
#include "workspace.h"
#include "x11client.h"
#include "group.h"
#include "netinfo.h"
#include "shadow.h"
#include "xdgshellclient.h"
#include "decorations/decoratedclient.h"
#include "decorations/decorationrenderer.h"
#include <QDebug>
namespace KWin
{
Deleted::Deleted()
: Toplevel()
, delete_refcount(1)
, m_frame(XCB_WINDOW_NONE)
, no_border(true)
, m_layer(UnknownLayer)
, m_minimized(false)
, m_modal(false)
, m_wasClient(false)
, m_decorationRenderer(nullptr)
, m_fullscreen(false)
, m_keepAbove(false)
, m_keepBelow(false)
, m_wasActive(false)
, m_wasX11Client(false)
, m_wasWaylandClient(false)
, m_wasGroupTransient(false)
, m_wasPopupWindow(false)
, m_wasOutline(false)
{
}
Deleted::~Deleted()
{
if (delete_refcount != 0)
qCCritical(KWIN_CORE) << "Deleted client has non-zero reference count (" << delete_refcount << ")";
Q_ASSERT(delete_refcount == 0);
if (workspace()) {
workspace()->removeDeleted(this);
}
for (Toplevel *toplevel : qAsConst(m_transientFor)) {
if (auto *deleted = qobject_cast<Deleted *>(toplevel)) {
deleted->removeTransient(this);
}
}
for (Deleted *transient : qAsConst(m_transients)) {
transient->removeTransientFor(this);
}
deleteEffectWindow();
}
Deleted* Deleted::create(Toplevel* c)
{
Deleted* d = new Deleted();
d->copyToDeleted(c);
workspace()->addDeleted(d, c);
return d;
}
// to be used only from Workspace::finishCompositing()
void Deleted::discard()
{
delete_refcount = 0;
delete this;
}
void Deleted::copyToDeleted(Toplevel* c)
{
Q_ASSERT(dynamic_cast< Deleted* >(c) == nullptr);
Toplevel::copyToDeleted(c);
m_bufferGeometry = c->bufferGeometry();
m_bufferMargins = c->bufferMargins();
m_frameMargins = c->frameMargins();
m_bufferScale = c->bufferScale();
desk = c->desktop();
m_desktops = c->desktops();
activityList = c->activities();
contentsRect = QRect(c->clientPos(), c->clientSize());
m_contentPos = c->clientContentPos();
transparent_rect = c->transparentRect();
m_layer = c->layer();
m_frame = c->frameId();
m_opacity = c->opacity();
m_type = c->windowType();
m_windowRole = c->windowRole();
if (WinInfo* cinfo = dynamic_cast< WinInfo* >(info))
cinfo->disable();
if (AbstractClient *client = dynamic_cast<AbstractClient*>(c)) {
no_border = client->noBorder();
if (!no_border) {
client->layoutDecorationRects(decoration_left,
decoration_top,
decoration_right,
decoration_bottom);
if (client->isDecorated()) {
if (Decoration::Renderer *renderer = client->decoratedClient()->renderer()) {
m_decorationRenderer = renderer;
m_decorationRenderer->reparent(this);
}
}
}
m_wasClient = true;
m_minimized = client->isMinimized();
m_modal = client->isModal();
m_mainClients = client->mainClients();
foreach (AbstractClient *c, m_mainClients) {
addTransientFor(c);
connect(c, &AbstractClient::windowClosed, this, &Deleted::mainClientClosed);
}
m_fullscreen = client->isFullScreen();
m_keepAbove = client->keepAbove();
m_keepBelow = client->keepBelow();
m_caption = client->caption();
m_wasActive = client->isActive();
m_wasGroupTransient = client->groupTransient();
}
for (auto vd : m_desktops) {
connect(vd, &QObject::destroyed, this, [=] {
m_desktops.removeOne(vd);
});
}
m_wasWaylandClient = qobject_cast<XdgShellClient *>(c) != nullptr;
m_wasX11Client = qobject_cast<X11Client *>(c) != nullptr;
m_wasPopupWindow = c->isPopupWindow();
m_wasOutline = c->isOutline();
}
void Deleted::unrefWindow()
{
if (--delete_refcount > 0)
return;
// needs to be delayed
// a) when calling from effects, otherwise it'd be rather complicated to handle the case of the
// window going away during a painting pass
// b) to prevent dangeling pointers in the stacking order, see bug #317765
deleteLater();
}
QRect Deleted::bufferGeometry() const
{
return m_bufferGeometry;
}
QMargins Deleted::bufferMargins() const
{
return m_bufferMargins;
}
QMargins Deleted::frameMargins() const
{
return m_frameMargins;
}
qreal Deleted::bufferScale() const
{
return m_bufferScale;
}
int Deleted::desktop() const
{
return desk;
}
QStringList Deleted::activities() const
{
return activityList;
}
QVector<VirtualDesktop *> Deleted::desktops() const
{
return m_desktops;
}
QPoint Deleted::clientPos() const
{
return contentsRect.topLeft();
}
QSize Deleted::clientSize() const
{
return contentsRect.size();
}
void Deleted::debug(QDebug& stream) const
{
stream << "\'ID:" << window() << "\' (deleted)";
}
void Deleted::layoutDecorationRects(QRect& left, QRect& top, QRect& right, QRect& bottom) const
{
left = decoration_left;
top = decoration_top;
right = decoration_right;
bottom = decoration_bottom;
}
QRect Deleted::transparentRect() const
{
return transparent_rect;
}
bool Deleted::isDeleted() const
{
return true;
}
NET::WindowType Deleted::windowType(bool direct, int supportedTypes) const
{
Q_UNUSED(direct)
Q_UNUSED(supportedTypes)
return m_type;
}
void Deleted::mainClientClosed(Toplevel *client)
{
if (AbstractClient *c = dynamic_cast<AbstractClient*>(client))
m_mainClients.removeAll(c);
}
void Deleted::transientForClosed(Toplevel *toplevel, Deleted *deleted)
{
if (deleted == nullptr) {
m_transientFor.removeAll(toplevel);
return;
}
const int index = m_transientFor.indexOf(toplevel);
if (index == -1) {
return;
}
m_transientFor[index] = deleted;
deleted->addTransient(this);
}
xcb_window_t Deleted::frameId() const
{
return m_frame;
}
double Deleted::opacity() const
{
return m_opacity;
}
QByteArray Deleted::windowRole() const
{
return m_windowRole;
}
QVector<uint> Deleted::x11DesktopIds() const
{
const auto desks = desktops();
QVector<uint> x11Ids;
x11Ids.reserve(desks.count());
std::transform(desks.constBegin(), desks.constEnd(),
std::back_inserter(x11Ids),
[] (const VirtualDesktop *vd) {
return vd->x11DesktopNumber();
}
);
return x11Ids;
}
void Deleted::addTransient(Deleted *transient)
{
m_transients.append(transient);
}
void Deleted::removeTransient(Deleted *transient)
{
m_transients.removeAll(transient);
}
void Deleted::addTransientFor(AbstractClient *parent)
{
m_transientFor.append(parent);
connect(parent, &AbstractClient::windowClosed, this, &Deleted::transientForClosed);
}
void Deleted::removeTransientFor(Deleted *parent)
{
m_transientFor.removeAll(parent);
}
} // namespace