Re: g_io_add_watch can block redraw ?
- From: Havoc Pennington <hp redhat com>
- To: Diego Zuccato <diego otello alma unibo it>
- Cc: Gtk-list <gtk-list gnome org>
- Subject: Re: g_io_add_watch can block redraw ?
- Date: Thu, 5 Dec 2002 20:25:45 -0500
On Thu, Dec 05, 2002 at 11:13:36PM +0000, Diego Zuccato wrote:
> int main( int argc,
> char *argv[] )
> {
> GtkWidget *window;
> gtk_init (&argc, &argv);
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> w=gtk_button_new_with_label("Prova!");
> gtk_container_add(GTK_CONTAINER(window), w);
> gtk_widget_show_all(window);
> g_io_add_watch(g_io_channel_unix_new(1), G_IO_OUT, cbk, NULL);
> gtk_main ();
> return(0);
> }
>
> Since I'm not using file handle 1 (stdout), it's always write-ready. So
> cbk gets continuously called.
> If you drag the window around, you'll notice the button isn't redrawn,
> except when you click it.
>
> Is it normal? Is it a (mis-)feature?
Yes, it's normal. If you ask to have your callback invoked whenever
the fd is ready for writing, and it's always ready, then your callback
will be invoked continuously eating 100% CPU. That doesn't seem so
surprising - you get what you ask for. ;-)
GLib can't read your mind and only call the callback when you actually
have something to write!
Normally people only add an IO_OUT callback when they have stuff to
write, then they remove the callback when they no longer have a write
pending.
The reason it blocks widget redraw is that widget redraw only happens
in an idle handler (when there's nothing else to do).
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]