[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kwin_composite
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2007-04-16 22:47:52
Message-ID: 1176763672.418899.13892.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 654796 by lunakl:

Add the ability to move windows around in DesktopGridEffect.



 M  +36 -3     effects.cpp  
 M  +3 -0      effects.h  
 M  +102 -7    effects/desktopgrid.cpp  
 M  +6 -0      effects/desktopgrid.h  
 M  +3 -0      lib/kwineffects.h  


--- branches/work/kwin_composite/effects.cpp #654795:654796
@@ -278,6 +278,20 @@
     return Workspace::self()->activeClient() ? \
Workspace::self()->activeClient()->effectWindow() : NULL;  }
 
+void EffectsHandlerImpl::moveWindow( EffectWindow* w, const QPoint& pos )
+    {
+    Client* cl = dynamic_cast< Client* >( \
static_cast<EffectWindowImpl*>(w)->window()); +    if( cl && cl->isMovable())
+        cl->move( pos );
+    }
+
+void EffectsHandlerImpl::windowToDesktop( EffectWindow* w, int desktop )
+    {
+    Client* cl = dynamic_cast< Client* >( \
static_cast<EffectWindowImpl*>(w)->window()); +    if( cl && cl->isMovable())
+        Workspace::self()->sendClientToDesktop( cl, desktop, true );
+    }
+
 int EffectsHandlerImpl::currentDesktop() const
     {
     return Workspace::self()->currentDesktop();
@@ -439,12 +453,24 @@
             switch( e->type )
                 {
                 case ButtonPress:
+                    {
+                    XButtonEvent* e2 = &e->xbutton;
+                    Qt::MouseButton button = x11ToQtMouseButton( e2->button );
+                    Qt::MouseButtons buttons = x11ToQtMouseButtons( e2->state ) | \
button; +                    QMouseEvent ev( QEvent::MouseButtonPress,
+                        QPoint( e2->x, e2->y ), QPoint( e2->x_root, e2->y_root ),
+                        button, buttons, x11ToQtKeyboardModifiers( e2->state ));
+                    pos.first->windowInputMouseEvent( pos.second, &ev );
+                    break; // --->
+                    }
                 case ButtonRelease:
                     {
                     XButtonEvent* e2 = &e->xbutton;
-                    QMouseEvent ev( e->type == ButtonPress ? \
                QEvent::MouseButtonPress : QEvent::MouseButtonRelease,
-                        QPoint( e2->x, e2->y ), QPoint( e2->x_root, e2->y_root ), \
                x11ToQtMouseButton( e2->button ),
-                        x11ToQtMouseButtons( e2->state ), x11ToQtKeyboardModifiers( \
e2->state )); +                    Qt::MouseButton button = x11ToQtMouseButton( \
e2->button ); +                    Qt::MouseButtons buttons = x11ToQtMouseButtons( \
e2->state ) & ~button; +                    QMouseEvent ev( \
QEvent::MouseButtonRelease, +                        QPoint( e2->x, e2->y ), QPoint( \
e2->x_root, e2->y_root ), +                        button, buttons, \
x11ToQtKeyboardModifiers( e2->state ));  pos.first->windowInputMouseEvent( \
pos.second, &ev );  break; // --->
                     }
@@ -785,6 +811,13 @@
     return toplevel->rect();
     }
 
+bool EffectWindowImpl::isMovable() const
+    {
+    if( Client* c = dynamic_cast< Client* >( toplevel ))
+        return c->isMovable();
+    return false;
+    }
+
 bool EffectWindowImpl::isUserMove() const
     {
     if( Client* c = dynamic_cast< Client* >( toplevel ))
--- branches/work/kwin_composite/effects.h #654795:654796
@@ -36,6 +36,8 @@
 
         virtual void activateWindow( EffectWindow* c );
         virtual EffectWindow* activeWindow() const;
+        virtual void moveWindow( EffectWindow* w, const QPoint& pos );
+        virtual void windowToDesktop( EffectWindow* w, int desktop );
 
         virtual int currentDesktop() const;
         virtual int numberOfDesktops() const;
@@ -139,6 +141,7 @@
         virtual QPoint pos() const;
         virtual QSize size() const;
         virtual QRect rect() const;
+        virtual bool isMovable() const;
         virtual bool isUserMove() const;
         virtual bool isUserResize() const;
         virtual QRect iconGeometry() const;
--- branches/work/kwin_composite/effects/desktopgrid.cpp #654795:654796
@@ -26,6 +26,8 @@
     : progress( 0 )
     , activated( false )
     , keyboard_grab( false )
+    , was_window_move( false )
+    , window_move( NULL )
     , slide( false )
     {
     KActionCollection* actionCollection = new KActionCollection( this );
@@ -95,6 +97,8 @@
             w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
         else
             w->disablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
+        if( w == window_move )
+            *mask |= PAINT_WINDOW_TRANSFORMED;
         }
     effects->prePaintWindow( w, mask, paint, clip, time );
     }
@@ -213,7 +217,17 @@
         }
     else if( progress != 0 )
         {
-        if( painting_desktop != hover_desktop )
+        if( w == window_move )
+            {
+            int x, y;
+            Qt::Orientation orientation;
+            effects->calcDesktopLayout( &x, &y, &orientation );
+            QRect desktop = desktopRect( w->isOnCurrentDesktop()
+                ? effects->currentDesktop() : w->desktop(), false );
+            data.xTranslate += window_move_pos.x() * x - ( desktop.x() + w->x());
+            data.yTranslate += window_move_pos.y() * y - ( desktop.y() + w->y());
+            }
+        else if( painting_desktop != hover_desktop )
             data.brightness *= 0.7;
         }
     effects->paintWindow( w, mask, region, data );    
