1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
#include "tilinglayoutfactory.h"
28
#include "notifications.h"
32
#include "tilinglayouts/spiral/spiral.h"
33
#include "tilinglayouts/columns/columns.h"
34
#include "tilinglayouts/floating/floating.h"
36
// w is the workspace pointer
37
#define ADD_LAYOUT( lay, ctxt_name ) \
39
kDebug(1212) << #lay;\
40
layout = new lay( w );\
41
layout->setLayoutType( lay##Layout );\
42
Notify::raise( Notify::TilingLayoutChanged, \
43
i18n( "Layout changed to %1", i18nc( ctxt_name ) ) ); \
49
TilingLayout* TilingLayoutFactory::createLayout(int type, Workspace *w)
51
Q_ASSERT(type != FirstLayout && type != LastLayout);
54
/* For new layouts, make a case entry here */
56
case DefaultLayout: // NOTE: fall through makes first layout default
57
layout = createLayout(indexToLayoutIndex(options->tilingLayout), w);
60
ADD_LAYOUT(Spiral, I18N_NOOP2_NOSTRIP("Spiral tiling layout", "Spiral"));
61
ADD_LAYOUT(Columns, I18N_NOOP2_NOSTRIP("Two-column horizontal tiling layout", "Columns"));
62
ADD_LAYOUT(Floating, I18N_NOOP2_NOSTRIP("Floating layout, windows aren't tiled at all", "Floating"));
65
kDebug(1212) << "INVALID LAYOUT!";
71
// if next, goes next, otherwise previous
72
TilingLayout* TilingLayoutFactory::cycleLayout(TilingLayout *curr, bool next)
74
int type = curr->layoutType();
79
if (type >= LastLayout)
80
type = FirstLayout + 1;
84
if (type <= FirstLayout)
85
type = LastLayout - 1;
88
QList<Tile *> tiles = curr->tiles();
90
TilingLayout *l = createLayout(type, curr->workspace());
92
foreach (Tile * t, tiles) {
93
curr->removeTileNoArrange(t);
96
if (tiles.length() == 0)
99
// so that we don't rearrange after every call
100
Tile *last = tiles.takeLast();
101
foreach (Tile * t, tiles) {
102
l->addTileNoArrange(t);
110
* Returns the appropriate layout enum item
111
* Meant to be used with a combo box.
112
* This function handles the issues of DefaultL and First and Last layouts
114
int TilingLayoutFactory::indexToLayoutIndex(int index)
116
int layout = DefaultLayout + index + 1;
117
if (layout >= LastLayout)
118
layout = DefaultLayout + 1;
119
if (layout <= FirstLayout)
120
layout = LastLayout - 1;