diff --git a/effects/desktopgrid/desktopgrid.cpp b/effects/desktopgrid/desktopgrid.cpp index 57271d9e35..56a8334aaa 100644 --- a/effects/desktopgrid/desktopgrid.cpp +++ b/effects/desktopgrid/desktopgrid.cpp @@ -638,10 +638,16 @@ void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e ) { if( windowMove->isOnAllDesktops() ) { + const int targetDesktop = posToDesktop( cursorPos() ); for( int i=0; inumberOfDesktops(); ++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" diff --git a/effects/desktopgrid/desktopgrid.h b/effects/desktopgrid/desktopgrid.h index a23a7e40d8..f6b73a1d1f 100644 --- a/effects/desktopgrid/desktopgrid.h +++ b/effects/desktopgrid/desktopgrid.h @@ -75,6 +75,7 @@ class DesktopGridEffect void finish(); bool isMotionManagerMovingWindows(); bool isUsingPresentWindows() const; + QRectF moveGeometryToDesktop( int desktop ) const; QList borderActivate; int zoomDuration; diff --git a/lib/kwineffects.cpp b/lib/kwineffects.cpp index da14546e9c..f79619fa20 100644 --- a/lib/kwineffects.cpp +++ b/lib/kwineffects.cpp @@ -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() ); diff --git a/lib/kwineffects.h b/lib/kwineffects.h index c2178415f3..19430caf2e 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -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.