KWin
Loading...
Searching...
No Matches
group.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "group.h"
13#include "workspace.h"
14#include "x11window.h"
15
16#include <KX11Extras>
17#include <QDebug>
18
19namespace KWin
20{
21
22//********************************************
23// Group
24//********************************************
25
26Group::Group(xcb_window_t leader_P)
27 : leader_client(nullptr)
28 , leader_wid(leader_P)
29 , leader_info(nullptr)
30 , user_time(-1U)
31 , refcount(0)
32{
33 if (leader_P != XCB_WINDOW_NONE) {
34 leader_client = workspace()->findClient(Predicate::WindowMatch, leader_P);
35 leader_info = std::make_unique<NETWinInfo>(kwinApp()->x11Connection(), leader_P, kwinApp()->x11RootWindow(),
36 NET::Properties(), NET::WM2StartupId);
37 }
38 effect_group = std::make_unique<EffectWindowGroup>(this);
39 workspace()->addGroup(this);
40}
41
42Group::~Group() = default;
43
44QIcon Group::icon() const
45{
46 if (leader_client != nullptr) {
47 return leader_client->icon();
48 } else if (leader_wid != XCB_WINDOW_NONE) {
49 QIcon ic;
50 NETWinInfo info(kwinApp()->x11Connection(), leader_wid, kwinApp()->x11RootWindow(), NET::WMIcon, NET::WM2IconPixmap);
51 auto readIcon = [&ic, &info, this](int size, bool scale = true) {
52 const QPixmap pix = KX11Extras::icon(leader_wid, size, size, scale, KX11Extras::NETWM | KX11Extras::WMHints, &info);
53 if (!pix.isNull()) {
54 ic.addPixmap(pix);
55 }
56 };
57 readIcon(16);
58 readIcon(32);
59 readIcon(48, false);
60 readIcon(64, false);
61 readIcon(128, false);
62 return ic;
63 }
64 return QIcon();
65}
66
68{
69 _members.append(member_P);
70 // qDebug() << "GROUPADD:" << this << ":" << member_P;
71 // qDebug() << kBacktrace();
72}
73
75{
76 // qDebug() << "GROUPREMOVE:" << this << ":" << member_P;
77 // qDebug() << kBacktrace();
78 Q_ASSERT(_members.contains(member_P));
79 _members.removeAll(member_P);
80 // there are cases when automatic deleting of groups must be delayed,
81 // e.g. when removing a member and doing some operation on the possibly
82 // other members of the group (which would be however deleted already
83 // if there were no other members)
84 if (refcount == 0 && _members.isEmpty()) {
85 workspace()->removeGroup(this);
86 delete this;
87 }
88}
89
91{
92 ++refcount;
93}
94
96{
97 if (--refcount == 0 && _members.isEmpty()) {
98 workspace()->removeGroup(this);
99 delete this;
100 }
101}
102
104{
105 Q_ASSERT(leader_P->window() == leader_wid);
106 leader_client = leader_P;
107}
108
110{
111 Q_ASSERT(!_members.contains(leader_client));
112 leader_client = nullptr;
113 if (_members.isEmpty()) {
114 workspace()->removeGroup(this);
115 delete this;
116 }
117}
118
119} // namespace
void ref()
Definition group.cpp:90
Group(xcb_window_t leader)
Definition group.cpp:26
void lostLeader()
Definition group.cpp:109
void addMember(X11Window *member)
Definition group.cpp:67
void deref()
Definition group.cpp:95
void gotLeader(X11Window *leader)
Definition group.cpp:103
QIcon icon() const
Definition group.cpp:44
void removeMember(X11Window *member)
Definition group.cpp:74
QIcon icon
Definition window.h:327
X11Window * findClient(std::function< bool(const X11Window *)> func) const
Finds the first Client matching the condition expressed by passed in func.
void addGroup(Group *group)
Definition workspace.h:777
void removeGroup(Group *group)
Definition workspace.h:783
xcb_window_t window() const
Workspace * workspace()
Definition workspace.h:830