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

List:       kde-commits
Subject:    branches/work/kdelibs4_snapshot/kdecore
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2006-04-11 12:54:59
Message-ID: 1144760099.120226.7302.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 528575 by lunakl:

Handle X timestamp wrapping correctly even on 64bit platforms.



 M  +3 -3      kapplication.cpp  
 M  +3 -1      kxerrorhandler.cpp  
 M  +34 -0     netwm.cpp  
 M  +12 -0     netwm_def.h  


--- branches/work/kdelibs4_snapshot/kdecore/kapplication.cpp #528574:528575
@@ -1218,7 +1218,7 @@
                     && _event->xclient.data.l[ 3 ] != 0 )
                     {
                     if( QX11Info::appUserTime() == 0
-                        || ( _event->xclient.data.l[ 3 ] - QX11Info::appUserTime() ) \
< 100000U ) +                        || NET::timestampCompare( \
_event->xclient.data.l[ 3 ], QX11Info::appUserTime() ) > 0 )  { // and the timestamp \
                looks reasonable
                         QX11Info::setAppUserTime(_event->xclient.data.l[ 3 ]); // \
update our qt_x_user_time from it  }
@@ -1226,7 +1226,7 @@
                 else // normal DND, only needed until Qt updates qt_x_user_time from \
XdndDrop  {
                     if( QX11Info::appUserTime() == 0
-                        || ( _event->xclient.data.l[ 2 ] - QX11Info::appUserTime() ) \
< 100000U ) +                        || NET::timestampCompare( \
_event->xclient.data.l[ 2 ], QX11Info::appUserTime() ) > 0 )  { // the timestamp \
                looks reasonable
                         QX11Info::setAppUserTime(_event->xclient.data.l[ 2 ]); // \
update our qt_x_user_time from it  }
@@ -1346,7 +1346,7 @@
         XDestroyWindow( QX11Info::display(), w );
     }
     if( QX11Info::appUserTime() == 0
-        || time - QX11Info::appUserTime() < 1000000000U ) // check time > \
qt_x_user_time, handle wrapping +        || NET::timestampCompare( time, \
QX11Info::appUserTime()) > 0 ) // time > appUserTime  QX11Info::setAppUserTime(time);
 #endif
 }
--- branches/work/kdelibs4_snapshot/kdecore/kxerrorhandler.cpp #528574:528575
@@ -26,6 +26,7 @@
 #ifdef Q_WS_X11 //FIXME
 
 #include "kxerrorhandler.h"
+#include "netwm_def.h"
 
 KXErrorHandler** KXErrorHandler::handlers = NULL;
 int KXErrorHandler::pos = 0;
@@ -99,7 +100,8 @@
 int KXErrorHandler::handle( Display* dpy, XErrorEvent* e )
     {
     if( dpy == display
-        && e->serial - first_request < 1000000000 ) // e->serial > first_request, \
with wrapping +        // e->serial > first_request , compare like X timestamps to \
handle wrapping +        && NET::timestampCompare( e->serial, first_request ) > 0 )
         { // it's for us
         //qDebug( "Handling: %p", static_cast< void* >( this ));
         if( user_handler1 != NULL && user_handler1( e->request_code, e->error_code, \
                e->resourceid ))
--- branches/work/kdelibs4_snapshot/kdecore/netwm.cpp #528574:528575
@@ -4345,4 +4345,38 @@
 void NETWinInfo::virtual_hook( int, void* )
 { /*BASE::virtual_hook( id, data );*/ }
 
+// Functions for X timestamp comparing. For Time being 32bit they're fairly simple
+// (the #if 0 part), but on 64bit architectures Time is 64bit unsigned long,
+// so there special care needs to be taken to always use only the lower 32bits.
+#if 0
+int NET::timestampCompare( Time time1, Time time2 ) // like strcmp()
+    {
+    if( time1 == time2 )
+        return 0;
+    return ( time1 - time2 ) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, handle \
wrapping +    }
+
+Time NET::timestampDiff( Time time1, Time time2 ) // returns time2 - time1
+    { // no need to handle wrapping?
+    return time2 - time1;
+    }
+#else
+int NET::timestampCompare( unsigned long time1_, unsigned long time2_ ) // like \
strcmp() +    {
+    quint32 time1 = time1_;
+    quint32 time2 = time2_;
+    if( time1 == time2 )
+        return 0;
+    return quint32( time1 - time2 ) < 0x7fffffffU ? 1 : -1; // time1 > time2 -> 1, \
handle wrapping +    }
+
+int NET::timestampDiff( unsigned long time1_, unsigned long time2_ ) // returns \
time2 - time1 +    { // no need to handle wrapping?
+    quint32 time1 = time1_;
+    quint32 time2 = time2_;
+    return quint32( time2 - time1 );
+    }
 #endif
+
+
+#endif
--- branches/work/kdelibs4_snapshot/kdecore/netwm_def.h #528574:528575
@@ -635,6 +635,18 @@
         **/
         FromTool
     };
+    
+    /**
+     Compares two X timestamps, taking into account wrapping and 64bit \
architectures. +     Return value is like with strcmp(), 0 for equal, -1 for time1 < \
time2, 1 for time1 > time2. +    */
+    static int timestampCompare( unsigned long time1, unsigned long time2 );
+    /**
+     Returns a difference of two X timestamps, time2 - time1, where time2 must be \
later than time1, +     as returned by timestampCompare().
+    */
+    static int timestampDiff( unsigned long time1_, unsigned long time2_ );
+
 };
 
 


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

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