[mutter/wip/gbsneto/tiling-improvements: 17/17] window: Also consider touching edges for matching tiled windows



commit b4b66c50a0e0e550e6fa361a0114ce94c1ed8104
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jun 15 21:29:48 2017 -0300

    window: Also consider touching edges for matching tiled windows
    
    When computing a potential match for a tiled window, there is a
    chance we face the case where 2 windows really complement each
    other's tile mode (i.e. left and right) but they have different
    sizes, and their borders don't really touch each other.
    
    In that case, the current code would mistakenly assume they're
    tile matches, and would resize them with either a hole or an
    overlapping area between windows. This is clearly a misbehavior
    that is a consequence of the previous assumptions pre-resizable
    tiles.
    
    This patch adapts the tile match algorithm to also consider the
    touching edges when computing the matching tile. The touching
    edges, however, are not always considered. They obey the following
    rules:
    
     * After successfully resizing or moving, touching edges are
       considered.
     * When previewing the tile (i.e. when dragging the window to a
       corner), touching borders are ignored.
     * When actually tiling the window, touching edges are also ignored.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645153

 src/core/constraints.c    |    2 ++
 src/core/screen.c         |    1 +
 src/core/stack.c          |    3 ++-
 src/core/window-private.h |    4 +++-
 src/core/window.c         |   21 +++++++++++++++++++--
 5 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/core/constraints.c b/src/core/constraints.c
index 160ddbb..b713f4d 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -947,6 +947,7 @@ constrain_maximization (MetaWindow         *window,
                                           META_TILE_MAXIMIZED,
                                           window->tile_mode,
                                           window->monitor->number,
+                                          FALSE,
                                           &target_size);
     }
   else if (META_WINDOW_MAXIMIZED (window))
@@ -1038,6 +1039,7 @@ constrain_tiling (MetaWindow         *window,
                                       window->tile_mode,
                                       window->tile_mode,
                                       window->monitor->number,
+                                      TRUE,
                                       &target_size);
 
   /* Check min size constraints; max size constraints are ignored as for
diff --git a/src/core/screen.c b/src/core/screen.c
index f1db989..dbe8e9d 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -1436,6 +1436,7 @@ meta_screen_update_tile_preview_timeout (gpointer data)
                                           window->preview_tile_mode,
                                           window->tile_mode,
                                           monitor,
+                                          FALSE,
                                           &tile_rect);
       meta_compositor_show_tile_preview (screen->display->compositor,
                                          window, &tile_rect, monitor);
diff --git a/src/core/stack.c b/src/core/stack.c
index 01fdc4b..835c024 100644
--- a/src/core/stack.c
+++ b/src/core/stack.c
@@ -271,7 +271,8 @@ meta_stack_update_window_tile_matches (MetaStack     *stack,
 
       window->tile_match = meta_window_compute_tile_match (window,
                                                            window->tile_mode,
-                                                           window->monitor->number);
+                                                           window->monitor->number,
+                                                           TRUE);
       tmp = tmp->next;
     }
 
diff --git a/src/core/window-private.h b/src/core/window-private.h
index fc6a398..e40a15a 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -662,6 +662,7 @@ void meta_window_get_tile_area_for_mode        (MetaWindow    *window,
                                                 MetaTileMode   mode,
                                                 MetaTileMode   previous_mode,
                                                 guint          monitor_number,
+                                                gboolean       consider_edges,
                                                 MetaRectangle *tile_area);
 
 
@@ -706,7 +707,8 @@ gboolean meta_window_can_tile_side_by_side   (MetaWindow *window);
 
 MetaWindow* meta_window_compute_tile_match (MetaWindow   *window,
                                             MetaTileMode  current_mode,
-                                            gint          target_monitor);
+                                            gint          target_monitor,
+                                            gboolean      consider_edges);
 
 gboolean meta_window_updates_are_frozen (MetaWindow *window);
 
diff --git a/src/core/window.c b/src/core/window.c
index e4c5c9e..fc06a11 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -2897,6 +2897,7 @@ meta_window_calculate_area_for_tile_mode (MetaWindow    *window,
                                           MetaTileMode   mode,
                                           MetaTileMode   previous_mode,
                                           gint           monitor_number,
+                                          gboolean       consider_edges,
                                           MetaRectangle *rect)
 {
   MetaRectangle monitor_area;
@@ -2906,7 +2907,7 @@ meta_window_calculate_area_for_tile_mode (MetaWindow    *window,
   /* When tiling a window, the new matching tile window is not yet synchronized,
    * so we must do that now manually. It is not necessary to recompute all windows'
    * tile matches, just the current one */
-  tile_match = meta_window_compute_tile_match (window, mode, monitor_number);
+  tile_match = meta_window_compute_tile_match (window, mode, monitor_number, consider_edges);
   window->tile_match = tile_match;
 
   meta_window_get_work_area_for_monitor (window, monitor_number, &monitor_area);
@@ -2982,6 +2983,7 @@ meta_window_tile (MetaWindow   *window,
                                             mode,
                                             window->tile_mode,
                                             monitor_number,
+                                            TRUE,
                                             &new_rect);
 
   /* Track the previous mode */
@@ -6406,6 +6408,7 @@ meta_window_get_tile_area_for_mode (MetaWindow    *window,
                                     MetaTileMode   mode,
                                     MetaTileMode   previous_mode,
                                     guint          monitor_number,
+                                    gboolean       consider_edges,
                                     MetaRectangle *tile_area)
 {
   g_return_if_fail (mode != META_TILE_NONE);
@@ -6414,6 +6417,7 @@ meta_window_get_tile_area_for_mode (MetaWindow    *window,
                                             mode,
                                             previous_mode,
                                             monitor_number,
+                                            consider_edges,
                                             tile_area);
 }
 
@@ -7522,7 +7526,8 @@ meta_window_get_tile_match (MetaWindow *window)
 MetaWindow *
 meta_window_compute_tile_match (MetaWindow   *window,
                                 MetaTileMode  current_mode,
-                                gint          target_monitor)
+                                gint          target_monitor,
+                                gboolean      consider_edges)
 {
   MetaWindow *match;
   MetaStack *stack;
@@ -7558,6 +7563,9 @@ meta_window_compute_tile_match (MetaWindow   *window,
     {
       MetaWindow *above, *bottommost, *topmost;
       MetaRectangle above_rect, bottommost_rect, topmost_rect;
+      gint threshold;
+
+      threshold = meta_prefs_get_drag_threshold ();
 
       if (meta_stack_windows_cmp (window->screen->stack, match, window) > 0)
         {
@@ -7591,6 +7599,15 @@ meta_window_compute_tile_match (MetaWindow   *window,
               meta_rectangle_overlap (&above_rect, &topmost_rect))
             return NULL;
         }
+
+      /* If we're not ignoring the edges (i.e. the window effectively resized or
+       * changed workspaces) then check if windows really match.
+       */
+      if (consider_edges &&
+          window->tile_match != match &&
+          ABS (topmost_rect.x - bottommost_rect.x - bottommost_rect.width) > threshold &&
+          ABS (bottommost_rect.x - topmost_rect.x - topmost_rect.width)  > threshold)
+        return NULL;
     }
 
   return match;


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