kwin/tiling/tile.cpp

150 lines
3.6 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 "tile.h"
#include <assert.h>
#include <QQueue>
#include "client.h"
#include "workspace.h"
#include "tiling/tiling.h"
namespace KWin
{
2011-01-30 14:34:42 +00:00
Tile::Tile(Client *c, const QRect& area)
: m_client(c),
m_floating(false)
2011-01-30 14:34:42 +00:00
{
setGeometry(area);
2011-01-30 14:34:42 +00:00
if (c) {
m_prevGeom = c->geometry();
}
2011-01-30 14:34:42 +00:00
if (c && !c->isResizable())
floatTile();
}
/*
* NOTE: Why isn't left/right/parent copied?
* Because they might be deleted at any point, so we can't keep pointers to them
* Also it doesn't make sense in the areas where copy is actually going to be used.
* Since we will be getting a new parent and children.
*/
2011-01-30 14:34:42 +00:00
Tile::Tile(const Tile& orig)
: m_client(orig.client()),
m_prevGeom(orig.m_prevGeom),
m_floating(orig.floating())
{
setGeometry(orig.geometry());
}
Tile::~Tile()
2011-01-30 14:34:42 +00:00
{
restorePreviousGeometry();
m_client = NULL;
2011-01-30 14:34:42 +00:00
}
void Tile::commit()
2011-01-30 14:34:42 +00:00
{
m_client->setGeometry(geometry(), ForceGeometrySet);
}
void Tile::setGeometry(int x, int y, int w, int h)
2011-01-30 14:34:42 +00:00
{
QRect old = m_geom;
2011-01-30 14:34:42 +00:00
m_geom.setTopLeft(QPoint(x, y));
m_geom.setWidth(w);
m_geom.setHeight(h);
2011-01-30 14:34:42 +00:00
if (old == m_geom)
return;
2011-01-30 14:34:42 +00:00
if (floating())
m_prevGeom = m_geom;
2011-01-30 14:34:42 +00:00
}
void Tile::floatTile()
2011-01-30 14:34:42 +00:00
{
if (floating()) return;
// note, order of setting m_floating to true
// then calling restore is important
// childGeometryChanged will check for ignoreGeometry()
m_floating = true;
restorePreviousGeometry();
commit();
client()->workspace()->tiling()->notifyTilingWindowActivated(client());
// TODO: notify layout manager
2011-01-30 14:34:42 +00:00
}
void Tile::unfloatTile()
2011-01-30 14:34:42 +00:00
{
if (!floating()) return;
m_floating = false;
m_prevGeom = m_client->geometry();
2011-01-30 14:34:42 +00:00
setGeometry(m_client->workspace()->clientArea(PlacementArea, m_client));
commit();
// TODO: notify layout manager
2011-01-30 14:34:42 +00:00
}
void Tile::restorePreviousGeometry()
2011-01-30 14:34:42 +00:00
{
// why this check?
// sometimes we remove a Tile, but don't want to remove the children
// so the children are set to NULL. In this case leaf() will return
// true but m_client will still be null
2011-01-30 14:34:42 +00:00
if (!m_client) return;
if (m_prevGeom.isNull()) {
QRect area = m_client->workspace()->clientArea(PlacementArea, m_client);
m_client->workspace()->place(m_client, area);
} else {
m_client->setGeometry(m_prevGeom, ForceGeometrySet);
}
2011-01-30 14:34:42 +00:00
setGeometry(m_client->geometry());
}
bool Tile::minimized() const
2011-01-30 14:34:42 +00:00
{
return m_client->isMinimized();
2011-01-30 14:34:42 +00:00
}
void Tile::focus()
2011-01-30 14:34:42 +00:00
{
m_client->workspace()->activateClient(m_client, true);
}
2011-01-30 14:34:42 +00:00
void Tile::dumpTile(const QString& indent) const
{
kDebug(1212) << indent << m_client
2011-01-30 14:34:42 +00:00
<< (floating() ? "floating" : "not floating")
<< (ignoreGeometry() ? "ignored" : "tiled")
<< m_geom ;
}
}