summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Wood <thos@gnome.org>2008-02-26 09:17:01 +0000
committerThomas Wood <thos@src.gnome.org>2008-02-26 09:17:01 +0000
commitb1396a7bf3d26755740079db4691329dfd9391c2 (patch)
treea94389836864ef02fa2d214d2d583479caca54bd
parent8f58453c053933b2919cbdc631fcd8f26576ea54 (diff)
downloadmetacity-b1396a7bf3d26755740079db4691329dfd9391c2.tar.gz
allow users of the preview widget to get a mask for windows in the correct
2008-02-25 Thomas Wood <thos@gnome.org> * src/ui/preview-widget.[ch] (meta_preview_get_clip_region): allow users of the preview widget to get a mask for windows in the correct shape for the current theme. svn path=/branches/gnome-2-22/; revision=3597
-rw-r--r--ChangeLog6
-rw-r--r--src/ui/preview-widget.c109
-rw-r--r--src/ui/preview-widget.h3
3 files changed, 118 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 369d2a27..22bdeb80 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-02-25 Thomas Wood <thos@gnome.org>
+
+ * src/ui/preview-widget.[ch] (meta_preview_get_clip_region):
+ allow users of the preview widget to get a mask for windows
+ in the correct shape for the current theme.
+
2008-02-12 Thomas Thurman <tthurman@gnome.org>
* configure.in: Post-release bump to 2.21.21.
diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c
index 08048e7b..57bb8b31 100644
--- a/src/ui/preview-widget.c
+++ b/src/ui/preview-widget.c
@@ -460,3 +460,112 @@ meta_preview_get_mini_icon (void)
return default_icon;
}
+
+GdkRegion *
+meta_preview_get_clip_region (MetaPreview *preview, gint new_window_width, gint new_window_height)
+{
+ GdkRectangle xrect;
+ GdkRegion *corners_xregion, *window_xregion;
+ gint flags;
+ MetaFrameLayout *fgeom;
+ MetaFrameStyle *frame_style;
+
+ g_return_if_fail (META_IS_PREVIEW (preview));
+
+ flags = (META_PREVIEW (preview)->flags);
+
+ frame_style = meta_theme_get_frame_style (preview->theme,
+ META_FRAME_TYPE_NORMAL, flags);
+
+ fgeom = frame_style->layout;
+
+ corners_xregion = gdk_region_new ();
+
+ if (fgeom->top_left_corner_rounded_radius != 0)
+ {
+ const int corner = fgeom->top_left_corner_rounded_radius;
+ const float radius = sqrt(corner) + corner;
+ int i;
+
+ for (i=0; i<corner; i++)
+ {
+
+ const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
+ xrect.x = 0;
+ xrect.y = i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ gdk_region_union_with_rect (corners_xregion, &xrect);
+ }
+ }
+
+ if (fgeom->top_right_corner_rounded_radius != 0)
+ {
+ const int corner = fgeom->top_right_corner_rounded_radius;
+ const float radius = sqrt(corner) + corner;
+ int i;
+
+ for (i=0; i<corner; i++)
+ {
+ const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
+ xrect.x = new_window_width - width;
+ xrect.y = i;
+ xrect.width = width;
+ xrect.height = 1;
+
+ gdk_region_union_with_rect (corners_xregion, &xrect);
+ }
+ }
+
+ if (fgeom->bottom_left_corner_rounded_radius != 0)
+ {
+ const int corner = fgeom->bottom_left_corner_rounded_radius;
+ const float radius = sqrt(corner) + corner;
+ int i;
+
+ for (i=0; i<corner; i++)
+ {
+ const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
+ xrect.x = 0;
+ xrect.y = new_window_height - i - 1;
+ xrect.width = width;
+ xrect.height = 1;
+
+ gdk_region_union_with_rect (corners_xregion, &xrect);
+ }
+ }
+
+ if (fgeom->bottom_right_corner_rounded_radius != 0)
+ {
+ const int corner = fgeom->bottom_right_corner_rounded_radius;
+ const float radius = sqrt(corner) + corner;
+ int i;
+
+ for (i=0; i<corner; i++)
+ {
+ const int width = floor(0.5 + radius - sqrt(radius*radius - (radius-(i+0.5))*(radius-(i+0.5))));
+ xrect.x = new_window_width - width;
+ xrect.y = new_window_height - i - 1;
+ xrect.width = width;
+ xrect.height = 1;
+
+ gdk_region_union_with_rect (corners_xregion, &xrect);
+ }
+ }
+
+ window_xregion = gdk_region_new ();
+
+ xrect.x = 0;
+ xrect.y = 0;
+ xrect.width = new_window_width;
+ xrect.height = new_window_height;
+
+ gdk_region_union_with_rect (window_xregion, &xrect);
+ gdk_region_subtract (window_xregion, corners_xregion);
+ gdk_region_destroy (corners_xregion);
+
+ return window_xregion;
+}
+
+
diff --git a/src/ui/preview-widget.h b/src/ui/preview-widget.h
index bfa964b3..32b3c487 100644
--- a/src/ui/preview-widget.h
+++ b/src/ui/preview-widget.h
@@ -77,6 +77,9 @@ void meta_preview_set_frame_flags (MetaPreview *preview,
void meta_preview_set_button_layout (MetaPreview *preview,
const MetaButtonLayout *button_layout);
+GdkRegion * meta_preview_get_clip_region (MetaPreview *preview,
+ gint new_window_width,
+ gint new_window_height);
GdkPixbuf* meta_preview_get_icon (void);
GdkPixbuf* meta_preview_get_mini_icon (void);