From 83835a8757a3863c499de96242c0c33a1bbaa5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Fri, 10 Oct 2003 12:48:09 +0000 Subject: [PATCH] Small cleanup related to timestamp handling. svn path=/trunk/kdebase/kwin/; revision=257715 --- events.cpp | 2 +- utils.cpp | 2 +- utils.h | 8 +++++++- workspace.cpp | 43 ++++++++----------------------------------- workspace.h | 3 +-- 5 files changed, 18 insertions(+), 40 deletions(-) diff --git a/events.cpp b/events.cpp index 708371a5ee..540b7d9193 100644 --- a/events.cpp +++ b/events.cpp @@ -132,7 +132,7 @@ void RootInfo::moveResize(Window w, int x_root, int y_root, unsigned long direct Client* c = workspace->findClient( WindowMatchPredicate( w )); if ( c ) { - kwin_updateTime(); // otherwise grabbing may have old timestamp - this message should include timestamp + updateXTime(); // otherwise grabbing may have old timestamp - this message should include timestamp c->NETMoveResize( x_root, y_root, (Direction)direction); } } diff --git a/utils.cpp b/utils.cpp index 9e95864ff6..1f04b84db8 100644 --- a/utils.cpp +++ b/utils.cpp @@ -218,7 +218,7 @@ QCString getStringProperty(WId w, Atom prop, char separator) Use this function only when really necessary. Keep in mind that it's a roundtrip to the X-Server. */ -void kwin_updateTime() +void updateXTime() { static QWidget* w = 0; if ( !w ) diff --git a/utils.h b/utils.h index d2ae3e8a98..08363c4d0b 100644 --- a/utils.h +++ b/utils.h @@ -130,7 +130,7 @@ class KWinSelectionOwner QCString getStringProperty(WId w, Atom prop, char separator=0); -void kwin_updateTime(); +void updateXTime(); // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint #ifndef UrgencyHint @@ -169,6 +169,12 @@ int timestampCompare( Time time1, Time time2 ) // like strcmp() return ( time1 - time2 ) < 1000000000 ? 1 : -1; // time1 > time2 -> 1, handle wrapping } +inline +Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1 + { // no need to handle wrapping? + return time2 - time1; + } + } // namespace #endif diff --git a/workspace.cpp b/workspace.cpp index e3da9ecb31..ffce80dfa6 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -92,8 +92,6 @@ Workspace::Workspace( bool restore ) electric_bottom_border(None), electric_left_border(None), electric_right_border(None), - electric_time_first(0), - electric_time_last(0), layoutOrientation(Qt::Vertical), layoutX(-1), layoutY(2), @@ -110,6 +108,9 @@ Workspace::Workspace( bool restore ) updateXTime(); // needed for proper initialization of user_time in Client ctor + electric_time_first = qt_x_time; + electric_time_last = qt_x_time; + if ( restore ) loadSessionInfo(); @@ -1650,16 +1651,7 @@ void Workspace::destroyBorderWindows() electric_right_border = None; } -// Do we have a proper timediff function?? -static int TimeDiff(unsigned long a, unsigned long b) - { - if (a > b) - return a-b; - else - return b-a; - } - -void Workspace::clientMoved(const QPoint &pos, unsigned long now) +void Workspace::clientMoved(const QPoint &pos, Time now) { if (options->electricBorders() == Options::ElectricDisabled) return; @@ -1670,8 +1662,8 @@ void Workspace::clientMoved(const QPoint &pos, unsigned long now) (pos.y() != electricBottom)) return; - int treshold_set = options->electricBorderDelay(); // set timeout - int treshold_reset = 250; // reset timeout + Time treshold_set = options->electricBorderDelay(); // set timeout + Time treshold_reset = 250; // reset timeout int distance_reset = 10; // Mouse should not move more than this many pixels int border = 0; @@ -1685,12 +1677,12 @@ void Workspace::clientMoved(const QPoint &pos, unsigned long now) border = 4; if ((electric_current_border == border) && - (TimeDiff(electric_time_last, now) < treshold_reset) && + (timestampDiff(electric_time_last, now) < treshold_reset) && ((pos-electric_push_point).manhattanLength() < distance_reset)) { electric_time_last = now; - if (TimeDiff(electric_time_first, now) > treshold_set) + if (timestampDiff(electric_time_first, now) > treshold_set) { electric_current_border = 0; @@ -1836,25 +1828,6 @@ QString Workspace::desktopName( int desk ) const return QString::fromUtf8( rootInfo->desktopName( desk ) ); } -/*! - Updates qt_x_time by receiving a current timestamp from the server. - - Use this function only when really necessary. Keep in mind that it's - a roundtrip to the X-Server. - */ -void Workspace::updateXTime() - { - static QWidget* w = 0; - if ( !w ) - w = new QWidget; - long data = 1; - XChangeProperty(qt_xdisplay(), w->winId(), atoms->kwin_running, atoms->kwin_running, 32, - PropModeAppend, (unsigned char*) &data, 1); - XEvent ev; - XWindowEvent( qt_xdisplay(), w->winId(), PropertyChangeMask, &ev ); - qt_x_time = ev.xproperty.time; - } - bool Workspace::checkStartupNotification( const Client* c, KStartupInfoData& data ) { return startup->checkStartup( c->window(), data ) == KStartupInfo::Match; diff --git a/workspace.h b/workspace.h index fb2496a50c..622dfddc66 100644 --- a/workspace.h +++ b/workspace.h @@ -150,7 +150,7 @@ class Workspace : public QObject, public KWinInterface, public KDecorationDefine void clientHidden( Client* ); void clientAttentionChanged( Client* c, bool set ); - void clientMoved(const QPoint &pos, unsigned long time); + void clientMoved(const QPoint &pos, Time time); /** * Returns the current virtual desktop of this workspace @@ -327,7 +327,6 @@ class Workspace : public QObject, public KWinInterface, public KDecorationDefine void initShortcuts(); void readShortcuts(); void initDesktopPopup(); - void updateXTime(); bool startKDEWalkThroughWindows(); bool startWalkThroughDesktops( int mode ); // TabBox::Mode::DesktopMode | DesktopListMode