From 6d7f113304fe12474dc1e66a3f1c3bcceac7b705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Fri, 5 Jul 2002 20:00:02 +0000 Subject: [PATCH] Implemented _NET_WM_MOVERESIZE. Fixed some minor bugs with resizing. svn path=/trunk/kdebase/kwin/; revision=165071 --- client.cpp | 62 +++++++++++++++++++++++++-------------------------- client.h | 4 +++- workspace.cpp | 13 ++++++++--- 3 files changed, 44 insertions(+), 35 deletions(-) diff --git a/client.cpp b/client.cpp index 73531de404..286a712af0 100644 --- a/client.cpp +++ b/client.cpp @@ -114,8 +114,6 @@ static int nullErrorHandler(Display *, XErrorEvent *) using namespace KWinInternal; -static bool resizeHorizontalDirectionFixed = FALSE; -static bool resizeVerticalDirectionFixed = FALSE; static bool blockAnimation = FALSE; static QRect* visible_bound = 0; @@ -1571,8 +1569,10 @@ void Client::resizeEvent( QResizeEvent * e) void Client::mouseMoveEvent( QMouseEvent * e) { if ( !buttonDown ) { - mode = mousePosition( e->pos() ); - setMouseCursor( mode ); + MousePosition newmode = mousePosition( e->pos() ); + if( newmode != mode ) + setMouseCursor( newmode ); + mode = newmode; geom = geometry(); return; } @@ -1601,7 +1601,6 @@ void Client::mouseMoveEvent( QMouseEvent * e) QPoint globalPos = e->globalPos(); // pos() + geometry().topLeft(); - QPoint p = globalPos + invertedMoveOffset; QPoint pp = globalPos - moveOffset; @@ -2643,6 +2642,7 @@ bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPo buttonDown = TRUE; moveOffset = mapFromGlobal( globalPos ); invertedMoveOffset = rect().bottomRight() - moveOffset; + setMouseCursor( mode ); startMoveResize(); break; case Options::MouseResize: { @@ -2672,8 +2672,6 @@ bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPo invertedMoveOffset = rect().bottomRight() - moveOffset; setMouseCursor( mode ); startMoveResize(); - resizeHorizontalDirectionFixed = FALSE; - resizeVerticalDirectionFixed = FALSE; } break; case Options::MouseNothing: // fall through @@ -2684,6 +2682,32 @@ bool Client::performMouseCommand( Options::MouseCommand command, QPoint globalPo return replay; } +// performs _NET_WM_MOVERESIZE +void Client::NETMoveResize( int x_root, int y_root, NET::Direction direction ) +{ + if( direction == NET::Move ) + performMouseCommand( Options::MouseMove, QPoint( x_root, y_root )); + else if( direction >= NET::TopLeft && direction <= NET::Left ) { + static const MousePosition convert[] = { TopLeft, Top, TopRight, Right, BottomRight, Bottom, + BottomLeft, Left }; + if (!isMovable()) + return; + geom=geometry(); + if ( isMaximized() ) { + // in case we were maximized, reset state + max_mode = MaximizeRestore; + maximizeChange(FALSE ); + Events::raise( Events::UnMaximize ); + info->setState( 0, NET::Max ); + } + buttonDown = TRUE; + moveOffset = mapFromGlobal( QPoint( x_root, y_root )); + invertedMoveOffset = rect().bottomRight() - moveOffset; + mode = convert[ direction ]; + setMouseCursor( mode ); + startMoveResize(); + } +} void Client::keyPressEvent( uint key_code ) { @@ -2696,39 +2720,15 @@ void Client::keyPressEvent( uint key_code ) switch ( key_code ) { case Key_Left: pos.rx() -= delta; - if ( isResize() && !resizeHorizontalDirectionFixed ) { - resizeHorizontalDirectionFixed = TRUE; - resizeVerticalDirectionFixed = FALSE; - mode = Right; - setMouseCursor( mode ); - } break; case Key_Right: pos.rx() += delta; - if ( isResize() && !resizeHorizontalDirectionFixed ) { - resizeHorizontalDirectionFixed = TRUE; - resizeVerticalDirectionFixed = FALSE; - mode = Right; - setMouseCursor( mode ); - } break; case Key_Up: pos.ry() -= delta; - if ( isResize() && !resizeVerticalDirectionFixed ) { - resizeVerticalDirectionFixed = TRUE; - resizeHorizontalDirectionFixed = FALSE; - mode = Bottom; - setMouseCursor( mode ); - } break; case Key_Down: pos.ry() += delta; - if ( isResize() && !resizeVerticalDirectionFixed ) { - resizeVerticalDirectionFixed = TRUE; - resizeHorizontalDirectionFixed = FALSE; - mode = Bottom; - setMouseCursor( mode ); - } break; case Key_Space: case Key_Return: diff --git a/client.h b/client.h index d515bcbaef..bf2d389730 100644 --- a/client.h +++ b/client.h @@ -212,7 +212,9 @@ public: void updateUserTime(); - const QPoint gravitate( bool invert ) const; + const QPoint gravitate( bool invert ) const; + + void NETMoveResize( int x_root, int y_root, NET::Direction direction ); public slots: void iconify(); diff --git a/workspace.cpp b/workspace.cpp index d33bc41970..0695cfc7f8 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -86,7 +86,12 @@ public: c->closeWindow(); } } - void moveResize(Window, int, int, unsigned long) { } + void moveResize(Window w, int x_root, int y_root, unsigned long direction) { + KWinInternal::Client* c = workspace->findClient( (WId) w ); + if ( c ) { + c->NETMoveResize( x_root, y_root, (Direction)direction); + } + } private: KWinInternal::Workspace* workspace; @@ -379,6 +384,7 @@ void Workspace::init() NET::WMIconGeometry | NET::WMIcon | NET::WMPid | + NET::WMMoveResize | NET::WMKDESystemTrayWinFor | NET::WMKDEFrameStrut ; @@ -1671,9 +1677,10 @@ void Workspace::performWindowOperation( Client* c, Options::WindowOperation op ) if ( !c ) return; - if (op == Options::MoveOp || op == Options::ResizeOp) { + if (op == Options::MoveOp) QCursor::setPos( c->geometry().center() ); - } + if (op == Options::ResizeOp) + QCursor::setPos( c->geometry().bottomRight()); switch ( op ) { case Options::MoveOp: c->performMouseCommand( Options::MouseMove, QCursor::pos() );