Re: Xlib: unexpected async reply (sequence #####)!

2007-08-05 Thread Gabriel Schulhof
On Sun, 2007-08-05 at 11:29 +0800, Gregory Hosler wrote:
> I'm looking for code examples specifically on how to use/implement 
> g_idle_add().
> Know any projects that uses g_idle_add() and related infrastructure?


static gboolean
make_insensitive_idle_cb(gpointer data)
{
  GtkWidget *widget = GTK_WIDGET(data);

  gtk_widget_set_sensitive(widget, FALSE);

/* Return FALSE so as not to keep executing this function over and over
   again */
  return FALSE;
}

static gpointer
my_thread(gpointer data)
{
/* ... do something of long duration, during which ... */

g_idle_add(make_insensitive_idle_cb, some_widget);

/* ... do the rest of the long duration stuff ... */

return NULL;
}

Have a look at

http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#id2603517

HTH,



Gabriel

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Xlib: unexpected async reply (sequence #####)!

2007-08-05 Thread Chris Vine
On Sun, 2007-08-05 at 11:24 +0800, Gregory Hosler wrote:

> The main loop is already protected (by threads_enter()/threads_leave() so I
> didn't need to add any code at all to the main code (and I don't have any
> timeout callbacks either), so the only places I needed to add the
> threads_enter/leave was in the threads (2 small ones) themselves.

That's fine, except that you will also need it in any handler called
from the glib main loop, such as GIOChannel callbacks, child watch
callbacks and any custom GSource objects that you attach to the main
loop, where any of these call GDK/GTK+ functions.

> having said that...
> 
> > That is why
> > using g_idle_add() is often a better approach.
> 
> just looked at the man/devhelp page. Looks interesting. I'm looking for some
> code examples. actual working examples would be nice.

All you need to do is have an idle handler returning FALSE which calls
the GDK/GTK+ functions that you want to have executed from the calling
thread.  The only other point to remember is that you need to ensure
that any data passed by reference via the data argument is still valid
when the main loop executes the idle handler, which usually means that
you need to allocate it on the heap and free it in the idle handler when
you are finished with it.

Chris


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Xlib: unexpected async reply (sequence #####)!

2007-08-05 Thread Gregory Hosler
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Gabriel Schulhof wrote:
> On Sun, 2007-08-05 at 11:29 +0800, Gregory Hosler wrote:
>> I'm looking for code examples specifically on how to use/implement 
>> g_idle_add().
>> Know any projects that uses g_idle_add() and related infrastructure?
> 
> 
> static gboolean
> make_insensitive_idle_cb(gpointer data)
> {
>   GtkWidget *widget = GTK_WIDGET(data);
> 
>   gtk_widget_set_sensitive(widget, FALSE);
> 
> /* Return FALSE so as not to keep executing this function over and over
>again */
>   return FALSE;
> }
> 
> static gpointer
> my_thread(gpointer data)
> {
> /* ... do something of long duration, during which ... */
> 
> g_idle_add(make_insensitive_idle_cb, some_widget);
> 
> /* ... do the rest of the long duration stuff ... */
> 
> return NULL;
> }
> 
> Have a look at
> 
> http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#id2603517

I actually had a look at that page prior to my post. It didn't answer some of
the basic questions / concerns I had.

Your example clears up alot of stuff for me. One of my questions (that your
example pretty much clarifies for me), was "what do I g_idle_add()" ?
If I understand correctly, you basically add callback functions, and in
particular, ones that are gtk/gdk related (i.e. that deal with the displaying of
widgets).

is this more or less correct ?

so, um, when a g_idle_add does a "gtk_widget_show()" on a widget, and that
widget would get displayed as part of the main thread.

Am I correct to say that things like gtk_label_new(), and all the related calls
to build a label widget, can be done in a thread, but the "show" must be done in
the main loop (via the g_adle_add() call) ?

If there a list (or guideline) of which gtk_calls should be done in the idle,
and which need not be ?

many thanks,

- -Greg

> HTH,

yes, it did!

- -G

> 
> 
> Gabriel
> 


- --
+-+

Please also check the log file at "/dev/null" for additional information.
(from /var/log/Xorg.setup.log)

| Greg Hosler   [EMAIL PROTECTED]|
+-+
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFGtb57404fl/0CV/QRAtJHAKCcPTvYTNlvKN71ttWyEGUTkuBd2ACcDmvx
eJuwrFcdbeHq0vHmnwBHets=
=S79l
-END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Which OS are supported by GLib?

2007-08-05 Thread Tomasz Jankowski
Hello!

Where can I find information about operating systems supported by GLib?

-- 
Cya!
Tom
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list