File indexing completed on 2024-05-12 05:34:36
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 #include "../config.h" 0010 0011 #include <gdk/gdk.h> 0012 #include <iostream> 0013 0014 namespace Oxygen 0015 { 0016 0017 //____________________________________________________ 0018 void Timer::start( int delay, GSourceFunc func, gpointer data ) 0019 { 0020 0021 // make sure timer is not already running 0022 g_return_if_fail( _timerId == 0 ); 0023 0024 _func = func; 0025 _data = data; 0026 _timerId = gdk_threads_add_timeout( delay, (GSourceFunc)timeOut, this ); 0027 0028 } 0029 0030 //____________________________________________________ 0031 gboolean Timer::timeOut( gpointer data ) 0032 { 0033 0034 // cast to timer, and execute relevant function 0035 Timer& timer( *static_cast<Timer*>( data ) ); 0036 gboolean result = (timer._func)( timer._data ); 0037 0038 // make sure timerId is properly reset if the embedded function returns false 0039 if( !result ) timer.reset(); 0040 return result; 0041 0042 } 0043 0044 }