From 672c95e435a75dcdf3be3724b0bfa48ffefe4d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Sat, 14 Apr 2007 16:10:58 +0000 Subject: [PATCH] Work properly even with idle paint passes (react on mouse events). svn path=/branches/work/kwin_composite/; revision=653927 --- composite.cpp | 1 + effects/demo_taskbarthumbnail.cpp | 10 +++++- effects/demo_taskbarthumbnail.h | 2 +- effects/magnifier.cpp | 54 +++++++++++++++++-------------- effects/magnifier.h | 1 + effects/zoom.cpp | 6 ++++ effects/zoom.h | 1 + workspace.cpp | 19 ++++++++++- workspace.h | 1 + 9 files changed, 67 insertions(+), 28 deletions(-) diff --git a/composite.cpp b/composite.cpp index 5ccf8a87e9..473b0d442c 100644 --- a/composite.cpp +++ b/composite.cpp @@ -220,6 +220,7 @@ void Workspace::performCompositing() // is started. if( lastCompositePaint.elapsed() < 5 ) return; + checkCursorPos(); if( repaints_region.isEmpty() && !windowRepaintsPending()) // no damage { scene->idle(); diff --git a/effects/demo_taskbarthumbnail.cpp b/effects/demo_taskbarthumbnail.cpp index 2b17f17556..8e6c0de401 100644 --- a/effects/demo_taskbarthumbnail.cpp +++ b/effects/demo_taskbarthumbnail.cpp @@ -101,5 +101,13 @@ QRect TaskbarThumbnailEffect::getThumbnailPosition( EffectWindow* c, int* space return thumb; } -} // namespace +void TaskbarThumbnailEffect::cursorMoved( const QPoint& pos, Qt::MouseButtons ) + { + // this should check if the mouse position change actually means something + // (just like it should be done in prePaintScreen()), but since this effect + // will be replaced in the future, just trigger a repaint + if( pos != mLastCursorPos ) + effects->addRepaintFull(); + } +} // namespace diff --git a/effects/demo_taskbarthumbnail.h b/effects/demo_taskbarthumbnail.h index 10941306f1..7528efa3d0 100644 --- a/effects/demo_taskbarthumbnail.h +++ b/effects/demo_taskbarthumbnail.h @@ -34,7 +34,7 @@ class TaskbarThumbnailEffect virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time ); virtual void postPaintScreen(); - + void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons ); protected: QRect getThumbnailPosition( EffectWindow* c, int* space ) const; diff --git a/effects/magnifier.cpp b/effects/magnifier.cpp index 320ff331cd..bee9d9626c 100644 --- a/effects/magnifier.cpp +++ b/effects/magnifier.cpp @@ -25,6 +25,8 @@ namespace KWin KWIN_EFFECT( Magnifier, MagnifierEffect ) +const int FRAME_WIDTH = 5; + MagnifierEffect::MagnifierEffect() : zoom( 1 ) , target_zoom( 1 ) @@ -51,6 +53,7 @@ void MagnifierEffect::prePaintScreen( int* mask, QRegion* region, int time ) zoom = qMax( zoom * qMin( 1 - diff, 0.8 ), target_zoom ); } effects->prePaintScreen( mask, region, time ); + *region |= magnifierArea().adjusted( -FRAME_WIDTH, -FRAME_WIDTH, FRAME_WIDTH, FRAME_WIDTH ); } void MagnifierEffect::paintScreen( int mask, QRegion region, ScreenPaintData& data ) @@ -77,22 +80,22 @@ void MagnifierEffect::paintScreen( int mask, QRegion region, ScreenPaintData& da glPushAttrib( GL_CURRENT_BIT ); glColor4f( 0, 0, 0, 1 ); // black glBegin( GL_QUADS ); - glVertex2i( area.left() - 5, area.top() - 5 ); // top frame - glVertex2i( area.right() + 5, area.top() - 5 ); - glVertex2i( area.right() + 5, area.top() - 1 ); - glVertex2i( area.left() - 5, area.top() - 1 ); - glVertex2i( area.left() - 5, area.top() - 5 ); // left frame - glVertex2i( area.left() - 1, area.top() - 5 ); - glVertex2i( area.left() - 1, area.bottom() + 5 ); - glVertex2i( area.left() - 5, area.bottom() + 5 ); - glVertex2i( area.right() + 1, area.top() - 5 ); // right frame - glVertex2i( area.right() + 5, area.top() - 5 ); - glVertex2i( area.right() + 5, area.bottom() + 5 ); - glVertex2i( area.right() + 1, area.bottom() + 5 ); - glVertex2i( area.left() - 5, area.bottom() + 1 ); // bottom frame - glVertex2i( area.right() + 5, area.bottom() + 1 ); - glVertex2i( area.right() + 5, area.bottom() + 5 ); - glVertex2i( area.left() - 5, area.bottom() + 5 ); + glVertex2i( area.left() - FRAME_WIDTH, area.top() - FRAME_WIDTH ); // top frame + glVertex2i( area.right() + FRAME_WIDTH, area.top() - FRAME_WIDTH ); + glVertex2i( area.right() + FRAME_WIDTH, area.top() - 1 ); + glVertex2i( area.left() - FRAME_WIDTH, area.top() - 1 ); + glVertex2i( area.left() - FRAME_WIDTH, area.top() - FRAME_WIDTH ); // left frame + glVertex2i( area.left() - 1, area.top() - FRAME_WIDTH ); + glVertex2i( area.left() - 1, area.bottom() + FRAME_WIDTH ); + glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + FRAME_WIDTH ); + glVertex2i( area.right() + 1, area.top() - FRAME_WIDTH ); // right frame + glVertex2i( area.right() + FRAME_WIDTH, area.top() - FRAME_WIDTH ); + glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + FRAME_WIDTH ); + glVertex2i( area.right() + 1, area.bottom() + FRAME_WIDTH ); + glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + 1 ); // bottom frame + glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + 1 ); + glVertex2i( area.right() + FRAME_WIDTH, area.bottom() + FRAME_WIDTH ); + glVertex2i( area.left() - FRAME_WIDTH, area.bottom() + FRAME_WIDTH ); glEnd(); glPopAttrib(); } @@ -101,12 +104,7 @@ void MagnifierEffect::paintScreen( int mask, QRegion region, ScreenPaintData& da void MagnifierEffect::postPaintScreen() { if( zoom != target_zoom ) - effects->addRepaintFull(); - if( zoom != 1.0 ) - { // TODO repaint only what's need and when needed -// effects->addRepaint( magnifierArea()); - effects->addRepaintFull(); - } + effects->addRepaint( magnifierArea()); effects->postPaintScreen(); } @@ -120,7 +118,7 @@ QRect MagnifierEffect::magnifierArea() const void MagnifierEffect::zoomIn() { target_zoom *= 1.2; - effects->addRepaintFull(); + effects->addRepaint( magnifierArea()); } void MagnifierEffect::zoomOut() @@ -128,7 +126,7 @@ void MagnifierEffect::zoomOut() target_zoom /= 1.2; if( target_zoom < 1 ) target_zoom = 1; - effects->addRepaintFull(); + effects->addRepaint( magnifierArea()); } void MagnifierEffect::toggle() @@ -137,7 +135,13 @@ void MagnifierEffect::toggle() target_zoom = 2; else target_zoom = 1; - effects->addRepaintFull(); + effects->addRepaint( magnifierArea()); + } + +void MagnifierEffect::cursorMoved( const QPoint&, Qt::MouseButtons ) + { + if( zoom != 1 ) + effects->addRepaint( magnifierArea()); } } // namespace diff --git a/effects/magnifier.h b/effects/magnifier.h index 302eeafabf..276a2e0c86 100644 --- a/effects/magnifier.h +++ b/effects/magnifier.h @@ -25,6 +25,7 @@ class MagnifierEffect virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); virtual void postPaintScreen(); + void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons ); private slots: void zoomIn(); void zoomOut(); diff --git a/effects/zoom.cpp b/effects/zoom.cpp index 56dea8ec45..5a73372ba7 100644 --- a/effects/zoom.cpp +++ b/effects/zoom.cpp @@ -89,6 +89,12 @@ void ZoomEffect::actualSize() effects->addRepaintFull(); } +void ZoomEffect::cursorMoved( const QPoint&, Qt::MouseButtons ) + { + if( zoom != 1 ) + effects->addRepaintFull(); + } + } // namespace #include "zoom.moc" diff --git a/effects/zoom.h b/effects/zoom.h index 44eda47cac..48a2a0520d 100644 --- a/effects/zoom.h +++ b/effects/zoom.h @@ -25,6 +25,7 @@ class ZoomEffect virtual void prePaintScreen( int* mask, QRegion* region, int time ); virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ); virtual void postPaintScreen(); + void cursorMoved( const QPoint& pos, Qt::MouseButtons buttons ); private slots: void zoomIn(); void zoomOut(); diff --git a/workspace.cpp b/workspace.cpp index fb23fd1ef5..f6e2425b34 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -2579,6 +2579,7 @@ void Workspace::slotBlockShortcuts( int data ) // Optimized version of QCursor::pos() that tries to avoid X roundtrips // by updating the value only when the X timestamp changes. static QPoint last_cursor_pos; +static int last_buttons = 0; static Time last_cursor_timestamp = CurrentTime; QPoint Workspace::cursorPos() @@ -2587,7 +2588,14 @@ QPoint Workspace::cursorPos() || last_cursor_timestamp != QX11Info::appTime()) { last_cursor_timestamp = QX11Info::appTime(); - last_cursor_pos = QCursor::pos(); + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint state; + XQueryPointer( display(), rootWindow(), &root, &child, + &root_x, &root_y, &win_x, &win_y, &state ); + last_cursor_pos = QPoint( root_x, root_y ); + last_buttons = state; QTimer::singleShot( 0, this, SLOT( resetCursorPosTime())); } return last_cursor_pos; @@ -2601,6 +2609,15 @@ void Workspace::resetCursorPosTime() last_cursor_timestamp = CurrentTime; } +void Workspace::checkCursorPos() + { + QPoint last = last_cursor_pos; + int lastb = last_buttons; + cursorPos(); // update if needed + if( last != last_cursor_pos || lastb != last_buttons ) + static_cast< EffectsHandlerImpl* >( effects )->cursorMoved( cursorPos(), x11ToQtMouseButtons( last_buttons )); + } + } // namespace #include "workspace.moc" diff --git a/workspace.h b/workspace.h index bcd71b45f2..7bb1e21c62 100644 --- a/workspace.h +++ b/workspace.h @@ -462,6 +462,7 @@ class Workspace : public QObject, public KDecorationDefines void readShortcuts(); void initDesktopPopup(); void setupWindowShortcut( Client* c ); + void checkCursorPos(); bool startKDEWalkThroughWindows(); bool startWalkThroughDesktops( TabBoxMode mode ); // TabBoxDesktopMode | TabBoxDesktopListMode