vcl/unx/gtk3/gtkdata.cxx |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

New commits:
commit 4812c8df39cb03b59d8c033005e8e9dc45a260dd
Author:     Hossein <hoss...@libreoffice.org>
AuthorDate: Tue Dec 14 13:53:21 2021 +0100
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Wed Dec 15 12:09:42 2021 +0100

    tdf#146225 Fix delay when exiting from the gtk3 ui
    
    While removing the deprecated g_get_current_time and replacing it
    with g_get_real_time in 489d7298d2e609ee5900f05ba0064845a7a551ce,
    a behaviour change in sal_gtk_timeout_expired static method is
    done, which lead to tdf#146225.
    With this commit, it is changed back to the previous state, with 2
    additional variables of tv_sec and tv_usec.
    Eventually, the method should be simplified.
    
    Change-Id: I2f1bb22b9a2d518e6f0332472535be8d4adf92f2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126829
    Tested-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Hossein <hoss...@libreoffice.org>

diff --git a/vcl/unx/gtk3/gtkdata.cxx b/vcl/unx/gtk3/gtkdata.cxx
index 8903c2e5e15c..7c64db06225e 100644
--- a/vcl/unx/gtk3/gtkdata.cxx
+++ b/vcl/unx/gtk3/gtkdata.cxx
@@ -653,19 +653,29 @@ extern "C" {
     static gboolean sal_gtk_timeout_expired( SalGtkTimeoutSource *pTSource,
                                              gint *nTimeoutMS, gint64 const 
pTimeNow )
     {
-        gint64 nDeltaUSec = pTSource->aFireTime - pTimeNow;
-        if( nDeltaUSec < 0 )
+        glong tv_sec = pTimeNow / 1000000;
+        glong tv_usec = pTimeNow - tv_sec * 1000000;
+        glong nDeltaSec = pTSource->aFireTime / 1000000 - tv_sec;
+        glong nDeltaUSec = pTSource->aFireTime - (nDeltaSec * 1000000) - 
tv_usec;
+        if( nDeltaSec < 0 || ( nDeltaSec == 0 && nDeltaUSec < 0) )
         {
             *nTimeoutMS = 0;
             return true;
         }
+        if( nDeltaUSec < 0 )
+        {
+            nDeltaUSec += 1000000;
+            nDeltaSec -= 1;
+        }
         // if the clock changes backwards we need to cope ...
-        if( o3tl::make_unsigned(nDeltaUSec) > 1000000 + ( 
pTSource->pInstance->m_nTimeoutMS / 1000 ) )
+        if( o3tl::make_unsigned(nDeltaSec) > 1 + ( 
pTSource->pInstance->m_nTimeoutMS / 1000 ) )
         {
             sal_gtk_timeout_defer( pTSource );
             return true;
         }
-        *nTimeoutMS = MIN( G_MAXINT,  (nDeltaUSec + 999) / 1000 );
+
+        *nTimeoutMS = MIN( G_MAXINT, ( nDeltaSec * 1000 + (nDeltaUSec + 999) / 
1000 ) );
+
         return *nTimeoutMS == 0;
     }
 

Reply via email to