Simplify the frame testing logic in callers to grab borders

A lot of code did something similar to:

  MetaFrameBorders borders;

  if (window->frame)
    meta_frame_calc_borders (window->frame, &borders);
  else
    meta_frame_borders_clear (&borders);

Sometimes, the else part was omitted and we were unknowingly using
uninitalized values for OR windows. Clean this up by just testing
for a NULL frame in meta_frame_calc_borders and clearing for the
caller if so.

https://bugzilla.gnome.org/show_bug.cgi?id=643606
This commit is contained in:
Jasper St. Pierre 2012-03-12 23:11:07 -04:00
parent 578b1c06c7
commit 8c1b2d5eda
4 changed files with 53 additions and 71 deletions

View File

@ -1616,24 +1616,16 @@ meta_window_actor_update_bounding_region_and_borders (MetaWindowActor *self,
int height) int height)
{ {
MetaWindowActorPrivate *priv = self->priv; MetaWindowActorPrivate *priv = self->priv;
MetaFrame *frame;
MetaFrameBorders borders; MetaFrameBorders borders;
cairo_rectangle_int_t bounding_rectangle; cairo_rectangle_int_t bounding_rectangle;
bounding_rectangle.x = 0; meta_frame_calc_borders (priv->window->frame, &borders);
bounding_rectangle.y = 0;
frame = priv->window->frame; bounding_rectangle.x = borders.invisible.left;
if (frame != NULL) bounding_rectangle.y = borders.invisible.top;
{
meta_frame_calc_borders (frame, &borders);
bounding_rectangle.x = borders.invisible.left; width -= borders.invisible.left + borders.invisible.right;
bounding_rectangle.y = borders.invisible.top; height -= borders.invisible.top + borders.invisible.bottom;
width -= borders.invisible.left + borders.invisible.right;
height -= borders.invisible.top + borders.invisible.bottom;
}
bounding_rectangle.width = width; bounding_rectangle.width = width;
bounding_rectangle.height = height; bounding_rectangle.height = height;
@ -2163,10 +2155,7 @@ check_needs_reshape (MetaWindowActor *self)
meta_shaped_texture_set_shape_region (META_SHAPED_TEXTURE (priv->actor), NULL); meta_shaped_texture_set_shape_region (META_SHAPED_TEXTURE (priv->actor), NULL);
meta_window_actor_clear_shape_region (self); meta_window_actor_clear_shape_region (self);
if (priv->window->frame) meta_frame_calc_borders (priv->window->frame, &borders);
meta_frame_calc_borders (priv->window->frame, &borders);
else
meta_frame_borders_clear (&borders);
region = meta_window_get_frame_bounds (priv->window); region = meta_window_get_frame_bounds (priv->window);
if (region != NULL) if (region != NULL)

View File

@ -573,7 +573,7 @@ place_window_if_needed(MetaWindow *window,
META_MAXIMIZE_VERTICAL : 0), &info->current); META_MAXIMIZE_VERTICAL : 0), &info->current);
/* maximization may have changed frame geometry */ /* maximization may have changed frame geometry */
if (window->frame && !window->fullscreen) if (!window->fullscreen)
meta_frame_calc_borders (window->frame, info->borders); meta_frame_calc_borders (window->frame, info->borders);
if (window->fullscreen_after_placement) if (window->fullscreen_after_placement)

View File

@ -322,9 +322,14 @@ void
meta_frame_calc_borders (MetaFrame *frame, meta_frame_calc_borders (MetaFrame *frame,
MetaFrameBorders *borders) MetaFrameBorders *borders)
{ {
meta_ui_get_frame_borders (frame->window->screen->ui, /* Save on if statements and potential uninitialized values
frame->xwindow, * in callers -- if there's no frame, then zero the borders. */
borders); if (frame == NULL)
meta_frame_borders_clear (borders);
else
meta_ui_get_frame_borders (frame->window->screen->ui,
frame->xwindow,
borders);
} }
void void

View File

