static void test_intersect () { MetaRectangle a = {100, 200, 50, 40}; MetaRectangle b = { 0, 50, 110, 152}; MetaRectangle c = { 0, 0, 10, 10}; MetaRectangle d = {100, 100, 50, 50}; MetaRectangle b_intersect_d = {100, 100, 10, 50}; MetaRectangle temp; MetaRectangle temp2; meta_rectangle_intersect (&a, &b, &temp); temp2 = meta_rect (100, 200, 10, 2); g_assert (meta_rectangle_equal (&temp, &temp2)); g_assert (meta_rectangle_area (&temp) == 20); meta_rectangle_intersect (&a, &c, &temp); g_assert (meta_rectangle_area (&temp) == 0); meta_rectangle_intersect (&a, &d, &temp); g_assert (meta_rectangle_area (&temp) == 0); meta_rectangle_intersect (&b, &d, &b); g_assert (meta_rectangle_equal (&b, &b_intersect_d)); printf ("%s passed.\n", G_STRFUNC); }
static void test_equal () { MetaRectangle a = {10, 12, 4, 18}; MetaRectangle b = a; MetaRectangle c = {10, 12, 4, 19}; MetaRectangle d = {10, 12, 7, 18}; MetaRectangle e = {10, 62, 4, 18}; MetaRectangle f = {27, 12, 4, 18}; g_assert ( meta_rectangle_equal (&a, &b)); g_assert (!meta_rectangle_equal (&a, &c)); g_assert (!meta_rectangle_equal (&a, &d)); g_assert (!meta_rectangle_equal (&a, &e)); g_assert (!meta_rectangle_equal (&a, &f)); printf ("%s passed.\n", G_STRFUNC); }
//some math utilities static gboolean rect_is_overlapping_any(MetaRectangle rect, MetaRectangle* rects, gint n, MetaRectangle border) { if (!meta_rectangle_contains_rect(&border, &rect)) return TRUE; for (int i = 0; i < n; i++) { if (meta_rectangle_equal(&rects[i], &rect)) continue; if (meta_rectangle_overlap(&rects[i], &rect)) return TRUE; } return FALSE; }
static gboolean strut_lists_equal (GSList *l, GSList *m) { for (; l && m; l = l->next, m = m->next) { MetaStrut *a = l->data; MetaStrut *b = m->data; if (a->side != b->side || !meta_rectangle_equal (&a->rect, &b->rect)) return FALSE; } return l == NULL && m == NULL; }
static void verify_edge_lists_are_equal (GList *code, GList *answer) { int which = 0; while (code && answer) { MetaEdge *a = code->data; MetaEdge *b = answer->data; if (!meta_rectangle_equal (&a->rect, &b->rect) || a->side_type != b->side_type || a->edge_type != b->edge_type) { g_error ("%dth item in code answer answer lists do not match; " "code rect: %d,%d + %d,%d; answer rect: %d,%d + %d,%d\n", which, a->rect.x, a->rect.y, a->rect.width, a->rect.height, b->rect.x, b->rect.y, b->rect.width, b->rect.height); } code = code->next; answer = answer->next; which++; } /* Ought to be at the end of both lists; check if we aren't */ if (code) { MetaEdge *tmp = code->data; g_error ("code list longer than answer list by %d items; " "first extra item rect: %d,%d +%d,%d\n", g_list_length (code), tmp->rect.x, tmp->rect.y, tmp->rect.width, tmp->rect.height); } if (answer) { MetaEdge *tmp = answer->data; g_error ("answer list longer than code list by %d items; " "first extra item rect: %d,%d +%d,%d\n", g_list_length (answer), tmp->rect.x, tmp->rect.y, tmp->rect.width, tmp->rect.height); } }
void meta_ui_resize_popup_set (MetaResizePopup *popup, MetaRectangle rect, int base_width, int base_height, int width_inc, int height_inc) { gboolean need_update_size; int display_w, display_h; g_return_if_fail (popup != NULL); need_update_size = FALSE; display_w = rect.width - base_width; if (width_inc > 0) display_w /= width_inc; display_h = rect.height - base_height; if (height_inc > 0) display_h /= height_inc; if (!meta_rectangle_equal(&popup->rect, &rect) || display_w != popup->horizontal_size || display_h != popup->vertical_size) need_update_size = TRUE; popup->rect = rect; popup->vertical_size = display_h; popup->horizontal_size = display_w; if (need_update_size) { ensure_size_window (popup); update_size_window (popup); } sync_showing (popup); }
/* * make_logical_config: * * Turn outputs and CRTCs into logical MetaMonitorInfo, * that will be used by the core and API layer (MetaScreen * and friends) */ static void make_logical_config (MetaMonitorManager *manager) { GArray *monitor_infos; unsigned int i, j; monitor_infos = g_array_sized_new (FALSE, TRUE, sizeof (MetaMonitorInfo), manager->n_outputs); /* Walk the list of MetaCRTCs, and build a MetaMonitorInfo for each of them, unless they reference a rectangle that is already there. */ for (i = 0; i < manager->n_crtcs; i++) { MetaCRTC *crtc = &manager->crtcs[i]; /* Ignore CRTCs not in use */ if (crtc->current_mode == NULL) continue; for (j = 0; j < monitor_infos->len; j++) { MetaMonitorInfo *info = &g_array_index (monitor_infos, MetaMonitorInfo, i); if (meta_rectangle_equal (&crtc->rect, &info->rect)) { crtc->logical_monitor = info; break; } } if (crtc->logical_monitor == NULL) { MetaMonitorInfo info; info.number = monitor_infos->len; info.rect = crtc->rect; info.is_primary = FALSE; /* This starts true because we want is_presentation only if all outputs are marked as such (while for primary it's enough that any is marked) */ info.is_presentation = TRUE; info.in_fullscreen = -1; info.output_id = 0; g_array_append_val (monitor_infos, info); crtc->logical_monitor = &g_array_index (monitor_infos, MetaMonitorInfo, info.number); } } /* Now walk the list of outputs applying extended properties (primary and presentation) */ for (i = 0; i < manager->n_outputs; i++) { MetaOutput *output; MetaMonitorInfo *info; output = &manager->outputs[i]; /* Ignore outputs that are not active */ if (output->crtc == NULL) continue; /* We must have a logical monitor on every CRTC at this point */ g_assert (output->crtc->logical_monitor != NULL); info = output->crtc->logical_monitor; info->is_primary = info->is_primary || output->is_primary; info->is_presentation = info->is_presentation && output->is_presentation; if (output->is_primary || info->output_id == 0) info->output_id = output->output_id; if (info->is_primary) manager->primary_monitor_index = info->number; } manager->n_monitor_infos = monitor_infos->len; manager->monitor_infos = (void*)g_array_free (monitor_infos, FALSE); }
static void test_shoving_into_region () { GList* region; MetaRectangle rect, temp; FixedDirections fixed_directions = 0; int i; region = get_screen_region (3); for (i = 0; i < NUM_RANDOM_RUNS; i++) { get_random_rect (&rect); if (meta_rectangle_could_fit_in_region (region, &rect)) { meta_rectangle_shove_into_region (region, 0, &rect); g_assert (meta_rectangle_contained_in_region (region, &rect)); } } meta_rectangle_free_list_and_elements (region); /* Do some manual tests too */ region = get_screen_region (2); rect = meta_rect (300, 1000, 400, 200); temp = meta_rect (300, 950, 400, 200); meta_rectangle_shove_into_region (region, fixed_directions, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (425, 1000, 300, 200); temp = meta_rect (450, 1000, 300, 200); meta_rectangle_shove_into_region (region, fixed_directions, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (425, 1000, 300, 200); temp = meta_rect (425, 950, 300, 200); meta_rectangle_shove_into_region (region, FIXED_DIRECTION_X, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 300, 1000, 400, 200); temp = meta_rect (1200, 1000, 400, 200); meta_rectangle_shove_into_region (region, FIXED_DIRECTION_Y, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 800, 1150, 400, 50); /* Completely "offscreen" :) */ temp = meta_rect ( 800, 1050, 400, 50); meta_rectangle_shove_into_region (region, 0, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (-1000, 0, 400, 150); /* Offscreen in 2 directions */ temp = meta_rect ( 0, 20, 400, 150); meta_rectangle_shove_into_region (region, 0, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); meta_rectangle_free_list_and_elements (region); printf ("%s passed.\n", G_STRFUNC); }
static void test_clipping_to_region () { GList* region; MetaRectangle rect, temp; FixedDirections fixed_directions = 0; int i; region = get_screen_region (3); for (i = 0; i < NUM_RANDOM_RUNS; i++) { get_random_rect (&rect); if (rect_overlaps_region (region, &rect)) { meta_rectangle_clip_to_region (region, 0, &rect); g_assert (meta_rectangle_contained_in_region (region, &rect) == TRUE); } } meta_rectangle_free_list_and_elements (region); /* Do some manual tests too */ region = get_screen_region (2); rect = meta_rect (-50, -10, 10000, 10000); meta_rectangle_clip_to_region (region, fixed_directions, &rect); g_assert (meta_rectangle_equal (region->data, &rect)); rect = meta_rect (300, 1000, 400, 200); temp = meta_rect (300, 1000, 400, 150); meta_rectangle_clip_to_region (region, fixed_directions, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (400, 1000, 300, 200); temp = meta_rect (450, 1000, 250, 200); meta_rectangle_clip_to_region (region, fixed_directions, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (400, 1000, 300, 200); temp = meta_rect (400, 1000, 300, 150); meta_rectangle_clip_to_region (region, FIXED_DIRECTION_X, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (400, 1000, 300, 200); temp = meta_rect (400, 1000, 300, 150); meta_rectangle_clip_to_region (region, FIXED_DIRECTION_X, &rect); g_assert (meta_rectangle_equal (&rect, &temp)); meta_rectangle_free_list_and_elements (region); printf ("%s passed.\n", G_STRFUNC); }
static void test_gravity_resize () { MetaRectangle oldrect, rect, temp; rect.x = -500; /* Some random amount not equal to oldrect.x to ensure that * the resize is done with respect to oldrect instead of rect */ oldrect = meta_rect ( 50, 300, 250, 400); temp = meta_rect ( 50, 300, 20, 5); meta_rectangle_resize_with_gravity (&oldrect, &rect, NorthWestGravity, 20, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 50, 300, 250, 400); temp = meta_rect (165, 300, 20, 5); meta_rectangle_resize_with_gravity (&rect, &rect, NorthGravity, 20, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 50, 300, 250, 400); temp = meta_rect (280, 300, 20, 5); meta_rectangle_resize_with_gravity (&rect, &rect, NorthEastGravity, 20, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 50, 300, 250, 400); temp = meta_rect ( 50, 695, 50, 5); meta_rectangle_resize_with_gravity (&rect, &rect, SouthWestGravity, 50, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 50, 300, 250, 400); temp = meta_rect (150, 695, 50, 5); meta_rectangle_resize_with_gravity (&rect, &rect, SouthGravity, 50, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 50, 300, 250, 400); temp = meta_rect (250, 695, 50, 5); meta_rectangle_resize_with_gravity (&rect, &rect, SouthEastGravity, 50, 5); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (167, 738, 237, 843); temp = meta_rect (167, 1113, 832, 93); meta_rectangle_resize_with_gravity (&rect, &rect, WestGravity, 832, 93); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect ( 167, 738, 237, 843); temp = meta_rect (-131, 1113, 833, 93); meta_rectangle_resize_with_gravity (&rect, &rect, CenterGravity, 832, 93); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (300, 1000, 400, 200); temp = meta_rect (270, 994, 430, 212); meta_rectangle_resize_with_gravity (&rect, &rect, EastGravity, 430, 211); g_assert (meta_rectangle_equal (&rect, &temp)); rect = meta_rect (300, 1000, 400, 200); temp = meta_rect (300, 1000, 430, 211); meta_rectangle_resize_with_gravity (&rect, &rect, StaticGravity, 430, 211); g_assert (meta_rectangle_equal (&rect, &temp)); printf ("%s passed.\n", G_STRFUNC); }