Merge DesktopLayout class into Workspace.

svn path=/trunk/KDE/kdebase/workspace/; revision=926020
This commit is contained in:
Lucas Murray 2009-02-14 15:40:52 +00:00
parent dd28e15a1b
commit 893b0c2c71
8 changed files with 249 additions and 340 deletions

View file

@ -18,35 +18,28 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
#include "desktoplayout.h" #include "workspace.h"
#include "assert.h"
namespace KWin namespace KWin
{ {
DesktopLayout::DesktopLayout() void Workspace::updateDesktopLayout()
: m_count( 0 ) // This is an invalid state
, m_gridSize( 1, 2 ) // Default to two rows
, m_grid( new int[2] )
, m_current( 0 )
, m_dynamic( false )
{ {
m_grid[0] = 0; // TODO: Is there a sane way to avoid overriding the existing grid?
m_grid[1] = 0; 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.
);
} }
DesktopLayout::~DesktopLayout() void Workspace::setNETDesktopLayout( Qt::Orientation orientation, int width, int height,
{
delete[] m_grid;
}
void DesktopLayout::setNumberOfDesktops( int count )
{
m_count = count;
// Make sure our grid is valid. TODO: Is there a sane way to avoid overriding the existing grid?
setNETDesktopLayout( Qt::Horizontal, m_count / m_gridSize.height() + 1, m_gridSize.height(), 0 );
}
void DesktopLayout::setNETDesktopLayout( Qt::Orientation orientation, int width, int height,
int startingCorner ) int startingCorner )
{ {
Q_UNUSED( startingCorner ); // Not really worth implementing right now. Q_UNUSED( startingCorner ); // Not really worth implementing right now.
@ -54,38 +47,38 @@ void DesktopLayout::setNETDesktopLayout( Qt::Orientation orientation, int width,
// Calculate valid grid size // Calculate valid grid size
assert( width > 0 && height > 0 ); assert( width > 0 && height > 0 );
if(( width <= 0 ) && ( height > 0 )) if(( width <= 0 ) && ( height > 0 ))
width = ( m_count + height - 1 ) / height; width = ( desktopCount_ + height - 1 ) / height;
else if(( height <= 0 ) && ( width > 0 )) else if(( height <= 0 ) && ( width > 0 ))
height = ( m_count + width - 1 ) / width; height = ( desktopCount_ + width - 1 ) / width;
// Set private variables // Set private variables
delete[] m_grid; delete[] desktopGrid_;
m_gridSize = QSize( width, height ); desktopGridSize_ = QSize( width, height );
int size = width * height; int size = width * height;
m_grid = new int[size]; desktopGrid_ = new int[size];
// Populate grid // Populate grid
int desktop = 1; int desktop = 1;
if( orientation == Qt::Horizontal ) if( orientation == Qt::Horizontal )
for( int y = 0; y < height; y++ ) for( int y = 0; y < height; y++ )
for( int x = 0; x < width; x++ ) for( int x = 0; x < width; x++ )
m_grid[y * width + x] = (desktop <= m_count ? desktop++ : 0); desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
else else
for( int x = 0; x < width; x++ ) for( int x = 0; x < width; x++ )
for( int y = 0; y < height; y++ ) for( int y = 0; y < height; y++ )
m_grid[y * width + x] = (desktop <= m_count ? desktop++ : 0); desktopGrid_[y * width + x] = (desktop <= desktopCount_ ? desktop++ : 0);
} }
QPoint DesktopLayout::desktopGridCoords( int id ) const QPoint Workspace::desktopGridCoords( int id ) const
{ {
for( int y = 0; y < m_gridSize.height(); y++ ) for( int y = 0; y < desktopGridSize_.height(); y++ )
for( int x = 0; x < m_gridSize.width(); x++ ) for( int x = 0; x < desktopGridSize_.width(); x++ )
if( m_grid[y * m_gridSize.height() + x] == id ) if( desktopGrid_[y * desktopGridSize_.height() + x] == id )
return QPoint( x, y ); return QPoint( x, y );
return QPoint( -1, -1 ); return QPoint( -1, -1 );
} }
QPoint DesktopLayout::desktopCoords( int id ) const QPoint Workspace::desktopCoords( int id ) const
{ {
QPoint coords = desktopGridCoords( id ); QPoint coords = desktopGridCoords( id );
if( coords.x() == -1 ) if( coords.x() == -1 )
@ -93,7 +86,7 @@ QPoint DesktopLayout::desktopCoords( int id ) const
return QPoint( coords.x() * displayWidth(), coords.y() * displayHeight() ); return QPoint( coords.x() * displayWidth(), coords.y() * displayHeight() );
} }
int DesktopLayout::desktopAbove( int id, bool wrap ) const int Workspace::desktopAbove( int id, bool wrap ) const
{ {
if( id == 0 ) if( id == 0 )
id = currentDesktop(); id = currentDesktop();
@ -105,7 +98,7 @@ int DesktopLayout::desktopAbove( int id, bool wrap ) const
if( coords.y() < 0 ) if( coords.y() < 0 )
{ {
if( wrap ) if( wrap )
coords.setY( m_gridSize.height() - 1 ); coords.setY( desktopGridSize_.height() - 1 );
else else
return id; // Already at the top-most desktop return id; // Already at the top-most desktop
} }
@ -115,7 +108,7 @@ int DesktopLayout::desktopAbove( int id, bool wrap ) const
} }
} }
int DesktopLayout::desktopToRight( int id, bool wrap ) const int Workspace::desktopToRight( int id, bool wrap ) const
{ {
if( id == 0 ) if( id == 0 )
id = currentDesktop(); id = currentDesktop();
@ -124,7 +117,7 @@ int DesktopLayout::desktopToRight( int id, bool wrap ) const
for(;;) for(;;)
{ {
coords.rx()++; coords.rx()++;
if( coords.x() >= m_gridSize.width() ) if( coords.x() >= desktopGridSize_.width() )
{ {
if( wrap ) if( wrap )
coords.setX( 0 ); coords.setX( 0 );
@ -137,7 +130,7 @@ int DesktopLayout::desktopToRight( int id, bool wrap ) const
} }
} }
int DesktopLayout::desktopBelow( int id, bool wrap ) const int Workspace::desktopBelow( int id, bool wrap ) const
{ {
if( id == 0 ) if( id == 0 )
id = currentDesktop(); id = currentDesktop();
@ -146,7 +139,7 @@ int DesktopLayout::desktopBelow( int id, bool wrap ) const
for(;;) for(;;)
{ {
coords.ry()++; coords.ry()++;
if( coords.y() >= m_gridSize.height() ) if( coords.y() >= desktopGridSize_.height() )
{ {
if( wrap ) if( wrap )
coords.setY( 0 ); coords.setY( 0 );
@ -159,7 +152,7 @@ int DesktopLayout::desktopBelow( int id, bool wrap ) const
} }
} }
int DesktopLayout::desktopToLeft( int id, bool wrap ) const int Workspace::desktopToLeft( int id, bool wrap ) const
{ {
if( id == 0 ) if( id == 0 )
id = currentDesktop(); id = currentDesktop();
@ -171,7 +164,7 @@ int DesktopLayout::desktopToLeft( int id, bool wrap ) const
if( coords.x() < 0 ) if( coords.x() < 0 )
{ {
if( wrap ) if( wrap )
coords.setX( m_gridSize.width() - 1 ); coords.setX( desktopGridSize_.width() - 1 );
else else
return id; // Already at the left-most desktop return id; // Already at the left-most desktop
} }
@ -181,12 +174,12 @@ int DesktopLayout::desktopToLeft( int id, bool wrap ) const
} }
} }
int DesktopLayout::addDesktop( QPoint coords ) int Workspace::addDesktop( QPoint coords )
{ // TODO { // TODO
return 0; return 0;
} }
void DesktopLayout::deleteDesktop( int id ) void Workspace::deleteDesktop( int id )
{ // TODO { // TODO
} }

