[mutter] window: Make the caller decide when to constrain



commit f4645b0a37f61b7667f4d7f94b4a2467b8e85006
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Fri Mar 4 15:23:38 2022 +0100

    window: Make the caller decide when to constrain
    
    There were some magic conditions that decided when
    meta_window_constrain() was to be called or not. Reasoning about and
    changing these conditions were complicated, and in practice the caller
    knows when constraining should be done. Lets change things by adding a
    'constrain' flag to the move-resize flags that makes this clearer. This
    way we can, if needed, have better control of when a window is
    constrained or not without leaking that logic into the generic
    to-constrain-or-not expression.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2338>

 src/core/window-private.h         |  1 +
 src/core/window.c                 | 41 +++++++++++++++++++++++++--------------
 src/wayland/meta-window-wayland.c |  3 ++-
 src/x11/window-x11.c              | 13 +++++++++----
 4 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 4f269ff37a..473e162565 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -73,6 +73,7 @@ typedef enum
   META_MOVE_RESIZE_FORCE_UPDATE_MONITOR = 1 << 10,
   META_MOVE_RESIZE_PLACEMENT_CHANGED = 1 << 11,
   META_MOVE_RESIZE_WAYLAND_CLIENT_RESIZE = 1 << 12,
+  META_MOVE_RESIZE_CONSTRAIN = 1 << 13,
 } MetaMoveResizeFlags;
 
 typedef enum
diff --git a/src/core/window.c b/src/core/window.c
index 003437c3d2..df5b19b132 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -2120,7 +2120,9 @@ meta_window_force_placement (MetaWindow *window,
    */
   window->calc_placement = TRUE;
 
-  flags = META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION;
+  flags = (META_MOVE_RESIZE_MOVE_ACTION |
+           META_MOVE_RESIZE_RESIZE_ACTION |
+           META_MOVE_RESIZE_CONSTRAIN);
   if (force_move)
     flags |= META_MOVE_RESIZE_FORCE_MOVE;
 
@@ -2681,7 +2683,8 @@ meta_window_maximize (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_CONSTRAIN),
                                         META_GRAVITY_NORTH_WEST,
                                         window->unconstrained_rect);
     }
@@ -2949,7 +2952,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_CONSTRAIN),
                                     META_GRAVITY_NORTH_WEST,
                                     window->unconstrained_rect);
 
@@ -3275,7 +3279,8 @@ meta_window_make_fullscreen (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_CONSTRAIN),
                                         META_GRAVITY_NORTH_WEST,
                                         window->unconstrained_rect);
     }
@@ -3581,7 +3586,8 @@ meta_window_reposition (MetaWindow *window)
 {
   meta_window_move_resize_internal (window,
                                     (META_MOVE_RESIZE_MOVE_ACTION |
-                                     META_MOVE_RESIZE_RESIZE_ACTION),
+                                     META_MOVE_RESIZE_RESIZE_ACTION |
+                                     META_MOVE_RESIZE_CONSTRAIN),
                                     META_GRAVITY_NORTH_WEST,
                                     window->rect);
 }
@@ -3855,10 +3861,7 @@ meta_window_move_resize_internal (MetaWindow          *window,
 
   constrained_rect = unconstrained_rect;
   temporary_rect = window->rect;
-  if (flags & (META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION) &&
-      !(flags & META_MOVE_RESIZE_WAYLAND_FINISH_MOVE_RESIZE) &&
-      !(flags & (META_MOVE_RESIZE_UNMAXIMIZE | META_MOVE_RESIZE_UNFULLSCREEN)) &&
-      window->monitor)
+  if (flags & META_MOVE_RESIZE_CONSTRAIN && window->monitor)
     {
       MetaRectangle old_rect;
       meta_window_get_frame_rect (window, &old_rect);
@@ -3989,7 +3992,9 @@ meta_window_move_frame (MetaWindow *window,
 
   g_return_if_fail (!window->override_redirect);
 
-  flags = (user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | META_MOVE_RESIZE_MOVE_ACTION;
+  flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) |
+           META_MOVE_RESIZE_MOVE_ACTION |
+           META_MOVE_RESIZE_CONSTRAIN);
   meta_window_move_resize_internal (window, flags, META_GRAVITY_NORTH_WEST, rect);
 }
 
@@ -4020,9 +4025,10 @@ meta_window_move_between_rects (MetaWindow  *window,
   window->saved_rect.y = window->unconstrained_rect.y;
 
   meta_window_move_resize_internal (window,
-                                    move_resize_flags |
-                                    META_MOVE_RESIZE_MOVE_ACTION |
-                                    META_MOVE_RESIZE_RESIZE_ACTION,
+                                    (move_resize_flags |
+                                     META_MOVE_RESIZE_MOVE_ACTION |
+                                     META_MOVE_RESIZE_RESIZE_ACTION |
+                                     META_MOVE_RESIZE_CONSTRAIN),
                                     META_GRAVITY_NORTH_WEST,
                                     window->unconstrained_rect);
 }
@@ -4052,7 +4058,10 @@ meta_window_move_resize_frame (MetaWindow  *window,
 
   g_return_if_fail (!window->override_redirect);
 
-  flags = (user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | META_MOVE_RESIZE_MOVE_ACTION | 
META_MOVE_RESIZE_RESIZE_ACTION;
+  flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) |
+           META_MOVE_RESIZE_MOVE_ACTION |
+           META_MOVE_RESIZE_RESIZE_ACTION |
+           META_MOVE_RESIZE_CONSTRAIN);
 
   meta_window_move_resize_internal (window, flags, META_GRAVITY_NORTH_WEST, rect);
 }
