diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index 1719a4500..3a5839695 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -22,6 +22,7 @@ #include "backends/meta-monitor-transform.h" #include "compositor/region-utils.h" +#include "core/boxes-private.h" #include @@ -392,51 +393,13 @@ meta_region_transform (cairo_region_t *region, rects = g_new0 (cairo_rectangle_int_t, n_rects); for (i = 0; i < n_rects; i++) { - cairo_rectangle_int_t rect; - cairo_region_get_rectangle (region, i, &rects[i]); - rect = rects[i]; - - switch (transform) - { - case META_MONITOR_TRANSFORM_90: - rects[i].x = width - (rect.y + rect.height); - rects[i].y = rect.x; - rects[i].width = rect.height; - rects[i].height = rect.width; - break; - case META_MONITOR_TRANSFORM_180: - rects[i].x = width - (rect.x + rect.width); - rects[i].y = height - (rect.y + rect.height); - break; - case META_MONITOR_TRANSFORM_270: - rects[i].x = rect.y; - rects[i].y = height - (rect.x + rect.width); - rects[i].width = rect.height; - rects[i].height = rect.width; - break; - case META_MONITOR_TRANSFORM_FLIPPED: - rects[i].x = width - (rect.x + rect.width); - break; - case META_MONITOR_TRANSFORM_FLIPPED_90: - rects[i].x = width - (rect.y + rect.height); - rects[i].y = height - (rect.x + rect.width); - rects[i].width = rect.height; - rects[i].height = rect.width; - break; - case META_MONITOR_TRANSFORM_FLIPPED_180: - rects[i].y = height - (rect.y + rect.height); - break; - case META_MONITOR_TRANSFORM_FLIPPED_270: - rects[i].x = rect.y; - rects[i].y = rect.x; - rects[i].width = rect.height; - rects[i].height = rect.width; - break; - case META_MONITOR_TRANSFORM_NORMAL: - g_assert_not_reached (); - } + meta_rectangle_transform (&rects[i], + transform, + width, + height, + &rects[i]); } transformed_region = cairo_region_create_rectangles (rects, n_rects); diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h index 4c6fd08ab..fba9021c9 100644 --- a/src/core/boxes-private.h +++ b/src/core/boxes-private.h @@ -24,6 +24,7 @@ #include +#include "backends/meta-backend-types.h" #include "meta/boxes.h" #include "meta/common.h" @@ -245,4 +246,10 @@ meta_rectangle_to_clutter_rect (MetaRectangle *rect) }; } +void meta_rectangle_transform (const MetaRectangle *rect, + MetaMonitorTransform transform, + int width, + int height, + MetaRectangle *dest); + #endif /* META_BOXES_PRIVATE_H */ diff --git a/src/core/boxes.c b/src/core/boxes.c index 98a8d3586..471258f40 100644 --- a/src/core/boxes.c +++ b/src/core/boxes.c @@ -30,6 +30,7 @@ #include "config.h" +#include "backends/meta-monitor-transform.h" #include "core/boxes-private.h" #include @@ -2071,3 +2072,79 @@ meta_rectangle_scale_double (const MetaRectangle *rect, break; } } + +void +meta_rectangle_transform (const MetaRectangle *rect, + MetaMonitorTransform transform, + int width, + int height, + MetaRectangle *dest) +{ + switch (transform) + { + case META_MONITOR_TRANSFORM_NORMAL: + *dest = (MetaRectangle) { + .x = rect->x, + .y = rect->y, + .width = rect->width, + .height = rect->height, + }; + break; + case META_MONITOR_TRANSFORM_90: + *dest = (MetaRectangle) { + .x = width - (rect->y + rect->height), + .y = rect->x, + .width = rect->height, + .height = rect->width, + }; + break; + case META_MONITOR_TRANSFORM_180: + *dest = (MetaRectangle) { + .x = width - (rect->x + rect->width), + .y = height - (rect->y + rect->height), + .width = rect->width, + .height = rect->height, + }; + break; + case META_MONITOR_TRANSFORM_270: + *dest = (MetaRectangle) { + .x = rect->y, + .y = height - (rect->x + rect->width), + .width = rect->height, + .height = rect->width, + }; + break; + case META_MONITOR_TRANSFORM_FLIPPED: + *dest = (MetaRectangle) { + .x = width - (rect->x + rect->width), + .y = rect->y, + .width = rect->width, + .height = rect->height, + }; + break; + case META_MONITOR_TRANSFORM_FLIPPED_90: + *dest = (MetaRectangle) { + .x = width - (rect->y + rect->height), + .y = height - (rect->x + rect->width), + .width = rect->height, + .height = rect->width, + }; + break; + case META_MONITOR_TRANSFORM_FLIPPED_180: + *dest = (MetaRectangle) { + .x = rect->x, + .y = height - (rect->y + rect->height), + .width = rect->width, + .height = rect->height, + }; + break; + case META_MONITOR_TRANSFORM_FLIPPED_270: + *dest = (MetaRectangle) { + .x = rect->y, + .y = rect->x, + .width = rect->height, + .height = rect->width, + }; + break; + } +}