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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2011-07-28 11:36:25 +00:00
|
|
|
#include "tiling/tilinglayout.h"
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
#include <QCursor>
|
|
|
|
|
|
|
|
#include "client.h"
|
2011-07-28 11:36:25 +00:00
|
|
|
#include "tiling/tile.h"
|
2010-04-25 16:43:14 +00:00
|
|
|
#include "workspace.h"
|
2011-07-13 16:48:56 +00:00
|
|
|
#include "tiling/tiling.h"
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
TilingLayout::TilingLayout(Workspace *w)
|
2011-07-18 09:09:12 +00:00
|
|
|
: QObject()
|
|
|
|
, m_workspace(w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-18 09:09:12 +00:00
|
|
|
connect(m_workspace, SIGNAL(configChanged()), this, SLOT(reconfigureTiling()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
TilingLayout::~TilingLayout()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
qDeleteAll(m_tiles);
|
2010-07-13 16:02:54 +00:00
|
|
|
m_tiles.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int TilingLayout::findTilePos(Client *c) const
|
|
|
|
{
|
2010-04-25 23:37:38 +00:00
|
|
|
int i = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * t, m_tiles) {
|
|
|
|
if (t->client() == c)
|
2010-04-25 16:43:14 +00:00
|
|
|
return i;
|
|
|
|
i++;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Tile* TilingLayout::findTile(Client *c) const
|
|
|
|
{
|
|
|
|
int i = findTilePos(c);
|
|
|
|
if (i != -1)
|
2010-04-25 16:43:14 +00:00
|
|
|
return m_tiles[ i ];
|
|
|
|
return NULL;
|
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 TilingLayout::clientMinimizeToggled(Client *c)
|
|
|
|
{
|
2010-05-09 06:15:40 +00:00
|
|
|
// just rearrange since that will check for state
|
2011-01-30 14:34:42 +00:00
|
|
|
Tile *t = findTile(c);
|
|
|
|
if (t)
|
|
|
|
arrange(layoutArea(t));
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool TilingLayout::clientResized(Client *c, const QRect &moveResizeGeom, const QRect &orig)
|
|
|
|
{
|
|
|
|
if (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);
|
|
|
|
if (!t || t->ignoreGeometry()) {
|
|
|
|
c->setGeometry(moveResizeGeom);
|
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
|
|
|
|
2010-07-11 06:47:09 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-05-09 06:15:40 +00:00
|
|
|
// tries to swap the tile with the one in the new position right now
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::clientMoved(Client *c, const QRect &moveResizeGeom, const QRect &orig)
|
|
|
|
{
|
|
|
|
if (moveResizeGeom == orig)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Tile *t = findTile(c);
|
|
|
|
if (!t) {
|
|
|
|
c->setGeometry(moveResizeGeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (t->floating()) {
|
|
|
|
t->setGeometry(moveResizeGeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
t->commit();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Tile *r = findTileBelowPoint(QCursor::pos());
|
2010-04-25 16:43:14 +00:00
|
|
|
// TODO: if the client moved in from another desktop, don't swap, add
|
2011-01-30 14:34:42 +00:00
|
|
|
if (r && t) {
|
|
|
|
swapTiles(r, t);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
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 TilingLayout::swapTiles(Tile *a, Tile *b)
|
|
|
|
{
|
|
|
|
if (a && b) {
|
2010-04-25 16:43:14 +00:00
|
|
|
// t is the tile the user requested a move of
|
|
|
|
// r is the tile below it
|
2011-01-30 14:34:42 +00:00
|
|
|
int a_index = tiles().indexOf(a);
|
|
|
|
int b_index = tiles().indexOf(b);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// use m_tiles since tiles() is const
|
|
|
|
// not sure how good an idea this is
|
2011-01-30 14:34:42 +00:00
|
|
|
m_tiles.replace(a_index, b);
|
|
|
|
m_tiles.replace(b_index, a);
|
|
|
|
arrange(layoutArea(a));
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
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 TilingLayout::addTileNoArrange(Tile * t)
|
|
|
|
{
|
|
|
|
if (findTile(t->client()))
|
2010-05-05 13:52:09 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_tiles.append(t);
|
|
|
|
postAddTile(t);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::addTile(Tile *t)
|
|
|
|
{
|
|
|
|
addTileNoArrange(t);
|
|
|
|
arrange(layoutArea(t));
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::addTile(Client *c)
|
|
|
|
{
|
|
|
|
Q_UNUSED(c)
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::removeTileNoArrange(Tile * t)
|
|
|
|
{
|
|
|
|
if (t == NULL)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
preRemoveTile(t);
|
|
|
|
m_tiles.removeOne(t);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
const QRect TilingLayout::layoutArea(Tile *t) const
|
|
|
|
{
|
|
|
|
return m_workspace->clientArea(PlacementArea, t->client());
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::removeTile(Tile *t)
|
|
|
|
{
|
|
|
|
if (t == NULL)
|
|
|
|
return;
|
|
|
|
removeTileNoArrange(t);
|
|
|
|
if (!m_tiles.empty())
|
|
|
|
arrange(layoutArea(m_tiles.first()));
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::removeTile(Client *c)
|
|
|
|
{
|
|
|
|
removeTile(findTile(c));
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TilingLayout::toggleFloatTile(Client *c)
|
|
|
|
{
|
|
|
|
Tile *t = findTile(c);
|
|
|
|
if (t && t->floating())
|
2010-04-25 16:43:14 +00:00
|
|
|
t->unfloatTile();
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (t)
|
2010-04-25 16:43:14 +00:00
|
|
|
t->floatTile();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t)
|
|
|
|
arrange(layoutArea(t));
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-05-05 13:52:09 +00:00
|
|
|
void TilingLayout::reconfigureTiling()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
//TODO also check 'untiled' windows to see if they are now requesting tiling
|
|
|
|
foreach (Tile * t, tiles()) {
|
|
|
|
if (t->client()->rules()->checkTilingOption(t->floating() ? 1 : 0) == 1)
|
2010-05-05 13:52:09 +00:00
|
|
|
t->floatTile();
|
|
|
|
else
|
|
|
|
t->unfloatTile();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-05 13:52:09 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tiles().length() > 0)
|
|
|
|
arrange(layoutArea(tiles().first()));
|
2010-05-05 13:52:09 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Client * c, workspace()->stackingOrder()) {
|
|
|
|
if (c->rules()->checkTilingOption(0) == 1)
|
2011-07-13 16:48:56 +00:00
|
|
|
workspace()->tiling()->createTile(c);
|
2010-05-05 13:52:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Tile* TilingLayout::findTileBelowPoint(const QPoint &p) const
|
|
|
|
{
|
|
|
|
foreach (Tile * t, tiles()) {
|
|
|
|
if (t->floating())
|
2010-04-25 16:43:14 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t->geometry().contains(p))
|
2010-04-25 16:43:14 +00:00
|
|
|
return t;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void TilingLayout::commit()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
foreach (Tile * t, m_tiles)
|
2011-09-10 07:57:37 +00:00
|
|
|
t->commit();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Default is to allow no resizing
|
|
|
|
*/
|
2011-01-30 14:34:42 +00:00
|
|
|
KDecorationDefines::Position TilingLayout::resizeMode(Client *c, KDecorationDefines::Position currentMode) const
|
|
|
|
{
|
|
|
|
Tile *t = findTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
// if not tiled, allow resize
|
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;
|
|
|
|
// We return PositionCenter since it makes
|
|
|
|
// no sense in resizing.
|
|
|
|
return KDecorationDefines::PositionCenter;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
} // end namespace
|
|
|
|
|