View file

@ -1,207 +0,0 @@
/********************************************************************
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/>.
*********************************************************************/
#ifndef KWIN_DESKTOPLAYOUT_H
#define KWIN_DESKTOPLAYOUT_H
#include <assert.h>
#include <QPoint>
#include <QSize>
#include "utils.h"
namespace KWin
{
class DesktopLayout
{
public:
DesktopLayout();
~DesktopLayout();
/**
* @returns Total number of desktops currently in existance.
*/
int numberOfDesktops() const;
/**
* Set the number of available desktops to @a count. It is not recommended to use this
* function as it overrides any previous grid layout.
*/
void setNumberOfDesktops( int count );
/**
* @returns The size of desktop layout in grid units.
*/
QSize gridSize() const;
/**
* @returns The width of desktop layout in grid units.
*/
int gridWidth() const;
/**
* @returns The height of desktop layout in grid units.
*/
int gridHeight() const;
/**
* @returns The width of desktop layout in pixels. Equivalent to gridWidth() *
* ::displayWidth().
*/
int width() const;
/**
* @returns The height of desktop layout in pixels. Equivalent to gridHeight() *
* ::displayHeight().
*/
int height() const;
/**
* @returns The ID of the current desktop.
*/
int currentDesktop() const;
/**
* Set the current desktop to @a current.
*/
void setCurrentDesktop( int current );
/**
* Generate a desktop layout from EWMH _NET_DESKTOP_LAYOUT property parameters.
*/
void setNETDesktopLayout( Qt::Orientation orientation, int width, int height, int startingCorner );
/**
* @returns The ID of the desktop at the point @a coords or 0 if no desktop exists at that
* point. @a coords is to be in grid units.
*/
int desktopAtCoords( QPoint coords ) const;
/**
* @returns The coords of desktop @a id in grid units.
*/
QPoint desktopGridCoords( int id ) const;
/**
* @returns The coords of the top-left corner of desktop @a id in pixels.
*/
QPoint desktopCoords( int id ) const;
/**
* @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of
* the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopAbove( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop to the right of desktop @a id. Wraps around to the
* left of the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopToRight( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop below desktop @a id. Wraps around to the top of the
* layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopBelow( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop to the left of desktop @a id. Wraps around to the
* right of the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopToLeft( int id = 0, bool wrap = true ) const;
/**
* @returns Whether or not the layout is allowed to be modified by the user.
*/
bool isDynamic() const;
/**
* Sets whether or not this layout can be modified by the user.
*/
void setDynamic( bool dynamic );
/**
* Create new desktop at the point @a coords
* @returns The ID of the created desktop
*/
int addDesktop( QPoint coords );
/**
* Deletes the desktop with the ID @a id. All desktops with an ID greater than the one that
* was deleted will have their IDs' decremented.
*/
void deleteDesktop( int id );
private:
int m_count;
QSize m_gridSize;
int* m_grid;
int m_current;
bool m_dynamic;
};
inline int DesktopLayout::numberOfDesktops() const
{
return m_count;
}
inline QSize DesktopLayout::gridSize() const
{
return m_gridSize;
}
inline int DesktopLayout::gridWidth() const
{
return m_gridSize.width();
}
inline int DesktopLayout::gridHeight() const
{
return m_gridSize.height();
}
inline int DesktopLayout::width() const
{
return m_gridSize.width() * displayWidth();
}
inline int DesktopLayout::height() const
{
return m_gridSize.height() * displayHeight();
}
inline int DesktopLayout::currentDesktop() const
{
return m_current;
}
inline void DesktopLayout::setCurrentDesktop( int current )
{
assert( current >= 1 );
assert( current <= m_count );
m_current = current;
}
inline int DesktopLayout::desktopAtCoords( QPoint coords ) const
{
return m_grid[coords.y() * m_gridSize.width() + coords.x()];
}
inline bool DesktopLayout::isDynamic() const
{
return m_dynamic;
}
inline void DesktopLayout::setDynamic( bool dynamic )
{
m_dynamic = dynamic;
}
} // namespace
#endif

