-
Notifications
You must be signed in to change notification settings - Fork 6
/
group.cpp
125 lines (108 loc) · 3.11 KB
/
group.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
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
//#define QT_CLEAN_NAMESPACE
#include "group.h"
#include "workspace.h"
#include "x11client.h"
#include "effects.h"
#include <KWindowSystem>
#include <QDebug>
namespace KWin
{
//********************************************
// Group
//********************************************
Group::Group(xcb_window_t leader_P)
: leader_client(nullptr),
leader_wid(leader_P),
leader_info(nullptr),
user_time(-1U),
refcount(0)
{
if (leader_P != XCB_WINDOW_NONE) {
leader_client = workspace()->findClient(Predicate::WindowMatch, leader_P);
leader_info = new NETWinInfo(connection(), leader_P, rootWindow(),
NET::Properties(), NET::WM2StartupId);
}
effect_group = new EffectWindowGroupImpl(this);
workspace()->addGroup(this);
}
Group::~Group()
{
delete leader_info;
delete effect_group;
}
QIcon Group::icon() const
{
if (leader_client != nullptr)
return leader_client->icon();
else if (leader_wid != XCB_WINDOW_NONE) {
QIcon ic;
NETWinInfo info(connection(), leader_wid, rootWindow(), NET::WMIcon, NET::WM2IconPixmap);
auto readIcon = [&ic, &info, this](int size, bool scale = true) {
const QPixmap pix = KWindowSystem::icon(leader_wid, size, size, scale, KWindowSystem::NETWM | KWindowSystem::WMHints, &info);
if (!pix.isNull()) {
ic.addPixmap(pix);
}
};
readIcon(16);
readIcon(32);
readIcon(48, false);
readIcon(64, false);
readIcon(128, false);
return ic;
}
return QIcon();
}
void Group::addMember(X11Client *member_P)
{
_members.append(member_P);
// qDebug() << "GROUPADD:" << this << ":" << member_P;
// qDebug() << kBacktrace();
}
void Group::removeMember(X11Client *member_P)
{
// qDebug() << "GROUPREMOVE:" << this << ":" << member_P;
// qDebug() << kBacktrace();
Q_ASSERT(_members.contains(member_P));
_members.removeAll(member_P);
// there are cases when automatic deleting of groups must be delayed,
// e.g. when removing a member and doing some operation on the possibly
// other members of the group (which would be however deleted already
// if there were no other members)
if (refcount == 0 && _members.isEmpty()) {
workspace()->removeGroup(this);
delete this;
}
}
void Group::ref()
{
++refcount;
}
void Group::deref()
{
if (--refcount == 0 && _members.isEmpty()) {
workspace()->removeGroup(this);
delete this;
}
}
void Group::gotLeader(X11Client *leader_P)
{
Q_ASSERT(leader_P->window() == leader_wid);
leader_client = leader_P;
}
void Group::lostLeader()
{
Q_ASSERT(!_members.contains(leader_client));
leader_client = nullptr;
if (_members.isEmpty()) {
workspace()->removeGroup(this);
delete this;
}
}
} // namespace