window: Add place flags

Replace a boolean argument and a temporary MetaWindow struct field with
a `MetaPlaceFlag` passed where relevant. This includes
`meta_window_move_resize_internal()` and `meta_window_constrain()`, as
placement may happen during constraining, and also
`meta_window_force_placement()`.

The struct field (denied_focus_and_not_transient) was only ever set in
meta_window_show(), before meta_window_force_placement(), and
immediately unset as a side effect of that. In .._show() we'll always
force placement if the window wasn't already placed, and in
meta_window_constrain(), we'd only ever call meta_window_place() if the
window wasn't already placed, meaning the variable would only ever be
relevant during `meta_window_show()`. Having it as a flag makes that
relationship and temporary state clearer.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3879>
This commit is contained in:
Jonas Ådahl 2024-07-11 14:23:26 +02:00 committed by Sebastian Wick
parent f4b79441fa
commit 9ebbf83e95
9 changed files with 88 additions and 41 deletions

View File

@ -220,6 +220,7 @@ static void setup_constraint_info (MetaBackend *backend,
const MtkRectangle *orig, const MtkRectangle *orig,
MtkRectangle *new); MtkRectangle *new);
static void place_window_if_needed (MetaWindow *window, static void place_window_if_needed (MetaWindow *window,
MetaPlaceFlag place_flags,
ConstraintInfo *info); ConstraintInfo *info);
static void update_onscreen_requirements (MetaWindow *window, static void update_onscreen_requirements (MetaWindow *window,
ConstraintInfo *info); ConstraintInfo *info);
@ -292,6 +293,7 @@ do_all_constraints (MetaWindow *window,
void void
meta_window_constrain (MetaWindow *window, meta_window_constrain (MetaWindow *window,
MetaMoveResizeFlags flags, MetaMoveResizeFlags flags,
MetaPlaceFlag place_flags,
MetaGravity resize_gravity, MetaGravity resize_gravity,
const MtkRectangle *orig, const MtkRectangle *orig,
MtkRectangle *new, MtkRectangle *new,
@ -319,7 +321,7 @@ meta_window_constrain (MetaWindow *window,
resize_gravity, resize_gravity,
orig, orig,
new); new);
place_window_if_needed (window, &info); place_window_if_needed (window, place_flags, &info);
while (!satisfied && priority <= PRIORITY_MAXIMUM) { while (!satisfied && priority <= PRIORITY_MAXIMUM) {
gboolean check_only = TRUE; gboolean check_only = TRUE;
@ -532,8 +534,9 @@ get_start_rect_for_resize (MetaWindow *window,
} }
static void static void
place_window_if_needed(MetaWindow *window, place_window_if_needed (MetaWindow *window,
ConstraintInfo *info) MetaPlaceFlag place_flags,
ConstraintInfo *info)
{ {
gboolean did_placement; gboolean did_placement;
@ -576,7 +579,8 @@ place_window_if_needed(MetaWindow *window,
} }
else else
{ {
meta_window_place (window, orig_rect.x, orig_rect.y, meta_window_place (window, place_flags,
orig_rect.x, orig_rect.y,
&placed_rect.x, &placed_rect.y); &placed_rect.x, &placed_rect.y);
/* placing the window may have changed the monitor. Find the /* placing the window may have changed the monitor. Find the

View File

@ -27,6 +27,7 @@
void meta_window_constrain (MetaWindow *window, void meta_window_constrain (MetaWindow *window,
MetaMoveResizeFlags flags, MetaMoveResizeFlags flags,
MetaPlaceFlag place_flags,
MetaGravity resize_gravity, MetaGravity resize_gravity,
const MtkRectangle *orig, const MtkRectangle *orig,
MtkRectangle *new, MtkRectangle *new,

View File

@ -384,9 +384,10 @@ window_place_centered (MetaWindow *window)
} }
static void static void
avoid_being_obscured_as_second_modal_dialog (MetaWindow *window, avoid_being_obscured_as_second_modal_dialog (MetaWindow *window,
int *x, MetaPlaceFlag flags,
int *y) int *x,
int *y)
{ {
/* We can't center this dialog if it was denied focus and it /* We can't center this dialog if it was denied focus and it
* overlaps with the focus window and this dialog is modal and this * overlaps with the focus window and this dialog is modal and this
@ -408,7 +409,7 @@ avoid_being_obscured_as_second_modal_dialog (MetaWindow *window,
/* denied_focus_and_not_transient is only set when focus_window != NULL */ /* denied_focus_and_not_transient is only set when focus_window != NULL */
if (window->denied_focus_and_not_transient && if (flags & META_PLACE_FLAG_DENIED_FOCUS_AND_NOT_TRANSIENT &&
window->type == META_WINDOW_MODAL_DIALOG && window->type == META_WINDOW_MODAL_DIALOG &&
#ifdef HAVE_X11_CLIENT #ifdef HAVE_X11_CLIENT
meta_window_x11_same_application (window, focus_window) && meta_window_x11_same_application (window, focus_window) &&
@ -762,6 +763,7 @@ find_windows_relevant_for_placement (MetaWindow *window)
void void
meta_window_place (MetaWindow *window, meta_window_place (MetaWindow *window,
MetaPlaceFlag flags,
int x, int x,
int y, int y,
int *new_x, int *new_x,
@ -862,7 +864,7 @@ meta_window_place (MetaWindow *window,
{ {
meta_topic (META_DEBUG_PLACEMENT, meta_topic (META_DEBUG_PLACEMENT,
"Not placing window with PROGRAM_POSITION or USER_POSITION set"); "Not placing window with PROGRAM_POSITION or USER_POSITION set");
avoid_being_obscured_as_second_modal_dialog (window, &x, &y); avoid_being_obscured_as_second_modal_dialog (window, flags, &x, &y);
goto done; goto done;
} }
} }
@ -897,7 +899,7 @@ meta_window_place (MetaWindow *window,
"Centered window %s over transient parent", "Centered window %s over transient parent",
window->desc); window->desc);
avoid_being_obscured_as_second_modal_dialog (window, &x, &y); avoid_being_obscured_as_second_modal_dialog (window, flags, &x, &y);
goto done; goto done;
} }
@ -976,7 +978,7 @@ meta_window_place (MetaWindow *window,
* if at all possible. This is guaranteed to only be called if the * if at all possible. This is guaranteed to only be called if the
* focus_window is non-NULL, and we try to avoid that window. * focus_window is non-NULL, and we try to avoid that window.
*/ */
if (window->denied_focus_and_not_transient) if (flags & META_PLACE_FLAG_DENIED_FOCUS_AND_NOT_TRANSIENT)
{ {
MetaWindow *focus_window; MetaWindow *focus_window;
gboolean found_fit; gboolean found_fit;

View File

@ -28,8 +28,9 @@ void meta_window_process_placement (MetaWindow *window,
int *rel_x, int *rel_x,
int *rel_y); int *rel_y);
void meta_window_place (MetaWindow *window, void meta_window_place (MetaWindow *window,
int x, MetaPlaceFlag place_flags,
int y, int x,
int *new_x, int y,
int *new_y); int *new_x,
int *new_y);

View File

@ -72,6 +72,13 @@ typedef enum
META_MOVE_RESIZE_CONSTRAIN = 1 << 13, META_MOVE_RESIZE_CONSTRAIN = 1 << 13,
} MetaMoveResizeFlags; } MetaMoveResizeFlags;
typedef enum _MetaPlaceFlag
{
META_PLACE_FLAG_NONE = 0,
META_PLACE_FLAG_FORCE_MOVE = 1 << 0,
META_PLACE_FLAG_DENIED_FOCUS_AND_NOT_TRANSIENT = 1 << 1,
} MetaPlaceFlag;
typedef enum typedef enum
{ {
META_MOVE_RESIZE_RESULT_MOVED = 1 << 0, META_MOVE_RESIZE_RESULT_MOVED = 1 << 0,
@ -515,9 +522,6 @@ struct _MetaWindow
/* Have we placed this window? */ /* Have we placed this window? */
guint placed : 1; guint placed : 1;
/* Is this not a transient of the focus window which is being denied focus? */
guint denied_focus_and_not_transient : 1;
/* Has this window not ever been shown yet? */ /* Has this window not ever been shown yet? */
guint showing_for_first_time : 1; guint showing_for_first_time : 1;
@ -801,6 +805,7 @@ void meta_window_set_urgent (MetaWindow *window,
void meta_window_move_resize_internal (MetaWindow *window, void meta_window_move_resize_internal (MetaWindow *window,
MetaMoveResizeFlags flags, MetaMoveResizeFlags flags,
MetaPlaceFlag place_flags,
MetaGravity gravity, MetaGravity gravity,
MtkRectangle frame_rect); MtkRectangle frame_rect);
@ -818,8 +823,8 @@ void meta_window_emit_size_changed (MetaWindow *window);
MetaPlacementRule *meta_window_get_placement_rule (MetaWindow *window); MetaPlacementRule *meta_window_get_placement_rule (MetaWindow *window);
void meta_window_force_placement (MetaWindow *window, void meta_window_force_placement (MetaWindow *window,
gboolean force_move); MetaPlaceFlag flags);
void meta_window_force_restore_shortcuts (MetaWindow *window, void meta_window_force_restore_shortcuts (MetaWindow *window,
ClutterInputDevice *source); ClutterInputDevice *source);

View File

@ -1065,7 +1065,6 @@ meta_window_constructed (GObject *object)
/* if already mapped we don't want to do the placement thing; /* if already mapped we don't want to do the placement thing;
* override-redirect windows are placed by the app */ * override-redirect windows are placed by the app */
window->placed = ((window->mapped && !window->hidden) || window->override_redirect); window->placed = ((window->mapped && !window->hidden) || window->override_redirect);
window->denied_focus_and_not_transient = FALSE;
window->unmanaging = FALSE; window->unmanaging = FALSE;
window->withdrawn = FALSE; window->withdrawn = FALSE;
window->initial_workspace_set = FALSE; window->initial_workspace_set = FALSE;
@ -2069,8 +2068,8 @@ window_would_be_covered_by_always_above_window (MetaWindow *window)
} }
void void
meta_window_force_placement (MetaWindow *window, meta_window_force_placement (MetaWindow *window,
gboolean force_move) MetaPlaceFlag place_flags)
{ {
MetaMoveResizeFlags flags; MetaMoveResizeFlags flags;
@ -2090,11 +2089,12 @@ meta_window_force_placement (MetaWindow *window,
flags = (META_MOVE_RESIZE_MOVE_ACTION | flags = (META_MOVE_RESIZE_MOVE_ACTION |
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_CONSTRAIN); META_MOVE_RESIZE_CONSTRAIN);
if (force_move) if (place_flags & META_PLACE_FLAG_FORCE_MOVE)
flags |= META_MOVE_RESIZE_FORCE_MOVE; flags |= META_MOVE_RESIZE_FORCE_MOVE;
meta_window_move_resize_internal (window, meta_window_move_resize_internal (window,
flags, flags,
place_flags,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
window->calc_placement = FALSE; window->calc_placement = FALSE;
@ -2104,11 +2104,6 @@ meta_window_force_placement (MetaWindow *window,
* still get placed when they are ultimately shown. * still get placed when they are ultimately shown.
*/ */
window->placed = TRUE; window->placed = TRUE;
/* Don't want to accidentally reuse the fact that we had been denied
* focus in any future constraints unless we're denied focus again.
*/
window->denied_focus_and_not_transient = FALSE;
} }
static gboolean static gboolean
@ -2225,7 +2220,7 @@ implement_showing (MetaWindow *window,
* see #751887 * see #751887
*/ */
if (!window->placed && window_has_buffer (window)) if (!window->placed && window_has_buffer (window))
meta_window_force_placement (window, FALSE); meta_window_force_placement (window, META_PLACE_FLAG_NONE);
meta_window_hide (window); meta_window_hide (window);
@ -2258,6 +2253,7 @@ meta_window_show (MetaWindow *window)
gboolean needs_stacking_adjustment; gboolean needs_stacking_adjustment;
MetaWindow *focus_window; MetaWindow *focus_window;
gboolean notify_demands_attention = FALSE; gboolean notify_demands_attention = FALSE;
MetaPlaceFlag place_flags = META_PLACE_FLAG_NONE;
meta_topic (META_DEBUG_WINDOW_STATE, meta_topic (META_DEBUG_WINDOW_STATE,
"Showing window %s, iconic: %d placed: %d", "Showing window %s, iconic: %d placed: %d",
@ -2294,7 +2290,7 @@ meta_window_show (MetaWindow *window)
{ {
needs_stacking_adjustment = TRUE; needs_stacking_adjustment = TRUE;
if (!window->placed) if (!window->placed)
window->denied_focus_and_not_transient = TRUE; place_flags |= META_PLACE_FLAG_DENIED_FOCUS_AND_NOT_TRANSIENT;
} }
} }
@ -2314,7 +2310,7 @@ meta_window_show (MetaWindow *window)
window->maximize_vertically_after_placement = TRUE; window->maximize_vertically_after_placement = TRUE;
} }
} }
meta_window_force_placement (window, FALSE); meta_window_force_placement (window, place_flags);
} }
if (needs_stacking_adjustment) if (needs_stacking_adjustment)
@ -2779,6 +2775,7 @@ meta_window_maximize (MetaWindow *window,
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_STATE_CHANGED | META_MOVE_RESIZE_STATE_CHANGED |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
} }
@ -3064,6 +3061,7 @@ meta_window_tile (MetaWindow *window,
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_STATE_CHANGED | META_MOVE_RESIZE_STATE_CHANGED |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
} }
@ -3276,6 +3274,7 @@ meta_window_unmaximize (MetaWindow *window,
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_STATE_CHANGED | META_MOVE_RESIZE_STATE_CHANGED |
META_MOVE_RESIZE_UNMAXIMIZE), META_MOVE_RESIZE_UNMAXIMIZE),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
target_rect); target_rect);
@ -3374,6 +3373,7 @@ meta_window_make_fullscreen (MetaWindow *window)
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_STATE_CHANGED | META_MOVE_RESIZE_STATE_CHANGED |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
} }
@ -3422,6 +3422,7 @@ meta_window_unmake_fullscreen (MetaWindow *window)
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_STATE_CHANGED | META_MOVE_RESIZE_STATE_CHANGED |
META_MOVE_RESIZE_UNFULLSCREEN), META_MOVE_RESIZE_UNFULLSCREEN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
target_rect); target_rect);
@ -3628,6 +3629,7 @@ meta_window_reposition (MetaWindow *window)
(META_MOVE_RESIZE_MOVE_ACTION | (META_MOVE_RESIZE_MOVE_ACTION |
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->rect); window->rect);
} }
@ -3839,6 +3841,7 @@ meta_window_update_monitor (MetaWindow *window,
void void
meta_window_move_resize_internal (MetaWindow *window, meta_window_move_resize_internal (MetaWindow *window,
MetaMoveResizeFlags flags, MetaMoveResizeFlags flags,
MetaPlaceFlag place_flags,
MetaGravity gravity, MetaGravity gravity,
MtkRectangle frame_rect) MtkRectangle frame_rect)
{ {
@ -3930,6 +3933,7 @@ meta_window_move_resize_internal (MetaWindow *window,
meta_window_constrain (window, meta_window_constrain (window,
flags, flags,
place_flags,
gravity, gravity,
&old_rect, &old_rect,
&constrained_rect, &constrained_rect,
@ -4063,7 +4067,11 @@ meta_window_move_frame (MetaWindow *window,
flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) |
META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_MOVE_ACTION |
META_MOVE_RESIZE_CONSTRAIN); META_MOVE_RESIZE_CONSTRAIN);
meta_window_move_resize_internal (window, flags, META_GRAVITY_NORTH_WEST, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST,
rect);
} }
static void static void
@ -4123,6 +4131,7 @@ meta_window_move_between_rects (MetaWindow *window,
META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_MOVE_ACTION |
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
} }
@ -4157,7 +4166,11 @@ meta_window_move_resize_frame (MetaWindow *window,
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_CONSTRAIN); META_MOVE_RESIZE_CONSTRAIN);
meta_window_move_resize_internal (window, flags, META_GRAVITY_NORTH_WEST, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST,
rect);
} }
/** /**
@ -4276,7 +4289,11 @@ meta_window_resize_frame_with_gravity (MetaWindow *window,
flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) | flags = ((user_op ? META_MOVE_RESIZE_USER_ACTION : 0) |
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_CONSTRAIN); META_MOVE_RESIZE_CONSTRAIN);
meta_window_move_resize_internal (window, flags, gravity, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
gravity,
rect);
} }
void void

View File

@ -471,7 +471,7 @@ xdg_toplevel_set_maximized (struct wl_client *client,
if (!window) if (!window)
return; return;
meta_window_force_placement (window, TRUE); meta_window_force_placement (window, META_PLACE_FLAG_FORCE_MOVE);
meta_window_maximize (window, META_MAXIMIZE_BOTH); meta_window_maximize (window, META_MAXIMIZE_BOTH);
} }

View File

@ -1266,7 +1266,11 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
gravity = meta_resize_gravity_from_grab_op (meta_window_drag_get_grab_op (window_drag)); gravity = meta_resize_gravity_from_grab_op (meta_window_drag_get_grab_op (window_drag));
else else
gravity = META_GRAVITY_STATIC; gravity = META_GRAVITY_STATIC;
meta_window_move_resize_internal (window, flags, gravity, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
gravity,
rect);
} }
void void
@ -1292,6 +1296,7 @@ meta_window_place_with_placement_rule (MetaWindow *window,
META_MOVE_RESIZE_RESIZE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION |
META_MOVE_RESIZE_PLACEMENT_CHANGED | META_MOVE_RESIZE_PLACEMENT_CHANGED |
META_MOVE_RESIZE_CONSTRAIN), META_MOVE_RESIZE_CONSTRAIN),
META_PLACE_FLAG_NONE,
META_GRAVITY_NORTH_WEST, META_GRAVITY_NORTH_WEST,
window->unconstrained_rect); window->unconstrained_rect);
window->calc_placement = FALSE; window->calc_placement = FALSE;

View File

@ -544,7 +544,11 @@ meta_window_apply_session_info (MetaWindow *window,
adjust_for_gravity (window, FALSE, gravity, &rect); adjust_for_gravity (window, FALSE, gravity, &rect);
meta_window_client_rect_to_frame_rect (window, &rect, &rect); meta_window_client_rect_to_frame_rect (window, &rect, &rect);
meta_window_move_resize_internal (window, flags, gravity, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
gravity,
rect);
} }
} }
@ -624,7 +628,11 @@ meta_window_x11_initialize_state (MetaWindow *window)
adjust_for_gravity (window, TRUE, gravity, &rect); adjust_for_gravity (window, TRUE, gravity, &rect);
meta_window_client_rect_to_frame_rect (window, &rect, &rect); meta_window_client_rect_to_frame_rect (window, &rect, &rect);
meta_window_move_resize_internal (window, flags, gravity, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
gravity,
rect);
} }
meta_window_x11_update_shape_region (window); meta_window_x11_update_shape_region (window);
@ -2911,7 +2919,11 @@ meta_window_move_resize_request (MetaWindow *window,
adjust_for_gravity (window, TRUE, gravity, &rect); adjust_for_gravity (window, TRUE, gravity, &rect);
meta_window_client_rect_to_frame_rect (window, &rect, &rect); meta_window_client_rect_to_frame_rect (window, &rect, &rect);
meta_window_move_resize_internal (window, flags, gravity, rect); meta_window_move_resize_internal (window,
flags,
META_PLACE_FLAG_NONE,
gravity,
rect);
} }
} }