2009-02-14 09:46:12 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
#include "workspace.h"
|
2012-05-03 17:48:20 +00:00
|
|
|
#include "options.h"
|
2009-02-14 15:40:52 +00:00
|
|
|
|
|
|
|
#include "assert.h"
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
void Workspace::updateDesktopLayout()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-05-03 17:48:20 +00:00
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
|
|
|
if (options->electricBorders() == Options::ElectricAlways) {
|
|
|
|
m_screenEdge.reserveDesktopSwitching(false, m_screenEdgeOrientation);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-14 15:40:52 +00:00
|
|
|
// TODO: Is there a sane way to avoid overriding the existing grid?
|
|
|
|
int width = rootInfo->desktopLayoutColumnsRows().width();
|
|
|
|
int height = rootInfo->desktopLayoutColumnsRows().height();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (width == 0 && height == 0) // Not given, set default layout
|
2009-02-14 15:40:52 +00:00
|
|
|
height = 2;
|
|
|
|
setNETDesktopLayout(
|
|
|
|
rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical,
|
|
|
|
width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now.
|
2011-01-30 14:34:42 +00:00
|
|
|
);
|
2012-05-03 17:48:20 +00:00
|
|
|
|
|
|
|
#ifdef KWIN_BUILD_SCREENEDGES
|
|
|
|
m_screenEdgeOrientation = 0;
|
|
|
|
if (width > 1)
|
|
|
|
m_screenEdgeOrientation |= Qt::Horizontal;
|
|
|
|
if (height > 1)
|
|
|
|
m_screenEdgeOrientation |= Qt::Vertical;
|
|
|
|
if (options->electricBorders() == Options::ElectricAlways) {
|
|
|
|
m_screenEdge.reserveDesktopSwitching(true, m_screenEdgeOrientation);
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Workspace::setNETDesktopLayout(Qt::Orientation orientation, int width, int height,
|
|
|
|
int startingCorner)
|
|
|
|
{
|
|
|
|
Q_UNUSED(startingCorner); // Not really worth implementing right now.
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
// Calculate valid grid size
|
2011-01-30 14:34:42 +00:00
|
|
|
assert(width > 0 || height > 0);
|
|
|
|
if ((width <= 0) && (height > 0))
|
|
|
|
width = (desktopCount_ + height - 1) / height;
|
|
|
|
else if ((height <= 0) && (width > 0))
|
|
|
|
height = (desktopCount_ + width - 1) / width;
|
|
|
|
while (width * height < desktopCount_) {
|
|
|
|
if (orientation == Qt::Horizontal)
|
2010-03-28 09:02:10 +00:00
|
|
|
++width;
|
|
|
|
else
|
|
|
|
++height;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
// Set private variables
|
2009-02-14 15:40:52 +00:00
|
|
|
delete[] desktopGrid_;
|
2011-01-30 14:34:42 +00:00
|
|
|
desktopGridSize_ = QSize(width, height);
|
2009-02-14 14:49:46 +00:00
|
|
|
int size = width * height;
|
2009-02-14 15:40:52 +00:00
|
|
|
desktopGrid_ = new int[size];
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
// Populate grid
|
|
|
|
int desktop = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
for (int y = 0; y < height; y++)
|
|
|
|
for (int x = 0; x < width; x++)
|
2009-02-14 15:40:52 +00:00
|
|
|
desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
for (int y = 0; y < height; y++)
|
2009-02-14 15:40:52 +00:00
|
|
|
desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QPoint Workspace::desktopGridCoords(int id) const
|
|
|
|
{
|
|
|
|
for (int y = 0; y < desktopGridSize_.height(); y++)
|
|
|
|
for (int x = 0; x < desktopGridSize_.width(); x++)
|
|
|
|
if (desktopGrid_[y * desktopGridSize_.width() + x] == id)
|
|
|
|
return QPoint(x, y);
|
|
|
|
return QPoint(-1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Workspace::desktopCoords(int id) const
|
|
|
|
{
|
|
|
|
QPoint coords = desktopGridCoords(id);
|
|
|
|
if (coords.x() == -1)
|
|
|
|
return QPoint(-1, -1);
|
|
|
|
return QPoint(coords.x() * displayWidth(), coords.y() * displayHeight());
|
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int Workspace::desktopAbove(int id, bool wrap) const
|
|
|
|
{
|
|
|
|
if (id == 0)
|
2009-02-14 09:46:12 +00:00
|
|
|
id = currentDesktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
QPoint coords = desktopGridCoords(id);
|
|
|
|
assert(coords.x() >= 0);
|
|
|
|
for (;;) {
|
2009-02-14 09:46:12 +00:00
|
|
|
coords.ry()--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (coords.y() < 0) {
|
|
|
|
if (wrap)
|
|
|
|
coords.setY(desktopGridSize_.height() - 1);
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the top-most desktop
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
int desktop = desktopAtCoords(coords);
|
|
|
|
if (desktop > 0)
|
|
|
|
return desktop;
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int Workspace::desktopToRight(int id, bool wrap) const
|
|
|
|
{
|
|
|
|
if (id == 0)
|
2009-02-14 09:46:12 +00:00
|
|
|
id = currentDesktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
QPoint coords = desktopGridCoords(id);
|
|
|
|
assert(coords.x() >= 0);
|
|
|
|
for (;;) {
|
2009-02-14 09:46:12 +00:00
|
|
|
coords.rx()++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (coords.x() >= desktopGridSize_.width()) {
|
|
|
|
if (wrap)
|
|
|
|
coords.setX(0);
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the right-most desktop
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
int desktop = desktopAtCoords(coords);
|
|
|
|
if (desktop > 0)
|
|
|
|
return desktop;
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int Workspace::desktopBelow(int id, bool wrap) const
|
|
|
|
{
|
|
|
|
if (id == 0)
|
2009-02-14 09:46:12 +00:00
|
|
|
id = currentDesktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
QPoint coords = desktopGridCoords(id);
|
|
|
|
assert(coords.x() >= 0);
|
|
|
|
for (;;) {
|
2009-02-14 09:46:12 +00:00
|
|
|
coords.ry()++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (coords.y() >= desktopGridSize_.height()) {
|
|
|
|
if (wrap)
|
|
|
|
coords.setY(0);
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the bottom-most desktop
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
int desktop = desktopAtCoords(coords);
|
|
|
|
if (desktop > 0)
|
|
|
|
return desktop;
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
int Workspace::desktopToLeft(int id, bool wrap) const
|
|
|
|
{
|
|
|
|
if (id == 0)
|
2009-02-14 09:46:12 +00:00
|
|
|
id = currentDesktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
QPoint coords = desktopGridCoords(id);
|
|
|
|
assert(coords.x() >= 0);
|
|
|
|
for (;;) {
|
2009-02-14 09:46:12 +00:00
|
|
|
coords.rx()--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (coords.x() < 0) {
|
|
|
|
if (wrap)
|
|
|
|
coords.setX(desktopGridSize_.width() - 1);
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the left-most desktop
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
int desktop = desktopAtCoords(coords);
|
|
|
|
if (desktop > 0)
|
|
|
|
return desktop;
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
} // namespace
|