Re: Adding custom GDK events

On Sunday 07 January 2007 13:06, Doron Singer wrote:
> Hello,
> I need to be able to send special events to the GTK event-processing
> loop. Looking at the GDKEvent union, it seems the way to add my own
> events is to subclass GdkEventAny. The question is, what would go in
> the type field? I see no support for user types, and it's not
> documented what the main loop does with events of an unknown type.
> Is it safe to just randomly use types as long as they're not already in
> use? Is there an easier way to submit events to the main loop, a-la Qt's
> QApplication::postEvent?

Use Glib::signal_idle(), or Glib::Dispatcher.  Either will cause the main loop 
to execute the connect slot.

With Glib::signal_idle() you have to reconnect the slot every time you want it 
to fire (and make sure you return false).  With Glib::Dispatcher you just 
call emit on it (it is in effect a thread safe version of 
sigc::signal0<void>).  Glib::signal_idle() is more convenient if you want to 
pass different data on each invocation, because you can do that by binding to 
the slot.  You should only emit Glib::Dispatcher from a different thread from 
the main GUI thread.  Glib::signal_idle() is thread safe and can be called 
from the main GUI thread or any other thread.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]