@@ -4161,7 +4170,9 @@ meta_window_resize_frame_with_gravity (MetaWindow *window,
       meta_window_update_tile_fraction (window, w, h);
     }
 
-  flags = (user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | META_MOVE_RESIZE_RESIZE_ACTION;
+  flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) |
+           META_MOVE_RESIZE_RESIZE_ACTION |
+           META_MOVE_RESIZE_CONSTRAIN);
   meta_window_move_resize_internal (window, flags, gravity, rect);
 }
 
diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c
index d8ece0bd79..878e448bd0 100644
--- a/src/wayland/meta-window-wayland.c
+++ b/src/wayland/meta-window-wayland.c
@@ -1119,7 +1119,8 @@ meta_window_place_with_placement_rule (MetaWindow        *window,
   meta_window_move_resize_internal (window,
                                     (META_MOVE_RESIZE_MOVE_ACTION |
                                      META_MOVE_RESIZE_RESIZE_ACTION |
-                                     META_MOVE_RESIZE_PLACEMENT_CHANGED),
+                                     META_MOVE_RESIZE_PLACEMENT_CHANGED |
+                                     META_MOVE_RESIZE_CONSTRAIN),
                                     META_GRAVITY_NORTH_WEST,
                                     window->unconstrained_rect);
   window->calc_placement = FALSE;
diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c
index ac9450669f..5e11472033 100644
--- a/src/x11/window-x11.c
+++ b/src/x11/window-x11.c
@@ -507,7 +507,9 @@ meta_window_apply_session_info (MetaWindow *window,
       window->size_hints.win_gravity = info->gravity;
       gravity = window->size_hints.win_gravity;
 
-      flags = META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION;
+      flags = (META_MOVE_RESIZE_MOVE_ACTION |
+               META_MOVE_RESIZE_RESIZE_ACTION |
+               META_MOVE_RESIZE_CONSTRAIN);
 
       adjust_for_gravity (window, FALSE, gravity, &rect);
       meta_window_client_rect_to_frame_rect (window, &rect, &rect);
@@ -575,7 +577,10 @@ meta_window_x11_manage (MetaWindow *window)
       rect.width = window->size_hints.width;
       rect.height = window->size_hints.height;
 
-      flags = META_MOVE_RESIZE_CONFIGURE_REQUEST | META_MOVE_RESIZE_MOVE_ACTION | 
META_MOVE_RESIZE_RESIZE_ACTION;
+      flags = (META_MOVE_RESIZE_CONFIGURE_REQUEST |
+               META_MOVE_RESIZE_MOVE_ACTION |
+               META_MOVE_RESIZE_RESIZE_ACTION |
+               META_MOVE_RESIZE_CONSTRAIN);
 
       adjust_for_gravity (window, TRUE, gravity, &rect);
       meta_window_client_rect_to_frame_rect (window, &rect, &rect);
@@ -2700,9 +2705,9 @@ meta_window_move_resize_request (MetaWindow  *window,
    */
   flags = META_MOVE_RESIZE_CONFIGURE_REQUEST;
   if (value_mask & (CWX | CWY))
-    flags |= META_MOVE_RESIZE_MOVE_ACTION;
+    flags |= META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_CONSTRAIN;
   if (value_mask & (CWWidth | CWHeight))
-    flags |= META_MOVE_RESIZE_RESIZE_ACTION;
+    flags |= META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_CONSTRAIN;
 
   if (flags & (META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION))
     {


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