diff --git a/desktoplayout.cpp b/desktoplayout.cpp
index 53fe1982d9..bbd37664a8 100644
--- a/desktoplayout.cpp
+++ b/desktoplayout.cpp
@@ -18,35 +18,28 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*********************************************************************/
-#include "desktoplayout.h"
+#include "workspace.h"
+
+#include "assert.h"
namespace KWin
{
-DesktopLayout::DesktopLayout()
- : 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 )
+void Workspace::updateDesktopLayout()
{
- m_grid[0] = 0;
- m_grid[1] = 0;
+ // 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.
+ );
}
-DesktopLayout::~DesktopLayout()
- {
- 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,
+void Workspace::setNETDesktopLayout( Qt::Orientation orientation, int width, int height,
int startingCorner )
{
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
assert( 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 ))
- height = ( m_count + width - 1 ) / width;
+ height = ( desktopCount_ + width - 1 ) / width;
// Set private variables
- delete[] m_grid;
- m_gridSize = QSize( width, height );
+ delete[] desktopGrid_;
+ desktopGridSize_ = QSize( width, height );
int size = width * height;
- m_grid = new int[size];
+ desktopGrid_ = new int[size];
// Populate grid
int desktop = 1;
if( orientation == Qt::Horizontal )
for( int y = 0; y < height; y++ )
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
for( int x = 0; x < width; x++ )
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 x = 0; x < m_gridSize.width(); x++ )
- if( m_grid[y * m_gridSize.height() + x] == id )
+ for( int y = 0; y < desktopGridSize_.height(); y++ )
+ for( int x = 0; x < desktopGridSize_.width(); x++ )
+ if( desktopGrid_[y * desktopGridSize_.height() + x] == id )
return QPoint( x, y );
return QPoint( -1, -1 );
}
-QPoint DesktopLayout::desktopCoords( int id ) const
+QPoint Workspace::desktopCoords( int id ) const
{
QPoint coords = desktopGridCoords( id );
if( coords.x() == -1 )
@@ -93,7 +86,7 @@ QPoint DesktopLayout::desktopCoords( int id ) const
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 )
id = currentDesktop();
@@ -105,7 +98,7 @@ int DesktopLayout::desktopAbove( int id, bool wrap ) const
if( coords.y() < 0 )
{
if( wrap )
- coords.setY( m_gridSize.height() - 1 );
+ coords.setY( desktopGridSize_.height() - 1 );
else
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 )
id = currentDesktop();
@@ -124,7 +117,7 @@ int DesktopLayout::desktopToRight( int id, bool wrap ) const
for(;;)
{
coords.rx()++;
- if( coords.x() >= m_gridSize.width() )
+ if( coords.x() >= desktopGridSize_.width() )
{
if( wrap )
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 )
id = currentDesktop();
@@ -146,7 +139,7 @@ int DesktopLayout::desktopBelow( int id, bool wrap ) const
for(;;)
{
coords.ry()++;
- if( coords.y() >= m_gridSize.height() )
+ if( coords.y() >= desktopGridSize_.height() )
{
if( wrap )
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 )
id = currentDesktop();
@@ -171,7 +164,7 @@ int DesktopLayout::desktopToLeft( int id, bool wrap ) const
if( coords.x() < 0 )
{
if( wrap )
- coords.setX( m_gridSize.width() - 1 );
+ coords.setX( desktopGridSize_.width() - 1 );
else
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
return 0;
}
-void DesktopLayout::deleteDesktop( int id )
+void Workspace::deleteDesktop( int id )
{ // TODO
}
diff --git a/desktoplayout.h b/desktoplayout.h
deleted file mode 100644
index 8a1e49bdff..0000000000
--- a/desktoplayout.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/********************************************************************
- KWin - the KDE window manager
- This file is part of the KDE project.
-
-Copyright (C) 2009 Lucas Murray
-
-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 .
-*********************************************************************/
-
-#ifndef KWIN_DESKTOPLAYOUT_H
-#define KWIN_DESKTOPLAYOUT_H
-
-#include
-#include
-#include
-
-#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
diff --git a/effects.cpp b/effects.cpp
index 8eb5c6de0b..f03e0341c7 100644
--- a/effects.cpp
+++ b/effects.cpp
@@ -448,77 +448,77 @@ void EffectsHandlerImpl::setCurrentDesktop( int desktop )
QSize EffectsHandlerImpl::desktopGridSize() const
{
- return Workspace::self()->getDesktopLayout()->gridSize();
+ return Workspace::self()->desktopGridSize();
}
int EffectsHandlerImpl::desktopGridWidth() const
{
- return Workspace::self()->getDesktopLayout()->gridWidth();
+ return Workspace::self()->desktopGridWidth();
}
int EffectsHandlerImpl::desktopGridHeight() const
{
- return Workspace::self()->getDesktopLayout()->gridHeight();
+ return Workspace::self()->desktopGridHeight();
}
int EffectsHandlerImpl::workspaceWidth() const
{
- return Workspace::self()->getDesktopLayout()->width();
+ return Workspace::self()->workspaceWidth();
}
int EffectsHandlerImpl::workspaceHeight() const
{
- return Workspace::self()->getDesktopLayout()->height();
+ return Workspace::self()->workspaceHeight();
}
int EffectsHandlerImpl::desktopAtCoords( QPoint coords ) const
{
- return Workspace::self()->getDesktopLayout()->desktopAtCoords( coords );
+ return Workspace::self()->desktopAtCoords( coords );
}
QPoint EffectsHandlerImpl::desktopGridCoords( int id ) const
{
- return Workspace::self()->getDesktopLayout()->desktopGridCoords( id );
+ return Workspace::self()->desktopGridCoords( id );
}
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
{
- return Workspace::self()->getDesktopLayout()->desktopAbove( desktop, wrap );
+ return Workspace::self()->desktopAbove( desktop, wrap );
}
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
{
- return Workspace::self()->getDesktopLayout()->desktopBelow( desktop, wrap );
+ return Workspace::self()->desktopBelow( desktop, wrap );
}
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 )
{
- return Workspace::self()->getDesktopLayout()->addDesktop( coords );
+ return Workspace::self()->addDesktop( coords );
}
void EffectsHandlerImpl::deleteDesktop( int id )
{
- Workspace::self()->getDesktopLayout()->deleteDesktop( id );
+ Workspace::self()->deleteDesktop( id );
}
QString EffectsHandlerImpl::desktopName( int desktop ) const
diff --git a/effects.h b/effects.h
index c76d85c6bc..902924c085 100644
--- a/effects.h
+++ b/effects.h
@@ -23,7 +23,6 @@ along with this program. If not, see .
#include "kwineffects.h"
-#include "desktoplayout.h"
#include "scene.h"
#include
@@ -72,7 +71,7 @@ class EffectsHandlerImpl : public EffectsHandler
virtual int desktopToRight( 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 bool desktopLayoutIsDynamic() const;
+ virtual bool isDesktopLayoutDynamic() const;
virtual int addDesktop( QPoint coords );
virtual void deleteDesktop( int id );
virtual QString desktopName( int desktop ) const;
diff --git a/lib/kwineffects.h b/lib/kwineffects.h
index b5a4680fd5..b8060a1fc4 100644
--- a/lib/kwineffects.h
+++ b/lib/kwineffects.h
@@ -617,7 +617,7 @@ class KWIN_EXPORT EffectsHandler
/**
* @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
* @returns The ID of the created desktop
diff --git a/useractions.cpp b/useractions.cpp
index 0ca721f5bc..4df38edeef 100644
--- a/useractions.cpp
+++ b/useractions.cpp
@@ -822,7 +822,7 @@ void Workspace::slotSwitchDesktopLeft()
void Workspace::slotSwitchDesktopUp()
{
- int desktop = desktopUp( currentDesktop(), options->rollOverDesktops);
+ int desktop = desktopAbove( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@@ -830,7 +830,7 @@ void Workspace::slotSwitchDesktopUp()
void Workspace::slotSwitchDesktopDown()
{
- int desktop = desktopDown( currentDesktop(), options->rollOverDesktops);
+ int desktop = desktopBelow( currentDesktop(), options->rollOverDesktops);
if( desktop == currentDesktop())
return;
setCurrentDesktop( desktop );
@@ -1088,7 +1088,7 @@ void Workspace::slotWindowToDesktopLeft()
void Workspace::slotWindowToDesktopUp()
{
- int d = desktopUp( currentDesktop(), options->rollOverDesktops);
+ int d = desktopAbove( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;
@@ -1103,7 +1103,7 @@ void Workspace::slotWindowToDesktopUp()
void Workspace::slotWindowToDesktopDown()
{
- int d = desktopDown( currentDesktop(), options->rollOverDesktops);
+ int d = desktopBelow( currentDesktop(), options->rollOverDesktops);
if( d == currentDesktop())
return;
Client* c = active_popup_client ? active_popup_client : active_client;
diff --git a/workspace.cpp b/workspace.cpp
index 424746da45..92953f55eb 100644
--- a/workspace.cpp
+++ b/workspace.cpp
@@ -88,6 +88,13 @@ Workspace* Workspace::_self = 0;
Workspace::Workspace( bool restore )
: 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_client( NULL )
, temporaryRulesMessages( "_KDE_NET_WM_TEMPORARY_RULES", NULL, false )
@@ -152,6 +159,10 @@ Workspace::Workspace( bool restore )
dbus.connect( QString(), "/KWin", "org.kde.KWin", "reinitCompositing",
this, SLOT( slotReinitCompositing() ));
+ // Initialize desktop grid array
+ desktopGrid_[0] = 0;
+ desktopGrid_[1] = 0;
+
_self = this;
mgr = new PluginMgr;
QX11Info info;
@@ -500,6 +511,8 @@ Workspace::~Workspace()
// TODO: ungrabXServer();
+ delete[] desktopGrid_;
+
_self = 0;
}
@@ -1116,7 +1129,7 @@ void Workspace::loadDesktopSettings()
KConfigGroup group( c, groupname );
int n = group.readEntry( "Number", 4 );
- desktopLayout.setNumberOfDesktops( n );
+ desktopCount_ = n;
workarea.clear();
workarea.resize( n + 1 );
screenarea.clear();
@@ -1321,7 +1334,7 @@ bool Workspace::setCurrentDesktop( int new_desktop )
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();
it != stacking_order.constEnd();
@@ -1443,7 +1456,8 @@ void Workspace::setNumberOfDesktops( int n )
if( n == numberOfDesktops() )
return;
int old_number_of_desktops = numberOfDesktops();
- desktopLayout.setNumberOfDesktops( n );
+ desktopCount_ = n;
+ updateDesktopLayout(); // Make sure the layout is still valid
if( currentDesktop() > numberOfDesktops() )
setCurrentDesktop( numberOfDesktops() );
@@ -1600,18 +1614,6 @@ void Workspace::sendClientToScreen( Client* c, int 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 )
{
if( window_to_kill == None )
@@ -2162,12 +2164,12 @@ void Workspace::electricBorderSwitchDesktop( ElectricBorder border, const QPoint
}
if( border == ElectricTop || border == ElectricTopLeft || border == ElectricTopRight )
{
- desk = desktopUp( desk, options->rollOverDesktops );
+ desk = desktopAbove( desk, options->rollOverDesktops );
pos.setY( displayHeight() - 1 - OFFSET );
}
if( border == ElectricBottom || border == ElectricBottomLeft || border == ElectricBottomRight )
{
- desk = desktopDown( desk, options->rollOverDesktops );
+ desk = desktopBelow( desk, options->rollOverDesktops );
pos.setY( OFFSET );
}
int desk_before = currentDesktop();
diff --git a/workspace.h b/workspace.h
index 39a3505223..baf291fded 100644
--- a/workspace.h
+++ b/workspace.h
@@ -4,6 +4,7 @@
Copyright (C) 1999, 2000 Matthias Ettrich
Copyright (C) 2003 Lubos Lunak
+Copyright (C) 2009 Lucas Murray
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
@@ -31,7 +32,6 @@ along with this program. If not, see .
#include
#include
-#include "desktoplayout.h"
#include "plugins.h"
#include "utils.h"
#include "kdecoration.h"
@@ -158,21 +158,127 @@ class Workspace : public QObject, public KDecorationDefines
void unreserveElectricBorder( ElectricBorder border );
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;
/**
- * 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;
- 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;
+ bool 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 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 numScreens() const;
void checkActiveScreen( const Client* c );
@@ -266,7 +372,6 @@ class Workspace : public QObject, public KDecorationDefines
void unclutterDesktop();
void doNotManage( const QString& );
QList decorationSupportedColors() const;
- bool setCurrentDesktop( int new_desktop );
void nextDesktop();
void previousDesktop();
void circulateDesktopApplications();
@@ -276,7 +381,6 @@ class Workspace : public QObject, public KDecorationDefines
void setCurrentScreen( int new_screen );
QString desktopName( int desk ) const;
- void updateDesktopLayout();
void setShowingDesktop( bool showing );
void resetShowingDesktop( bool keep_hidden );
bool showingDesktop() const;
@@ -746,8 +850,6 @@ class Workspace : public QObject, public KDecorationDefines
QPoint electric_push_point;
int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something
- DesktopLayout desktopLayout;
-
Placement* initPositioning;
QVector workarea; // Array of workareas for virtual desktops
@@ -834,6 +936,61 @@ class RootInfo : public NETRootInfo
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
{
@@ -850,41 +1007,6 @@ inline Client* Workspace::mostRecentlyActivatedClient() const
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 )
{
groups.append( group );