View file

@ -448,77 +448,77 @@ void EffectsHandlerImpl::setCurrentDesktop( int desktop )
QSize EffectsHandlerImpl::desktopGridSize() const QSize EffectsHandlerImpl::desktopGridSize() const
{ {
return Workspace::self()->getDesktopLayout()->gridSize(); return Workspace::self()->desktopGridSize();
} }
int EffectsHandlerImpl::desktopGridWidth() const int EffectsHandlerImpl::desktopGridWidth() const
{ {
return Workspace::self()->getDesktopLayout()->gridWidth(); return Workspace::self()->desktopGridWidth();
} }
int EffectsHandlerImpl::desktopGridHeight() const int EffectsHandlerImpl::desktopGridHeight() const
{ {
return Workspace::self()->getDesktopLayout()->gridHeight(); return Workspace::self()->desktopGridHeight();
} }
int EffectsHandlerImpl::workspaceWidth() const int EffectsHandlerImpl::workspaceWidth() const
{ {
return Workspace::self()->getDesktopLayout()->width(); return Workspace::self()->workspaceWidth();
} }
int EffectsHandlerImpl::workspaceHeight() const int EffectsHandlerImpl::workspaceHeight() const
{ {
return Workspace::self()->getDesktopLayout()->height(); return Workspace::self()->workspaceHeight();
} }
int EffectsHandlerImpl::desktopAtCoords( QPoint coords ) const int EffectsHandlerImpl::desktopAtCoords( QPoint coords ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopAtCoords( coords ); return Workspace::self()->desktopAtCoords( coords );
} }
QPoint EffectsHandlerImpl::desktopGridCoords( int id ) const QPoint EffectsHandlerImpl::desktopGridCoords( int id ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopGridCoords( id ); return Workspace::self()->desktopGridCoords( id );
} }
QPoint EffectsHandlerImpl::desktopCoords( int id ) const QPoint EffectsHandlerImpl::desktopCoords( int id ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopCoords( id ); return Workspace::self()->desktopCoords( id );
} }
int EffectsHandlerImpl::desktopAbove( int desktop, bool wrap ) const int EffectsHandlerImpl::desktopAbove( int desktop, bool wrap ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopAbove( desktop, wrap ); return Workspace::self()->desktopAbove( desktop, wrap );
} }
int EffectsHandlerImpl::desktopToRight( int desktop, bool wrap ) const int EffectsHandlerImpl::desktopToRight( int desktop, bool wrap ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopToRight( desktop, wrap ); return Workspace::self()->desktopToRight( desktop, wrap );
} }
int EffectsHandlerImpl::desktopBelow( int desktop, bool wrap ) const int EffectsHandlerImpl::desktopBelow( int desktop, bool wrap ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopBelow( desktop, wrap ); return Workspace::self()->desktopBelow( desktop, wrap );
} }
int EffectsHandlerImpl::desktopToLeft( int desktop, bool wrap ) const int EffectsHandlerImpl::desktopToLeft( int desktop, bool wrap ) const
{ {
return Workspace::self()->getDesktopLayout()->desktopToLeft( desktop, wrap ); return Workspace::self()->desktopToLeft( desktop, wrap );
} }
bool EffectsHandlerImpl::desktopLayoutIsDynamic() const bool EffectsHandlerImpl::isDesktopLayoutDynamic() const
{ {
return Workspace::self()->getDesktopLayout()->isDynamic(); return Workspace::self()->isDesktopLayoutDynamic();
} }
int EffectsHandlerImpl::addDesktop( QPoint coords ) int EffectsHandlerImpl::addDesktop( QPoint coords )
{ {
return Workspace::self()->getDesktopLayout()->addDesktop( coords ); return Workspace::self()->addDesktop( coords );
} }
void EffectsHandlerImpl::deleteDesktop( int id ) void EffectsHandlerImpl::deleteDesktop( int id )
{ {
Workspace::self()->getDesktopLayout()->deleteDesktop( id ); Workspace::self()->deleteDesktop( id );
} }
QString EffectsHandlerImpl::desktopName( int desktop ) const QString EffectsHandlerImpl::desktopName( int desktop ) const

