1/*******************************************************************************
2KWin - the KDE window manager
3This file is part of the KDE project.
4
5Copyright (C) 2011/2012 The KWin team <kwin@kde.org>
6
7This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program. If not, see <http://www.gnu.org/licenses/>.
19*******************************************************************************/
20
21#ifndef KWIN_TABGROUP_H
22#define KWIN_TABGROUP_H
23
24#include <QObject>
25
26#include "kdecoration.h"
27#include "utils.h"
28
29namespace KWin
30{
31
32class Client;
33
34/**
35 * This class represents a group of clients for use in window tabbing. All
36 * clients in the group share the same geometry and state information; I.e if
37 * one client changes then all others should also be changed.
38 *
39 * A group contains at least one client and DOES NOT contain multiple
40 * copies of the same client. A client MUST NOT be in two groups at the same
41 * time. All decorated clients SHOULD be in a group, even if it's a group of
42 * one client.
43 *
44 * rohanp: Had to convert this object to a QObject to make it easier for adding
45 * scripting interface to TabGroup.
46 *
47 * If a group contains multiple clients then only one will ever be mapped at
48 * any given time.
49 */
50class TabGroup
51{
52public:
53 /**
54 * Creates a new group containing \p c.
55 */
56 explicit TabGroup(Client* c);
57 ~TabGroup();
58
59 enum State {
60 None = 0, Minimized = 1<<0, Maximized = 1<<1, Shaded = 1<<2,
61 Geometry = 1<<3, Desktop = 1<<4, Activity = 1<<5,
62 Layer = 1<<6, QuickTile = 1<<7, All = 0xffffffff
63 };
64 Q_DECLARE_FLAGS(States, State)
65
66 /**
67 * Activate next tab (flips)
68 */
69 void activateNext();
70
71 /**
72 * Activate previous tab (flips)
73 */
74 void activatePrev();
75
76 /**
77 * Allows to alter several attributes in random order and trigger a general update at the end
78 * (must still be explicitly called)
79 * this is to prevent side effects, mostly for geometry adjustments during maximization and QuickTiling
80 */
81 void blockStateUpdates(bool);
82
83 /**
84 * Close all clients in this group.
85 */
86 void closeAll();
87
88 /**
89 * Whether client \p c is member of this group
90 */
91 bool contains(Client* c) const;
92
93 /**
94 * The amount of clients in this group
95 */
96 int count() const;
97
98 /**
99 * Returns whether or not this group contains the active client.
100 */
101 bool isActive() const;
102
103 /**
104 * Returns whether this group is empty (used by workspace to remove it)
105 */
106 bool isEmpty() const;
107
108 /**
109 * Returns the list of all the clients contained in this group in their current order.
110 */
111 const ClientList &clients() const;
112
113 /**
114 * Returns the currently visible client.
115 */
116 Client* current() const;
117 /**
118 * Makes \p c the visible client in the group - force is only used when the window becomes ready for painting.
119 * Any other usage just causes pointless action
120 */
121 void setCurrent(Client* c, bool force = false);
122
123 /**
124 * Alignes the dynamic Qt @param property of all clients to the one of @param c
125 */
126 void sync(const char *property, Client *c);
127
128 /**
129 * Returns combined minimum size of all clients in the group.
130 */
131 QSize minSize() const;
132 /**
133 * Returns combined maximum size of all clients in the group.
134 */
135 QSize maxSize() const;
136
137 /**
138 * Ensures that all the clients in the group have identical geometries and states using
139 * \p main as the primary client to copy the settings off. If \p only is set then only
140 * that client is updated to match \p main.
141 */
142 void updateStates(Client* main, States states, Client* only = NULL);
143
144 /**
145 * updates geometry restrictions of this group, basically called from Client::getWmNormalHints(), otherwise rather private
146 */
147 void updateMinMaxSize();
148
149signals:
150 void minSizeChanged();
151 void maxSizeChanged();
152
153private:
154 friend class Client;
155// friend bool Client::tabTo(Client*, bool, bool);
156 bool add(KWin::Client *c, Client *other, bool behind, bool activateC);
157 void move(KWin::Client* c, KWin::Client* before, bool behind);
158
159// friend bool Client::untab(const QRect&);
160 bool remove(KWin::Client *c);
161
162 ClientList m_clients;
163 Client *m_current;
164 QSize m_minSize;
165 QSize m_maxSize;
166 int m_stateUpdatesBlocked;
167 States m_pendingUpdates;
168};
169
170inline bool TabGroup::contains(Client* c) const
171{
172 return c && m_clients.contains(c);
173}
174
175inline int TabGroup::count() const
176{
177 return m_clients.count();
178}
179
180inline const ClientList &TabGroup::clients() const
181{
182 return m_clients;
183}
184
185inline bool TabGroup::isEmpty() const
186{
187 return m_clients.isEmpty();
188}
189
190inline Client* TabGroup::current() const
191{
192 return m_current;
193}
194
195inline QSize TabGroup::minSize() const
196{
197 return m_minSize;
198}
199
200inline QSize TabGroup::maxSize() const
201{
202 return m_maxSize;
203}
204
205}
206
207Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::TabGroup::States)
208
209#endif
210