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 <hossein@libreoffice.org>
Reviewed-by: Hossein <hossein@libreoffice.org>
diff --git a/vcl/unx/gtk3/gtkdata.cxx b/vcl/unx/gtk3/gtkdata.cxx
index 8903c2e..7c64db0 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;
}