[mutter] Simplify the frame testing logic in callers to grab borders



commit 8c1b2d5eda5f52fb644291d321f4af6ee29695c1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Mar 12 23:11:07 2012 -0400

    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

 src/compositor/meta-window-actor.c |   23 +++-------
 src/core/constraints.c             |    2 +-
 src/core/frame.c                   |   11 +++-
 src/core/window.c                  |   88 +++++++++++++++--------------------
 4 files changed, 53 insertions(+), 71 deletions(-)
---
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index 5e5e2c8..2633372 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1616,24 +1616,16 @@ meta_window_actor_update_bounding_region_and_borders (MetaWindowActor *self,
                                                       int              height)
 {
   MetaWindowActorPrivate *priv = self->priv;
-  MetaFrame *frame;
   MetaFrameBorders borders;
   cairo_rectangle_int_t bounding_rectangle;
 
-  bounding_rectangle.x = 0;
-  bounding_rectangle.y = 0;
+  meta_frame_calc_borders (priv->window->frame, &borders);
 
-  frame = priv->window->frame;
-  if (frame != NULL)
-    {
-      meta_frame_calc_borders (frame, &borders);
-
-      bounding_rectangle.x = borders.invisible.left;
-      bounding_rectangle.y = borders.invisible.top;
+  bounding_rectangle.x = borders.invisible.left;
+  bounding_rectangle.y = borders.invisible.top;
 
-      width -= borders.invisible.left + borders.invisible.right;
-      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.height = height;
@@ -2163,10 +2155,7 @@ check_needs_reshape (MetaWindowActor *self)
   meta_shaped_texture_set_shape_region (META_SHAPED_TEXTURE (priv->actor), NULL);
   meta_window_actor_clear_shape_region (self);
 
-  if (priv->window->frame)
-    meta_frame_calc_borders (priv->window->frame, &borders);
-  else
-    meta_frame_borders_clear (&borders);
+  meta_frame_calc_borders (priv->window->frame, &borders);
 
   region = meta_window_get_frame_bounds (priv->window);
   if (region != NULL)
diff --git a/src/core/constraints.c b/src/core/constraints.c
index bf12133..e5e390f 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -573,7 +573,7 @@ place_window_if_needed(MetaWindow     *window,
                  META_MAXIMIZE_VERTICAL : 0), &info->current);
 
           /* maximization may have changed frame geometry */
-          if (window->frame && !window->fullscreen)
+          if (!window->fullscreen)
             meta_frame_calc_borders (window->frame, info->borders);
 
           if (window->fullscreen_after_placement)
diff --git a/src/core/frame.c b/src/core/frame.c
index 2038053..15eb0cd 100644
--- a/src/core/frame.c
+++ b/src/core/frame.c
@@ -322,9 +322,14 @@ void
 meta_frame_calc_borders (MetaFrame        *frame,
                          MetaFrameBorders *borders)
 {
-  meta_ui_get_frame_borders (frame->window->screen->ui,
-                             frame->xwindow,
-                             borders);
+  /* Save on if statements and potential uninitialized values
+   * in callers -- if there's no frame, then zero the borders. */
+  if (frame == NULL)
+    meta_frame_borders_clear (borders);
+  else
+    meta_ui_get_frame_borders (frame->window->screen->ui,
+                               frame->xwindow,
+                               borders);
 }
 
 void
diff --git a/src/core/window.c b/src/core/window.c
index c237c0d..e37c0fe 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3704,6 +3704,7 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
 {
   const MetaMonitorInfo *monitor;
   MetaRectangle tile_area;
+  MetaFrameBorders borders;
 
   if (!meta_window_can_tile_maximized (window))
     return FALSE;
@@ -3717,15 +3718,10 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
 
   tile_area.width /= 2;
 
-  if (window->frame)
-    {
-      MetaFrameBorders borders;
+  meta_frame_calc_borders (window->frame, &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 &&
          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)" : "",
               old_rect.x, old_rect.y, old_rect.width, old_rect.height);
 
-  if (window->frame)
-    meta_frame_calc_borders (window->frame,
-                             &borders);
+  meta_frame_calc_borders (window->frame,
+                           &borders);
 
   new_rect.x = root_x_nw;
   new_rect.y = root_y_nw;
@@ -5109,20 +5104,18 @@ meta_window_move_frame (MetaWindow  *window,
 {
   int x = root_x_nw;
   int y = root_y_nw;
+  MetaFrameBorders borders;
 
-  if (window->frame)
-    {
-      MetaFrameBorders borders;
-      meta_frame_calc_borders (window->frame, &borders);
+  meta_frame_calc_borders (window->frame, &borders);
+
+  /* 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;
 
-      /* 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);
 }
 
@@ -5171,18 +5164,17 @@ meta_window_move_resize_frame (MetaWindow  *window,
                                int          w,
                                int          h)
 {
-  if (window->frame)
-    {
-      MetaFrameBorders borders;
-      meta_frame_calc_borders (window->frame, &borders);
-      /* offset by the distance between the origin of the window
-       * and the origin of the enclosing window decorations ( + border)
-       */
-      root_x_nw += borders.visible.left;
-      root_y_nw += borders.visible.top;
-      w -= borders.visible.left + borders.visible.right;
-      h -= borders.visible.top + borders.visible.bottom;
-    }
+  MetaFrameBorders borders;
+
+  meta_frame_calc_borders (window->frame, &borders);
+  /* offset by the distance between the origin of the window
+   * and the origin of the enclosing window decorations ( + border)
+   */
+  root_x_nw += borders.visible.left;
+  root_y_nw += borders.visible.top;
+  w -= borders.visible.left + borders.visible.right;
+  h -= borders.visible.top + borders.visible.bottom;
+
   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
 update_net_frame_extents (MetaWindow *window)
 {
-  unsigned long data[4] = { 0, 0, 0, 0 };
-
-  if (window->frame)
-    {
-      MetaFrameBorders borders;
+  unsigned long data[4];
+  MetaFrameBorders borders;
 
-      meta_frame_calc_borders (window->frame, &borders);
-      /* Left */
-      data[0] = borders.visible.left;
-      /* Right */
-      data[1] = borders.visible.right;
-      /* Top */
-      data[2] = borders.visible.top;
-      /* Bottom */
-      data[3] = borders.visible.bottom;
-    }
+  meta_frame_calc_borders (window->frame, &borders);
+  /* Left */
+  data[0] = borders.visible.left;
+  /* Right */
+  data[1] = borders.visible.right;
+  /* Top */
+  data[2] = borders.visible.top;
+  /* Bottom */
+  data[3] = borders.visible.bottom;
 
   meta_topic (META_DEBUG_GEOMETRY,
               "Setting _NET_FRAME_EXTENTS on managed window 0x%lx "



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]