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 "tilinglayoutfactory.h"
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QList>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
2010-05-05 11:24:10 +00:00
|
|
|
#include "notifications.h"
|
2011-07-28 11:36:25 +00:00
|
|
|
#include "tiling/tile.h"
|
2010-04-25 16:43:14 +00:00
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#include "tilinglayouts/spiral/spiral.h"
|
|
|
|
#include "tilinglayouts/columns/columns.h"
|
|
|
|
#include "tilinglayouts/floating/floating.h"
|
|
|
|
|
|
|
|
// w is the workspace pointer
|
2010-07-14 05:09:01 +00:00
|
|
|
#define ADD_LAYOUT( lay, ctxt_name ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
case lay##Layout:\
|
|
|
|
kDebug(1212) << #lay;\
|
|
|
|
layout = new lay( w );\
|
|
|
|
layout->setLayoutType( lay##Layout );\
|
|
|
|
Notify::raise( Notify::TilingLayoutChanged, \
|
|
|
|
i18n( "Layout changed to %1", i18nc( ctxt_name ) ) ); \
|
|
|
|
break
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
TilingLayout* TilingLayoutFactory::createLayout(int type, Workspace *w)
|
|
|
|
{
|
|
|
|
Q_ASSERT(type != FirstLayout && type != LastLayout);
|
2010-04-25 16:43:14 +00:00
|
|
|
TilingLayout *layout;
|
|
|
|
|
|
|
|
/* For new layouts, make a case entry here */
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(type) {
|
|
|
|
case DefaultLayout: // NOTE: fall through makes first layout default
|
2012-02-20 09:25:13 +00:00
|
|
|
layout = createLayout(indexToLayoutIndex(options->tilingLayout()), w);
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
ADD_LAYOUT(Spiral, I18N_NOOP2_NOSTRIP("Spiral tiling layout", "Spiral"));
|
|
|
|
ADD_LAYOUT(Columns, I18N_NOOP2_NOSTRIP("Two-column horizontal tiling layout", "Columns"));
|
|
|
|
ADD_LAYOUT(Floating, I18N_NOOP2_NOSTRIP("Floating layout, windows aren't tiled at all", "Floating"));
|
|
|
|
|
|
|
|
default:
|
|
|
|
kDebug(1212) << "INVALID LAYOUT!";
|
|
|
|
return NULL;
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return layout;
|
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
// if next, goes next, otherwise previous
|
2011-01-30 14:34:42 +00:00
|
|
|
TilingLayout* TilingLayoutFactory::cycleLayout(TilingLayout *curr, bool next)
|
|
|
|
{
|
2010-04-25 16:43:14 +00:00
|
|
|
int type = curr->layoutType();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (next) {
|
2010-04-25 16:43:14 +00:00
|
|
|
type++;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (type >= LastLayout)
|
2010-05-05 11:43:26 +00:00
|
|
|
type = FirstLayout + 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-04-25 16:43:14 +00:00
|
|
|
type--;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (type <= FirstLayout)
|
2010-05-05 11:43:26 +00:00
|
|
|
type = LastLayout - 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2010-05-05 11:43:26 +00:00
|
|
|
QList<Tile *> tiles = curr->tiles();
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
TilingLayout *l = createLayout(type, curr->workspace());
|
2010-04-25 16:43:14 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * t, tiles) {
|
|
|
|
curr->removeTileNoArrange(t);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tiles.length() == 0)
|
|
|
|
return l;
|
2010-05-05 13:51:00 +00:00
|
|
|
|
|
|
|
// so that we don't rearrange after every call
|
2010-04-25 16:43:14 +00:00
|
|
|
Tile *last = tiles.takeLast();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (Tile * t, tiles) {
|
|
|
|
l->addTileNoArrange(t);
|
2010-04-25 16:43:14 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
l->addTile(last);
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
return l;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appropriate layout enum item
|
|
|
|
* Meant to be used with a combo box.
|
|
|
|
* This function handles the issues of DefaultL and First and Last layouts
|
|
|
|
*/
|
2011-01-30 14:34:42 +00:00
|
|
|
int TilingLayoutFactory::indexToLayoutIndex(int index)
|
|
|
|
{
|
2010-05-05 11:43:26 +00:00
|
|
|
int layout = DefaultLayout + index + 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (layout >= LastLayout)
|
2010-05-05 11:43:26 +00:00
|
|
|
layout = DefaultLayout + 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (layout <= FirstLayout)
|
2010-05-05 11:43:26 +00:00
|
|
|
layout = LastLayout - 1;
|
2010-04-25 16:43:14 +00:00
|
|
|
return layout;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-04-25 16:43:14 +00:00
|
|
|
} // end namespace
|