From a8c972cd6ba669147c01ccae57866e08b85957ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 1 Mar 2019 14:23:05 +0100 Subject: [PATCH] boxes: Add function to create a rectangle from floating clutter rect Meta rectangles are integer based while clutter works in floating coordinates, so when converting to integers we need a strategy. Implement the shrink strategy by ceiling the coordinates and flooring the width, and the grow strategy reusing clutter facility for this. https://gitlab.gnome.org/GNOME/mutter/merge_requests/3 --- src/core/boxes-private.h | 4 ++++ src/core/boxes.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h index d80cdacd3..24c596b5f 100644 --- a/src/core/boxes-private.h +++ b/src/core/boxes-private.h @@ -274,6 +274,10 @@ void meta_rectangle_transform (const MetaRectangle *rect, int height, MetaRectangle *dest); +void meta_rectangle_from_clutter_rect (ClutterRect *rect, + MetaRoundingStrategy rounding_strategy, + MetaRectangle *dest); + void meta_rectangle_crop_and_scale (const MetaRectangle *rect, ClutterRect *src_rect, int dst_width, diff --git a/src/core/boxes.c b/src/core/boxes.c index 938ec51e9..7b693e1b1 100644 --- a/src/core/boxes.c +++ b/src/core/boxes.c @@ -2151,6 +2151,39 @@ meta_rectangle_transform (const MetaRectangle *rect, } } +void +meta_rectangle_from_clutter_rect (ClutterRect *rect, + MetaRoundingStrategy rounding_strategy, + MetaRectangle *dest) +{ + switch (rounding_strategy) + { + case META_ROUNDING_STRATEGY_SHRINK: + { + *dest = (MetaRectangle) { + .x = ceilf (rect->origin.x), + .y = ceilf (rect->origin.y), + .width = floorf (rect->origin.x + rect->size.width) - dest->x, + .height = floorf (rect->origin.y + rect->size.height) - dest->x, + }; + } + break; + case META_ROUNDING_STRATEGY_GROW: + { + ClutterRect clamped = *rect; + clutter_rect_clamp_to_pixel (&clamped); + + *dest = (MetaRectangle) { + .x = clamped.origin.x, + .y = clamped.origin.y, + .width = clamped.size.width, + .height = clamped.size.height, + }; + } + break; + } +} + void meta_rectangle_crop_and_scale (const MetaRectangle *rect, ClutterRect *src_rect,