Set the transformed geometry in WindowMotionManager when a window is dropped to a desktop in grid. This way the window does not jump to a random position on mouse release.

svn path=/trunk/KDE/kdebase/workspace/; revision=1104672
This commit is contained in:
Martin Gräßlin 2010-03-18 09:27:01 +00:00
parent 3e4094ce72
commit 9a86e83d6e
4 changed files with 50 additions and 0 deletions

View file

@ -638,10 +638,16 @@ void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
{
if( windowMove->isOnAllDesktops() )
{
const int targetDesktop = posToDesktop( cursorPos() );
for( int i=0; i<effects->numberOfDesktops(); ++i )
{
WindowMotionManager& manager = m_managers[ (i)*(effects->numScreens()) + windowMove->screen() ];
manager.manage( windowMove );
if( i+1 == targetDesktop )
{
// for the desktop the window is dropped on, we use the current geometry
manager.setTransformedGeometry( windowMove, moveGeometryToDesktop( targetDesktop ) );
}
m_proxy->calculateWindowTransformations( manager.managedWindows(), windowMove->screen(), manager );
}
}
@ -649,6 +655,7 @@ void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
{
WindowMotionManager& manager = m_managers[ (windowMove->desktop()-1)*(effects->numScreens()) + windowMove->screen() ];
manager.manage( windowMove );
manager.setTransformedGeometry( windowMove, moveGeometryToDesktop( windowMove->desktop() ) );
m_proxy->calculateWindowTransformations( manager.managedWindows(), windowMove->screen(), manager );
}
effects->addRepaintFull();
@ -1234,6 +1241,35 @@ bool DesktopGridEffect::isUsingPresentWindows() const
return (m_proxy != NULL);
}
// transforms the geometry of the moved window to a geometry on the desktop
// internal method only used when a window is dropped onto a desktop
QRectF DesktopGridEffect::moveGeometryToDesktop( int desktop ) const
{
QPointF point = unscalePos( m_windowMoveGeometry.topLeft() + cursorPos() - m_windowMoveStartPoint );
const double scaleFactor = scale[ windowMove->screen() ];
if( posToDesktop( m_windowMoveGeometry.topLeft() + cursorPos() - m_windowMoveStartPoint ) != desktop )
{
// topLeft is not on the desktop - check other corners
// if all corners are not on the desktop the window is bigger than the desktop - no matter what it will look strange
if( posToDesktop( m_windowMoveGeometry.topRight() + cursorPos() - m_windowMoveStartPoint ) == desktop )
{
point = unscalePos( m_windowMoveGeometry.topRight() + cursorPos() - m_windowMoveStartPoint ) -
QPointF( m_windowMoveGeometry.width(), 0) / scaleFactor;
}
else if( posToDesktop( m_windowMoveGeometry.bottomLeft() + cursorPos() - m_windowMoveStartPoint ) == desktop )
{
point = unscalePos( m_windowMoveGeometry.bottomLeft() + cursorPos() - m_windowMoveStartPoint ) -
QPointF(0, m_windowMoveGeometry.height() ) / scaleFactor;
}
else if( posToDesktop( m_windowMoveGeometry.bottomRight() + cursorPos() - m_windowMoveStartPoint ) == desktop )
{
point = unscalePos( m_windowMoveGeometry.bottomRight() + cursorPos() - m_windowMoveStartPoint ) -
QPointF(m_windowMoveGeometry.width(), m_windowMoveGeometry.height() ) / scaleFactor;
}
}
return QRectF( point, m_windowMoveGeometry.size() / scaleFactor );
}
} // namespace
#include "desktopgrid.moc"

View file

@ -75,6 +75,7 @@ class DesktopGridEffect
void finish();
bool isMotionManagerMovingWindows();
bool isUsingPresentWindows() const;
QRectF moveGeometryToDesktop( int desktop ) const;
QList<ElectricBorder> borderActivate;
int zoomDuration;

View file

@ -1316,6 +1316,13 @@ QRectF WindowMotionManager::transformedGeometry( EffectWindow *w ) const
return geometry;
}
void WindowMotionManager::setTransformedGeometry( EffectWindow *w, const QRectF &geometry )
{
m_managedWindows[ w ].translation.setValue( geometry.topLeft() );
m_managedWindows[ w ].scale.setValue( QPointF( geometry.width()/qreal(w->width()),
geometry.height()/qreal(w->height())));
}
QRectF WindowMotionManager::targetGeometry( EffectWindow *w ) const
{
QRectF geometry( w->geometry() );

View file

@ -1596,6 +1596,12 @@ class KWIN_EXPORT WindowMotionManager
* window.
*/
QRectF transformedGeometry( EffectWindow *w ) const;
/**
* Sets the current transformed geometry of a registered window to the given geometry.
* @see transformedGeometry
* @since 4.5
*/
void setTransformedGeometry( EffectWindow *w, const QRectF &geometry );
/**
* Retrieve the current target geometry of a registered
* window.