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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
/*******************************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2011/2012 The KWin team <kwin@kde.org>
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 "tabgroup.h"
#include "client.h"
#include "effects.h"
#include "workspace.h"
namespace KWin
{
TabGroup::TabGroup(AbstractClient *c)
: m_clients()
, m_current(c)
, m_minSize(c->minSize())
, m_maxSize(c->maxSize())
, m_stateUpdatesBlocked(0)
, m_pendingUpdates(TabGroup::None)
{
QIcon icon(c->icon());
m_clients << c;
c->setTabGroup(this);
c->setClientShown(true);
}
TabGroup::~TabGroup()
{
}
void TabGroup::activateNext()
{
int index = m_clients.indexOf(m_current);
setCurrent(m_clients.at((index < m_clients.count() - 1) ? index + 1 : 0));
}
void TabGroup::activatePrev()
{
int index = m_clients.indexOf(m_current);
setCurrent(m_clients.at((index > 0) ? index - 1 : m_clients.count() - 1));
}
bool TabGroup::add(AbstractClient* c, AbstractClient *other, bool after, bool becomeVisible)
{
Q_ASSERT(!c->tabGroup());
if (contains(c) || !contains(other))
return false;
// Tabbed windows MUST have a decoration
c->setNoBorder(false);
if (c->noBorder())
return false;
// If it's not possible to have the same states then ungroup them, TODO: Check all states
// We do this here as the ungroup code in updateStates() cannot be called until add() completes
bool cannotTab = false;
ShadeMode oldShadeMode = c->shadeMode();
QRect oldGeom = c->geometry();
int oldDesktop = c->desktop();
c->setShade(m_current->shadeMode());
cannotTab = c->shadeMode() != m_current->shadeMode();
if (!cannotTab) {
c->setDesktop(m_current->desktop());
cannotTab = c->desktop() != m_current->desktop();
}
if (!cannotTab) {
c->setGeometry(m_current->geometry());
cannotTab = c->geometry() != m_current->geometry();
}
if (cannotTab) {
c->setShade(oldShadeMode);
c->setDesktop(oldDesktop);
c->setGeometry(oldGeom);
// trigger decoration repaint on the group to make sure that hover animations are properly reset.
m_current->triggerDecorationRepaint();
return false; // cannot tab
}
// Actually add to new group ----------------------------------------
// Notify effects of merge
if (effects)
static_cast<EffectsHandlerImpl*>(effects)->slotTabAdded(c->effectWindow(), other->effectWindow());
// next: aling the client states BEFORE adding it to the group
// otherwise the caused indirect state changes would be taken as the dominating ones and break
// the main client
// example: QuickTiling is aligned to None, this restores the former QuickTiled size and alignes
// all other windows in the group - including the actual main client! - to this size and thus
// breaks the actually required alignment to the main windows geometry (because that now has the
// restored geometry of the formerly Q'tiled window) - bug #303937
updateStates(m_current, All, c);
int index = other ? m_clients.indexOf(other) : m_clients.size();
index += after;
if (index > m_clients.size())
index = m_clients.size();
m_clients.insert(index, c);
c->setTabGroup(this); // Let the client know which group it belongs to
updateMinMaxSize();
if (!becomeVisible)
c->setClientShown(false);
else {
c->setClientShown(true);
if (!effects || c->readyForPainting()) {
setCurrent(c);
if (options->focusPolicyIsReasonable())
workspace()->requestFocus( c );
}
else {
if (options->focusPolicyIsReasonable())
workspace()->requestFocus( m_current );
m_current = c; // setCurrent will be called by Toplevel::setReadyForPainting()
}
}
m_current->triggerDecorationRepaint();
return true;
}
bool TabGroup::remove(AbstractClient* c)
{
if (!c)
return false;
int index = m_clients.indexOf(c);
if (index < 0)
return false;
c->setTabGroup(NULL);
m_clients.removeAt(index);
updateMinMaxSize();
if (m_clients.count() == 1) { // split
remove(m_clients.at(0));
}
if (m_clients.isEmpty()) { // remaining singleton "tab"
c->setClientShown(true);
return true; // group is gonna be deleted after this anyway
}
if (c == m_current) {
m_current = index < m_clients.count() ? m_clients.at(index) : m_clients.last();
m_current->setClientShown(true);
if (effects) // "c -> m_current" because c was m_current
static_cast<EffectsHandlerImpl*>(effects)->slotCurrentTabAboutToChange(c->effectWindow(), m_current->effectWindow());
}
// Notify effects of removal
if (effects)
static_cast<EffectsHandlerImpl*>(effects)->slotTabRemoved(c->effectWindow(), m_current->effectWindow());
m_current->triggerDecorationRepaint();
return true;
}
void TabGroup::closeAll()
{
// NOTICE - in theory it's OK to use the list because closing sends an event to the client and
// due to the async X11 nature, the client would be released and thus removed from m_clients
// after this function exits.
// However later Wayland support or similar might not share this bahaviour - and we really had
// enough trouble with a polluted client list around the tabbing code ....
auto list(m_clients);
for (auto i = list.constBegin(), end = list.constEnd(); i != end; ++i)
if (*i != m_current)
(*i)->closeWindow();
m_current->closeWindow();
}
void TabGroup::move(AbstractClient *c, AbstractClient *other, bool after)
{
if (c == other)
return;
int from = m_clients.indexOf(c);
if (from < 0)
return;
int to = other ? m_clients.indexOf(other) : m_clients.size() - 1;
if (to < 0)
return;
to += after;
if (to >= m_clients.size())
to = m_clients.size() - 1;
if (from == to)
return;
m_clients.move(from, to);
m_current->triggerDecorationRepaint();
}
bool TabGroup::isActive() const
{
return contains(Workspace::self()->activeClient());
}
void TabGroup::setCurrent(AbstractClient* c, bool force)
{
if ((c == m_current && !force) || !contains(c))
return;
// Notify effects of switch
if (effects)
static_cast<EffectsHandlerImpl*>(effects)->slotCurrentTabAboutToChange(m_current->effectWindow(), c->effectWindow());
m_current = c;
c->setClientShown(true); // reduce flicker?
for (auto i = m_clients.constBegin(), end = m_clients.constEnd(); i != end; ++i)
(*i)->setClientShown((*i) == m_current);
}
void TabGroup::sync(const char *property, AbstractClient *c)
{
if (c->metaObject()->indexOfProperty(property) > -1) {
qCWarning(KWIN_CORE, "caught attempt to sync non dynamic property: %s", property);
return;
}
QVariant v = c->property(property);
for (auto i = m_clients.begin(), end = m_clients.end(); i != end; ++i) {
if (*i != m_current)
(*i)->setProperty(property, v);
}
}
void TabGroup::updateMinMaxSize()
{
// Determine entire group's minimum and maximum sizes
// TODO this used to be signalled out but i didn't find a receiver - or got an idea what this would be good for
// find purpose & solution or kick it
// QSize oldMin = m_minSize;
// QSize oldMax = m_maxSize;
m_minSize = QSize(0, 0);
m_maxSize = QSize(INT_MAX, INT_MAX);
for (auto i = m_clients.constBegin(); i != m_clients.constEnd(); ++i) {
m_minSize = m_minSize.expandedTo((*i)->minSize());
m_maxSize = m_maxSize.boundedTo((*i)->maxSize());
}
// TODO: this actually resolves a conflict that should be caught when adding?
m_maxSize = m_maxSize.expandedTo(m_minSize);
// calculate this _once_ to get a common size.
// TODO this leaves another unresolved conflict about the base increment (luckily not used too often)
const QSize size = m_current->clientSize().expandedTo(m_minSize).boundedTo(m_maxSize);
if (size != m_current->clientSize()) {
const QRect r(m_current->pos(), m_current->sizeForClientSize(size));
for (auto i = m_clients.constBegin(), end = m_clients.constEnd(); i != end; ++i)
(*i)->setGeometry(r);
}
}
void TabGroup::blockStateUpdates(bool more) {
more ? ++m_stateUpdatesBlocked : --m_stateUpdatesBlocked;
if (m_stateUpdatesBlocked < 0) {
m_stateUpdatesBlocked = 0;
qCWarning(KWIN_CORE, "TabGroup: Something is messed up with TabGroup::blockStateUpdates() invocation\nReleased more than blocked!");
}
}
void TabGroup::updateStates(AbstractClient* main, States states, AbstractClient* only)
{
if (main == only)
return; // there's no need to only align "us" to "us"
if (m_stateUpdatesBlocked > 0) {
m_pendingUpdates |= states;
return;
}
states |= m_pendingUpdates;
m_pendingUpdates = TabGroup::None;
QVector<AbstractClient*> toBeRemoved, onlyDummy;
auto *list = &m_clients;
if (only) {
onlyDummy << only;
list = &onlyDummy;
}
for (auto i = list->constBegin(), end = list->constEnd(); i != end; ++i) {
auto *c = (*i);
if (c != main) {
if ((states & Minimized) && c->isMinimized() != main->isMinimized()) {
if (main->isMinimized())
c->minimize(true);
else
c->unminimize(true);
}
// the order QuickTile -> Maximized -> Geometry is somewhat important because one will change the other
// don't change w/o good reason and care
if ((states & QuickTile) && c->quickTileMode() != main->quickTileMode())
c->setQuickTileMode(main->quickTileMode());
if ((states & Maximized) && c->maximizeMode() != main->maximizeMode())
c->maximize(main->maximizeMode());
// the order Shaded -> Geometry is somewhat important because one will change the other
if ((states & Shaded))
c->setShade(main->shadeMode());
if ((states & Geometry) && c->geometry() != main->geometry())
c->setGeometry(main->geometry());
if (states & Desktop) {
if (c->isOnAllDesktops() != main->isOnAllDesktops())
c->setOnAllDesktops(main->isOnAllDesktops());
if (c->desktop() != main->desktop())
c->setDesktop(main->desktop());
}
if ((states & Activity) && c->activities() != main->activities()) {
c->setOnActivities(main->activities());
}
if (states & Layer) {
if (c->keepAbove() != main->keepAbove())
c->setKeepAbove(main->keepAbove());
if (c->keepBelow() != main->keepBelow())
c->setKeepBelow(main->keepBelow());
}
// If it's not possible to have the same states then ungroup them, TODO: Check all states
if (((states & Geometry) && c->geometry() != main->geometry()) ||
((states & Desktop) && c->desktop() != main->desktop()))
toBeRemoved << c;
}
}
for (auto i = toBeRemoved.constBegin(), end = toBeRemoved.constEnd(); i != end; ++i)
remove(*i);
}
}
|