You were exactly right. Adding gtk thread support and gdk_flush() fixed it.

On 2/2/07, Michael L Torrie <[EMAIL PROTECTED]> wrote:
>
> On Fri, 2007-02-02 at 16:02 -0700, Rob Barnes wrote:
> > I am using gtk_widget_queue_draw() already. The doc says,"Once the main
> loop
> > becomes idle (after the current batch of events has been processed,
> > roughly), the window will receive expose events for the union of all
> regions
> > that have been invalidated.", but this does not seem to be happening.
> > Placing a printf in my expose event revealed that expose is not being
> called
> > unless I move the mouse or something like that.  My program is
> > multithreaded, could that be causing problems?
>
> I was going to ask if your program was multithreaded as this is classic
> behavior when you try to use threads.
>
> Did you read the documentation on how to properly use threads in GTK?
> Are you initializing thread support in gdk?  Do you properly lock gdk
> when making any gtk or gdk call from a thread?
>
> In general (on all platforms and all widget toolkits), making gui calls
> from the thread is a bad idea.  Instead, notify the main loop when you
> want it to do something by doing g_idle_add and a callback.  This
> ensures that the callback, which could update the drawing area, for
> example, runs in the main thread at the next opportunity.  Note that you
> have to synchronize any data that you want to share between threads
> using locking primitives.


It seems to work fine without using g_idle and just using
gdk_threads_enter()/gdk_threads_leave(). What do I gain from using g_idle?

Thanks.

-RobB

Michael
>
>
> > Some code snippets:
> >
> > GtkWidget *drawing_area;
> > ....
> > //Inside main:
> > drawing_area = gtk_drawing_area_new ();
> > g_signal_connect (G_OBJECT (drawing_area), "expose_event", G_CALLBACK
> > (expose_event), NULL);
> > gtk_widget_set_events(drawing_area,GDK_ALL_EVENTS_MASK);
> > ....
> >
> > gboolean expose_event( GtkWidget      *widget,
> >                               GdkEventExpose *event )
> > {
> > printf("expose\n");
> >     //draw_player(players[0]);
> >   gdk_draw_drawable (widget->window,
> >              widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
> >              pixmap,
> >              event->area.x, event->area.y,
> >              event->area.x, event->area.y,
> >              event->area.width, event->area.height);
> >
> >   return FALSE;
> > }
> >
> > //Inside a asynchronous function
> > //marker is an ADT
> > gdk_draw_polygon (pixmap,marker.kontext,TRUE,marker->poly,4);
> > ....
> > gdk_widget_queue_draw(drawing_area);
> > ....
> >
> > Thanks.
> > -RobB
> >
> >
> > On 2/2/07, Michael Ekstrand <[EMAIL PROTECTED]> wrote:
> > >
> > > On Fri, 2007-02-02 at 12:20 -0700, Rob Barnes wrote:
> > > > I'm trying to write a simple program that draws a moving polygon on
> the
> > > > screen. I started with the scribble-simple example and modified to
> draw
> > > the
> > > > moving shape by redrawing the shape in the background color in the
> > > previous
> > > > position first then drawing it in the foreground color in the
> current
> > > > position. It works fine, except it only refreshes when something
> happens
> > >
> > > > such as mouse movement, click, expose, window adjustment. So to keep
> > > things
> > > > moving I have to keep moving the mouse around, but it stops if the
> mouse
> > > > stops, even though the polygon is being redrawn contently.
> > >
> > > Make sure you request a redraw every time the underlying state changes
> -
> > > check out gtk_widget_queue_draw.
> > >
> > > --
> > > Michael Ekstrand
> > > Research Assistant, Scalable Computing Laboratory
> > > Goanna, compute cluster and InfiniBand network monitor tool:
> > >         http://www.scl.ameslab.gov/Projects/Monitor/
> > >
> > >
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > gtk-app-devel-list@gnome.org
> > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
>
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to