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"
|
|
|
|
|
|
|
|
#include "assert.h"
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
void Workspace::updateDesktopLayout()
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
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();
|
|
|
|
if( width == 0 && height == 0 ) // Not given, set default layout
|
|
|
|
height = 2;
|
|
|
|
// TODO: Make sure desktopCount_ <= width * height
|
|
|
|
setNETDesktopLayout(
|
|
|
|
rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical,
|
|
|
|
width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now.
|
|
|
|
);
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
void Workspace::setNETDesktopLayout( Qt::Orientation orientation, int width, int height,
|
2009-02-14 09:46:12 +00:00
|
|
|
int startingCorner )
|
|
|
|
{
|
|
|
|
Q_UNUSED( startingCorner ); // Not really worth implementing right now.
|
|
|
|
|
|
|
|
// Calculate valid grid size
|
2009-02-14 19:36:40 +00:00
|
|
|
assert( width > 0 || height > 0 );
|
2009-02-14 09:46:12 +00:00
|
|
|
if(( width <= 0 ) && ( height > 0 ))
|
2009-02-14 15:40:52 +00:00
|
|
|
width = ( desktopCount_ + height - 1 ) / height;
|
2009-02-14 09:46:12 +00:00
|
|
|
else if(( height <= 0 ) && ( width > 0 ))
|
2009-02-14 15:40:52 +00:00
|
|
|
height = ( desktopCount_ + width - 1 ) / width;
|
2009-02-14 09:46:12 +00:00
|
|
|
|
|
|
|
// Set private variables
|
2009-02-14 15:40:52 +00:00
|
|
|
delete[] desktopGrid_;
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
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);
|
2009-02-14 09:46:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
QPoint Workspace::desktopGridCoords( int id ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
2009-02-14 15:40:52 +00:00
|
|
|
for( int y = 0; y < desktopGridSize_.height(); y++ )
|
|
|
|
for( int x = 0; x < desktopGridSize_.width(); x++ )
|
|
|
|
if( desktopGrid_[y * desktopGridSize_.height() + x] == id )
|
2009-02-14 09:46:12 +00:00
|
|
|
return QPoint( x, y );
|
|
|
|
return QPoint( -1, -1 );
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
QPoint Workspace::desktopCoords( int id ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
QPoint coords = desktopGridCoords( id );
|
|
|
|
if( coords.x() == -1 )
|
|
|
|
return QPoint( -1, -1 );
|
|
|
|
return QPoint( coords.x() * displayWidth(), coords.y() * displayHeight() );
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
int Workspace::desktopAbove( int id, bool wrap ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( id == 0 )
|
|
|
|
id = currentDesktop();
|
|
|
|
QPoint coords = desktopGridCoords( id );
|
|
|
|
assert( coords.x() >= 0 );
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
coords.ry()--;
|
|
|
|
if( coords.y() < 0 )
|
|
|
|
{
|
|
|
|
if( wrap )
|
2009-02-14 15:40:52 +00:00
|
|
|
coords.setY( desktopGridSize_.height() - 1 );
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the top-most desktop
|
|
|
|
}
|
|
|
|
int desktop = desktopAtCoords( coords );
|
|
|
|
if( desktop > 0 )
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
int Workspace::desktopToRight( int id, bool wrap ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( id == 0 )
|
|
|
|
id = currentDesktop();
|
|
|
|
QPoint coords = desktopGridCoords( id );
|
|
|
|
assert( coords.x() >= 0 );
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
coords.rx()++;
|
2009-02-14 15:40:52 +00:00
|
|
|
if( coords.x() >= desktopGridSize_.width() )
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( wrap )
|
|
|
|
coords.setX( 0 );
|
|
|
|
else
|
|
|
|
return id; // Already at the right-most desktop
|
|
|
|
}
|
|
|
|
int desktop = desktopAtCoords( coords );
|
|
|
|
if( desktop > 0 )
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
int Workspace::desktopBelow( int id, bool wrap ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( id == 0 )
|
|
|
|
id = currentDesktop();
|
|
|
|
QPoint coords = desktopGridCoords( id );
|
|
|
|
assert( coords.x() >= 0 );
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
coords.ry()++;
|
2009-02-14 15:40:52 +00:00
|
|
|
if( coords.y() >= desktopGridSize_.height() )
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( wrap )
|
|
|
|
coords.setY( 0 );
|
|
|
|
else
|
|
|
|
return id; // Already at the bottom-most desktop
|
|
|
|
}
|
|
|
|
int desktop = desktopAtCoords( coords );
|
|
|
|
if( desktop > 0 )
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
int Workspace::desktopToLeft( int id, bool wrap ) const
|
2009-02-14 09:46:12 +00:00
|
|
|
{
|
|
|
|
if( id == 0 )
|
|
|
|
id = currentDesktop();
|
|
|
|
QPoint coords = desktopGridCoords( id );
|
|
|
|
assert( coords.x() >= 0 );
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
coords.rx()--;
|
|
|
|
if( coords.x() < 0 )
|
|
|
|
{
|
|
|
|
if( wrap )
|
2009-02-14 15:40:52 +00:00
|
|
|
coords.setX( desktopGridSize_.width() - 1 );
|
2009-02-14 09:46:12 +00:00
|
|
|
else
|
|
|
|
return id; // Already at the left-most desktop
|
|
|
|
}
|
|
|
|
int desktop = desktopAtCoords( coords );
|
|
|
|
if( desktop > 0 )
|
|
|
|
return desktop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
int Workspace::addDesktop( QPoint coords )
|
2009-02-14 09:46:12 +00:00
|
|
|
{ // TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:40:52 +00:00
|
|
|
void Workspace::deleteDesktop( int id )
|
2009-02-14 09:46:12 +00:00
|
|
|
{ // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|