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>
|
2011-07-13 16:48:56 +00:00
|
|
|
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
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-13 16:48:56 +00:00
|
|
|
#include <tiling/tiling.h>
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
#include <klocale.h>
|
2011-07-13 16:48:56 +00:00
|
|
|
#include <knotification.h>
|
2010-06-14 15:17:17 +00:00
|
|
|
#include <kwindowinfo.h>
|
|
|
|
#include <kwindowsystem.h>
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-18 14:38:55 +00:00
|
|
|
#include <KActionCollection>
|
|
|
|
#include <KDE/KAction>
|
|
|
|
|
2011-07-28 11:36:25 +00:00
|
|
|
#include "tiling/tile.h"
|
|
|
|
#include "tiling/tilinglayout.h"
|
2011-07-13 16:48:56 +00:00
|
|
|
#include "tilinglayoutfactory.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
Tiling::Tiling(KWin::Workspace* w)
|
|
|
|
: QObject(w)
|
|
|
|
, m_workspace(w)
|
2011-07-28 11:48:57 +00:00
|
|
|
, m_enabled(false)
|
2011-07-13 16:48:56 +00:00
|
|
|
{
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
Tiling::~Tiling()
|
2010-04-25 16:43:14 +00:00
|
|
|
{
|
2011-07-13 16:48:56 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-18 14:38:55 +00:00
|
|
|
void Tiling::initShortcuts(KActionCollection* keys){
|
|
|
|
KAction *a = NULL;
|
|
|
|
#define KEY( name, key, fnSlot ) \
|
|
|
|
a = keys->addAction( name ); \
|
|
|
|
a->setText( i18n( name ) ); \
|
|
|
|
qobject_cast<KAction*>( a )->setGlobalShortcut(KShortcut(key)); \
|
|
|
|
connect(a, SIGNAL(triggered(bool)), SLOT(fnSlot));
|
|
|
|
|
|
|
|
a = keys->addAction("Group:Tiling");
|
|
|
|
a->setText(i18n("Tiling"));
|
|
|
|
KEY(I18N_NOOP("Enable/Disable Tiling"), Qt::SHIFT + Qt::ALT + Qt::Key_F11, slotToggleTiling());
|
|
|
|
KEY(I18N_NOOP("Toggle Floating"), Qt::META + Qt::Key_F, slotToggleFloating());
|
|
|
|
|
|
|
|
KEY(I18N_NOOP("Switch Focus Left") , Qt::META + Qt::Key_H, slotFocusTileLeft());
|
|
|
|
KEY(I18N_NOOP("Switch Focus Right") , Qt::META + Qt::Key_L, slotFocusTileRight());
|
|
|
|
KEY(I18N_NOOP("Switch Focus Up") , Qt::META + Qt::Key_K, slotFocusTileTop());
|
|
|
|
KEY(I18N_NOOP("Switch Focus Down") , Qt::META + Qt::Key_J, slotFocusTileBottom());
|
|
|
|
KEY(I18N_NOOP("Move Window Left") , Qt::SHIFT + Qt::META + Qt::Key_H, slotMoveTileLeft());
|
|
|
|
KEY(I18N_NOOP("Move Window Right") , Qt::SHIFT + Qt::META + Qt::Key_L, slotMoveTileRight());
|
|
|
|
KEY(I18N_NOOP("Move Window Up") , Qt::SHIFT + Qt::META + Qt::Key_K, slotMoveTileTop());
|
|
|
|
KEY(I18N_NOOP("Move Window Down") , Qt::SHIFT + Qt::META + Qt::Key_J, slotMoveTileBottom());
|
|
|
|
KEY(I18N_NOOP("Next Layout"), Qt::META + Qt::Key_PageDown, slotNextTileLayout());
|
|
|
|
KEY(I18N_NOOP("Previous Layout"), Qt::META + Qt::Key_PageUp, slotPreviousTileLayout());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
bool Tiling::isEnabled() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
return m_enabled;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
void Tiling::setEnabled(bool tiling)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (isEnabled() == tiling) return;
|
2010-09-12 06:06:23 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_enabled = tiling;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-09-12 06:06:23 +00:00
|
|
|
KSharedConfig::Ptr _config = KGlobal::config();
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup config(_config, "Windows");
|
2011-07-28 11:48:57 +00:00
|
|
|
config.writeEntry("TilingOn", m_enabled);
|
2010-09-12 06:06:23 +00:00
|
|
|
config.sync();
|
2011-07-28 11:48:57 +00:00
|
|
|
options->tilingOn = m_enabled;
|
2011-01-30 14:34:42 +00:00
|
|
|
options->tilingLayout = static_cast<TilingLayoutFactory::Layouts>(config.readEntry("TilingDefaultLayout", 0));
|
|
|
|
options->tilingRaisePolicy = config.readEntry("TilingRaisePolicy", 0);
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_enabled) {
|
2011-07-15 19:52:19 +00:00
|
|
|
connect(m_workspace, SIGNAL(clientAdded(KWin::Client*)), this, SLOT(createTile(KWin::Client*)));
|
|
|
|
connect(m_workspace, SIGNAL(clientAdded(KWin::Client*)), this, SLOT(slotResizeTilingLayouts()));
|
|
|
|
connect(m_workspace, SIGNAL(numberDesktopsChanged(int)), this, SLOT(slotResizeTilingLayouts()));
|
|
|
|
connect(m_workspace, SIGNAL(clientRemoved(KWin::Client*)), this, SLOT(removeTile(KWin::Client*)));
|
2011-07-19 10:38:49 +00:00
|
|
|
connect(m_workspace, SIGNAL(clientActivated(KWin::Client*)), this, SLOT(notifyTilingWindowActivated(KWin::Client*)));
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts.resize(Workspace::self()->numberOfDesktops() + 1);
|
2011-07-13 16:48:56 +00:00
|
|
|
foreach (Client * c, Workspace::self()->stackingOrder()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
createTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-07-15 19:52:19 +00:00
|
|
|
disconnect(m_workspace, SIGNAL(clientAdded(KWin::Client*)));
|
|
|
|
disconnect(m_workspace, SIGNAL(numberDesktopsChanged(int)));
|
|
|
|
disconnect(m_workspace, SIGNAL(clientRemoved(KWin::Client*)));
|
2011-07-28 11:48:57 +00:00
|
|
|
qDeleteAll(m_tilingLayouts);
|
|
|
|
m_tilingLayouts.clear();
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotToggleTiling()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (isEnabled()) {
|
|
|
|
setEnabled(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
QString message = i18n("Tiling Disabled");
|
|
|
|
KNotification::event("tilingdisabled", message, QPixmap(), NULL, KNotification::CloseOnTimeout, KComponentData("kwin"));
|
|
|
|
} else {
|
2011-07-28 11:48:57 +00:00
|
|
|
setEnabled(true);
|
2011-01-30 14:34:42 +00:00
|
|
|
QString message = i18n("Tiling Enabled");
|
|
|
|
KNotification::event("tilingenabled", message, QPixmap(), NULL, KNotification::CloseOnTimeout, KComponentData("kwin"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::createTile(Client* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (c == NULL)
|
2010-05-05 11:46:19 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
if (c->desktop() < 0 || c->desktop() >= m_tilingLayouts.size()) return;
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
kDebug(1212) << "Now tiling " << c->caption();
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!isEnabled() || !tileable(c))
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
Tile *t = new Tile(c, Workspace::self()->clientArea(PlacementArea, c));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!tileable(c)) {
|
2010-04-25 16:43:14 +00:00
|
|
|
kDebug(1212) << c->caption() << "is not tileable";
|
|
|
|
t->floatTile();
|
|
|
|
}
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!m_tilingLayouts.value(c->desktop())) {
|
|
|
|
m_tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, m_workspace);
|
|
|
|
m_tilingLayouts[c->desktop()]->setParent(this);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[c->desktop()]->addTile(t);
|
|
|
|
m_tilingLayouts[c->desktop()]->commit();
|
2011-07-19 10:21:35 +00:00
|
|
|
// if tiling is activated, connect to Client's signals and react with rearrangement when (un)minimizing
|
|
|
|
connect(c, SIGNAL(clientMinimized(KWin::Client*,bool)), this, SLOT(notifyTilingWindowMinimizeToggled(KWin::Client*)));
|
|
|
|
connect(c, SIGNAL(clientUnminimized(KWin::Client*,bool)), this, SLOT(notifyTilingWindowMinimizeToggled(KWin::Client*)));
|
2012-01-21 09:51:22 +00:00
|
|
|
connect(c, SIGNAL(clientUnminimized(KWin::Client*,bool)), this, SLOT(updateAllTiles()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::removeTile(Client *c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!m_tilingLayouts.value(c->desktop())) {
|
2011-07-15 19:52:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts[ c->desktop()])
|
|
|
|
m_tilingLayouts[ c->desktop()]->removeTile(c);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
bool Tiling::tileable(Client* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-06-14 15:17:17 +00:00
|
|
|
kDebug(1212) << c->caption();
|
2011-01-30 14:34:42 +00:00
|
|
|
KWindowInfo info = KWindowSystem::windowInfo(c->window(), -1U, NET::WM2WindowClass);
|
|
|
|
kDebug(1212) << "WINDOW CLASS IS " << info.windowClassClass();
|
|
|
|
if (info.windowClassClass() == "Plasma-desktop") {
|
2010-04-25 16:43:14 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-14 15:17:17 +00:00
|
|
|
// TODO: if application specific settings
|
|
|
|
// to ignore, put them here
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!c->isNormalWindow()) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-05-05 12:29:35 +00:00
|
|
|
// 0 means tile it, if we get 1 (floating), don't tile
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->rules()->checkTilingOption(0) == 1) {
|
2010-05-05 12:29:35 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-05-05 12:29:35 +00:00
|
|
|
|
2010-06-14 15:17:17 +00:00
|
|
|
kDebug() << "Tiling" << c;
|
2010-04-25 16:43:14 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::belowCursor()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-09-10 07:57:37 +00:00
|
|
|
// TODO ... "WHAT?" remove? What's a parameterless void function supposed to do?
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
Tile* Tiling::getNiceTile() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!isEnabled()) return NULL;
|
2011-09-10 07:57:37 +00:00
|
|
|
if (!m_workspace->activeClient()) return NULL;
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!m_tilingLayouts.value(m_workspace->activeClient()->desktop())) return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
return m_tilingLayouts[ m_workspace->activeClient()->desktop()]->findTile(m_workspace->activeClient());
|
2011-09-10 07:57:37 +00:00
|
|
|
// TODO ... WHAT?
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::updateAllTiles()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
foreach (TilingLayout * t, m_tilingLayouts) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t) continue;
|
2010-04-25 16:43:14 +00:00
|
|
|
t->commit();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Resize the neighbouring clients to close any gaps
|
|
|
|
*/
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowResize(Client *c, const QRect &moveResizeGeom, const QRect &orig)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop()) == NULL)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ c->desktop()]->clientResized(c, moveResizeGeom, orig);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, const QRect &orig)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop()) == NULL) {
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ c->desktop()]->clientMoved(c, moveResizeGeom, orig);
|
2011-01-30 14:34:42 +00:00
|
|
|
updateAllTiles();
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (canceled)
|
|
|
|
notifyTilingWindowResize(c, orig, moveResizeGeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
notifyTilingWindowResize(c, moveResizeGeom, orig);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (canceled)
|
|
|
|
notifyTilingWindowMove(c, orig, moveResizeGeom);
|
2010-04-25 16:43:14 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
notifyTilingWindowMove(c, moveResizeGeom, orig);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowDesktopChanged(Client *c, int old_desktop)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-13 16:48:56 +00:00
|
|
|
if (c->desktop() < 1 || c->desktop() > m_workspace->numberOfDesktops())
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(old_desktop)) {
|
|
|
|
Tile *t = m_tilingLayouts[ old_desktop ]->findTile(c);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2010-04-25 16:43:14 +00:00
|
|
|
// TODO: copied from createTile(), move this into separate method?
|
2011-07-28 11:48:57 +00:00
|
|
|
if (!m_tilingLayouts.value(c->desktop())) {
|
|
|
|
m_tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, m_workspace);
|
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 (t)
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ c->desktop()]->addTile(t);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ old_desktop ]->removeTile(c);
|
|
|
|
m_tilingLayouts[ old_desktop ]->commit();
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
/*
|
2010-05-09 06:15:40 +00:00
|
|
|
* Implements the 3 raising modes in Window Behaviour -> Advanced
|
2010-04-25 16:43:14 +00:00
|
|
|
*/
|
2011-07-19 10:38:49 +00:00
|
|
|
void Tiling::notifyTilingWindowActivated(KWin::Client *c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (c == NULL)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (options->tilingRaisePolicy == 1) // individual raise/lowers
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop())) {
|
|
|
|
QList<Tile *> tiles = m_tilingLayouts[ c->desktop()]->tiles();
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
StackingUpdatesBlocker blocker(m_workspace);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
Tile *tile_to_raise = m_tilingLayouts[ c->desktop()]->findTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!tile_to_raise) {
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
kDebug(1212) << "FOUND TILE";
|
|
|
|
bool raise_floating = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (options->tilingRaisePolicy == 2) // floating always on top
|
2010-04-25 16:43:14 +00:00
|
|
|
raise_floating = true;
|
|
|
|
else
|
|
|
|
raise_floating = tile_to_raise->floating();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * t, tiles) {
|
|
|
|
if (t->floating() == raise_floating && t != tile_to_raise)
|
2011-07-13 16:48:56 +00:00
|
|
|
m_workspace->raiseClient(t->client());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
// raise the current tile last so that it ends up on top
|
|
|
|
// but only if it supposed to be raised, required to support tilingRaisePolicy
|
|
|
|
kDebug(1212) << "Raise floating? " << raise_floating << "to raise is floating?" << tile_to_raise->floating();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tile_to_raise->floating() == raise_floating)
|
2011-07-13 16:48:56 +00:00
|
|
|
m_workspace->raiseClient(tile_to_raise->client());
|
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-07-19 10:21:35 +00:00
|
|
|
void Tiling::notifyTilingWindowMinimizeToggled(KWin::Client* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop())) {
|
|
|
|
m_tilingLayouts[ c->desktop()]->clientMinimizeToggled(c);
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::notifyTilingWindowMaximized(Client *c, Options::WindowOperation op)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop())) {
|
|
|
|
Tile *t = m_tilingLayouts[ c->desktop()]->findTile(c);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t) {
|
|
|
|
createTile(c);
|
2011-07-28 11:48:57 +00:00
|
|
|
t = m_tilingLayouts[ c->desktop()]->findTile(c);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// if still no tile, it couldn't be tiled
|
|
|
|
// so ignore it
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t)
|
2010-04-25 16:43:14 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// if window IS tiled and a maximize
|
|
|
|
// is attempted, make the window float.
|
|
|
|
// That is all we do since that can
|
|
|
|
// mess up the layout.
|
|
|
|
// In all other cases, don't do
|
|
|
|
// anything, let the user manage toggling
|
|
|
|
// using Meta+F
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t->floating()
|
|
|
|
&& (op == Options::MaximizeOp
|
|
|
|
|| op == Options::HMaximizeOp
|
|
|
|
|| op == Options::VMaximizeOp)) {
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ c->desktop()]->toggleFloatTile(c);
|
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
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
Tile* Tiling::findAdjacentTile(Tile *ref, int d)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
QRect reference = ref->geometry();
|
|
|
|
QPoint origin = reference.center();
|
|
|
|
|
|
|
|
Tile *closest = NULL;
|
|
|
|
int minDist = -1;
|
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
QList<Tile *> tiles = m_tilingLayouts[ ref->client()->desktop()]->tiles();
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * t, tiles) {
|
|
|
|
if (t->client() == ref->client() || t->ignoreGeometry())
|
2010-04-25 16:43:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool consider = false;
|
|
|
|
|
|
|
|
QRect other = t->geometry();
|
|
|
|
QPoint otherCenter = other.center();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(d) {
|
|
|
|
case Tile::Top:
|
|
|
|
consider = otherCenter.y() < origin.y()
|
|
|
|
&& other.bottom() < reference.top();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tile::Right:
|
|
|
|
consider = otherCenter.x() > origin.x()
|
|
|
|
&& other.left() > reference.right();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tile::Bottom:
|
|
|
|
consider = otherCenter.y() > origin.y()
|
|
|
|
&& other.top() > reference.bottom();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Tile::Left:
|
|
|
|
consider = otherCenter.x() < origin.x()
|
|
|
|
&& other.right() < reference.left();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (consider) {
|
|
|
|
int dist = (otherCenter - origin).manhattanLength();
|
|
|
|
if (minDist > dist || minDist < 0) {
|
|
|
|
minDist = dist;
|
|
|
|
closest = t;
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return closest;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::focusTile(int d)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *t = getNiceTile();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t) {
|
|
|
|
Tile *adj = findAdjacentTile(t, d);
|
|
|
|
if (adj)
|
2011-07-13 16:48:56 +00:00
|
|
|
m_workspace->activateClient(adj->client());
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::moveTile(int d)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *t = getNiceTile();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (t) {
|
|
|
|
Tile* adj = findAdjacentTile(t, d);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[ t->client()->desktop()]->swapTiles(t, adj);
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotFocusTileLeft()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
focusTile(Tile::Left);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotFocusTileRight()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
focusTile(Tile::Right);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotFocusTileTop()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
focusTile(Tile::Top);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotFocusTileBottom()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
focusTile(Tile::Bottom);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotMoveTileLeft()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
moveTile(Tile::Left);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotMoveTileRight()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
moveTile(Tile::Right);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotMoveTileTop()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
moveTile(Tile::Top);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotMoveTileBottom()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
moveTile(Tile::Bottom);
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotToggleFloating()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-13 16:48:56 +00:00
|
|
|
Client *c = m_workspace->activeClient();
|
2011-09-10 07:57:37 +00:00
|
|
|
if (!c)
|
|
|
|
return;
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop())) {
|
|
|
|
m_tilingLayouts[ c->desktop()]->toggleFloatTile(c);
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotNextTileLayout()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(m_workspace->currentDesktop())) {
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts.replace(m_workspace->currentDesktop(), TilingLayoutFactory::nextLayout(m_tilingLayouts[m_workspace->currentDesktop()]));
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[m_workspace->currentDesktop()]->commit();
|
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-07-13 16:48:56 +00:00
|
|
|
void Tiling::slotPreviousTileLayout()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(m_workspace->currentDesktop())) {
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts.replace(m_workspace->currentDesktop(), TilingLayoutFactory::previousLayout(m_tilingLayouts[m_workspace->currentDesktop()]));
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts[m_workspace->currentDesktop()]->commit();
|
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-07-13 16:48:56 +00:00
|
|
|
KDecorationDefines::Position Tiling::supportedTilingResizeMode(Client *c, KDecorationDefines::Position currentMode)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
if (m_tilingLayouts.value(c->desktop())) {
|
|
|
|
return m_tilingLayouts[c->desktop()]->resizeMode(c, currentMode);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return currentMode;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
void Tiling::dumpTiles() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
foreach (TilingLayout * t, m_tilingLayouts) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!t) {
|
2010-04-25 16:43:14 +00:00
|
|
|
kDebug(1212) << "EMPTY DESKTOP";
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-28 11:48:57 +00:00
|
|
|
kDebug(1212) << "Desktop" << m_tilingLayouts.indexOf(t);
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * tile, t->tiles()) {
|
|
|
|
tile->dumpTile("--");
|
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-07-28 11:48:57 +00:00
|
|
|
const QVector< TilingLayout* >& Tiling::tilingLayouts() const
|
2011-07-13 16:48:56 +00:00
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
return m_tilingLayouts;
|
2011-07-13 16:48:56 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 19:52:19 +00:00
|
|
|
void Tiling::slotResizeTilingLayouts()
|
|
|
|
{
|
2011-07-28 11:48:57 +00:00
|
|
|
m_tilingLayouts.resize(m_workspace->numberOfDesktops() + 1);
|
2011-07-15 19:52:19 +00:00
|
|
|
}
|
|
|
|
|
2011-07-13 16:48:56 +00:00
|
|
|
}
|