From 15c8a4220ed2331374774446b213548cad7d7bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Sat, 14 Apr 2007 14:15:43 +0000 Subject: [PATCH] Fix and re-enable optimized cursorPos(). svn path=/branches/work/kwin_composite/; revision=653895 --- effects.cpp | 11 ++++++----- lib/kwineffects.cpp | 2 +- lib/kwineffects.h | 1 + lib/kwinglobals.cpp | 26 -------------------------- lib/kwinglobals.h | 2 -- utils.cpp | 6 ++++++ utils.h | 2 ++ workspace.cpp | 25 +++++++++++++++++++++++++ workspace.h | 2 ++ 9 files changed, 43 insertions(+), 34 deletions(-) diff --git a/effects.cpp b/effects.cpp index fed174cc70..b9379afb6c 100644 --- a/effects.cpp +++ b/effects.cpp @@ -272,11 +272,6 @@ int EffectsHandlerImpl::displayHeight() const return KWin::displayWidth(); } -QPoint EffectsHandlerImpl::cursorPos() const - { - return KWin::cursorPos(); - } - EffectWindowList EffectsHandlerImpl::stackingOrder() const { ClientList list = Workspace::self()->stackingOrder(); @@ -421,6 +416,7 @@ bool EffectsHandlerImpl::checkInputWindowEvent( XEvent* e ) } return false; } + void EffectsHandlerImpl::checkInputWindowStacking() { if( input_windows.count() == 0 ) @@ -434,6 +430,11 @@ void EffectsHandlerImpl::checkInputWindowStacking() delete[] wins; } +QPoint EffectsHandlerImpl::cursorPos() const + { + return Workspace::self()->cursorPos(); + } + void EffectsHandlerImpl::checkElectricBorder(const QPoint &pos, Time time) { Workspace::self()->checkElectricBorder( pos, time ); diff --git a/lib/kwineffects.cpp b/lib/kwineffects.cpp index 46d88142b9..61e2ed8eda 100644 --- a/lib/kwineffects.cpp +++ b/lib/kwineffects.cpp @@ -182,7 +182,7 @@ int Effect::displayHeight() QPoint Effect::cursorPos() { - return KWin::cursorPos(); + return effects->cursorPos(); } //**************************************** diff --git a/lib/kwineffects.h b/lib/kwineffects.h index f276a7cf47..d28c84a150 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -170,6 +170,7 @@ class KWIN_EXPORT EffectsHandler virtual Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor ); virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor ); virtual void destroyInputWindow( Window w ) = 0; + virtual QPoint cursorPos() const = 0; virtual void checkElectricBorder(const QPoint &pos, Time time) = 0; virtual void reserveElectricBorder( ElectricBorder border ) = 0; diff --git a/lib/kwinglobals.cpp b/lib/kwinglobals.cpp index edf3f46d55..c709d1da79 100644 --- a/lib/kwinglobals.cpp +++ b/lib/kwinglobals.cpp @@ -10,34 +10,8 @@ License. See the file "COPYING" for the exact licensing terms. #include "kwinglobals.h" -#include - -#include "kdebug.h" - -#include - - namespace KWin { - -// 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 Time last_cursor_timestamp = CurrentTime; - -QPoint cursorPos() - { - last_cursor_timestamp = CurrentTime; - if( last_cursor_timestamp == CurrentTime - || last_cursor_timestamp != QX11Info::appTime()) - { - last_cursor_timestamp = QX11Info::appTime(); - last_cursor_pos = QCursor::pos(); - } - return last_cursor_pos; - } - - } // namespace diff --git a/lib/kwinglobals.h b/lib/kwinglobals.h index a7ab3bc467..332e675de0 100644 --- a/lib/kwinglobals.h +++ b/lib/kwinglobals.h @@ -131,8 +131,6 @@ KWIN_EXPORT int displayHeight() return XDisplayHeight( display(), DefaultScreen( display())); } -KWIN_EXPORT QPoint cursorPos(); - } // namespace #endif diff --git a/utils.cpp b/utils.cpp index 19c264b90b..caec7d60ee 100644 --- a/utils.cpp +++ b/utils.cpp @@ -36,6 +36,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "atoms.h" #include "notifications.h" +#include "workspace.h" #endif @@ -353,6 +354,11 @@ bool grabbedXServer() return server_grab_count > 0; } +QPoint cursorPos() + { + return Workspace::self()->cursorPos(); + } + // converting between X11 mouse/keyboard state mask and Qt button/keyboard states int qtToX11Button( Qt::MouseButton button ) diff --git a/utils.h b/utils.h index 1d564c13ab..b9ebde5577 100644 --- a/utils.h +++ b/utils.h @@ -308,6 +308,8 @@ Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1 bool isLocalMachine( const QByteArray& host ); +QPoint cursorPos(); + // converting between X11 mouse/keyboard state mask and Qt button/keyboard states int qtToX11Button( Qt::MouseButton button ); Qt::MouseButton x11ToQtMouseButton( int button ); diff --git a/workspace.cpp b/workspace.cpp index cf55faf588..fb23fd1ef5 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -2576,6 +2576,31 @@ void Workspace::slotBlockShortcuts( int data ) (*it)->updateMouseGrab(); } +// 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 Time last_cursor_timestamp = CurrentTime; + +QPoint Workspace::cursorPos() + { + if( last_cursor_timestamp == CurrentTime + || last_cursor_timestamp != QX11Info::appTime()) + { + last_cursor_timestamp = QX11Info::appTime(); + last_cursor_pos = QCursor::pos(); + QTimer::singleShot( 0, this, SLOT( resetCursorPosTime())); + } + return last_cursor_pos; + } + +// Because of QTimer's and the impossibility to get events for all mouse +// movements (at least I haven't figured out how) the position needs +// to be also refetched after each return to the event loop. +void Workspace::resetCursorPosTime() + { + last_cursor_timestamp = CurrentTime; + } + } // namespace #include "workspace.moc" diff --git a/workspace.h b/workspace.h index d5f3149201..bcd71b45f2 100644 --- a/workspace.h +++ b/workspace.h @@ -279,6 +279,7 @@ class Workspace : public QObject, public KDecorationDefines bool globalShortcutsDisabled() const; void disableGlobalShortcuts( bool disable ); void disableGlobalShortcutsForClient( bool disable ); + QPoint cursorPos(); void sessionSaveStarted(); void sessionSaveDone(); @@ -449,6 +450,7 @@ class Workspace : public QObject, public KDecorationDefines void performCompositing(); void lostCMSelection(); void updateElectricBorders(); + void resetCursorPosTime(); protected: bool keyPressMouseEmulation( XKeyEvent& ev );