[mutter/wip/gbsneto/edge-constraints: 2/4] window: Track edge constraints



commit cb3e31713eda192588718a9f06ba0e5e8a4d83ca
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Aug 17 00:43:21 2017 -0300

    window: Track edge constraints
    
    GTK has the ability to handle client-decorated windows
    in such a way that the behavior of these windows must
    match the behavior of the current window manager.
    
    In Mutter, windows can be tiled horizontally (and, in
    the future, vertically as well), which comes with a few
    requirements that the toolkit must supply. Tiled windows
    have their borders' behavior changed depending on the
    tiled position, and the toolkit must be aware of this
    information in order to properly match the window manager
    behavior.
    
    In order to provide toolkits with more precise and general
    data regarding resizable and constrained edges, this patch
    makes MetaWindow track its own edge constraints.
    
    This will later be used by the backends to send information
    to the toolkit.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751857

 src/core/window-private.h |   13 ++++++++
 src/core/window.c         |   68 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 0c58675..f3e9a5c 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -129,6 +129,13 @@ typedef struct _MetaPlacementRule
   int height;
 } MetaPlacementRule;
 
+typedef enum
+{
+  META_EDGE_CONSTRAINT_NONE    = 0,
+  META_EDGE_CONSTRAINT_WINDOW  = 1,
+  META_EDGE_CONSTRAINT_MONITOR = 2,
+} MetaEdgeConstraint;
+
 struct _MetaWindow
 {
   GObject parent_instance;
@@ -208,6 +215,12 @@ struct _MetaWindow
   guint saved_maximize : 1;
   int tile_monitor_number;
 
+  /* 0 - top
+   * 1 - right
+   * 2 - bottom
+   * 3 - left */
+  MetaEdgeConstraint edge_constraints[4];
+
   /* Keep track of the previous tile mode so when changing between left and
    * right tiles we can resize the window with the complementary width */
   guint previous_tile_mode : 2;
diff --git a/src/core/window.c b/src/core/window.c
index 4bf8609..fb29fa5 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -131,6 +131,8 @@ static void set_workspace_state (MetaWindow    *window,
                                  gboolean       on_all_workspaces,
                                  MetaWorkspace *workspace);
 
+static void update_edge_constraints (MetaWindow *window);
+
 /* 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.
@@ -2684,6 +2686,9 @@ meta_window_maximize_internal (MetaWindow        *window,
   window->maximized_vertically =
     window->maximized_vertically   || maximize_vertically;
 
+  /* Update the edge constraints */
+  update_edge_constraints (window);;
+
   meta_window_recalc_features (window);
   set_net_wm_state (window);
 
@@ -2941,6 +2946,63 @@ meta_window_calculate_area_for_tile_mode (MetaWindow    *window,
     rect->x = monitor_area.x + monitor_area.width - rect->width;
 }
 
+static void
+update_edge_constraints (MetaWindow *window)
+{
+  switch (window->tile_mode)
+    {
+    case META_TILE_NONE:
+      window->edge_constraints[0] = META_EDGE_CONSTRAINT_NONE;
+      window->edge_constraints[1] = META_EDGE_CONSTRAINT_NONE;
+      window->edge_constraints[2] = META_EDGE_CONSTRAINT_NONE;
+      window->edge_constraints[3] = META_EDGE_CONSTRAINT_NONE;
+      break;
+
+    case META_TILE_MAXIMIZED:
+      window->edge_constraints[0] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[1] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[2] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[3] = META_EDGE_CONSTRAINT_MONITOR;
+      break;
+
+    case META_TILE_LEFT:
+      window->edge_constraints[0] = META_EDGE_CONSTRAINT_MONITOR;
+
+      if (window->tile_match)
+        window->edge_constraints[1] = META_EDGE_CONSTRAINT_WINDOW;
+      else
+        window->edge_constraints[1] = META_EDGE_CONSTRAINT_NONE;
+
+      window->edge_constraints[2] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[3] = META_EDGE_CONSTRAINT_MONITOR;
+      break;
+
+    case META_TILE_RIGHT:
+      window->edge_constraints[0] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[1] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[2] = META_EDGE_CONSTRAINT_MONITOR;
+
+      if (window->tile_match)
+        window->edge_constraints[3] = META_EDGE_CONSTRAINT_WINDOW;
+      else
+        window->edge_constraints[3] = META_EDGE_CONSTRAINT_NONE;
+      break;
+    }
+
+  /* h/vmaximize also modify the edge constraints */
+  if (window->maximized_vertically)
+    {
+      window->edge_constraints[0] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[2] = META_EDGE_CONSTRAINT_MONITOR;
+    }
+
+  if (window->maximized_horizontally)
+    {
+      window->edge_constraints[1] = META_EDGE_CONSTRAINT_MONITOR;
+      window->edge_constraints[3] = META_EDGE_CONSTRAINT_MONITOR;
+    }
+}
+
 void
 meta_window_tile (MetaWindow   *window,
                   MetaTileMode  mode)
@@ -2991,6 +3053,9 @@ meta_window_tile (MetaWindow   *window,
   window->previous_tile_mode = window->tile_mode;
   window->tile_mode = mode;
 
+  /* Setup the edge constraints */
+  update_edge_constraints (window);
+
   meta_window_get_frame_rect (window, &old_frame_rect);
   meta_window_get_buffer_rect (window, &old_buffer_rect);
 
@@ -3125,6 +3190,9 @@ meta_window_unmaximize (MetaWindow        *window,
       window->maximized_vertically =
         window->maximized_vertically   && !unmaximize_vertically;
 
+      /* Update the edge constraints */
+      update_edge_constraints (window);
+
       /* recalc_features() will eventually clear the cached frame
        * extents, but we need the correct frame extents in the code below,
        * so invalidate the old frame extents manually up front.


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