@@ -264,6 +278,19 @@
     return 0;
     }
 
+QRect DesktopGridEffect::windowRect( EffectWindow* w ) const
+    {
+    int x, y;
+    Qt::Orientation orientation;
+    effects->calcDesktopLayout( &x, &y, &orientation );
+    if( w == window_move ) // it's being moved, return moved position
+        return QRect( window_move_pos, QSize( w->width() / x, w->height() / y ));
+    QRect desktop = desktopRect( w->isOnCurrentDesktop()
+        ? effects->currentDesktop() : w->desktop(), true );
+    return QRect( desktop.x() + w->x() / x, desktop.y() + w->y() / y,
+        w->width() / x, w->height() / y );
+    }
+
 void DesktopGridEffect::desktopChanged( int old )
     {
     if( activated )
@@ -357,34 +384,102 @@
     if( keyboard_grab )
         effects->ungrabKeyboard();
     keyboard_grab = false;
+    window_move = NULL;
     effects->destroyInputWindow( input );
     effects->addRepaintFull(); // to get rid of hover
     }
 
 void DesktopGridEffect::windowInputMouseEvent( Window, QEvent* e )
     {
-    if( e->type() == QEvent::MouseButtonPress )
-        {
-        effects->setCurrentDesktop( posToDesktop( static_cast< QMouseEvent* >( e \
                )->pos()));
-        setActive( false );
-        }
+    if( e->type() != QEvent::MouseMove
+        && e->type() != QEvent::MouseButtonPress
+        && e->type() != QEvent::MouseButtonRelease )
+        return;
+    QMouseEvent* me = static_cast< QMouseEvent* >( e );
     if( e->type() == QEvent::MouseMove )
         {
-        int d = posToDesktop( static_cast< QMouseEvent* >( e )->pos());
+        // highlight desktop under mouse
+        int d = posToDesktop( me->pos());
         if( d != hover_desktop )
             {
             effects->addRepaint( desktopRect( hover_desktop, true ));
             hover_desktop = d;
             effects->addRepaint( desktopRect( hover_desktop, true ));
             }
+        if( window_move != NULL ) // handle window moving
+            {
+            was_window_move = true;
+            // windowRect() handles window_move specially
+            effects->addRepaint( windowRect( window_move ));
+            window_move_pos = me->pos() + window_move_diff;
+            effects->addRepaint( windowRect( window_move ));
+            }
         }
+    if( e->type() == QEvent::MouseButtonPress && me->buttons() == Qt::LeftButton )
+        {
+        EffectWindowList windows = effects->stackingOrder();
+        // qReverse()
+        EffectWindowList::Iterator begin = windows.begin();
+        EffectWindowList::Iterator end = windows.end();
+        --end;
+        while( begin < end )
+            qSwap( *begin++, *end-- );
+        window_move = NULL;
+        foreach( EffectWindow* w, windows )
+            {
+            QRect rect = windowRect( w );
+            if( rect.contains( me->pos()))
+                { // window is under mouse
+                if( w->isMovable())
+                    { // prepare it for moving
+                    window_move = w;
+                    window_move_pos = rect.topLeft();
+                    window_move_diff = window_move_pos - me->pos();
+                    }
+                break;
+                }
+            }
+        }
+    if( e->type() == QEvent::MouseButtonRelease && me->buttons() == 0
+        && me->button() == Qt::LeftButton )
+        {
+        if( was_window_move )
+            {
+            if( window_move != NULL )
+                {
+                QRect rect = windowRect( window_move );
+                int desktop = posToDesktop( rect.center());
+                // to desktop's coordinates
+                rect.moveBy( -desktopRect( desktop, true ).topLeft());
+                int x, y;
+                Qt::Orientation orientation;
+                effects->calcDesktopLayout( &x, &y, &orientation );
+                effects->moveWindow( window_move, QPoint( rect.x() * x, rect.y() * y \
)); +                effects->windowToDesktop( window_move, desktop );
+                window_move = NULL;
+                }
+            was_window_move = false;
+            }
+        else
+            {
+            effects->setCurrentDesktop( posToDesktop( me->pos()));
+            setActive( false );
+            }
+        }
     }
 
