I just do a timer event as following:

to initial a time beat and handler
==================================

#include <signal.h>
#include <uinstd.h>
#include <sys/time.h>

#include <gnome.h>

enum {
  BEAT,
  LAST_SIGNAL
};

struct itimerval itv, oitv;
guint time_signals[LAST_SIGNAL];

void beat_close()
{
  setitimer( ITIMER_REAL, &oitv, &itv );
}

void beat_handler( int sig )
{
  /**************************
   * emit signal to objects *
   **************************/
  gtk_signal_emit( /* gtk object */, time_signals[BEAT] );
  ...
}

int beat_init()
{
  static struct sigatcion act;

  /******************
   * clear old beat *
   ******************/
  itv.it_interval.tv_sec  = 0;
  itv.it_interval.tv_usec = 0;

  it.it_value.tv_sec  = 0;
  it.it_value.tv_usec = 0;

  setitimer( ITIMER_REAL, &itv, &oitv );

  /****************************
   * create new signal "beat" *
   ****************************/ 
  time_signals[BEAT] = gtk_signal_new( "beat",
                                       GTK_RUN_LAST | GTK_RUN_ACTION,
                                       GTK_TYPE_OBJECT,
                                       0,
                                       gtk_marshall_NONE__NONE,
                                       GTK_TYPE_NONE, 0 );

  /************************
   * set action for alarm *
   ************************/
  act.sa_handler = beat_handler;
  sigemptyset( &act.sa_mask );
  sigaddset( &act.sa_mask, SIGALRM );
  return( sigaction( SIGALRM, &act, NULL ) );
}


to connect to signal "beat"
===========================
...
gtk_object_class_add_signals( GTK_OBJECT(widget)->klass,
                              time_signals, LAST_SIGNAL );

gtk_signal_connect( GTK_OBJECT(widget), "beat"
                    GTK_SIGNAL_FUNC(on_what_object_handler_when_beat),
                    NULL );
...


HTH

On Thu, May 18, 2000 at 06:41:35PM -0700, Dominique Nerriere wrote:
> Hi all,
> 
> I didn't find a way to generate an event with a timer, does gtk/gtk/glib provide 
>such a thing?
> 
> I need a function to be called every 1/33 seconde
> 
> Thanks for your help :)
> 
> Dominique
> 
> 
> Get your FREE Email at http://mailcity.lycos.com
> Get your PERSONALIZED START PAGE at http://my.lycos.com
> 
> _______________________________________________
> gtk-app-devel-list mailing list
> [EMAIL PROTECTED]
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

-- 
Reed Lai http://w3.icpdas.com/reed/ | ICPDAS http://www.icpdas.com
GnuPG (DSA/ElGamal) 0x7199EAD3 Reed Lai (key #1) <[EMAIL PROTECTED]>
KeyServer: search.keyserver.net |  HAM: BV4QO | NIC-handle: RL7000
ICQ 64518529

Reply via email to