Re: glib - main event loop



On Sun, 20 Mar 2016 06:25:10 +0100
Krzysztof <kj limes com pl> wrote:
Thanks Chris. It worked.
Does it mean that idle source can be effectively added to global loop 
only? Can't I have idle source in other contexts?

You can, but you have to use g_source_attach().  So you would have
something like:

guint idle_add_with_context(GMainContext *context, gint priority,
                            GSourceFunc func, gpointer data,
                            GDestroyNotify notify)
{
  GSource *source = g_idle_source_new();
  if (priority != G_PRIORITY_DEFAULT_IDLE)
    g_source_set_priority(source, priority);
  g_source_set_callback(source, func, data, notify);
  guint id = g_source_attach(source, context);
  g_source_unref(source);
  return id;
}

Chris


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