2010-04-25 16:43:14 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
|
|
|
|
|
|
|
|
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 "columns.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
2011-07-28 11:36:25 +00:00
|
|
|
#include "tiling/tile.h"
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-02-19 08:34:20 +00:00
|
|
|
#include <kdecoration.h>
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
// TODO: caching of actually tiled windows
|
|
|
|
// Columns is doing a lot of looping
|
|
|
|
// checking which tiles are actually *tiled*
|
|
|
|
// ( ie. not floating or minimized )
|
|
|
|
// This can probably be moved to TilingLayout
|
|
|
|
// and cached. But remember to preserve order!
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Columns::Columns(Workspace *w)
|
|
|
|
: TilingLayout(w)
|
|
|
|
, m_leftWidth(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecorationDefines::Position Columns::resizeMode(Client *c, KDecorationDefines::Position currentMode) const
|
|
|
|
{
|
|
|
|
Tile *t = findTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t)
|
2010-04-25 16:43:14 +00:00
|
|
|
return currentMode;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t && t->floating())
|
2010-04-25 16:43:14 +00:00
|
|
|
return currentMode;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QList<Tile *> tiled(tiles());
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
QMutableListIterator<Tile *> i(tiled);
|
2011-01-30 14:34:42 +00:00
|
|
|
while (i.hasNext()) {
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *tile = i.next();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tile->ignoreGeometry())
|
2010-04-25 16:43:14 +00:00
|
|
|
i.remove();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tiled.first() == t
|
|
|
|
&& (currentMode == KDecorationDefines::PositionRight
|
|
|
|
|| currentMode == KDecorationDefines::PositionTopRight
|
|
|
|
|| currentMode == KDecorationDefines::PositionBottomRight)) {
|
2010-04-25 16:43:14 +00:00
|
|
|
return KDecorationDefines::PositionRight;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// in right column so only left resize allowed
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tiled.contains(t)
|
|
|
|
&& (tiled.first() != t)
|
|
|
|
&& (currentMode == KDecorationDefines::PositionLeft
|
|
|
|
|| currentMode == KDecorationDefines::PositionTopLeft
|
|
|
|
|| currentMode == KDecorationDefines::PositionBottomLeft)) {
|
2010-04-25 16:43:14 +00:00
|
|
|
return KDecorationDefines::PositionLeft;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
return KDecorationDefines::PositionCenter;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Columns::clientResized(Client *c, const QRect &moveResizeGeom, const QRect &orig)
|
|
|
|
{
|
|
|
|
if (TilingLayout::clientResized(c, moveResizeGeom, orig))
|
2010-07-11 06:47:09 +00:00
|
|
|
return true;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Tile *t = findTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QList<Tile *> tiled(tiles());
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
QMutableListIterator<Tile *> i(tiled);
|
2011-01-30 14:34:42 +00:00
|
|
|
while (i.hasNext()) {
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *tile = i.next();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tile->ignoreGeometry())
|
2010-04-25 16:43:14 +00:00
|
|
|
i.remove();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tiled.first() == t) {
|
2010-04-25 16:43:14 +00:00
|
|
|
m_leftWidth = moveResizeGeom.width();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
m_leftWidth = layoutArea(t).width() - moveResizeGeom.width();
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
arrange(layoutArea(t));
|
2010-07-11 06:47:09 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Columns::arrange(QRect wgeom)
|
|
|
|
{
|
|
|
|
QList<Tile *> tiled(tiles());
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
QMutableListIterator<Tile *> i(tiled);
|
2011-01-30 14:34:42 +00:00
|
|
|
while (i.hasNext()) {
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *t = i.next();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t->ignoreGeometry())
|
2010-04-25 16:43:14 +00:00
|
|
|
i.remove();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
int n = tiled.length();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (n < 1)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (n == 1) {
|
|
|
|
tiled.first()->setGeometry(wgeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
tiled.first()->commit();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// save the original before we mangle it
|
|
|
|
int totalWidth = wgeom.width();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_leftWidth == 0)
|
2010-04-25 16:43:14 +00:00
|
|
|
m_leftWidth = wgeom.width() / 2;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (n > 1)
|
|
|
|
wgeom.setWidth(m_leftWidth);
|
|
|
|
tiled.first()->setGeometry(wgeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
tiled.first()->commit();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
wgeom.moveLeft(wgeom.x() + m_leftWidth);
|
|
|
|
wgeom.setWidth(totalWidth - m_leftWidth);
|
|
|
|
int ht = wgeom.height() / (n - 1);
|
|
|
|
wgeom.setHeight(ht);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
int mult = 0;
|
|
|
|
int originalTop = wgeom.y();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (QList<Tile *>::const_iterator it = ++tiled.constBegin() ; it != tiled.constEnd() ; ++it) {
|
|
|
|
if ((*it)->floating())
|
2010-04-25 16:43:14 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
(*it)->setGeometry(wgeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
(*it)->commit();
|
|
|
|
mult++;
|
2011-01-30 14:34:42 +00:00
|
|
|
wgeom.moveTop(originalTop + mult * ht);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|