From 522ad73e73b9101dc8cf74f81669321fc28fac8e Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Sun, 20 Mar 2011 16:26:27 -0400 Subject: Convert frame region handling to cairo regions It's useful to get frame shapes and manipulate them within Mutter, for example so that the compositor can use them to clip drawing. For this, we'll need the regions as cairo regions not X regions, so convert frame shaping code to work in terms of cairo_region_t. https://bugzilla.gnome.org/show_bug.cgi?id=635268 --- src/ui/frames.c | 122 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/ui/frames.c b/src/ui/frames.c index c0ad3ede..c7f411d7 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -780,6 +780,39 @@ meta_frames_unflicker_bg (MetaFrames *frames, set_background_none (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow); } +#ifdef HAVE_SHAPE +static void +apply_cairo_region_to_window (Display *display, + Window xwindow, + cairo_region_t *region, + int op) +{ + int n_rects, i; + XRectangle *rects; + + n_rects = cairo_region_num_rectangles (region); + rects = g_new (XRectangle, n_rects); + + for (i = 0; i < n_rects; i++) + { + cairo_rectangle_int_t rect; + + cairo_region_get_rectangle (region, i, &rect); + + rects[i].x = rect.x; + rects[i].y = rect.y; + rects[i].width = rect.width; + rects[i].height = rect.height; + } + + XShapeCombineRectangles (display, xwindow, + ShapeBounding, 0, 0, rects, n_rects, + ShapeSet, YXBanded); + + g_free (rects); +} +#endif + void meta_frames_apply_shapes (MetaFrames *frames, Window xwindow, @@ -794,6 +827,9 @@ meta_frames_apply_shapes (MetaFrames *frames, XRectangle xrect; Region corners_xregion; Region window_xregion; + cairo_rectangle_int_t rect; + cairo_region_t *corners_region; + cairo_region_t *window_region; gint scale; frame = meta_frames_lookup_window (frames, xwindow); @@ -827,7 +863,7 @@ meta_frames_apply_shapes (MetaFrames *frames, return; /* nothing to do */ } - corners_xregion = XCreateRegion (); + corners_region = cairo_region_create (); scale = gdk_window_get_scale_factor (frame->window); if (fgeom.top_left_corner_rounded_radius != 0) @@ -839,12 +875,12 @@ meta_frames_apply_shapes (MetaFrames *frames, for (i=0; ixwindow, ShapeBounding, @@ -999,13 +1035,13 @@ meta_frames_apply_shapes (MetaFrames *frames, "Frame 0x%lx has shaped corners\n", frame->xwindow); - XShapeCombineRegion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow, - ShapeBounding, 0, 0, window_xregion, ShapeSet); + apply_cairo_region_to_window (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow, + window_region, ShapeSet); } frame->shape_applied = TRUE; - XDestroyRegion (window_xregion); + cairo_region_destroy (window_region); #endif /* HAVE_SHAPE */ } -- cgit v1.2.1