Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only handle exposes on native window, propagate to children via draw()
We now consider non-native windows non-opaque, which means any invalid
area in a subwindow will also be invalid all the way up to the nearest
native windows. We take advantage of this by ignoring all expose events
on non-native windows (which typically means just the toplevel) and instead
propagating down the draw() calls to children directly via
gtk_container_propagate_draw.

This is nice as it means we always draw widgets the same way, and it
will let us do some interesting ways in the future.

We also clean up the GtkWidget opacity handling as we can now always
rely on the draing happening via cairo.

We can't really just draw by walking down the widget hierarchy, as
this doesn't get the clipping right (so e.g. widgets doing cairo_paint
may draw outside the expected gdkwindow subarea) nor does it let
us paint window backgrounds.

So, we now do multiple draws for each widget, once for each GdkWindow,
although we still do it on the same base cairo_t that we get for the
toplevel native window. The difference is only the clipping, the rendering
order, and which other widgets we propagate into.

We also collect all the windows of a widget so we can expose them inside
the same opacity group if needed.

NOTE: This change neuters gtk_widget_set_double_buffered for
widgets without native windows. Its impossible to disable
the double buffering in this model.
  • Loading branch information
alexlarsson committed May 7, 2013
1 parent fc645f2 commit d22fd72
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 202 deletions.
17 changes: 0 additions & 17 deletions gdk/gdkwindow.c
Expand Up @@ -3651,23 +3651,6 @@ _gdk_window_process_updates_recurse (GdkWindow *window,

g_object_unref (window);
}
else if (window->window_type != GDK_WINDOW_FOREIGN)
{
/* No exposure mask set, so nothing will be drawn, the
* app relies on the background being what it specified
* for the window. So, we need to clear this manually.
*
* For foreign windows if expose is not set that generally
* means some other client paints them, so don't clear
* there.
*
* We use begin/end_paint around the clear so that we can
* piggyback on the implicit paint */

gdk_window_begin_paint_region (window, clipped_expose_region);
/* The actual clear happens in begin_paint_region */
gdk_window_end_paint (window);
}
}
cairo_region_destroy (clipped_expose_region);

Expand Down
29 changes: 21 additions & 8 deletions gtk/gtkcontainer.c
Expand Up @@ -3366,7 +3366,7 @@ gtk_container_propagate_draw (GtkContainer *container,
{
GdkEventExpose *event;
GtkAllocation allocation;
GdkWindow *window, *w;
GdkWindow *window, *w, *event_window, *child_in_window;
int x, y;

g_return_if_fail (GTK_IS_CONTAINER (container));
Expand All @@ -3375,13 +3375,26 @@ gtk_container_propagate_draw (GtkContainer *container,

g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (container));

if (!gtk_widget_is_drawable (child))
return;

/* Only propagate to native child window if we're not handling
an expose (i.e. in a pure gtk_widget_draw() call */
event = _gtk_cairo_get_event (cr);
if (event)
{
if (gtk_widget_get_has_window (child) ||
gtk_widget_get_window (child) != event->window)
return;
}
if (event &&
(gtk_widget_get_has_window (child) &&
gdk_window_has_native (gtk_widget_get_window (child))))
return;

/* Never propagate to a child window when exposing a window
that is not the one the child widget is in. */
event_window = _gtk_cairo_get_event_window (cr);
if (gtk_widget_get_has_window (child))
child_in_window = gdk_window_get_parent (gtk_widget_get_window (child));
else
child_in_window = gtk_widget_get_window (child);
if (event_window != NULL && child_in_window != event_window)
return;

cairo_save (cr);

Expand Down Expand Up @@ -3423,7 +3436,7 @@ gtk_container_propagate_draw (GtkContainer *container,

cairo_translate (cr, x, y);

_gtk_widget_draw_internal (child, cr, TRUE);
_gtk_widget_draw (child, cr);

cairo_restore (cr);
}
Expand Down
14 changes: 11 additions & 3 deletions gtk/gtkmain.c
Expand Up @@ -1615,9 +1615,17 @@ gtk_main_do_event (GdkEvent *event)
case GDK_EXPOSE:
if (event->any.window && gtk_widget_get_double_buffered (event_widget))
{
gdk_window_begin_paint_region (event->any.window, event->expose.region);
gtk_widget_send_expose (event_widget, event);
gdk_window_end_paint (event->any.window);
/* We handle exposes only on native windows, relying on the
* draw() handler to propagate down to non-native windows.
* This is ok now that we child windows always are considered
* (semi)transparent.
*/
if (gdk_window_has_native (event->expose.window))
{
gdk_window_begin_paint_region (event->any.window, event->expose.region);
gtk_widget_send_expose (event_widget, event);
gdk_window_end_paint (event->any.window);
}
}
else
{
Expand Down

0 comments on commit d22fd72

Please sign in to comment.