Re: GDK bug

I have tried to connect the "expose-event" signal of my window to the
callback in charge of the resizing and it seems the signal isn't
emitted until the window is obscured and "unobscured" by another one.

Using "configure-event", it works perfectly. This is logical, since
the configure-event is emitted when the window is configured by the
window manager (isn't it?) and expose-event is emitted when an aera of
the widget has to be repainted after being covered by another window.

Generally speaking, you should connect:

1) the expose-event, to a function that is responsible 
for drawing a drawing area or gl_area; This signal will
be triggered automatically by X, everytime a situation
occurs where it is obvious that the image needs to be
redrawn, in particular a configure event always triggers
the expose-event, in the end. This function
has nothing to do with resizing, so no commands to handle
resizing should go here. You can always force a redrawing
yourself, calling for example gtk_widget_queue_draw.

2) the configure event, to a function that handles
aspects related with resizing, a typical example
is to define the new size of a OpenGL viewport. You
must realize that this function has actually nothing
to do with redrawing: no draw commands at all should
be in this callback, because the expose_event callback 
is always executed after the configure_event callback.
configure_event and expose_event should be totally
independent, they handle two totally different things.

See this example below, when the window is resized,
app_mesa_configure_gl_area() informs OpenGL of the new size, 
and then app_mesa_configure_gl_area() redraws the picture, 
already using the new size. app_mesa_configure_gl_area()
doesn't know nothing about drawing, and app_mesa_expose_gl_area()
doesn't know nothing about resizing, they are totally


gtk_signal_connect (GTK_OBJECT (gl_area), "expose_event",
                    GTK_SIGNAL_FUNC (app_mesa_expose_gl_area), data);

gtk_signal_connect (GTK_OBJECT (gl_area), "configure_event",
                    GTK_SIGNAL_FUNC (app_mesa_configure_gl_area), data);

gint app_mesa_configure_gl_area (GtkWidget *widget, GdkEventConfigure *event, gpointer data)
if (gtk_gl_area_make_current (GTK_GL_AREA (widget)))
  glViewport (0, 0, widget->allocation.width, widget->allocation.height);

return TRUE;

gint app_mesa_expose_gl_area (GtkWidget *widget, GdkEventExpose *event, gpointer data)
GtkGLArea *gl_area = GTK_GL_AREA (widget);
app_window *window = APP_CAST_WINDOW data;

/* Draw only last expose. */
if (event->count > 0) return TRUE;


if (gtk_gl_area_make_current(gl_area))
  /* actual drawing function */
  app_mesa_draw_window (window);
  gtk_gl_area_swapbuffers (gl_area);
return TRUE;

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