@ -3704,6 +3704,7 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
{ {
const MetaMonitorInfo *monitor; const MetaMonitorInfo *monitor;
MetaRectangle tile_area; MetaRectangle tile_area;
MetaFrameBorders borders;
if (!meta_window_can_tile_maximized (window)) if (!meta_window_can_tile_maximized (window))
return FALSE; return FALSE;
@ -3717,15 +3718,10 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
tile_area.width /= 2; tile_area.width /= 2;
if (window->frame) meta_frame_calc_borders (window->frame, &borders);
{
MetaFrameBorders borders;
meta_frame_calc_borders (window->frame, &borders); tile_area.width -= (borders.visible.left + borders.visible.right);
tile_area.height -= (borders.visible.top + borders.visible.bottom);
tile_area.width -= (borders.visible.left + borders.visible.right);
tile_area.height -= (borders.visible.top + borders.visible.bottom);
}
return tile_area.width >= window->size_hints.min_width && return tile_area.width >= window->size_hints.min_width &&
tile_area.height >= window->size_hints.min_height; tile_area.height >= window->size_hints.min_height;
@ -4646,9 +4642,8 @@ meta_window_move_resize_internal (MetaWindow *window,
is_user_action ? " (user move/resize)" : "", is_user_action ? " (user move/resize)" : "",
old_rect.x, old_rect.y, old_rect.width, old_rect.height); old_rect.x, old_rect.y, old_rect.width, old_rect.height);
if (window->frame) meta_frame_calc_borders (window->frame,
meta_frame_calc_borders (window->frame, &borders);
&borders);
new_rect.x = root_x_nw; new_rect.x = root_x_nw;
new_rect.y = root_y_nw; new_rect.y = root_y_nw;
@ -5109,20 +5104,18 @@ meta_window_move_frame (MetaWindow *window,
{ {
int x = root_x_nw; int x = root_x_nw;
int y = root_y_nw; int y = root_y_nw;
MetaFrameBorders borders;
if (window->frame) meta_frame_calc_borders (window->frame, &borders);
{
MetaFrameBorders borders; /* root_x_nw and root_y_nw correspond to where the top of
meta_frame_calc_borders (window->frame, &borders); * the visible frame should be. Offset by the distance between
* the origin of the window and the origin of the enclosing
* window decorations.
*/
x += window->frame->child_x - borders.invisible.left;
y += window->frame->child_y - borders.invisible.top;
/* root_x_nw and root_y_nw correspond to where the top of
* the visible frame should be. Offset by the distance between
* the origin of the window and the origin of the enclosing
* window decorations.
*/
x += window->frame->child_x - borders.invisible.left;
y += window->frame->child_y - borders.invisible.top;
}
meta_window_move (window, user_op, x, y); meta_window_move (window, user_op, x, y);
} }
@ -5171,18 +5164,17 @@ meta_window_move_resize_frame (MetaWindow *window,
int w, int w,
int h) int h)
{ {
if (window->frame) MetaFrameBorders borders;
{
MetaFrameBorders borders; meta_frame_calc_borders (window->frame, &borders);
meta_frame_calc_borders (window->frame, &borders); /* offset by the distance between the origin of the window
/* offset by the distance between the origin of the window * and the origin of the enclosing window decorations ( + border)
* and the origin of the enclosing window decorations ( + border) */
*/ root_x_nw += borders.visible.left;
root_x_nw += borders.visible.left; root_y_nw += borders.visible.top;
root_y_nw += borders.visible.top; w -= borders.visible.left + borders.visible.right;
w -= borders.visible.left + borders.visible.right; h -= borders.visible.top + borders.visible.bottom;
h -= borders.visible.top + borders.visible.bottom;
}
meta_window_move_resize (window, user_op, root_x_nw, root_y_nw, w, h); meta_window_move_resize (window, user_op, root_x_nw, root_y_nw, w, h);
} }
@ -5814,22 +5806,18 @@ meta_window_get_net_wm_desktop (MetaWindow *window)
static void static void
update_net_frame_extents (MetaWindow *window) update_net_frame_extents (MetaWindow *window)
{ {
unsigned long data[4] = { 0, 0, 0, 0 }; unsigned long data[4];
MetaFrameBorders borders;
if (window->frame) meta_frame_calc_borders (window->frame, &borders);
{ /* Left */
MetaFrameBorders borders; data[0] = borders.visible.left;
/* Right */
meta_frame_calc_borders (window->frame, &borders); data[1] = borders.visible.right;
/* Left */ /* Top */
data[0] = borders.visible.left; data[2] = borders.visible.top;
/* Right */ /* Bottom */
data[1] = borders.visible.right; data[3] = borders.visible.bottom;
/* Top */
data[2] = borders.visible.top;
/* Bottom */
data[3] = borders.visible.bottom;
}
meta_topic (META_DEBUG_GEOMETRY, meta_topic (META_DEBUG_GEOMETRY,
"Setting _NET_FRAME_EXTENTS on managed window 0x%lx " "Setting _NET_FRAME_EXTENTS on managed window 0x%lx "