View file

@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kwineffects.h" #include "kwineffects.h"
#include "desktoplayout.h"
#include "scene.h" #include "scene.h"
#include <QStack> #include <QStack>
@ -72,7 +71,7 @@ class EffectsHandlerImpl : public EffectsHandler
virtual int desktopToRight( int desktop = 0, bool wrap = true ) const; virtual int desktopToRight( int desktop = 0, bool wrap = true ) const;
virtual int desktopBelow( int desktop = 0, bool wrap = true ) const; virtual int desktopBelow( int desktop = 0, bool wrap = true ) const;
virtual int desktopToLeft( int desktop = 0, bool wrap = true ) const; virtual int desktopToLeft( int desktop = 0, bool wrap = true ) const;
virtual bool desktopLayoutIsDynamic() const; virtual bool isDesktopLayoutDynamic() const;
virtual int addDesktop( QPoint coords ); virtual int addDesktop( QPoint coords );
virtual void deleteDesktop( int id ); virtual void deleteDesktop( int id );
virtual QString desktopName( int desktop ) const; virtual QString desktopName( int desktop ) const;

View file

@ -617,7 +617,7 @@ class KWIN_EXPORT EffectsHandler
/** /**
* @returns Whether or not the desktop layout is allowed to be modified by the user. * @returns Whether or not the desktop layout is allowed to be modified by the user.
*/ */
virtual bool desktopLayoutIsDynamic() const = 0; virtual bool isDesktopLayoutDynamic() const = 0;
/** /**
* Create new desktop at the point @a coords * Create new desktop at the point @a coords
* @returns The ID of the created desktop * @returns The ID of the created desktop

View file

@ -822,7 +822,7 @@ void Workspace::slotSwitchDesktopLeft()
void Workspace::slotSwitchDesktopUp() void Workspace::slotSwitchDesktopUp()
{ {
int desktop = desktopUp( currentDesktop(), options->rollOverDesktops); int desktop = desktopAbove( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop()) if( desktop == currentDesktop())
return; return;
setCurrentDesktop( desktop ); setCurrentDesktop( desktop );
@ -830,7 +830,7 @@ void Workspace::slotSwitchDesktopUp()
void Workspace::slotSwitchDesktopDown() void Workspace::slotSwitchDesktopDown()
{ {
int desktop = desktopDown( currentDesktop(), options->rollOverDesktops); int desktop = desktopBelow( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop()) if( desktop == currentDesktop())
return; return;
setCurrentDesktop( desktop ); setCurrentDesktop( desktop );
@ -1088,7 +1088,7 @@ void Workspace::slotWindowToDesktopLeft()
void Workspace::slotWindowToDesktopUp() void Workspace::slotWindowToDesktopUp()
{ {
int d = desktopUp( currentDesktop(), options->rollOverDesktops); int d = desktopAbove( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop()) if( d == currentDesktop())
return; return;
Client* c = active_popup_client ? active_popup_client : active_client; Client* c = active_popup_client ? active_popup_client : active_client;
@ -1103,7 +1103,7 @@ void Workspace::slotWindowToDesktopUp()
void Workspace::slotWindowToDesktopDown() void Workspace::slotWindowToDesktopDown()
{ {
int d = desktopDown( currentDesktop(), options->rollOverDesktops); int d = desktopBelow( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop()) if( d == currentDesktop())
return; return;
Client* c = active_popup_client ? active_popup_client : active_client; Client* c = active_popup_client ? active_popup_client : active_client;

View file

@ -88,6 +88,13 @@ Workspace* Workspace::_self = 0;
Workspace::Workspace( bool restore ) Workspace::Workspace( bool restore )
: QObject( 0 ) : QObject( 0 )
// Desktop layout
, desktopCount_( 0 ) // This is an invalid state
, desktopGridSize_( 1, 2 ) // Default to two rows
, desktopGrid_( new int[2] )
, currentDesktop_( 0 )
, desktopLayoutDynamicity_( false )
// Unsorted
, active_popup( NULL ) , active_popup( NULL )
, active_popup_client( NULL ) , active_popup_client( NULL )
, temporaryRulesMessages( "_KDE_NET_WM_TEMPORARY_RULES", NULL, false ) , temporaryRulesMessages( "_KDE_NET_WM_TEMPORARY_RULES", NULL, false )
@ -152,6 +159,10 @@ Workspace::Workspace( bool restore )
dbus.connect( QString(), "/KWin", "org.kde.KWin", "reinitCompositing", dbus.connect( QString(), "/KWin", "org.kde.KWin", "reinitCompositing",
this, SLOT( slotReinitCompositing() )); this, SLOT( slotReinitCompositing() ));
// Initialize desktop grid array
desktopGrid_[0] = 0;
desktopGrid_[1] = 0;
_self = this; _self = this;
mgr = new PluginMgr; mgr = new PluginMgr;
QX11Info info; QX11Info info;
@ -500,6 +511,8 @@ Workspace::~Workspace()
// TODO: ungrabXServer(); // TODO: ungrabXServer();
delete[] desktopGrid_;
_self = 0; _self = 0;
} }
@ -1116,7 +1129,7 @@ void Workspace::loadDesktopSettings()
KConfigGroup group( c, groupname ); KConfigGroup group( c, groupname );
int n = group.readEntry( "Number", 4 ); int n = group.readEntry( "Number", 4 );
desktopLayout.setNumberOfDesktops( n ); desktopCount_ = n;
workarea.clear(); workarea.clear();
workarea.resize( n + 1 ); workarea.resize( n + 1 );
screenarea.clear(); screenarea.clear();
@ -1321,7 +1334,7 @@ bool Workspace::setCurrentDesktop( int new_desktop )
ObscuringWindows obs_wins; ObscuringWindows obs_wins;
desktopLayout.setCurrentDesktop( new_desktop ); // Change the desktop (so that Client::updateVisibility() works) currentDesktop_ = new_desktop; // Change the desktop (so that Client::updateVisibility() works)
for( ClientList::ConstIterator it = stacking_order.constBegin(); for( ClientList::ConstIterator it = stacking_order.constBegin();
it != stacking_order.constEnd(); it != stacking_order.constEnd();
@ -1443,7 +1456,8 @@ void Workspace::setNumberOfDesktops( int n )
if( n == numberOfDesktops() ) if( n == numberOfDesktops() )
return; return;
int old_number_of_desktops = numberOfDesktops(); int old_number_of_desktops = numberOfDesktops();
desktopLayout.setNumberOfDesktops( n ); desktopCount_ = n;
updateDesktopLayout(); // Make sure the layout is still valid
if( currentDesktop() > numberOfDesktops() ) if( currentDesktop() > numberOfDesktops() )
setCurrentDesktop( numberOfDesktops() ); setCurrentDesktop( numberOfDesktops() );
@ -1600,18 +1614,6 @@ void Workspace::sendClientToScreen( Client* c, int screen )
active_screen = screen; active_screen = screen;
} }
void Workspace::updateDesktopLayout()
{
int width = rootInfo->desktopLayoutColumnsRows().width();
int height = rootInfo->desktopLayoutColumnsRows().height();
if( width == 0 && height == 0 ) // Not given, set default layout
height = 2;
desktopLayout.setNETDesktopLayout(
rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical,
width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now.
);
}
void Workspace::killWindowId( Window window_to_kill ) void Workspace::killWindowId( Window window_to_kill )
{ {
if( window_to_kill == None ) if( window_to_kill == None )
@ -2162,12 +2164,12 @@ void Workspace::electricBorderSwitchDesktop( ElectricBorder border, const QPoint
} }
if( border == ElectricTop || border == ElectricTopLeft || border == ElectricTopRight ) if( border == ElectricTop || border == ElectricTopLeft || border == ElectricTopRight )
{ {
desk = desktopUp( desk, options->rollOverDesktops ); desk = desktopAbove( desk, options->rollOverDesktops );
pos.setY( displayHeight() - 1 - OFFSET ); pos.setY( displayHeight() - 1 - OFFSET );
} }
if( border == ElectricBottom || border == ElectricBottomLeft || border == ElectricBottomRight ) if( border == ElectricBottom || border == ElectricBottomLeft || border == ElectricBottomRight )
{ {
desk = desktopDown( desk, options->rollOverDesktops ); desk = desktopBelow( desk, options->rollOverDesktops );
pos.setY( OFFSET ); pos.setY( OFFSET );
} }
int desk_before = currentDesktop(); int desk_before = currentDesktop();

View file

@ -4,6 +4,7 @@
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org> Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org> Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -31,7 +32,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDateTime> #include <QDateTime>
#include <kmanagerselection.h> #include <kmanagerselection.h>
#include "desktoplayout.h"
#include "plugins.h" #include "plugins.h"
#include "utils.h" #include "utils.h"
#include "kdecoration.h" #include "kdecoration.h"
@ -158,21 +158,127 @@ class Workspace : public QObject, public KDecorationDefines
void unreserveElectricBorder( ElectricBorder border ); void unreserveElectricBorder( ElectricBorder border );
void reserveElectricBorderSwitching( bool reserve ); void reserveElectricBorderSwitching( bool reserve );
//-------------------------------------------------
// Desktop layout
public:
/** /**
* Returns the current virtual desktop of this workspace * @returns Total number of desktops currently in existance.
*/
int numberOfDesktops() const;
/**
* Set the number of available desktops to @a count. This function overrides any previous
* grid layout.
*/
void setNumberOfDesktops( int count );
/**
* Called from within setNumberOfDesktops() to ensure the desktop layout is still valid.
*/
void updateDesktopLayout();
/**
* @returns The size of desktop layout in grid units.
*/
QSize desktopGridSize() const;
/**
* @returns The width of desktop layout in grid units.
*/
int desktopGridWidth() const;
/**
* @returns The height of desktop layout in grid units.
*/
int desktopGridHeight() const;
/**
* @returns The width of desktop layout in pixels. Equivalent to gridWidth() *
* ::displayWidth().
*/
int workspaceWidth() const;
/**
* @returns The height of desktop layout in pixels. Equivalent to gridHeight() *
* ::displayHeight().
*/
int workspaceHeight() const;
/**
* @returns The ID of the current desktop.
*/ */
int currentDesktop() const; int currentDesktop() const;
/** /**
* Returns the number of virtual desktops of this workspace * Set the current desktop to @a current.
* @returns True on success, false otherwise.
*/ */
int numberOfDesktops() const; bool setCurrentDesktop( int current );
void setNumberOfDesktops( int n );
DesktopLayout* getDesktopLayout();
int desktopToRight( int desktop, bool wrap ) const;
int desktopToLeft( int desktop, bool wrap ) const;
int desktopUp( int desktop, bool wrap ) const;
int desktopDown( int desktop, bool wrap ) const;
/**
* Generate a desktop layout from EWMH _NET_DESKTOP_LAYOUT property parameters.
*/
void setNETDesktopLayout( Qt::Orientation orientation, int width, int height, int startingCorner );
/**
* @returns The ID of the desktop at the point @a coords or 0 if no desktop exists at that
* point. @a coords is to be in grid units.
*/
int desktopAtCoords( QPoint coords ) const;
/**
* @returns The coords of desktop @a id in grid units.
*/
QPoint desktopGridCoords( int id ) const;
/**
* @returns The coords of the top-left corner of desktop @a id in pixels.
*/
QPoint desktopCoords( int id ) const;
/**
* @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of
* the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopAbove( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop to the right of desktop @a id. Wraps around to the
* left of the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopToRight( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop below desktop @a id. Wraps around to the top of the
* layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopBelow( int id = 0, bool wrap = true ) const;
/**
* @returns The ID of the desktop to the left of desktop @a id. Wraps around to the
* right of the layout if @a wrap is set. If @a id is not set use the current one.
*/
int desktopToLeft( int id = 0, bool wrap = true ) const;
/**
* @returns Whether or not the layout is allowed to be modified by the user.
*/
bool isDesktopLayoutDynamic() const;
/**
* Sets whether or not this layout can be modified by the user.
*/
void setDesktopLayoutDynamicity( bool dynamicity );
/**
* Create new desktop at the point @a coords
* @returns The ID of the created desktop
*/
int addDesktop( QPoint coords );
/**
* Deletes the desktop with the ID @a id. All desktops with an ID greater than the one that
* was deleted will have their IDs' decremented.
*/
void deleteDesktop( int id );
private:
int desktopCount_;
QSize desktopGridSize_;
int* desktopGrid_;
int currentDesktop_;
bool desktopLayoutDynamicity_;
//-------------------------------------------------
// Unsorted
public:
int activeScreen( bool checkClient = true ) const; int activeScreen( bool checkClient = true ) const;
int numScreens() const; int numScreens() const;
void checkActiveScreen( const Client* c ); void checkActiveScreen( const Client* c );
@ -266,7 +372,6 @@ class Workspace : public QObject, public KDecorationDefines
void unclutterDesktop(); void unclutterDesktop();
void doNotManage( const QString& ); void doNotManage( const QString& );
QList<int> decorationSupportedColors() const; QList<int> decorationSupportedColors() const;
bool setCurrentDesktop( int new_desktop );
void nextDesktop(); void nextDesktop();
void previousDesktop(); void previousDesktop();
void circulateDesktopApplications(); void circulateDesktopApplications();
@ -276,7 +381,6 @@ class Workspace : public QObject, public KDecorationDefines
void setCurrentScreen( int new_screen ); void setCurrentScreen( int new_screen );
QString desktopName( int desk ) const; QString desktopName( int desk ) const;
void updateDesktopLayout();
void setShowingDesktop( bool showing ); void setShowingDesktop( bool showing );
void resetShowingDesktop( bool keep_hidden ); void resetShowingDesktop( bool keep_hidden );
bool showingDesktop() const; bool showingDesktop() const;
@ -746,8 +850,6 @@ class Workspace : public QObject, public KDecorationDefines
QPoint electric_push_point; QPoint electric_push_point;
int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something
DesktopLayout desktopLayout;
Placement* initPositioning; Placement* initPositioning;
QVector<QRect> workarea; // Array of workareas for virtual desktops QVector<QRect> workarea; // Array of workareas for virtual desktops
@ -834,6 +936,61 @@ class RootInfo : public NETRootInfo
Workspace* workspace; Workspace* workspace;
}; };
//---------------------------------------------------------
// Desktop layout
inline int Workspace::numberOfDesktops() const
{
return desktopCount_;
}
inline QSize Workspace::desktopGridSize() const
{
return desktopGridSize_;
}
inline int Workspace::desktopGridWidth() const
{
return desktopGridSize_.width();
}
inline int Workspace::desktopGridHeight() const
{
return desktopGridSize_.height();
}
inline int Workspace::workspaceWidth() const
{
return desktopGridSize_.width() * displayWidth();
}
inline int Workspace::workspaceHeight() const
{
return desktopGridSize_.height() * displayHeight();
}
inline int Workspace::currentDesktop() const
{
return currentDesktop_;
}
inline int Workspace::desktopAtCoords( QPoint coords ) const
{
return desktopGrid_[coords.y() * desktopGridSize_.width() + coords.x()];
}
inline bool Workspace::isDesktopLayoutDynamic() const
{
return desktopLayoutDynamicity_;
}
inline void Workspace::setDesktopLayoutDynamicity( bool dynamicity )
{
desktopLayoutDynamicity_ = dynamicity;
}
//---------------------------------------------------------
// Unsorted
inline bool Workspace::initializing() const inline bool Workspace::initializing() const
{ {
@ -850,41 +1007,6 @@ inline Client* Workspace::mostRecentlyActivatedClient() const
return should_get_focus.count() > 0 ? should_get_focus.last() : active_client; return should_get_focus.count() > 0 ? should_get_focus.last() : active_client;
} }
inline int Workspace::currentDesktop() const
{
return desktopLayout.currentDesktop();
}
inline int Workspace::numberOfDesktops() const
{
return desktopLayout.numberOfDesktops();
}
inline DesktopLayout* Workspace::getDesktopLayout()
{
return &desktopLayout;
}
inline int Workspace::desktopToRight( int desktop, bool wrap ) const
{
return desktopLayout.desktopToRight( desktop, wrap );
}
inline int Workspace::desktopToLeft( int desktop, bool wrap ) const
{
return desktopLayout.desktopToLeft( desktop, wrap );
}
inline int Workspace::desktopUp( int desktop, bool wrap ) const
{
return desktopLayout.desktopAbove( desktop, wrap );
}
inline int Workspace::desktopDown( int desktop, bool wrap ) const
{
return desktopLayout.desktopBelow( desktop, wrap );
}
inline void Workspace::addGroup( Group* group, allowed_t ) inline void Workspace::addGroup( Group* group, allowed_t )
{ {
groups.append( group ); groups.append( group );