From ec51e41c6213ca8bb48bfd8c030f2ec669a132f9 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 3 Apr 2007 18:40:00 +0000 Subject: [PATCH] Patch from Carlo Wood to do some miscellaneous code cleanups found while 2007-04-02 Elijah Newren Patch from Carlo Wood to do some miscellaneous code cleanups found while working on #358311. * src/constraints.c (do_screen_and_xinerama_relative_constraints): nicer way of avoiding compilation warning * src/boxes.c (meta_rectangle_clamp_to_fit_into_region, meta_rectangle_clip_to_region, meta_rectangle_shove_into_region): Much cleaner way of ignoring invalid boxes in comparisons svn path=/trunk/; revision=3145 --- ChangeLog | 12 ++++++++ src/boxes.c | 72 +++++++++++++++++------------------------------ src/constraints.c | 4 ++- 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2df40b110..d76d8b220 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-04-02 Elijah Newren + + Patch from Carlo Wood to do some miscellaneous code cleanups found + while working on #358311. + + * src/constraints.c (do_screen_and_xinerama_relative_constraints): + nicer way of avoiding compilation warning + + * src/boxes.c (meta_rectangle_clamp_to_fit_into_region, + meta_rectangle_clip_to_region, meta_rectangle_shove_into_region): + Much cleaner way of ignoring invalid boxes in comparisons + 2007-04-02 Elijah Newren Patch from Carlo Wood to fix handling of unidirectional diff --git a/src/boxes.c b/src/boxes.c index cc0fbac96..c7bf8cdba 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -808,39 +808,36 @@ meta_rectangle_clamp_to_fit_into_region (const GList *spanning_rects, /* First, find best rectangle from spanning_rects to which we can clamp * rect to fit into. */ - temp = spanning_rects; - while (temp) + for (temp = spanning_rects; temp; temp = temp->next) { - int factor = 1; MetaRectangle *compare_rect = temp->data; int maximal_overlap_amount_for_compare; - /* If x is fixed and the entire width of rect doesn't fit in compare, set - * factor to 0. + /* If x is fixed and the entire width of rect doesn't fit in compare, + * skip this rectangle. */ if ((fixed_directions & FIXED_DIRECTION_X) && (compare_rect->x > rect->x || compare_rect->x + compare_rect->width < rect->x + rect->width)) - factor = 0; + continue; - /* If y is fixed and the entire height of rect doesn't fit in compare, set - * factor to 0. + /* If y is fixed and the entire height of rect doesn't fit in compare, + * skip this rectangle. */ if ((fixed_directions & FIXED_DIRECTION_Y) && (compare_rect->y > rect->y || compare_rect->y + compare_rect->height < rect->y + rect->height)) - factor = 0; + continue; - /* If compare can't hold the min_size window, set factor to 0 */ + /* If compare can't hold the min_size window, skip this rectangle. */ if (compare_rect->width < min_size->width || compare_rect->height < min_size->height) - factor = 0; + continue; /* Determine maximal overlap amount */ maximal_overlap_amount_for_compare = MIN (rect->width, compare_rect->width) * MIN (rect->height, compare_rect->height); - maximal_overlap_amount_for_compare *= factor; /* See if this is the best rect so far */ if (maximal_overlap_amount_for_compare > best_overlap) @@ -848,8 +845,6 @@ meta_rectangle_clamp_to_fit_into_region (const GList *spanning_rects, best_rect = compare_rect; best_overlap = maximal_overlap_amount_for_compare; } - - temp = temp->next; } /* Clamp rect appropriately */ @@ -882,34 +877,31 @@ meta_rectangle_clip_to_region (const GList *spanning_rects, /* First, find best rectangle from spanning_rects to which we will clip * rect into. */ - temp = spanning_rects; - while (temp) + for (temp = spanning_rects; temp; temp = temp->next) { - int factor = 1; MetaRectangle *compare_rect = temp->data; MetaRectangle overlap; int maximal_overlap_amount_for_compare; - - /* If x is fixed and the entire width of rect doesn't fit in compare, set - * factor to 0. + + /* If x is fixed and the entire width of rect doesn't fit in compare, + * skip the rectangle. */ if ((fixed_directions & FIXED_DIRECTION_X) && (compare_rect->x > rect->x || compare_rect->x + compare_rect->width < rect->x + rect->width)) - factor = 0; + continue; - /* If y is fixed and the entire height of rect doesn't fit in compare, set - * factor to 0. + /* If y is fixed and the entire height of rect doesn't fit in compare, + * skip the rectangle. */ if ((fixed_directions & FIXED_DIRECTION_Y) && (compare_rect->y > rect->y || compare_rect->y + compare_rect->height < rect->y + rect->height)) - factor = 0; + continue; /* Determine maximal overlap amount */ meta_rectangle_intersect (rect, compare_rect, &overlap); maximal_overlap_amount_for_compare = meta_rectangle_area (&overlap); - maximal_overlap_amount_for_compare *= factor; /* See if this is the best rect so far */ if (maximal_overlap_amount_for_compare > best_overlap) @@ -917,8 +909,6 @@ meta_rectangle_clip_to_region (const GList *spanning_rects, best_rect = compare_rect; best_overlap = maximal_overlap_amount_for_compare; } - - temp = temp->next; } /* Clip rect appropriately */ @@ -965,36 +955,35 @@ meta_rectangle_shove_into_region (const GList *spanning_rects, /* First, find best rectangle from spanning_rects to which we will shove * rect into. */ - temp = spanning_rects; - while (temp) + + for (temp = spanning_rects; temp; temp = temp->next) { - int factor = 1; MetaRectangle *compare_rect = temp->data; int maximal_overlap_amount_for_compare; int dist_to_compare; - /* If x is fixed and the entire width of rect doesn't fit in compare, set - * factor to 0. + /* If x is fixed and the entire width of rect doesn't fit in compare, + * skip this rectangle. */ if ((fixed_directions & FIXED_DIRECTION_X) && (compare_rect->x > rect->x || compare_rect->x + compare_rect->width < rect->x + rect->width)) - factor = 0; + continue; - /* If y is fixed and the entire height of rect doesn't fit in compare, set - * factor to 0. + /* If y is fixed and the entire height of rect doesn't fit in compare, + * skip this rectangle. */ if ((fixed_directions & FIXED_DIRECTION_Y) && (compare_rect->y > rect->y || compare_rect->y + compare_rect->height < rect->y + rect->height)) - factor = 0; + continue; /* Determine maximal overlap amount between rect & compare_rect */ maximal_overlap_amount_for_compare = MIN (rect->width, compare_rect->width) * MIN (rect->height, compare_rect->height); - /* Determine distance necessary to put rect into comapre_rect */ + /* Determine distance necessary to put rect into compare_rect */ dist_to_compare = 0; if (compare_rect->x > rect->x) dist_to_compare += compare_rect->x - rect->x; @@ -1007,13 +996,6 @@ meta_rectangle_shove_into_region (const GList *spanning_rects, dist_to_compare += (rect->y + rect->height) - (compare_rect->y + compare_rect->height); - /* If we'd have to move in the wrong direction, disqualify compare_rect */ - if (factor == 0) - { - maximal_overlap_amount_for_compare = 0; - dist_to_compare = G_MAXINT; - } - /* See if this is the best rect so far */ if ((maximal_overlap_amount_for_compare > best_overlap) || (maximal_overlap_amount_for_compare == best_overlap && @@ -1023,8 +1005,6 @@ meta_rectangle_shove_into_region (const GList *spanning_rects, best_overlap = maximal_overlap_amount_for_compare; shortest_distance = dist_to_compare; } - - temp = temp->next; } /* Shove rect appropriately */ diff --git a/src/constraints.c b/src/constraints.c index d868c9646..250ca7c55 100644 --- a/src/constraints.c +++ b/src/constraints.c @@ -1026,13 +1026,15 @@ do_screen_and_xinerama_relative_constraints ( gboolean exit_early = FALSE, constraint_satisfied; MetaRectangle how_far_it_can_be_smushed, min_size, max_size; +#ifdef WITH_VERBOSE_MODE /* First, log some debugging information */ char spanning_region[1 + 28 * g_list_length (region_spanning_rectangles)]; - (void) spanning_region; /* Avoid stupid & incorrect compiler warnings... */ + meta_topic (META_DEBUG_GEOMETRY, "screen/xinerama constraint; region_spanning_rectangles: %s\n", meta_rectangle_region_to_string (region_spanning_rectangles, ", ", spanning_region)); +#endif /* Determine whether constraint applies; exit if it doesn't */ how_far_it_can_be_smushed = info->current;