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 "tile.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <QQueue>
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#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
|
|
|
Tile::Tile(Client *c, const QRect& area)
|
2010-04-25 16:43:14 +00:00
|
|
|
: m_client(c),
|
|
|
|
m_floating(false)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-09-10 07:57:37 +00:00
|
|
|
Q_ASSERT(c != NULL);
|
2010-04-25 16:43:14 +00:00
|
|
|
setGeometry(area);
|
2011-09-10 07:57:37 +00:00
|
|
|
m_prevGeom = c->geometry();
|
|
|
|
if (!c->isResizable())
|
2011-01-30 14:34:42 +00:00
|
|
|
floatTile();
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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());
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
Tile::~Tile()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
restorePreviousGeometry();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::commit()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
m_client->setGeometry(geometry(), ForceGeometrySet);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::setGeometry(int x, int y, int w, int h)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +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);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (old == m_geom)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (floating())
|
2010-04-25 16:43:14 +00:00
|
|
|
m_prevGeom = m_geom;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::floatTile()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (floating()) return;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// note, order of setting m_floating to true
|
|
|
|
// then calling restore is important
|
|
|
|
// childGeometryChanged will check for ignoreGeometry()
|
|
|
|
m_floating = true;
|
|
|
|
|
|
|
|
restorePreviousGeometry();
|
|
|
|
|
|
|
|
commit();
|
2011-07-13 16:48:56 +00:00
|
|
|
client()->workspace()->tiling()->notifyTilingWindowActivated(client());
|
2010-04-25 16:43:14 +00:00
|
|
|
// TODO: notify layout manager
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::unfloatTile()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!floating()) return;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
m_floating = false;
|
|
|
|
m_prevGeom = m_client->geometry();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setGeometry(m_client->workspace()->clientArea(PlacementArea, m_client));
|
2010-04-25 16:43:14 +00:00
|
|
|
commit();
|
|
|
|
// TODO: notify layout manager
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::restorePreviousGeometry()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
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);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
setGeometry(m_client->geometry());
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-04-25 18:18:06 +00:00
|
|
|
bool Tile::minimized() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
return m_client->isMinimized();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
void Tile::focus()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
m_client->workspace()->activateClient(m_client, true);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Tile::dumpTile(const QString& indent) const
|
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
kDebug(1212) << indent << m_client
|
2011-01-30 14:34:42 +00:00
|
|
|
<< (floating() ? "floating" : "not floating")
|
|
|
|
<< (ignoreGeometry() ? "ignored" : "tiled")
|
|
|
|
<< m_geom ;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|