Allow desktop effects to access the new DesktopLayout class. Replaced

all code that used calcDesktopLayout() so the function could be removed.
Minor changes to the DesktopLayout class itself.

svn path=/trunk/KDE/kdebase/workspace/; revision=925930
icc-effect-5.14.5
Lucas Murray 2009-02-14 14:49:46 +00:00
parent 4681129e4b
commit dd28e15a1b
12 changed files with 238 additions and 152 deletions

View File

@ -59,20 +59,21 @@ void DesktopLayout::setNETDesktopLayout( Qt::Orientation orientation, int width,
height = ( m_count + width - 1 ) / width; height = ( m_count + width - 1 ) / width;
// Set private variables // Set private variables
m_gridSize = QSize( width, height );
delete[] m_grid; delete[] m_grid;
m_grid = new int[width * height]; m_gridSize = QSize( width, height );
int size = width * height;
m_grid = 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 * height + x] = (desktop <= m_count ? desktop++ : 0); m_grid[y * width + x] = (desktop <= m_count ? 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 * height + x] = (desktop <= m_count ? desktop++ : 0); m_grid[y * width + x] = (desktop <= m_count ? desktop++ : 0);
} }
QPoint DesktopLayout::desktopGridCoords( int id ) const QPoint DesktopLayout::desktopGridCoords( int id ) const

View File

