kwin/tilinglayouts/columns/columns.cpp

155 lines
4.2 KiB
C++
Raw Normal View History

/********************************************************************
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"
#include "tiling/tile.h"
#include <kdecoration.h>
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);
2011-01-30 14:34:42 +00:00
if (!t)
return currentMode;
2011-01-30 14:34:42 +00:00
if (t && t->floating())
return currentMode;
2011-01-30 14:34:42 +00:00
QList<Tile *> tiled(tiles());
QMutableListIterator<Tile *> i(tiled);
2011-01-30 14:34:42 +00:00
while (i.hasNext()) {
Tile *tile = i.next();
2011-01-30 14:34:42 +00:00
if (tile->ignoreGeometry())
i.remove();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (tiled.first() == t
&& (currentMode == KDecorationDefines::PositionRight
|| currentMode == KDecorationDefines::PositionTopRight
|| currentMode == KDecorationDefines::PositionBottomRight)) {
return KDecorationDefines::PositionRight;
2011-01-30 14:34:42 +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)) {
return KDecorationDefines::PositionLeft;
2011-01-30 14:34:42 +00:00
}
return KDecorationDefines::PositionCenter;
2011-01-30 14:34:42 +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))
return true;
2011-01-30 14:34:42 +00:00
Tile *t = findTile(c);
2011-01-30 14:34:42 +00:00
QList<Tile *> tiled(tiles());
QMutableListIterator<Tile *> i(tiled);
2011-01-30 14:34:42 +00:00
while (i.hasNext()) {
Tile *tile = i.next();
2011-01-30 14:34:42 +00:00
if (tile->ignoreGeometry())
i.remove();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (tiled.first() == t) {
m_leftWidth = moveResizeGeom.width();
2011-01-30 14:34:42 +00:00
} else {
m_leftWidth = layoutArea(t).width() - moveResizeGeom.width();
}
2011-01-30 14:34:42 +00:00
arrange(layoutArea(t));
return true;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Columns::arrange(QRect wgeom)
{
QList<Tile *> tiled(tiles());
QMutableListIterator<Tile *> i(tiled);
2011-01-30 14:34:42 +00:00
while (i.hasNext()) {
Tile *t = i.next();
2011-01-30 14:34:42 +00:00
if (t->ignoreGeometry())
i.remove();
2011-01-30 14:34:42 +00:00
}
int n = tiled.length();
2011-01-30 14:34:42 +00:00
if (n < 1)
return;
2011-01-30 14:34:42 +00:00
if (n == 1) {
tiled.first()->setGeometry(wgeom);
tiled.first()->commit();
return;
2011-01-30 14:34:42 +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)
m_leftWidth = wgeom.width() / 2;
2011-01-30 14:34:42 +00:00
if (n > 1)
wgeom.setWidth(m_leftWidth);
tiled.first()->setGeometry(wgeom);
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);
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())
continue;
2011-01-30 14:34:42 +00:00
(*it)->setGeometry(wgeom);
(*it)->commit();
mult++;
2011-01-30 14:34:42 +00:00
wgeom.moveTop(originalTop + mult * ht);
}
}
2011-01-30 14:34:42 +00:00
}