[mutter/wip/fmuellner/contraint-tiling: 3/10] window: Tile and resize considering the tile match



commit 8ef455d092baeadbb46c9e0f4a7d41e7ac54a15b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Jun 11 22:13:03 2017 -0300

    window: Tile and resize considering the tile match
    
    After the introduction of the possibility to resize tiled windows,
    it is a sensible decision to make windows aware of their tiling
    match. A tiling match is another window that is tiled in such a
    way that is the complement of the current window.
    
    The newly introduced behavior attepts to make tiling as smooth as
    possible, with the following rules:
    
     * Windows now compute their tile match when tiling and, if there's
       a match, they automatically complement the sibling's width.
     * Resizing a window with a sibling automatically resizes the sibling
       too to be the complement of the window's width.
     * It is not possible to resize below windows' minimum widths.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645153

 src/core/window.c |   78 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 67 insertions(+), 11 deletions(-)
---
diff --git a/src/core/window.c b/src/core/window.c
index ba0013f..bfc227f 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -133,6 +133,9 @@ static void set_workspace_state (MetaWindow    *window,
                                  gboolean       on_all_workspaces,
                                  MetaWorkspace *workspace);
 
+static MetaWindow * meta_window_find_tile_match (MetaWindow   *window,
+                                                 MetaTileMode  mode);
+
 /* Idle handlers for the three queues (run with meta_later_add()). The
  * "data" parameter in each case will be a GINT_TO_POINTER of the
  * index into the queue arrays to use.
@@ -2973,10 +2976,19 @@ static double
 meta_window_get_tile_fraction (MetaWindow   *window,
                                MetaTileMode  tile_mode)
 {
+  MetaWindow *tile_match;
+
+  /* Make sure the tile match is up-to-date and matches the
+   * passed in mode rather than the current state
+   */
+  tile_match = meta_window_find_tile_match (window, tile_mode);
+
   if (tile_mode == META_TILE_NONE)
     return -1.;
   else if (tile_mode == META_TILE_MAXIMIZED)
     return 1.;
+  else if (tile_match)
+    return 1. - tile_match->tile_hfraction;
   else if (META_WINDOW_TILED_SIDE_BY_SIDE (window))
     {
       if (window->tile_mode != tile_mode)
@@ -2993,6 +3005,7 @@ meta_window_update_tile_fraction (MetaWindow *window,
                                   int         new_w,
                                   int         new_h)
 {
+  MetaWindow *tile_match = window->tile_match;
   MetaRectangle work_area;
 
   if (!META_WINDOW_TILED_SIDE_BY_SIDE (window))
@@ -3002,6 +3015,9 @@ meta_window_update_tile_fraction (MetaWindow *window,
                                          window->tile_monitor_number,
                                          &work_area);
   window->tile_hfraction = (double)new_w / work_area.width;
+
+  if (tile_match && window->display->grab_window == window)
+    meta_window_tile (tile_match, tile_match->tile_mode);
 }
 
 void
@@ -4060,6 +4076,34 @@ meta_window_move_to_monitor (MetaWindow  *window,
     meta_screen_queue_check_fullscreen (window->screen);
 }
 
+static void
+adjust_size_for_tile_match (MetaWindow *window,
+                            int        *new_w,
+                            int        *new_h)
+{
+  MetaRectangle work_area, rect;
+  MetaWindow *tile_match = window->tile_match;
+
+  if (!META_WINDOW_TILED_SIDE_BY_SIDE (window) || !tile_match)
+    return;
+
+  meta_window_get_work_area_for_monitor (window, window->tile_monitor_number, &work_area);
+
+  /* Make sure the resize does not break minimum sizes */
+  rect = work_area;
+  rect.width = *new_w;
+
+  meta_window_frame_rect_to_client_rect (window, &rect, &rect);
+  *new_w += MAX(0, window->size_hints.min_width - rect.width);
+
+  /* Make sure we're not resizing the tile match below its min width */
+  rect = work_area;
+  rect.width = work_area.width - *new_w;
+
+  meta_window_frame_rect_to_client_rect (tile_match, &rect, &rect);
+  *new_w -= MAX(0, tile_match->size_hints.min_width - rect.width);
+}
+
 void
 meta_window_resize_frame_with_gravity (MetaWindow *window,
                                        gboolean     user_op,
@@ -4074,7 +4118,14 @@ meta_window_resize_frame_with_gravity (MetaWindow *window,
   rect.height = h;
 
   if (user_op)
-    meta_window_update_tile_fraction (window, w, h);
+    {
+      /* When resizing in-tandem with a tile match, we need to respect
+       * its minimum width
+       */
+      if (window->display->grab_window == window)
+        adjust_size_for_tile_match (window, &w, &h);
+      meta_window_update_tile_fraction (window, w, h);
+    }
 
   flags = (user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | META_MOVE_RESIZE_RESIZE_ACTION;
   meta_window_move_resize_internal (window, flags, gravity, rect);
@@ -7567,21 +7618,26 @@ meta_window_get_tile_match (MetaWindow *window)
 void
 meta_window_compute_tile_match (MetaWindow *window)
 {
+  window->tile_match = meta_window_find_tile_match (window, window->tile_mode);
+}
+
+static MetaWindow *
+meta_window_find_tile_match (MetaWindow   *window,
+                             MetaTileMode  current_mode)
+{
   MetaWindow *match;
   MetaStack *stack;
   MetaTileMode match_tile_mode = META_TILE_NONE;
 
-  window->tile_match = NULL;
-
   if (window->shaded || window->minimized)
-    return;
+    return NULL;
 
-  if (META_WINDOW_TILED_LEFT (window))
+  if (current_mode == META_TILE_LEFT)
     match_tile_mode = META_TILE_RIGHT;
-  else if (META_WINDOW_TILED_RIGHT (window))
+  else if (current_mode == META_TILE_RIGHT)
     match_tile_mode = META_TILE_LEFT;
   else
-    return;
+    return NULL;
 
   stack = window->screen->stack;
 
@@ -7592,7 +7648,7 @@ meta_window_compute_tile_match (MetaWindow *window)
       if (!match->shaded &&
           !match->minimized &&
           match->tile_mode == match_tile_mode &&
-          match->monitor == window->monitor &&
+          match->tile_monitor_number == window->tile_monitor_number &&
           meta_window_get_workspace (match) == meta_window_get_workspace (window))
         break;
     }
@@ -7632,11 +7688,11 @@ meta_window_compute_tile_match (MetaWindow *window)
 
           if (meta_rectangle_overlap (&above_rect, &bottommost_rect) &&
               meta_rectangle_overlap (&above_rect, &topmost_rect))
-            return;
+            return NULL;
         }
-
-      window->tile_match = match;
     }
+
+  return match;
 }
 
 void


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