@ -46,6 +46,10 @@ class DesktopLayout
*/ */
void setNumberOfDesktops( int count ); 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. * @returns The width of desktop layout in grid units.
*/ */
@ -146,6 +150,11 @@ inline int DesktopLayout::numberOfDesktops() const
return m_count; return m_count;
} }
inline QSize DesktopLayout::gridSize() const
{
return m_gridSize;
}
inline int DesktopLayout::gridWidth() const inline int DesktopLayout::gridWidth() const
{ {
return m_gridSize.width(); return m_gridSize.width();
@ -180,7 +189,7 @@ inline void DesktopLayout::setCurrentDesktop( int current )
inline int DesktopLayout::desktopAtCoords( QPoint coords ) const inline int DesktopLayout::desktopAtCoords( QPoint coords ) const
{ {
return m_grid[coords.y() * m_gridSize.height() + coords.x()]; return m_grid[coords.y() * m_gridSize.width() + coords.x()];
} }
inline bool DesktopLayout::isDynamic() const inline bool DesktopLayout::isDynamic() const

View File

@ -446,41 +446,91 @@ void EffectsHandlerImpl::setCurrentDesktop( int desktop )
Workspace::self()->setCurrentDesktop( desktop ); Workspace::self()->setCurrentDesktop( desktop );
} }
QSize EffectsHandlerImpl::desktopGridSize() const
{
return Workspace::self()->getDesktopLayout()->gridSize();
}
int EffectsHandlerImpl::desktopGridWidth() const
{
return Workspace::self()->getDesktopLayout()->gridWidth();
}
int EffectsHandlerImpl::desktopGridHeight() const
{
return Workspace::self()->getDesktopLayout()->gridHeight();
}
int EffectsHandlerImpl::workspaceWidth() const
{
return Workspace::self()->getDesktopLayout()->width();
}
int EffectsHandlerImpl::workspaceHeight() const
{
return Workspace::self()->getDesktopLayout()->height();
}
int EffectsHandlerImpl::desktopAtCoords( QPoint coords ) const
{
return Workspace::self()->getDesktopLayout()->desktopAtCoords( coords );
}
QPoint EffectsHandlerImpl::desktopGridCoords( int id ) const
{
return Workspace::self()->getDesktopLayout()->desktopGridCoords( id );
}
QPoint EffectsHandlerImpl::desktopCoords( int id ) const
{
return Workspace::self()->getDesktopLayout()->desktopCoords( id );
}
int EffectsHandlerImpl::desktopAbove( int desktop, bool wrap ) const
{
return Workspace::self()->getDesktopLayout()->desktopAbove( desktop, wrap );
}
int EffectsHandlerImpl::desktopToRight( int desktop, bool wrap ) const
{
return Workspace::self()->getDesktopLayout()->desktopToRight( desktop, wrap );
}
int EffectsHandlerImpl::desktopBelow( int desktop, bool wrap ) const
{
return Workspace::self()->getDesktopLayout()->desktopBelow( desktop, wrap );
}
int EffectsHandlerImpl::desktopToLeft( int desktop, bool wrap ) const
{
return Workspace::self()->getDesktopLayout()->desktopToLeft( desktop, wrap );
}
bool EffectsHandlerImpl::desktopLayoutIsDynamic() const
{
return Workspace::self()->getDesktopLayout()->isDynamic();
}
int EffectsHandlerImpl::addDesktop( QPoint coords )
{
return Workspace::self()->getDesktopLayout()->addDesktop( coords );
}
void EffectsHandlerImpl::deleteDesktop( int id )
{
Workspace::self()->getDesktopLayout()->deleteDesktop( id );
}
QString EffectsHandlerImpl::desktopName( int desktop ) const QString EffectsHandlerImpl::desktopName( int desktop ) const
{ {
return Workspace::self()->desktopName( desktop ); return Workspace::self()->desktopName( desktop );
} }
void EffectsHandlerImpl::calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const
{
Workspace::self()->calcDesktopLayout( x, y, orientation );
}
bool EffectsHandlerImpl::optionRollOverDesktops() const bool EffectsHandlerImpl::optionRollOverDesktops() const
{ {
return options->rollOverDesktops; return options->rollOverDesktops;
} }
int EffectsHandlerImpl::desktopToLeft( int desktop, bool wrap ) const
{
return Workspace::self()->desktopToLeft( desktop, wrap );
}
int EffectsHandlerImpl::desktopToRight( int desktop, bool wrap ) const
{
return Workspace::self()->desktopToRight( desktop, wrap );
}
int EffectsHandlerImpl::desktopUp( int desktop, bool wrap ) const
{
return Workspace::self()->desktopUp( desktop, wrap );
}
int EffectsHandlerImpl::desktopDown( int desktop, bool wrap ) const
{
return Workspace::self()->desktopDown( desktop, wrap );
}
double EffectsHandlerImpl::animationTimeFactor() const double EffectsHandlerImpl::animationTimeFactor() const
{ {
return options->animationTimeFactor(); return options->animationTimeFactor();

View File

@ -23,6 +23,7 @@ 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>
@ -59,7 +60,24 @@ class EffectsHandlerImpl : public EffectsHandler
virtual int currentDesktop() const; virtual int currentDesktop() const;
virtual int numberOfDesktops() const; virtual int numberOfDesktops() const;
virtual void setCurrentDesktop( int desktop ); virtual void setCurrentDesktop( int desktop );
virtual QSize desktopGridSize() const;
virtual int desktopGridWidth() const;
virtual int desktopGridHeight() const;
virtual int workspaceWidth() const;
virtual int workspaceHeight() const;
virtual int desktopAtCoords( QPoint coords ) const;
virtual QPoint desktopGridCoords( int id ) const;
virtual QPoint desktopCoords( int id ) const;
virtual int desktopAbove( 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 desktopToLeft( int desktop = 0, bool wrap = true ) const;
virtual bool desktopLayoutIsDynamic() const;
virtual int addDesktop( QPoint coords );
virtual void deleteDesktop( int id );
virtual QString desktopName( int desktop ) const; virtual QString desktopName( int desktop ) const;
virtual bool optionRollOverDesktops() const;
virtual int displayWidth() const; virtual int displayWidth() const;
virtual int displayHeight() const; virtual int displayHeight() const;
virtual QPoint cursorPos() const; virtual QPoint cursorPos() const;
@ -98,12 +116,6 @@ class EffectsHandlerImpl : public EffectsHandler
virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const; virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const;
virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const; virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const;
virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const; virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const;
virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const;
virtual bool optionRollOverDesktops() const;
virtual int desktopToLeft( int desktop, bool wrap ) const;
virtual int desktopToRight( int desktop, bool wrap ) const;
virtual int desktopUp( int desktop, bool wrap ) const;
virtual int desktopDown( int desktop, bool wrap ) const;
virtual double animationTimeFactor() const; virtual double animationTimeFactor() const;
virtual WindowQuadType newWindowQuadType(); virtual WindowQuadType newWindowQuadType();

View File

@ -148,7 +148,7 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
case Upwards: case Upwards:
firstFaceRot.axis = RotationData::XAxis; firstFaceRot.axis = RotationData::XAxis;
secondFaceRot.axis = RotationData::XAxis; secondFaceRot.axis = RotationData::XAxis;
secondDesktop = effects->desktopUp( front_desktop, true); secondDesktop = effects->desktopAbove( front_desktop, true);
firstFaceRot.angle = -90.0f*timeLine.value(); firstFaceRot.angle = -90.0f*timeLine.value();
secondFaceRot.angle = 90.0f*(1.0f - timeLine.value()); secondFaceRot.angle = 90.0f*(1.0f - timeLine.value());
point = rect.height()/2*tan(45.0f*M_PI/180.0f); point = rect.height()/2*tan(45.0f*M_PI/180.0f);
@ -156,7 +156,7 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
case Downwards: case Downwards:
firstFaceRot.axis = RotationData::XAxis; firstFaceRot.axis = RotationData::XAxis;
secondFaceRot.axis = RotationData::XAxis; secondFaceRot.axis = RotationData::XAxis;
secondDesktop = effects->desktopDown( front_desktop, true ); secondDesktop = effects->desktopBelow( front_desktop, true );
firstFaceRot.angle = 90.0f*timeLine.value(); firstFaceRot.angle = 90.0f*timeLine.value();
secondFaceRot.angle = -90.0f*(1.0f - timeLine.value()); secondFaceRot.angle = -90.0f*(1.0f - timeLine.value());
point = rect.height()/2*tan(45.0f*M_PI/180.0f); point = rect.height()/2*tan(45.0f*M_PI/180.0f);
@ -233,10 +233,10 @@ void CubeSlideEffect::postPaintScreen()
front_desktop = effects->desktopToRight( front_desktop, true ); front_desktop = effects->desktopToRight( front_desktop, true );
break; break;
case Upwards: case Upwards:
front_desktop = effects->desktopUp( front_desktop, true ); front_desktop = effects->desktopAbove( front_desktop, true );
break; break;
case Downwards: case Downwards:
front_desktop = effects->desktopDown( front_desktop, true ); front_desktop = effects->desktopBelow( front_desktop, true );
break; break;
} }
timeLine.setProgress( 0.0 ); timeLine.setProgress( 0.0 );
@ -265,47 +265,43 @@ void CubeSlideEffect::desktopChanged( int old )
slideRotations.enqueue( direction ); slideRotations.enqueue( direction );
} }
// calculate distance in respect to pager // calculate distance in respect to pager
int x, y; QPoint diff = effects->desktopGridCoords( effects->currentDesktop() ) - effects->desktopGridCoords( old );
Qt::Orientation orientation; if( qAbs( diff.x() ) > effects->desktopGridWidth()/2 )
effects->calcDesktopLayout( &x, &y, &orientation );
int x_distance = (( effects->currentDesktop() - 1 ) % x ) - (( old - 1 ) % x );
if( qAbs( x_distance ) > x/2 )
{ {
int sign = -1 * (x_distance/qAbs( x_distance )); int sign = -1 * (diff.x()/qAbs( diff.x() ));
x_distance = sign * ( x - qAbs( x_distance )); diff.setX( sign * ( effects->desktopGridWidth() - qAbs( diff.x() )));
} }
if( x_distance > 0 ) if( diff.x() > 0 )
{ {
for( int i=0; i<x_distance; i++ ) for( int i=0; i<diff.x(); i++ )
{ {
slideRotations.enqueue( Right ); slideRotations.enqueue( Right );
} }
} }
else if( x_distance < 0 ) else if( diff.x() < 0 )
{ {
x_distance *= -1; diff.setX( -diff.x() );
for( int i=0; i<x_distance; i++ ) for( int i=0; i<diff.x(); i++ )
{ {
slideRotations.enqueue( Left ); slideRotations.enqueue( Left );
} }
} }
int y_distance = (( effects->currentDesktop() -1 ) / x ) - (( old - 1 ) / x ); if( qAbs( diff.y() ) > effects->desktopGridHeight()/2 )
if( qAbs( y_distance ) > y/2 )
{ {
int sign = -1 * (y_distance/qAbs( y_distance )); int sign = -1 * (diff.y()/qAbs( diff.y() ));
y_distance = sign * ( y - qAbs( y_distance )); diff.setY( sign * ( effects->desktopGridHeight() - qAbs( diff.y() )));
} }
if( y_distance > 0 ) if( diff.y() > 0 )
{ {
for( int i=0; i<y_distance; i++ ) for( int i=0; i<diff.y(); i++ )
{ {
slideRotations.enqueue( Downwards ); slideRotations.enqueue( Downwards );
} }
} }
if( y_distance < 0 ) if( diff.y() < 0 )
{ {
y_distance *= -1; diff.setY( -diff.y() );
for( int i=0; i<y_distance; i++ ) for( int i=0; i<diff.y(); i++ )
{ {
slideRotations.enqueue( Upwards ); slideRotations.enqueue( Upwards );
} }

View File

@ -37,6 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin namespace KWin
{ {
// WARNING, TODO: This effect relies on the desktop layout being EWMH-compliant.
KWIN_EFFECT( desktopgrid, DesktopGridEffect ) KWIN_EFFECT( desktopgrid, DesktopGridEffect )
DesktopGridEffect::DesktopGridEffect() DesktopGridEffect::DesktopGridEffect()
@ -755,7 +757,8 @@ void DesktopGridEffect::setup()
{ {
default: default:
case LayoutPager: case LayoutPager:
effects->calcDesktopLayout( &gridSize.rwidth(), &gridSize.rheight(), &orientation ); orientation = Qt::Horizontal;
gridSize = effects->desktopGridSize();
break; break;
case LayoutAutomatic: case LayoutAutomatic:
y = sqrt( numDesktops ) + 0.5; y = sqrt( numDesktops ) + 0.5;
@ -767,7 +770,7 @@ void DesktopGridEffect::setup()
gridSize.setHeight( y ); gridSize.setHeight( y );
break; break;
case LayoutCustom: case LayoutCustom:
effects->calcDesktopLayout( &gridSize.rwidth(), &gridSize.rheight(), &orientation ); orientation = Qt::Horizontal;
gridSize.setWidth( ceil( effects->numberOfDesktops() / double( customLayoutRows ))); gridSize.setWidth( ceil( effects->numberOfDesktops() / double( customLayoutRows )));
gridSize.setHeight( customLayoutRows ); gridSize.setHeight( customLayoutRows );
break; break;

View File

@ -162,26 +162,8 @@ void HighlightWindowEffect::propertyNotify( EffectWindow* w, long a )
thumbRect = m_highlightedWindow->geometry(); thumbRect = m_highlightedWindow->geometry();
// Determine position of desktop relative to the current one // Determine position of desktop relative to the current one
QSize grid; QPoint direction = effects->desktopGridCoords( m_highlightedWindow->desktop() ) -
Qt::Orientation orientation; effects->desktopGridCoords( effects->currentDesktop() );
effects->calcDesktopLayout( &grid.rwidth(), &grid.rheight(), &orientation );
QPoint currentDesktop;
QPoint targetDesktop;
if( orientation == Qt::Horizontal )
{
currentDesktop.setX(( effects->currentDesktop() - 1 ) % grid.width() + 1 );
currentDesktop.setY(( effects->currentDesktop() - 1 ) / grid.width() + 1 );
targetDesktop.setX(( m_highlightedWindow->desktop() - 1 ) % grid.width() + 1 );
targetDesktop.setY(( m_highlightedWindow->desktop() - 1 ) / grid.width() + 1 );
}
else
{
currentDesktop.setX(( effects->currentDesktop() - 1 ) / grid.height() + 1 );
currentDesktop.setY(( effects->currentDesktop() - 1 ) % grid.height() + 1 );
targetDesktop.setX(( m_highlightedWindow->desktop() - 1 ) / grid.height() + 1 );
targetDesktop.setY(( m_highlightedWindow->desktop() - 1 ) % grid.height() + 1 );
}
QPoint direction = targetDesktop - currentDesktop;
// Draw a line from the center of the current desktop to the center of the target desktop. // Draw a line from the center of the current desktop to the center of the target desktop.
QPointF desktopLine( 0, 0, direction.x() * screenArea.width(), direction.y() * screenArea.height() ); QPointF desktopLine( 0, 0, direction.x() * screenArea.width(), direction.y() * screenArea.height() );

View File

@ -92,17 +92,14 @@ void SlideEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
of it, the destination is computed from the current desktop. Positions of desktops of it, the destination is computed from the current desktop. Positions of desktops
are done using their topleft corner. are done using their topleft corner.
*/ */
QPoint destPos = desktopRect( effects->currentDesktop(), false ).topLeft(); QPoint destPos = desktopRect( effects->currentDesktop() ).topLeft();
QPoint diffPos = destPos - slide_start_pos; QPoint diffPos = destPos - slide_start_pos;
int w = 0; int w = 0;
int h = 0; int h = 0;
if( effects->optionRollOverDesktops()) if( effects->optionRollOverDesktops())
{ {
int x, y; w = effects->workspaceWidth();
Qt::Orientation orientation; h = effects->workspaceHeight();
effects->calcDesktopLayout( &x, &y, &orientation );
w = x * displayWidth();
h = y * displayHeight();
// wrap around if shorter // wrap around if shorter
if( diffPos.x() > 0 && diffPos.x() > w / 2 ) if( diffPos.x() > 0 && diffPos.x() > w / 2 )
diffPos.setX( diffPos.x() - w ); diffPos.setX( diffPos.x() - w );
@ -128,7 +125,7 @@ void SlideEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data )
desktop <= effects->numberOfDesktops(); desktop <= effects->numberOfDesktops();
++desktop ) ++desktop )
{ {
QRect rect = desktopRect( desktop, false ); QRect rect = desktopRect( desktop );
if( currentRegion.contains( rect )) // part of the desktop needs painting if( currentRegion.contains( rect )) // part of the desktop needs painting
{ {
painting_desktop = desktop; painting_desktop = desktop;
@ -176,27 +173,10 @@ void SlideEffect::postPaintScreen()
} }
// Gives a position of the given desktop when all desktops are arranged in a grid // Gives a position of the given desktop when all desktops are arranged in a grid
QRect SlideEffect::desktopRect( int desktop, bool scaled ) const QRect SlideEffect::desktopRect( int desktop ) const
{ {
int x, y; QRect rect( 0, 0, displayWidth(), displayHeight() );
Qt::Orientation orientation; rect.translate( effects->desktopCoords( desktop ));
effects->calcDesktopLayout( &x, &y, &orientation );
--desktop; // make it start with 0
QRect rect;
if( orientation == Qt::Horizontal )
rect = QRect(( desktop % x ) * displayWidth(), ( desktop / x ) * displayHeight(),
displayWidth(), displayHeight());
else
rect = QRect(( desktop / y ) * displayWidth(), ( desktop % y ) * displayHeight(),
displayWidth(), displayHeight());
if( !scaled )
return rect;
QRect current = desktopRect( effects->currentDesktop(), false );
double progress = mTimeLine.value();
rect = QRect( qRound( interpolate( rect.x() - current.x(), rect.x() / double( x ), progress )),
qRound( interpolate( rect.y() - current.y(), rect.y() / double( y ), progress )),
qRound( interpolate( rect.width(), displayWidth() / double( x ), progress )),
qRound( interpolate( rect.height(), displayHeight() / double( y ), progress )));
return rect; return rect;
} }
@ -207,16 +187,13 @@ void SlideEffect::desktopChanged( int old )
if( slide ) // old slide still in progress if( slide ) // old slide still in progress
{ {
QPoint diffPos = desktopRect( old, false ).topLeft() - slide_start_pos; QPoint diffPos = desktopRect( old ).topLeft() - slide_start_pos;
int w = 0; int w = 0;
int h = 0; int h = 0;
if( effects->optionRollOverDesktops()) if( effects->optionRollOverDesktops())
{ {
int x, y; w = effects->workspaceWidth();
Qt::Orientation orientation; h = effects->workspaceHeight();
effects->calcDesktopLayout( &x, &y, &orientation );
w = x * displayWidth();
h = y * displayHeight();
// wrap around if shorter // wrap around if shorter
if( diffPos.x() > 0 && diffPos.x() > w / 2 ) if( diffPos.x() > 0 && diffPos.x() > w / 2 )
diffPos.setX( diffPos.x() - w ); diffPos.setX( diffPos.x() - w );
@ -236,7 +213,7 @@ void SlideEffect::desktopChanged( int old )
currentRegion |= ( currentRegion & QRect( w, 0, w, h )).translated( -w, 0 ); currentRegion |= ( currentRegion & QRect( w, 0, w, h )).translated( -w, 0 );
currentRegion |= ( currentRegion & QRect( 0, h, w, h )).translated( 0, -h ); currentRegion |= ( currentRegion & QRect( 0, h, w, h )).translated( 0, -h );
} }
QRect rect = desktopRect( effects->currentDesktop(), false ); QRect rect = desktopRect( effects->currentDesktop() );
if( currentRegion.contains( rect )) if( currentRegion.contains( rect ))
{ // current position is in new current desktop (e.g. quickly changing back), { // current position is in new current desktop (e.g. quickly changing back),
// don't do full progress // don't do full progress
@ -265,7 +242,7 @@ void SlideEffect::desktopChanged( int old )
if( effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this ) if( effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this )
return; return;
mTimeLine.setProgress(0); mTimeLine.setProgress(0);
slide_start_pos = desktopRect( old, false ).topLeft(); slide_start_pos = desktopRect( old ).topLeft();
slide = true; slide = true;
effects->setActiveFullScreenEffect( this ); effects->setActiveFullScreenEffect( this );
} }

View File

@ -42,7 +42,7 @@ class SlideEffect
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
virtual void desktopChanged( int old ); virtual void desktopChanged( int old );
private: private:
QRect desktopRect( int desktop, bool scaled ) const; QRect desktopRect( int desktop ) const;
TimeLine mTimeLine; TimeLine mTimeLine;
int painting_desktop; int painting_desktop;
bool slide; bool slide;

View File

@ -164,7 +164,7 @@ X-KDE-Library=kwin4_effect_cooleffect
#define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor )) #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
#define KWIN_EFFECT_API_VERSION_MAJOR 0 #define KWIN_EFFECT_API_VERSION_MAJOR 0
#define KWIN_EFFECT_API_VERSION_MINOR 60 #define KWIN_EFFECT_API_VERSION_MINOR 61
#define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \ #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR ) KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
@ -547,23 +547,96 @@ class KWIN_EXPORT EffectsHandler
virtual EffectWindow* activeWindow() const = 0 ; virtual EffectWindow* activeWindow() const = 0 ;
virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0; virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0; virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
//
// Desktops
/**
* @returns The ID of the current desktop.
*/
virtual int currentDesktop() const = 0; virtual int currentDesktop() const = 0;
/**
* @returns Total number of desktops currently in existance.
*/
virtual int numberOfDesktops() const = 0; virtual int numberOfDesktops() const = 0;
/**
* Set the current desktop to @a desktop.
*/
virtual void setCurrentDesktop( int desktop ) = 0; virtual void setCurrentDesktop( int desktop ) = 0;
/**
* @returns The size of desktop layout in grid units.
*/
virtual QSize desktopGridSize() const = 0;
/**
* @returns The width of desktop layout in grid units.
*/
virtual int desktopGridWidth() const = 0;
/**
* @returns The height of desktop layout in grid units.
*/
virtual int desktopGridHeight() const = 0;
/**
* @returns The width of desktop layout in pixels.
*/
virtual int workspaceWidth() const = 0;
/**
* @returns The height of desktop layout in pixels.
*/
virtual int workspaceHeight() const = 0;
/**
* @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.
*/
virtual int desktopAtCoords( QPoint coords ) const = 0;
/**
* @returns The coords of desktop @a id in grid units.
*/
virtual QPoint desktopGridCoords( int id ) const = 0;
/**
* @returns The coords of the top-left corner of desktop @a id in pixels.
*/
virtual QPoint desktopCoords( int id ) const = 0;
/**
* @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.
*/
virtual int desktopAbove( int desktop = 0, bool wrap = true ) const = 0;
/**
* @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.
*/
virtual int desktopToRight( int desktop = 0, bool wrap = true ) const = 0;
/**
* @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.
*/
virtual int desktopBelow( int desktop = 0, bool wrap = true ) const = 0;
/**
* @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.
*/
virtual int desktopToLeft( int desktop = 0, bool wrap = true ) const = 0;
/**
* @returns Whether or not the desktop layout is allowed to be modified by the user.
*/
virtual bool desktopLayoutIsDynamic() const = 0;
/**
* Create new desktop at the point @a coords
* @returns The ID of the created desktop
*/
virtual int addDesktop( QPoint coords ) = 0;
/**
* 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.
*/
virtual void deleteDesktop( int id ) = 0;
virtual QString desktopName( int desktop ) const = 0; virtual QString desktopName( int desktop ) const = 0;
virtual bool optionRollOverDesktops() const = 0;
virtual int activeScreen() const = 0; // Xinerama virtual int activeScreen() const = 0; // Xinerama
virtual int numScreens() const = 0; // Xinerama virtual int numScreens() const = 0; // Xinerama
virtual int screenNumber( const QPoint& pos ) const = 0; // Xinerama virtual int screenNumber( const QPoint& pos ) const = 0; // Xinerama
virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0; virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0; virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0; virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;
virtual bool optionRollOverDesktops() const = 0;
virtual int desktopToLeft( int desktop, bool wrap ) const = 0;
virtual int desktopToRight( int desktop, bool wrap ) const = 0;
virtual int desktopUp( int desktop, bool wrap ) const = 0;
virtual int desktopDown( int desktop, bool wrap ) const = 0;
/** /**
* Factor by which animation speed in the effect should be modified (multiplied). * Factor by which animation speed in the effect should be modified (multiplied).
* If configurable in the effect itself, the option should have also 'default' * If configurable in the effect itself, the option should have also 'default'

View File

@ -124,7 +124,6 @@ Workspace::Workspace( bool restore )
, global_shortcuts_disabled_for_client( false ) , global_shortcuts_disabled_for_client( false )
, workspaceInit( true ) , workspaceInit( true )
, startup( 0 ) , startup( 0 )
, layoutOrientation( Qt::Vertical )
, managing_topmenus( false ) , managing_topmenus( false )
, topmenu_selection( NULL ) , topmenu_selection( NULL )
, topmenu_watcher( NULL ) , topmenu_watcher( NULL )
@ -1607,32 +1606,12 @@ void Workspace::updateDesktopLayout()
int height = rootInfo->desktopLayoutColumnsRows().height(); int height = rootInfo->desktopLayoutColumnsRows().height();
if( width == 0 && height == 0 ) // Not given, set default layout if( width == 0 && height == 0 ) // Not given, set default layout
height = 2; height = 2;
layoutOrientation = rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ?
Qt::Horizontal : Qt::Vertical;
desktopLayout.setNETDesktopLayout( desktopLayout.setNETDesktopLayout(
layoutOrientation, width, height, rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical,
0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now. width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now.
); );
} }
void Workspace::calcDesktopLayout( int* xp, int* yp, Qt::Orientation* orientation ) const
{ // TODO: Deprecated, use desktopLayout instead
int x = desktopLayout.gridWidth(); // <= 0 means compute it from the other and total number of desktops
int y = desktopLayout.gridHeight();
if(( x <= 0 ) && ( y > 0 ))
x = ( numberOfDesktops() + y - 1 ) / y;
else if(( y <= 0) && ( x > 0 ))
y = ( numberOfDesktops() + x - 1 ) / x;
if( x <= 0 )
x = 1;
if( y <= 0 )
y = 1;
*xp = x;
*yp = y;
*orientation = layoutOrientation;
}
void Workspace::killWindowId( Window window_to_kill ) void Workspace::killWindowId( Window window_to_kill )
{ {
if( window_to_kill == None ) if( window_to_kill == None )

View File

@ -167,7 +167,7 @@ class Workspace : public QObject, public KDecorationDefines
*/ */
int numberOfDesktops() const; int numberOfDesktops() const;
void setNumberOfDesktops( int n ); void setNumberOfDesktops( int n );
void calcDesktopLayout( int* x, int* y, Qt::Orientation* orientation ) const; DesktopLayout* getDesktopLayout();
int desktopToRight( int desktop, bool wrap ) const; int desktopToRight( int desktop, bool wrap ) const;
int desktopToLeft( int desktop, bool wrap ) const; int desktopToLeft( int desktop, bool wrap ) const;
int desktopUp( int desktop, bool wrap ) const; int desktopUp( int desktop, bool wrap ) const;
@ -747,7 +747,6 @@ class Workspace : public QObject, public KDecorationDefines
int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something int electric_reserved[ELECTRIC_COUNT]; // Corners/edges used by something
DesktopLayout desktopLayout; DesktopLayout desktopLayout;
Qt::Orientation layoutOrientation; // TODO: Deprecated, remove when calcDesktopLayout() is.
Placement* initPositioning; Placement* initPositioning;
@ -861,6 +860,11 @@ inline int Workspace::numberOfDesktops() const
return desktopLayout.numberOfDesktops(); return desktopLayout.numberOfDesktops();
} }
inline DesktopLayout* Workspace::getDesktopLayout()
{
return &desktopLayout;
}
inline int Workspace::desktopToRight( int desktop, bool wrap ) const inline int Workspace::desktopToRight( int desktop, bool wrap ) const
{ {
return desktopLayout.desktopToRight( desktop, wrap ); return desktopLayout.desktopToRight( desktop, wrap );