From be6120752d2ff251a25851de1b7741f4be5dd69b Mon Sep 17 00:00:00 2001 From: Aleksey Samoilov Date: Tue, 12 Aug 2025 22:43:59 +0400 Subject: [PATCH] Fix Qt apps crash Avoid a crash by g_return_if_fail() and a return with the same condition Original Mutter's MR https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1559 --- src/wayland/meta-wayland-xdg-shell.c | 13 +++++++++++-- src/wayland/meta-window-wayland.c | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c index 67733fb8e..6abfee73b 100644 --- a/src/wayland/meta-wayland-xdg-shell.c +++ b/src/wayland/meta-wayland-xdg-shell.c @@ -89,6 +89,7 @@ typedef struct _MetaWaylandXdgSurfacePrivate struct wl_resource *resource; MetaWaylandXdgShellClient *shell_client; MetaRectangle geometry; + MetaRectangle unconstrained_geometry; guint configure_sent : 1; guint first_buffer_attached : 1; @@ -807,7 +808,7 @@ meta_wayland_xdg_toplevel_post_apply_state (MetaWaylandSurfaceRole *surface_rol META_WAYLAND_SURFACE_ROLE_CLASS (meta_wayland_xdg_toplevel_parent_class); surface_role_class->post_apply_state (surface_role, pending); - if (!pending->newly_attached) + if (!surface->buffer_ref.buffer) return; window_geometry = meta_wayland_xdg_surface_get_window_geometry (xdg_surface); @@ -1533,6 +1534,7 @@ meta_wayland_xdg_surface_real_reset (MetaWaylandXdgSurface *xdg_surface) priv->first_buffer_attached = FALSE; priv->configure_sent = FALSE; priv->geometry = (MetaRectangle) { 0 }; + priv->unconstrained_geometry = (MetaRectangle) { 0 }; priv->has_set_geometry = FALSE; } @@ -1575,12 +1577,19 @@ meta_wayland_xdg_surface_post_apply_state (MetaWaylandSurfaceRole *surface_role if (pending->has_new_geometry) { + priv->unconstrained_geometry = pending->new_geometry; meta_wayland_shell_surface_determine_geometry (shell_surface, &pending->new_geometry, &priv->geometry); priv->has_set_geometry = TRUE; } - else if (!priv->has_set_geometry) + else if (priv->has_set_geometry) + { + meta_wayland_shell_surface_determine_geometry (shell_surface, + &priv->unconstrained_geometry, + &priv->geometry); + } + else { MetaRectangle new_geometry = { 0 }; diff --git a/src/wayland/meta-window-wayland.c b/src/wayland/meta-window-wayland.c index ed030b937..61a71bda5 100644 --- a/src/wayland/meta-window-wayland.c +++ b/src/wayland/meta-window-wayland.c @@ -53,6 +53,7 @@ struct _MetaWindowWayland GList *pending_configurations; gboolean has_pending_state_change; + gboolean has_last_sent_configuration; int last_sent_x; int last_sent_y; int last_sent_width; @@ -188,6 +189,10 @@ surface_state_changed (MetaWindow *window) if (window->unmanaging) return; + g_return_if_fail (wl_window->has_last_sent_configuration); + if (!wl_window->has_last_sent_configuration) + return; + configuration = meta_wayland_window_configuration_new (wl_window->last_sent_x, wl_window->last_sent_y, @@ -401,6 +406,7 @@ meta_window_wayland_move_resize_internal (MetaWindow *window, } } + wl_window->has_last_sent_configuration = TRUE; wl_window->last_sent_x = configured_x; wl_window->last_sent_y = configured_y; wl_window->last_sent_width = configured_width; @@ -1000,7 +1006,14 @@ meta_window_wayland_finish_move_resize (MetaWindow *window, else { if (acked_configuration) - calculate_offset (acked_configuration, &new_geom, &rect); + { + calculate_offset (acked_configuration, &new_geom, &rect); + } + else + { + rect.x = window->rect.x; + rect.y = window->rect.y; + } } if (rect.x != window->rect.x || rect.y != window->rect.y)