[mutter/wip/gbsneto/edge-constraints: 22/26] constraints: Preserve window ratio in tile constraint



commit 3ed4b16beb06ac46eb8b39a8612aeaef20669e04
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Aug 18 21:27:35 2017 -0300

    constraints: Preserve window ratio in tile constraint
    
    Now that windows can be resized when tiled, the tiling
    constraint has no source of data to enforce a given size
    to the windowm and this aspect of the tiling constraint
    was lost.
    
    Fix that by storing the window screen ratio and applying
    it to the tiled windows in the tiling constraint.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645153

 src/core/constraints.c    |   30 +++++++++---------------------
 src/core/window-private.h |    3 +++
 src/core/window.c         |   19 ++++++++++++++++++-
 3 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/src/core/constraints.c b/src/core/constraints.c
index 558e43d..d1a775e 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -1020,8 +1020,6 @@ constrain_tiling (MetaWindow         *window,
                   gboolean            check_only)
 {
   MetaRectangle target_size;
-  MetaRectangle min_size, max_size;
-  gboolean hminbad, vminbad;
   gboolean horiz_equal, vert_equal;
   gboolean constraint_already_satisfied;
 
@@ -1032,24 +1030,13 @@ constrain_tiling (MetaWindow         *window,
   if (!META_WINDOW_TILED_SIDE_BY_SIDE (window))
     return TRUE;
 
-  /* Calculate target_size - as the tile previews need this as well, we
-   * use an external function for the actual calculation
-   */
-  meta_window_get_tile_area_for_mode (window,
-                                      window->tile_mode,
-                                      window->tile_mode,
-                                      window->tile_monitor_number,
-                                      TRUE,
-                                      &target_size);
-
-  /* Check min size constraints; max size constraints are ignored as for
-   * maximized windows.
-   */
-  get_size_limits (window, &min_size, &max_size);
-  hminbad = target_size.width < min_size.width;
-  vminbad = target_size.height < min_size.height;
-  if (hminbad || vminbad)
-    return TRUE;
+  target_size.x = info->work_area_monitor.x;
+  target_size.y = info->work_area_monitor.y;
+  target_size.width = info->work_area_monitor.width * window->hpercentage;
+  target_size.height = info->work_area_monitor.height * window->vpercentage;
+
+  if (window->tile_mode == META_TILE_RIGHT)
+    target_size.x += info->work_area_monitor.width - target_size.width;
 
   /* Determine whether constraint is already satisfied; exit if it is */
   horiz_equal = target_size.x      == info->current.x &&
@@ -1061,13 +1048,14 @@ constrain_tiling (MetaWindow         *window,
     return constraint_already_satisfied;
 
   /*** Enforce constraint ***/
+  info->current.x      = target_size.x;
   info->current.y      = target_size.y;
+  info->current.width  = target_size.width;
   info->current.height = target_size.height;
 
   return TRUE;
 }
 
-
 static gboolean
 constrain_fullscreen (MetaWindow         *window,
                       ConstraintInfo     *info,
diff --git a/src/core/window-private.h b/src/core/window-private.h
index ce11574..0c58675 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -213,6 +213,9 @@ struct _MetaWindow
   guint previous_tile_mode : 2;
   guint preview_tile_mode : 2;
 
+  gdouble hpercentage;
+  gdouble vpercentage;
+
   int preferred_output_winsys_id;
 
   /* Whether we're shaded */
diff --git a/src/core/window.c b/src/core/window.c
index ed67aa2..a57f59b 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3004,7 +3004,8 @@ meta_window_tile (MetaWindow   *window,
   meta_window_move_resize_internal (window,
                                     (META_MOVE_RESIZE_MOVE_ACTION |
                                      META_MOVE_RESIZE_RESIZE_ACTION |
-                                     META_MOVE_RESIZE_STATE_CHANGED),
+                                     META_MOVE_RESIZE_STATE_CHANGED |
+                                     META_MOVE_RESIZE_USER_ACTION),
                                     NorthWestGravity,
                                     new_rect);
 
@@ -3733,6 +3734,18 @@ meta_window_update_monitor (MetaWindow *window,
     }
 }
 
+static void
+meta_window_update_screen_ratio (MetaWindow    *window,
+                                 MetaRectangle  rect)
+{
+  MetaRectangle workarea;
+
+  meta_window_get_work_area_current_monitor (window, &workarea);
+
+  window->hpercentage = rect.width / (gdouble) workarea.width;
+  window->vpercentage = rect.height / (gdouble) workarea.height;
+}
+
 void
 meta_window_move_resize_internal (MetaWindow          *window,
                                   MetaMoveResizeFlags  flags,
@@ -3811,6 +3824,10 @@ meta_window_move_resize_internal (MetaWindow          *window,
   else
     g_assert_not_reached ();
 
+  /* Only update percentage when the user resizes the window */
+  if ((flags & META_MOVE_RESIZE_USER_ACTION) && (flags & META_MOVE_RESIZE_RESIZE_ACTION))
+    meta_window_update_screen_ratio (window, unconstrained_rect);
+
   constrained_rect = unconstrained_rect;
   if (flags & (META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION) &&
       window->monitor)


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