window: Use the MetaWindowConfig

This is a fairly large refactoring to replace the window rect and
fullscreen flag with the new MetaWindowConfig object.

No functional change intended at this point.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4076>
This commit is contained in:
Olivier Fourdan
2024-10-21 11:11:32 +02:00
parent a7ef0b137e
commit 4c20584b11
15 changed files with 181 additions and 127 deletions

View File

@ -34,6 +34,7 @@ meta_wayland_window_configuration_new (MetaWindow *window,
{
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
MetaWaylandWindowConfiguration *configuration;
int x, y;
configuration = g_new0 (MetaWaylandWindowConfiguration, 1);
*configuration = (MetaWaylandWindowConfiguration) {
@ -50,9 +51,10 @@ meta_wayland_window_configuration_new (MetaWindow *window,
.is_suspended = meta_window_is_suspended (window),
};
meta_window_config_get_position (window->config, &x, &y);
if (flags & META_MOVE_RESIZE_MOVE_ACTION ||
window->rect.x != rect.x ||
window->rect.y != rect.y)
x != rect.x ||
y != rect.y)
{
configuration->has_position = TRUE;
configuration->x = rect.x;

View File

@ -320,10 +320,12 @@ meta_wayland_xdg_session_state_save_window (MetaSessionState *state,
MetaWaylandXdgSessionState *xdg_session_state =
META_WAYLAND_XDG_SESSION_STATE (state);
MetaWaylandXdgToplevelState *toplevel_state;
MtkRectangle rect;
toplevel_state =
meta_wayland_xdg_session_state_ensure_toplevel (xdg_session_state,
name);
rect = meta_window_config_get_rect (window->config);
g_object_get (window,
"minimized", &toplevel_state->is_minimized,
@ -334,7 +336,7 @@ meta_wayland_xdg_session_state_save_window (MetaSessionState *state,
{
toplevel_state->window_state = WINDOW_STATE_MAXIMIZED;
toplevel_state->tiled.rect = window->rect;
toplevel_state->tiled.rect = rect;
}
else if (window->tile_mode == META_TILE_LEFT ||
window->tile_mode == META_TILE_RIGHT)
@ -344,13 +346,13 @@ meta_wayland_xdg_session_state_save_window (MetaSessionState *state,
else if (window->tile_mode == META_TILE_RIGHT)
toplevel_state->window_state = WINDOW_STATE_TILED_RIGHT;
toplevel_state->tiled.rect = window->rect;
toplevel_state->tiled.rect = rect;
}
else
{
toplevel_state->window_state = WINDOW_STATE_FLOATING;
toplevel_state->floating.rect = window->rect;
toplevel_state->floating.rect = rect;
}
toplevel_state->workspace_idx = meta_workspace_index (window->workspace);

View File

@ -878,8 +878,10 @@ meta_wayland_xdg_toplevel_apply_state (MetaWaylandSurfaceRole *surface_role,
{
MetaWaylandWindowConfiguration *configuration;
int bounds_width, bounds_height, geometry_scale;
MtkRectangle rect;
geometry_scale = meta_window_wayland_get_geometry_scale (window);
rect = meta_window_config_get_rect (window->config);
if (!meta_window_calculate_bounds (window, &bounds_width, &bounds_height))
{
@ -891,7 +893,7 @@ meta_wayland_xdg_toplevel_apply_state (MetaWaylandSurfaceRole *surface_role,
{
configuration =
meta_wayland_window_configuration_new (window,
window->rect,
rect,
bounds_width,
bounds_height,
geometry_scale,

View File

@ -263,6 +263,7 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
gboolean can_move_now = FALSE;
MtkRectangle configured_rect;
MtkRectangle frame_rect;
int geometry_scale;
int new_x;
int new_y;
@ -281,6 +282,7 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
* coordinate space so that we can have a scale independent size to pass
* to the Wayland surface. */
geometry_scale = meta_window_wayland_get_geometry_scale (window);
frame_rect = meta_window_config_get_rect (window->config);
configured_rect.width = constrained_rect.width;
configured_rect.height = constrained_rect.height;
@ -314,20 +316,21 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
new_width = unconstrained_rect.width;
new_height = unconstrained_rect.height;
}
if (window->rect.width != new_width ||
window->rect.height != new_height)
if (frame_rect.width != new_width ||
frame_rect.height != new_height)
{
*result |= META_MOVE_RESIZE_RESULT_RESIZED;
window->rect.width = new_width;
window->rect.height = new_height;
meta_window_config_set_size (window->config,
new_width, new_height);
}
frame_rect = meta_window_config_get_rect (window->config);
window->buffer_rect.width =
window->rect.width +
frame_rect.width +
window->custom_frame_extents.left +
window->custom_frame_extents.right;
window->buffer_rect.height =
window->rect.height +
frame_rect.height +
window->custom_frame_extents.top +
window->custom_frame_extents.bottom;
@ -353,8 +356,8 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
if (flags & META_MOVE_RESIZE_PLACEMENT_CHANGED ||
rel_x != wl_window->last_sent_rel_x ||
rel_y != wl_window->last_sent_rel_y ||
constrained_rect.width != window->rect.width ||
constrained_rect.height != window->rect.height)
constrained_rect.width != frame_rect.width ||
constrained_rect.height != frame_rect.height)
{
MetaWaylandWindowConfiguration *configuration;
@ -388,8 +391,8 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
break;
}
}
else if (constrained_rect.width != window->rect.width ||
constrained_rect.height != window->rect.height ||
else if (constrained_rect.width != frame_rect.width ||
constrained_rect.height != frame_rect.height ||
flags & META_MOVE_RESIZE_STATE_CHANGED)
{
MetaWaylandWindowConfiguration *configuration;
@ -445,11 +448,10 @@ meta_window_wayland_move_resize_internal (MetaWindow *window,
!!(flags & META_MOVE_RESIZE_STATE_CHANGED);
}
if (new_x != window->rect.x || new_y != window->rect.y)
if (new_x != frame_rect.x || new_y != frame_rect.y)
{
*result |= META_MOVE_RESIZE_RESULT_MOVED;
window->rect.x = new_x;
window->rect.y = new_y;
meta_window_config_set_position (window->config, new_x, new_y);
}
if (window->placement.rule &&
@ -526,7 +528,7 @@ meta_window_wayland_update_main_monitor (MetaWindow *window,
MetaLogicalMonitor *scaled_new;
float from_scale, to_scale;
float scale;
MtkRectangle rect;
MtkRectangle frame_rect;
from = window->monitor;
@ -540,7 +542,8 @@ meta_window_wayland_update_main_monitor (MetaWindow *window,
return;
}
if (window->rect.width == 0 || window->rect.height == 0)
frame_rect = meta_window_config_get_rect (window->config);
if (frame_rect.width == 0 || frame_rect.height == 0)
{
window->monitor = meta_window_find_monitor_from_id (window);
return;
@ -587,10 +590,9 @@ meta_window_wayland_update_main_monitor (MetaWindow *window,
* changes the main monitor, wait until both the current and the new scale
* will result in the same main monitor. */
scale = to_scale / from_scale;
rect = window->rect;
scale_rect_size (&rect, scale);
scale_rect_size (&frame_rect, scale);
scaled_new =
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager, &rect);
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager, &frame_rect);
if (to != scaled_new)
return;
@ -606,6 +608,7 @@ meta_window_wayland_main_monitor_changed (MetaWindow *window,
int geometry_scale;
float scale_factor;
MetaWaylandSurface *surface;
MtkRectangle frame_rect;
if (!window->monitor)
return;
@ -629,7 +632,8 @@ meta_window_wayland_main_monitor_changed (MetaWindow *window,
scale_factor = (float) geometry_scale / old_geometry_scale;
/* Window size. */
scale_rect_size (&window->rect, scale_factor);
frame_rect = meta_window_config_get_rect (window->config);
scale_rect_size (&frame_rect, scale_factor);
scale_rect_size (&window->unconstrained_rect, scale_factor);
scale_rect_size (&window->saved_rect, scale_factor);
scale_size (&window->size_hints.min_width, &window->size_hints.min_height, scale_factor);
@ -649,9 +653,9 @@ meta_window_wayland_main_monitor_changed (MetaWindow *window,
/* Buffer rect. */
scale_rect_size (&window->buffer_rect, scale_factor);
window->buffer_rect.x =
window->rect.x - window->custom_frame_extents.left;
frame_rect.x - window->custom_frame_extents.left;
window->buffer_rect.y =
window->rect.y - window->custom_frame_extents.top;
frame_rect.y - window->custom_frame_extents.top;
meta_compositor_sync_window_geometry (window->display->compositor,
window,
@ -861,10 +865,6 @@ meta_window_wayland_constructed (GObject *object)
window->client_type = META_WINDOW_CLIENT_TYPE_WAYLAND;
window->override_redirect = FALSE;
window->rect.x = 0;
window->rect.y = 0;
window->rect.width = 0;
window->rect.height = 0;
/* size_hints are the "request" */
window->size_hints.x = 0;
window->size_hints.y = 0;
@ -878,6 +878,8 @@ meta_window_wayland_constructed (GObject *object)
window->decorated = FALSE;
window->hidden = TRUE;
window->config = meta_window_config_new ();
G_OBJECT_CLASS (meta_window_wayland_parent_class)->constructed (object);
}
@ -1105,9 +1107,7 @@ meta_window_wayland_is_resize (MetaWindowWayland *wl_window,
else
{
MetaWindow *window = META_WINDOW (wl_window);
old_width = window->rect.width;
old_height = window->rect.height;
meta_window_config_get_size (window->config, &old_width, &old_height);
}
return !wl_window->has_last_sent_configuration ||
@ -1178,6 +1178,7 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
gboolean is_window_being_resized;
gboolean is_client_resize;
MetaWindowDrag *window_drag;
MtkRectangle frame_rect;
/* new_geom is in the logical pixel coordinate space, but MetaWindow wants its
* rects to represent what in turn will end up on the stage, i.e. we need to
@ -1225,9 +1226,10 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
meta_grab_op_is_resizing (meta_window_drag_get_grab_op (window_drag)) &&
meta_window_drag_get_window (window_drag) == window);
frame_rect = meta_window_config_get_rect (window->config);
rect = (MtkRectangle) {
.x = window->rect.x,
.y = window->rect.y,
.x = frame_rect.x,
.y = frame_rect.y,
.width = new_geom.width,
.height = new_geom.height
};
@ -1239,10 +1241,12 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
if (window->placement.rule)
{
MetaWindow *parent;
MtkRectangle parent_rect;
parent = meta_window_get_transient_for (window);
rect.x = parent->rect.x + acked_configuration->rel_x;
rect.y = parent->rect.y + acked_configuration->rel_y;
parent_rect = meta_window_config_get_rect (parent->config);
rect.x = parent_rect.x + acked_configuration->rel_x;
rect.y = parent_rect.y + acked_configuration->rel_y;
}
else
{
@ -1262,7 +1266,7 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
rect.x += dx;
rect.y += dy;
if (rect.x != window->rect.x || rect.y != window->rect.y)
if (rect.x != frame_rect.x || rect.y != frame_rect.y)
flags |= META_MOVE_RESIZE_MOVE_ACTION;
if (wl_window->has_pending_state_change && acked_configuration)
@ -1271,7 +1275,7 @@ meta_window_wayland_finish_move_resize (MetaWindow *window,
wl_window->has_pending_state_change = FALSE;
}
if (rect.width != window->rect.width || rect.height != window->rect.height)
if (rect.width != frame_rect.width || rect.height != frame_rect.height)
{
flags |= META_MOVE_RESIZE_RESIZE_ACTION;
@ -1310,8 +1314,9 @@ meta_window_place_with_placement_rule (MetaWindow *window,
window->placement.rule = g_new0 (MetaPlacementRule, 1);
*window->placement.rule = *placement_rule;
window->unconstrained_rect.x = window->rect.x;
window->unconstrained_rect.y = window->rect.y;
meta_window_config_get_position (window->config,
&window->unconstrained_rect.x,
&window->unconstrained_rect.y);
window->unconstrained_rect.width = placement_rule->width;
window->unconstrained_rect.height = placement_rule->height;

View File

@ -804,6 +804,7 @@ repick_drop_surface (MetaWaylandCompositor *compositor,
Display *xdisplay = meta_x11_display_get_xdisplay (x11_display);
MetaWaylandSurface *focus = NULL;
MetaWindow *focus_window;
MtkRectangle frame_rect;
focus = pick_drop_surface (compositor, event);
if (dnd->focus_surface == focus)
@ -825,11 +826,12 @@ repick_drop_surface (MetaWaylandCompositor *compositor,
dnd_window = next_dnd_window (dnd);
XMapRaised (xdisplay, dnd_window);
frame_rect = meta_window_config_get_rect (focus_window->config);
XMoveResizeWindow (xdisplay, dnd_window,
focus_window->rect.x,
focus_window->rect.y,
focus_window->rect.width,
focus_window->rect.height);
frame_rect.x,
frame_rect.y,
frame_rect.width,
frame_rect.height);
}
else
{