1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.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 "workspace.h"
28
void Workspace::updateDesktopLayout()
30
// TODO: Is there a sane way to avoid overriding the existing grid?
31
int width = rootInfo->desktopLayoutColumnsRows().width();
32
int height = rootInfo->desktopLayoutColumnsRows().height();
33
if (width == 0 && height == 0) // Not given, set default layout
36
rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical,
37
width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now.
41
void Workspace::setNETDesktopLayout(Qt::Orientation orientation, int width, int height,
44
Q_UNUSED(startingCorner); // Not really worth implementing right now.
46
// Calculate valid grid size
47
assert(width > 0 || height > 0);
48
if ((width <= 0) && (height > 0))
49
width = (desktopCount_ + height - 1) / height;
50
else if ((height <= 0) && (width > 0))
51
height = (desktopCount_ + width - 1) / width;
52
while (width * height < desktopCount_) {
53
if (orientation == Qt::Horizontal)
59
// Set private variables
60
delete[] desktopGrid_;
61
desktopGridSize_ = QSize(width, height);
62
int size = width * height;
63
desktopGrid_ = new int[size];
67
if (orientation == Qt::Horizontal)
68
for (int y = 0; y < height; y++)
69
for (int x = 0; x < width; x++)
70
desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
72
for (int x = 0; x < width; x++)
73
for (int y = 0; y < height; y++)
74
desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
77
QPoint Workspace::desktopGridCoords(int id) const
79
for (int y = 0; y < desktopGridSize_.height(); y++)
80
for (int x = 0; x < desktopGridSize_.width(); x++)
81
if (desktopGrid_[y * desktopGridSize_.width() + x] == id)
83
return QPoint(-1, -1);
86
QPoint Workspace::desktopCoords(int id) const
88
QPoint coords = desktopGridCoords(id);
90
return QPoint(-1, -1);
91
return QPoint(coords.x() * displayWidth(), coords.y() * displayHeight());
94
int Workspace::desktopAbove(int id, bool wrap) const
97
id = currentDesktop();
98
QPoint coords = desktopGridCoords(id);
99
assert(coords.x() >= 0);
102
if (coords.y() < 0) {
104
coords.setY(desktopGridSize_.height() - 1);
106
return id; // Already at the top-most desktop
108
int desktop = desktopAtCoords(coords);
114
int Workspace::desktopToRight(int id, bool wrap) const
117
id = currentDesktop();
118
QPoint coords = desktopGridCoords(id);
119
assert(coords.x() >= 0);
122
if (coords.x() >= desktopGridSize_.width()) {
126
return id; // Already at the right-most desktop
128
int desktop = desktopAtCoords(coords);
134
int Workspace::desktopBelow(int id, bool wrap) const
137
id = currentDesktop();
138
QPoint coords = desktopGridCoords(id);
139
assert(coords.x() >= 0);
142
if (coords.y() >= desktopGridSize_.height()) {
146
return id; // Already at the bottom-most desktop
148
int desktop = desktopAtCoords(coords);
154
int Workspace::desktopToLeft(int id, bool wrap) const
157
id = currentDesktop();
158
QPoint coords = desktopGridCoords(id);
159
assert(coords.x() >= 0);
162
if (coords.x() < 0) {
164
coords.setX(desktopGridSize_.width() - 1);
166
return id; // Already at the left-most desktop
168
int desktop = desktopAtCoords(coords);