+void DesktopGridEffect::windowClosed( EffectWindow* w )
+    {
+    if( w == window_move )
+        window_move = NULL;
+    }
+
 void DesktopGridEffect::grabbedKeyboardEvent( QKeyEvent* e )
     {
     // TODO
     }
 
+
 } // namespace
 
 #include "desktopgrid.moc"
--- branches/work/kwin_composite/effects/desktopgrid.h #654795:654796
@@ -28,6 +28,7 @@
         virtual void postPaintScreen();
         virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, \
                QRegion* clip, int time );
         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, \
WindowPaintData& data ); +        virtual void windowClosed( EffectWindow* w );
         virtual void desktopChanged( int old );
         virtual void windowInputMouseEvent( Window w, QEvent* e );
         virtual void grabbedKeyboardEvent( QKeyEvent* e );
@@ -36,6 +37,7 @@
     private:
         QRect desktopRect( int desktop, bool scaled ) const;
         int posToDesktop( const QPoint& pos ) const;
+        QRect windowRect( EffectWindow* w ) const; // returns always scaled
         void setActive( bool active );
         void setup();
         void finish();
@@ -47,6 +49,10 @@
         int hover_desktop;
         Window input;
         bool keyboard_grab;
+        bool was_window_move;
+        EffectWindow* window_move;
+        QPoint window_move_diff;
+        QPoint window_move_pos;
         bool slide;
         QPoint slide_start_pos;
         bool slide_painting_sticky;
--- branches/work/kwin_composite/lib/kwineffects.h #654795:654796
@@ -185,6 +185,8 @@
         // functions that allow controlling windows/desktop
         virtual void activateWindow( EffectWindow* c ) = 0;
         virtual EffectWindow* activeWindow() const = 0 ;
+        virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
+        virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
         // 
         virtual int currentDesktop() const = 0;
         virtual int numberOfDesktops() const = 0;
@@ -276,6 +278,7 @@
         virtual QPoint pos() const = 0;
         virtual QSize size() const = 0;
         virtual QRect rect() const = 0;
+        virtual bool isMovable() const = 0;
         virtual bool isUserMove() const = 0;
         virtual bool isUserResize() const = 0;
         virtual QRect iconGeometry() const = 0;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic