From 990267026a0f6b777e7f8acf547ef0ba6d63a697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 22 Jun 2021 16:10:05 +0200 Subject: [PATCH] boxes: Add rectangle init macro META_RECTANGLE_INIT() works like e.g. GRAPHENE_RECT_INIT() and similar macros. Part-of: --- src/meta/boxes.h | 8 ++++++++ src/tests/boxes-tests.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/meta/boxes.h b/src/meta/boxes.h index 7585e1312..40683bb1f 100644 --- a/src/meta/boxes.h +++ b/src/meta/boxes.h @@ -54,6 +54,14 @@ typedef struct _MetaRectangle MetaRectangle; typedef cairo_rectangle_int_t MetaRectangle; #endif +#define META_RECTANGLE_INIT(_x, _y, _width, _height) \ + (MetaRectangle) { \ + .x = (_x), \ + .y = (_y), \ + .width = (_width), \ + .height = (_height) \ + } + /** * MetaStrut: * @rect: #MetaRectangle the #MetaStrut is on diff --git a/src/tests/boxes-tests.c b/src/tests/boxes-tests.c index ea33b5544..8886a294c 100644 --- a/src/tests/boxes-tests.c +++ b/src/tests/boxes-tests.c @@ -103,6 +103,18 @@ new_monitor_edge (int x, int y, int width, int height, int side_type) return temporary; } +static void +test_init_rect (void) +{ + MetaRectangle rect; + + rect = META_RECTANGLE_INIT (1, 2, 3, 4); + g_assert_cmpint (rect.x, ==, 1); + g_assert_cmpint (rect.y, ==, 2); + g_assert_cmpint (rect.width, ==, 3); + g_assert_cmpint (rect.height, ==, 4); +} + static void test_area (void) { @@ -1364,6 +1376,7 @@ init_boxes_tests (void) { init_random_ness (); + g_test_add_func ("/util/boxes/init", test_init_rect); g_test_add_func ("/util/boxes/area", test_area); g_test_add_func ("/util/boxes/intersect", test_intersect); g_test_add_func ("/util/boxes/equal", test_equal);