File indexing completed on 2024-05-05 05:34:57

0001 /*
0002     this file is part of the oxygen gtk engine
0003     SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "oxygentimer.h"
0009 
0010 #include <gdk/gdk.h>
0011 #include <iostream>
0012 
0013 namespace Oxygen
0014 {
0015 
0016     //____________________________________________________
0017     void Timer::start( int delay, GSourceFunc func, gpointer data )
0018     {
0019 
0020         // make sure timer is not already running
0021         g_return_if_fail( _timerId == 0 );
0022 
0023         _func = func;
0024         _data = data;
0025         _timerId = gdk_threads_add_timeout( delay, (GSourceFunc)timeOut, this );
0026 
0027     }
0028 
0029     //____________________________________________________
0030     gboolean Timer::timeOut( gpointer data )
0031     {
0032 
0033         // cast to timer, and execute relevant function
0034         Timer& timer( *static_cast<Timer*>( data ) );
0035         gboolean result = (timer._func)( timer._data );
0036 
0037         // make sure timerId is properly reset if the embedded function returns false
0038         if( !result ) timer.reset();
0039         return result;
0040 
0041     }
0042 
0043 }