[mutter] edge-resistance: Add snapping for tiled windows



commit 1dbf6b096b25d826a6e17790367e658c77c8faa8
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jun 13 18:30:10 2017 -0300

    edge-resistance: Add snapping for tiled windows
    
    When windows are tiled, it improves the interaction with
    them when they have a set of snapping edges relative to
    the monitor. For example, when there's a document editor
    and a PDF file opened, I might want to rescale the former
    to 2/3 of the screen and the latter to 1/3.
    
    These snapping sections are not really tied to any other
    window, and only depend on the current work area of the
    window. Thus, it is not necessary to adapt the current
    snapping edge detection algorithm.
    
    This patch adds the necessary code in edge-resistance.c
    to special-case tiled windows and allow them to cover
    1/4, 1/3 and 1/2 (horizontally) of the screen. These
    values are hardcoded.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645153

 src/core/edge-resistance.c |   46 +++++++++++++++++++++++++++++++++++++++++++-
 src/core/window.c          |    4 +-
 2 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/src/core/edge-resistance.c b/src/core/edge-resistance.c
index 1c389a8..204165a 100644
--- a/src/core/edge-resistance.c
+++ b/src/core/edge-resistance.c
@@ -556,7 +556,7 @@ apply_edge_resistance_to_each_side (MetaDisplay         *display,
 
   edge_data = display->grab_edge_resistance_data;
 
-  if (auto_snap)
+  if (auto_snap && !META_WINDOW_TILED_SIDE_BY_SIDE (window))
     {
       /* Do the auto snapping instead of normal edge resistance; in all
        * cases, we allow snapping to opposite kinds of edges (e.g. left
@@ -591,6 +591,50 @@ apply_edge_resistance_to_each_side (MetaDisplay         *display,
                                         FALSE,
                                         keyboard_op);
     }
+  else if (auto_snap && META_WINDOW_TILED_SIDE_BY_SIDE (window))
+    {
+      MetaRectangle workarea;
+      guint i;
+
+      const gfloat tile_edges[] =
+        {
+          1./4.,
+          1./3.,
+          1./2.,
+          2./3.,
+          3./4.,
+        };
+
+      meta_window_get_work_area_current_monitor (window, &workarea);
+
+      new_left = new_outer->x;
+      new_top = new_outer->y;
+      new_right = new_outer->x + new_outer->width;
+      new_bottom = new_outer->y + new_outer->height;
+
+      /* When snapping tiled windows, we don't really care about the
+       * x and y position, only about the width and height. Also, it
+       * is special-cased (instead of relying on edge_data) because
+       * we don't really care for other windows when calculating the
+       * snapping points of tiled windows - we only care about the
+       * work area and the target position.
+       */
+      for (i = 0; i < G_N_ELEMENTS (tile_edges); i++)
+        {
+          guint horizontal_point = workarea.x + floor (workarea.width * tile_edges[i]);
+
+          if (ABS (horizontal_point - new_left) < 16)
+            {
+              new_left = horizontal_point;
+              new_right = workarea.x + workarea.width;
+            }
+          else if (ABS (horizontal_point - new_right) < 16)
+            {
+              new_left = workarea.x;
+              new_right = horizontal_point;
+            }
+        }
+    }
   else
     {
       /* Disable edge resistance for resizes when windows have size
diff --git a/src/core/window.c b/src/core/window.c
index e34f459..c3866ad 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6256,7 +6256,7 @@ end_grab_op (MetaWindow *window,
       else if (meta_grab_op_is_resizing (window->display->grab_op))
         {
           update_resize (window,
-                         modifiers & CLUTTER_SHIFT_MASK,
+                         modifiers & CLUTTER_SHIFT_MASK || window->tile_match != NULL,
                          x, y,
                          TRUE);
           maybe_maximize_tiled_window (window);
@@ -6333,7 +6333,7 @@ meta_window_handle_mouse_grab_op_event  (MetaWindow         *window,
       else if (meta_grab_op_is_resizing (window->display->grab_op))
         {
           update_resize (window,
-                         modifier_state & CLUTTER_SHIFT_MASK,
+                         modifier_state & CLUTTER_SHIFT_MASK || window->tile_match != NULL,
                          x, y,
                          FALSE);
         }


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